Example #1
0
 private void addCreatedBy(Manifest m) {
   Attributes global = m.getMainAttributes();
   if (global.getValue(new Attributes.Name("Created-By")) == null) {
     String javaVendor = System.getProperty("java.vendor");
     String jdkVersion = System.getProperty("java.version");
     global.put(new Attributes.Name("Created-By"), jdkVersion + " (" + javaVendor + ")");
   }
 }
Example #2
0
 private boolean isAmbiguousMainClass(Manifest m) {
   if (ename != null) {
     Attributes global = m.getMainAttributes();
     if ((global.get(Attributes.Name.MAIN_CLASS) != null)) {
       error(getMsg("error.bad.eflag"));
       usageError();
       return true;
     }
   }
   return false;
 }
Example #3
0
 private static Hashtable<String, String> getManifestAttributes(Manifest manifest) {
   Hashtable<String, String> h = new Hashtable<String, String>();
   try {
     Attributes attrs = manifest.getMainAttributes();
     Iterator it = attrs.keySet().iterator();
     while (it.hasNext()) {
       String key = it.next().toString();
       h.put(key, attrs.getValue(key));
     }
   } catch (Exception ignore) {
   }
   return h;
 }
Example #4
0
  private boolean addProfileName(Manifest m, String profile) {
    // check profile name
    boolean found = false;
    int i = 0;
    while (i < PROFILES.length) {
      if (profile.equals(PROFILES[i])) {
        found = true;
        break;
      }
      i++;
    }
    if (!found) {
      error(formatMsg("error.bad.pvalue", profile));
      return false;
    }

    // overrides any existing Profile attribute
    Attributes global = m.getMainAttributes();
    global.put(Attributes.Name.PROFILE, profile);
    return true;
  }
Example #5
0
  /** Generates the transitive closure of the Class-Path attribute for the specified jar file. */
  List<String> getJarPath(String jar) throws IOException {
    List<String> files = new ArrayList<String>();
    files.add(jar);
    jarPaths.add(jar);

    // take out the current path
    String path = jar.substring(0, Math.max(0, jar.lastIndexOf('/') + 1));

    // class path attribute will give us jar file name with
    // '/' as separators, so we need to change them to the
    // appropriate one before we open the jar file.
    JarFile rf = new JarFile(jar.replace('/', File.separatorChar));

    if (rf != null) {
      Manifest man = rf.getManifest();
      if (man != null) {
        Attributes attr = man.getMainAttributes();
        if (attr != null) {
          String value = attr.getValue(Attributes.Name.CLASS_PATH);
          if (value != null) {
            StringTokenizer st = new StringTokenizer(value);
            while (st.hasMoreTokens()) {
              String ajar = st.nextToken();
              if (!ajar.endsWith("/")) { // it is a jar file
                ajar = path.concat(ajar);
                /* check on cyclic dependency */
                if (!jarPaths.contains(ajar)) {
                  files.addAll(getJarPath(ajar));
                }
              }
            }
          }
        }
      }
    }
    rf.close();
    return files;
  }
 protected void definePackage(
     final File container, final String packageName, final Manifest manifest) {
   final String sectionName = packageName.replace('.', '/') + "/";
   String specificationTitle = null;
   String specificationVendor = null;
   String specificationVersion = null;
   String implementationTitle = null;
   String implementationVendor = null;
   String implementationVersion = null;
   String sealedString = null;
   URL sealBase = null;
   final Attributes sectionAttributes = manifest.getAttributes(sectionName);
   if (sectionAttributes != null) {
     specificationTitle = sectionAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE);
     specificationVendor = sectionAttributes.getValue(Attributes.Name.SPECIFICATION_VENDOR);
     specificationVersion = sectionAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
     implementationTitle = sectionAttributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
     implementationVendor = sectionAttributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
     implementationVersion = sectionAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
     sealedString = sectionAttributes.getValue(Attributes.Name.SEALED);
   }
   final Attributes mainAttributes = manifest.getMainAttributes();
   if (mainAttributes != null) {
     if (specificationTitle == null) {
       specificationTitle = mainAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE);
     }
     if (specificationVendor == null) {
       specificationVendor = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VENDOR);
     }
     if (specificationVersion == null) {
       specificationVersion = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
     }
     if (implementationTitle == null) {
       implementationTitle = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
     }
     if (implementationVendor == null) {
       implementationVendor = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
     }
     if (implementationVersion == null) {
       implementationVersion = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
     }
     if (sealedString == null) {
       sealedString = mainAttributes.getValue(Attributes.Name.SEALED);
     }
   }
   if (sealedString != null && sealedString.equalsIgnoreCase("true")) {
     try {
       sealBase = new URL(FileUtils.getFileUtils().toURI(container.getAbsolutePath()));
     } catch (MalformedURLException ex) {
     }
   }
   this.definePackage(
       packageName,
       specificationTitle,
       specificationVersion,
       specificationVendor,
       implementationTitle,
       implementationVersion,
       implementationVendor,
       sealBase);
 }
Example #7
0
  private void addMainClass(Manifest m, String mainApp) {
    Attributes global = m.getMainAttributes();

    // overrides any existing Main-Class attribute
    global.put(Attributes.Name.MAIN_CLASS, mainApp);
  }
Example #8
0
 private void addVersion(Manifest m) {
   Attributes global = m.getMainAttributes();
   if (global.getValue(Attributes.Name.MANIFEST_VERSION) == null) {
     global.put(Attributes.Name.MANIFEST_VERSION, VERSION);
   }
 }