Java 类java.util.jar.Attributes 实例源码

项目:picocli    文件:Demo.java   
public String[] getVersion() throws Exception {
    Enumeration<URL> resources = CommandLine.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
    while (resources.hasMoreElements()) {
        URL url = resources.nextElement();
        try {
            Manifest manifest = new Manifest(url.openStream());
            if (isApplicableManifest(manifest)) {
                Attributes attributes = manifest.getMainAttributes();
                return new String[] { attributes.get(key("Implementation-Title")) + " version \"" + attributes.get(key("Implementation-Version")) + "\"" };
            }
        } catch (IOException ex) {
            return new String[] { "Unable to read from " + url + ": " + ex };
        }
    }
    return new String[0];
}
项目:cf-mta-deploy-service    文件:MtaArchiveHelper.java   
private Map<String, String> getEntriesWithAttribute(String attributeName) throws ContentException {
    Map<String, String> result = new HashMap<>();
    for (Map.Entry<String, Attributes> entry : manifest.getEntries().entrySet()) {
        String attributeValue = entry.getValue().getValue(attributeName);
        if (attributeValue == null) {
            continue;
        }
        String fileName = entry.getKey();
        MtaPathValidator.validatePath(fileName);
        if (attributeName.equals(ATTR_MTA_MODULE)) {
            Arrays.asList(attributeValue.split(Constants.MODULE_SEPARATOR)).forEach(module -> result.put(module.trim(), fileName));
        } else {
            result.put(attributeValue, fileName);
        }
    }
    return result;
}
项目:FApkSigner    文件:ManifestWriter.java   
public static void writeMainSection(OutputStream out, Attributes attributes)
        throws IOException {

    // Main section must start with the Manifest-Version attribute.
    // See https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Signed_JAR_File.
    String manifestVersion = attributes.getValue(Attributes.Name.MANIFEST_VERSION);
    if (manifestVersion == null) {
        throw new IllegalArgumentException(
                "Mandatory " + Attributes.Name.MANIFEST_VERSION + " attribute missing");
    }
    writeAttribute(out, Attributes.Name.MANIFEST_VERSION, manifestVersion);

    if (attributes.size() > 1) {
        SortedMap<String, String> namedAttributes = getAttributesSortedByName(attributes);
        namedAttributes.remove(Attributes.Name.MANIFEST_VERSION.toString());
        writeAttributes(out, namedAttributes);
    }
    writeSectionDelimiter(out);
}
项目:lazycat    文件:WebappClassLoaderBase.java   
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);

}
项目:FApkSigner    文件:SignatureFileWriter.java   
public static void writeMainSection(OutputStream out, Attributes attributes)
        throws IOException {

    // Main section must start with the Signature-Version attribute.
    // See https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Signed_JAR_File.
    String signatureVersion = attributes.getValue(Attributes.Name.SIGNATURE_VERSION);
    if (signatureVersion == null) {
        throw new IllegalArgumentException(
                "Mandatory " + Attributes.Name.SIGNATURE_VERSION + " attribute missing");
    }
    ManifestWriter.writeAttribute(out, Attributes.Name.SIGNATURE_VERSION, signatureVersion);

    if (attributes.size() > 1) {
        SortedMap<String, String> namedAttributes =
                ManifestWriter.getAttributesSortedByName(attributes);
        namedAttributes.remove(Attributes.Name.SIGNATURE_VERSION.toString());
        ManifestWriter.writeAttributes(out, namedAttributes);
    }
    writeSectionDelimiter(out);
}
项目:imagingbook-common    文件:Info.java   
/**
 * Reads version information from the MANIFEST.MF file of the JAR file from
 * which this class was loaded. 
 * 
 * @return A string with the version information. 
 * The string "UNKNOWN" is returned if the class was not loaded from a JAR file or if 
 * the version information could not be determined.
 */
public static String getVersionInfo() {
    Manifest mf = FileUtils.getJarManifest(Info.class);
    if (mf == null) {
        return "UNKNOWN";
    }
    //IJ.log("listing attributes");
    Attributes attr = mf.getMainAttributes();
    String version = null;
    String buildDate = null;
    try {
        version = attr.getValue("Implementation-Version");
        buildDate = attr.getValue("Build-Date");
    } catch (IllegalArgumentException e) { }
    return version + " (" + buildDate + ")";
}
项目:openjdk-jdk10    文件:AutomaticModulesTest.java   
/**
 * Test that a JAR file with a Main-Class attribute results
 * in a module with a main class.
 */
public void testMainClass() throws IOException {
    String mainClass = "p.Main";

    Manifest man = new Manifest();
    Attributes attrs = man.getMainAttributes();
    attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
    attrs.put(Attributes.Name.MAIN_CLASS, mainClass);

    Path dir = Files.createTempDirectory(USER_DIR, "mods");
    String entry = mainClass.replace('.', '/') + ".class";
    createDummyJarFile(dir.resolve("m.jar"), man, entry);

    ModuleFinder finder = ModuleFinder.of(dir);

    Configuration parent = ModuleLayer.boot().configuration();
    Configuration cf = resolve(parent, finder, "m");

    ModuleDescriptor descriptor = findDescriptor(cf, "m");

    assertTrue(descriptor.mainClass().isPresent());
    assertEquals(descriptor.mainClass().get(), mainClass);
}
项目:javaide    文件:URLClassPath.java   
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();
    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        Manifest man = jar.getManifest();
        if (man != null) {
            Attributes attr = man.getMainAttributes();
            if (attr != null) {
                String value = attr.getValue(Name.CLASS_PATH);
                if (value != null) {
                    return parseClassPath(csu, value);
                }
            }
        }
    }
    return null;
}
项目:openjdk-jdk10    文件:IllegalAccessTest.java   
/**
 * Specify Add-Exports in JAR file manifest
 */
public void testWithAddExportsInManifest() throws Exception {
    Manifest man = new Manifest();
    Attributes attrs = man.getMainAttributes();
    attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    attrs.put(Attributes.Name.MAIN_CLASS, "TryAccess");
    attrs.put(new Attributes.Name("Add-Exports"), "java.base/sun.security.x509");
    Path jarfile = Paths.get("x.jar");
    Path classes = Paths.get(TEST_CLASSES);
    JarUtils.createJarFile(jarfile, man, classes, Paths.get("TryAccess.class"));

    run(jarfile, "reflectPublicMemberNonExportedPackage", successNoWarning());

    run(jarfile, "setAccessibleNonPublicMemberExportedPackage", successWithWarning());

    // attempt two illegal accesses, one allowed by Add-Exports
    run(jarfile, "reflectPublicMemberNonExportedPackage,"
            + "setAccessibleNonPublicMemberExportedPackage",
        successWithWarning());
}
项目:jdk8u-jdk    文件:URLClassPath.java   
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        Manifest man = jar.getManifest();
        if (man != null) {
            Attributes attr = man.getMainAttributes();
            if (attr != null) {
                String value = attr.getValue(Name.CLASS_PATH);
                if (value != null) {
                    return parseClassPath(csu, value);
                }
            }
        }
    }
    return null;
}
项目:instalint    文件:PluginManifest.java   
private void loadManifest(Manifest manifest) {
  Attributes attributes = manifest.getMainAttributes();
  this.key = attributes.getValue(KEY_ATTRIBUTE);
  this.mainClass = attributes.getValue(MAIN_CLASS_ATTRIBUTE);
  this.name = attributes.getValue(NAME_ATTRIBUTE);
  this.version = attributes.getValue(VERSION_ATTRIBUTE);
  this.useChildFirstClassLoader = StringUtils.equalsIgnoreCase(attributes.getValue(USE_CHILD_FIRST_CLASSLOADER), "true");
  String slSupported = attributes.getValue(SONARLINT_SUPPORTED);
  this.sonarLintSupported = slSupported != null ? StringUtils.equalsIgnoreCase(slSupported, "true") : null;
  this.basePlugin = attributes.getValue(BASE_PLUGIN);
  this.implementationBuild = attributes.getValue(IMPLEMENTATION_BUILD);

  String deps = attributes.getValue(DEPENDENCIES_ATTRIBUTE);
  this.dependencies = StringUtils.split(StringUtils.defaultString(deps), ' ');

  String requires = attributes.getValue(REQUIRE_PLUGINS_ATTRIBUTE);
  this.requirePlugins = StringUtils.split(StringUtils.defaultString(requires), ',');
}
项目:ApkMultiChannelPlugin    文件:ManifestWriter.java   
public static void writeMainSection(OutputStream out, Attributes attributes)
        throws IOException {

    // Main section must start with the Manifest-Version attribute.
    // See https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Signed_JAR_File.
    String manifestVersion = attributes.getValue(Attributes.Name.MANIFEST_VERSION);
    if (manifestVersion == null) {
        throw new IllegalArgumentException(
                "Mandatory " + Attributes.Name.MANIFEST_VERSION + " attribute missing");
    }
    writeAttribute(out, Attributes.Name.MANIFEST_VERSION, manifestVersion);

    if (attributes.size() > 1) {
        SortedMap<String, String> namedAttributes = getAttributesSortedByName(attributes);
        namedAttributes.remove(Attributes.Name.MANIFEST_VERSION.toString());
        writeAttributes(out, namedAttributes);
    }
    writeSectionDelimiter(out);
}
项目:googles-monorepo-demo    文件:ClassPathTest.java   
private static void writeSelfReferencingJarFile(File jarFile, String... entries)
    throws IOException {
  Manifest manifest = new Manifest();
  // Without version, the manifest is silently ignored. Ugh!
  manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
  manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, jarFile.getName());

  Closer closer = Closer.create();
  try {
    FileOutputStream fileOut = closer.register(new FileOutputStream(jarFile));
    JarOutputStream jarOut = closer.register(new JarOutputStream(fileOut));
    for (String entry : entries) {
      jarOut.putNextEntry(new ZipEntry(entry));
      Resources.copy(ClassPathTest.class.getResource(entry), jarOut);
      jarOut.closeEntry();
    }
  } catch (Throwable e) {
    throw closer.rethrow(e);
  } finally {
    closer.close();
  }
}
项目:FJ-VDMJ    文件:VDMJC.java   
private static String getVersion()
{
    try
    {
        String path = VDMJC.class.getName().replaceAll("\\.", "/");
        URL url = VDMJC.class.getResource("/" + path + ".class");
        JarURLConnection conn = (JarURLConnection)url.openConnection();
        JarFile jar = conn.getJarFile();
        Manifest mf = jar.getManifest();
        String version = (String)mf.getMainAttributes().get(Attributes.Name.IMPLEMENTATION_VERSION);
        return version;
    }
    catch (Exception e)
    {
        return null;
    }
}
项目:jerrydog    文件:WebappClassLoader.java   
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name + "/";
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);

}
项目:atlas    文件:MergePatch.java   
@SuppressWarnings("deprecation")
@Override
protected Manifest getMeta() {
    Manifest retManifest = new Manifest();
    Attributes main = retManifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (ApkPatch)");
    main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
    main.putValue("Patch-Name", name);

    try {
        fillManifest(main);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    return retManifest;
}
项目:OpenJSharp    文件:URLClassPath.java   
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        Manifest man = jar.getManifest();
        if (man != null) {
            Attributes attr = man.getMainAttributes();
            if (attr != null) {
                String value = attr.getValue(Name.CLASS_PATH);
                if (value != null) {
                    return parseClassPath(csu, value);
                }
            }
        }
    }
    return null;
}
项目:incubator-netbeans    文件:RecognizeInstanceObjectsOnModuleEnablementTest.java   
@Override
protected void setUp() throws Exception {
    clearWorkDir();
    f = new File(getWorkDir(), "m.jar");

    Manifest man = new Manifest();
    Attributes attr = man.getMainAttributes();
    attr.putValue("OpenIDE-Module", "m.test");
    attr.putValue("OpenIDE-Module-Public-Packages", "-");
    attr.putValue("Manifest-Version", "1.0");
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f), man);
    os.putNextEntry(new JarEntry("META-INF/namedservices/ui/javax.swing.JComponent"));
    os.write("javax.swing.JButton\n".getBytes("UTF-8"));
    os.closeEntry();
    os.close();

    FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), "ui/ch/my/javax-swing-JPanel.instance");
}
项目:lams    文件:InsertToolContextClasspathTask.java   
/** Add the jar file to the classpath in the MANIFEST.MF file */
   @Override
   protected void updateClasspath(Manifest manifest) throws DeployException {
Attributes mainAttributes = manifest.getMainAttributes();
String classpath = null;
if (mainAttributes != null) {
    classpath = mainAttributes.getValue(Attributes.Name.CLASS_PATH);
}

String newJar = getJarFileNameWithDotSlash();
if (classpath == null) {
    mainAttributes.put(Attributes.Name.CLASS_PATH, newJar);
    System.out.println("Added " + newJar + " to classpath");
} else if (classpath.indexOf(newJar) < 0) {
    mainAttributes.put(Attributes.Name.CLASS_PATH, classpath + " " + newJar);
    System.out.println("Added " + newJar + " to classpath");
} else {
    System.out.println(newJar + " already on the classpath.");
}
   }
项目:lams    文件:WebappClassLoader.java   
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    Attributes attr = man.getAttributes(path); 
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);

}
项目:mobile-store    文件:ZipSigner.java   
/**
 * Copy all the files in a manifest from input to output.  We set
 * the modification times in the output to a fixed time, so as to
 * reduce variation in the output file and make incremental OTAs
 * more efficient.
 */
private void copyFiles(Manifest manifest, Map<String,ZioEntry> input, ZipOutput output, long timestamp)
    throws IOException 
{
    Map<String, Attributes> entries = manifest.getEntries();
    List<String> names = new ArrayList<String>(entries.keySet());
    Collections.sort(names);
    int i = 1;
    for (String name : names) {
        if (canceled) break;
        progressHelper.progress(ProgressEvent.PRORITY_NORMAL, resourceAdapter.getString(ResourceAdapter.Item.COPYING_ZIP_ENTRY, i, names.size()));
        i += 1;
        ZioEntry inEntry = input.get(name);
        inEntry.setTime(timestamp);
        output.write(inEntry);

    }
}
项目:atlas    文件:ApkPatch.java   
@SuppressWarnings("deprecation")
protected Manifest getMeta() {
    Manifest manifest = new Manifest();
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (ApkPatch)");
    main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
    main.putValue("From-File", baseFiles.get(0).getName());
    main.putValue("To-File", newFiles.get(0).getName());
    main.putValue("Patch-Name", name);
    main.putValue(name + "-Patch-Classes", Formater.dotStringList(classes));
    main.putValue(name + "-Prepare-Classes", Formater.dotStringList(prepareClasses));
    main.putValue(name + "-Used-Methods", Formater.dotStringList(usedMethods));
    main.putValue(name + "-Modified-Classes", Formater.dotStringList(modifiedClasses));
    main.putValue(name + "-Used-Classes", Formater.dotStringList(usedClasses));
    main.putValue(name + "-add-classes", Formater.dotStringList(addClasses));

    return manifest;
}
项目:jerrydog    文件:Extension.java   
/**
 * If the specified manifest attributes entry represents an available
 * optional package, construct and return an <code>Extension</code>
 * instance representing this package; otherwise return <code>null</code>.
 *
 * @param attributes Manifest attributes to be parsed
 */
private static Extension getAvailable(Attributes attributes) {

    String name = attributes.getValue("Extension-Name");
    if (name == null)
        return (null);
    Extension extension = new Extension();
    extension.setExtensionName(name);

    extension.setImplementationVendor
        (attributes.getValue("Implementation-Vendor"));
    extension.setImplementationVendorId
        (attributes.getValue("Implementation-Vendor-Id"));
    extension.setImplementationVersion
        (attributes.getValue("Implementation-Version"));
    extension.setSpecificationVendor
        (attributes.getValue("Specification-Vendor"));
    extension.setSpecificationVersion
        (attributes.getValue("Specification-Version"));

    return (extension);

}
项目:MultiDexSample    文件:MyApp.java   
/**
 * Get classes.dex file signature
 *
 * @param context
 * @return
 */
private String get2thDexSHA1(Context context) {
    ApplicationInfo ai = context.getApplicationInfo();
    String source = ai.sourceDir;
    try {
        JarFile jar = new JarFile(source);
        java.util.jar.Manifest mf = jar.getManifest();
        Map<String, Attributes> map = mf.getEntries();
        Attributes a = map.get("classes2.dex");
        if(a!=null){
            return a.getValue("SHA1-Digest");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:javaide    文件:SignedJarBuilder.java   
/**
 * Creates a {@link SignedJarBuilder} with a given output stream, and signing information.
 * <p/>If either <code>key</code> or <code>certificate</code> is <code>null</code> then
 * the archive will not be signed.
 * @param out the {@link OutputStream} where to write the Jar archive.
 * @param key the {@link PrivateKey} used to sign the archive, or <code>null</code>.
 * @param certificate the {@link X509Certificate} used to sign the archive, or
 * <code>null</code>.
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
public SignedJarBuilder(OutputStream out, PrivateKey key, X509Certificate certificate)
        throws IOException, NoSuchAlgorithmException {
    mOutputJar = new JarOutputStream(new BufferedOutputStream(out));
    mOutputJar.setLevel(9);
    mKey = key;
    mCertificate = certificate;

    if (mKey != null && mCertificate != null) {
        mManifest = new Manifest();
        Attributes main = mManifest.getMainAttributes();
        main.putValue("Manifest-Version", "1.0");
        main.putValue("Created-By", "1.0 (Android)");

        mBase64Encoder = new BASE64Encoder();
        mMessageDigest = MessageDigest.getInstance(DIGEST_ALGORITHM);
    }
}
项目:shabdiz    文件:Platforms.java   
private static File makePlatformDetectorJar() throws IOException {

        final Manifest manifest = new Manifest();
        manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, PLATFORM_DETECTOR_JAR_VERSION);
        manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, PlatformDetector.class.getName());
        manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, ".");
        final File platform_detector_jar = File.createTempFile("platform_detector", ".jar");
        final JarOutputStream target = new JarOutputStream(new FileOutputStream(platform_detector_jar), manifest);

        try {
            addClassToJar(PlatformDetector.class, target);
            return platform_detector_jar;
        }
        catch (final URISyntaxException e) {
            throw new IOException(e);
        }
        finally {
            target.close();
        }
    }
项目:lams    文件:RemoveToolContextClasspathTask.java   
/** Remove the jar file to the classpath in the MANIFEST.MF file */
   @Override
   protected void updateClasspath(Manifest manifest) throws DeployException {
Attributes mainAttributes = manifest.getMainAttributes();
String classpath = null;
if (mainAttributes != null) {
    classpath = mainAttributes.getValue(Attributes.Name.CLASS_PATH);
}

String newJar = getJarFileNameWithDotSlash();
String newClasspath = null;
if (classpath != null) {
    newClasspath = StringUtils.replace(classpath, newJar, "");
    mainAttributes.put(Attributes.Name.CLASS_PATH, newClasspath);
    if (classpath.length() < newClasspath.length()) {
    System.out.println("Removed " + newJar + " from classpath");
    }
}
   }
项目:tomcat7    文件:WebappClassLoaderBase.java   
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);

}
项目:ibm-cos-sdk-java    文件:JodaTime.java   
private static String getVersion() {
    try {
        JarFile jf = Classes.jarFileOf(DateTimeZone.class);
        if (jf == null)
            return null;
        Manifest mf = jf.getManifest();
        Attributes attrs = mf.getMainAttributes();
        String name = attrs.getValue("Bundle-Name");
        String version = attrs.getValue("Bundle-Version");
        if ("Joda-Time".equals(name) && version != null) {
            return version;
        }
    } catch (Exception e) {
        InternalLogFactory.getLog(JodaTime.class).debug("FYI", e);
    }
    return null;
}
项目:guava-mock    文件:ClassPathTest.java   
private static void writeSelfReferencingJarFile(File jarFile, String... entries)
    throws IOException {
  Manifest manifest = new Manifest();
  // Without version, the manifest is silently ignored. Ugh!
  manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
  manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, jarFile.getName());

  Closer closer = Closer.create();
  try {
    FileOutputStream fileOut = closer.register(new FileOutputStream(jarFile));
    JarOutputStream jarOut = closer.register(new JarOutputStream(fileOut));
    for (String entry : entries) {
      jarOut.putNextEntry(new ZipEntry(entry));
      Resources.copy(ClassPathTest.class.getResource(entry), jarOut);
      jarOut.closeEntry();
    }
  } catch (Throwable e) {
    throw closer.rethrow(e);
  } finally {
    closer.close();
  }
}
项目:dxram    文件:ManifestHelper.java   
/**
 * Get the value of a property within the manifest file.
 *
 * @param p_class
 *     Target class within the jar package.
 * @param p_key
 *     Key for the value to get.
 * @return If value is found it is returned as a string, null otherwise.
 */
public static String getProperty(final Class<?> p_class, final String p_key) {
    String value = null;
    try {
        Enumeration<URL> resources = p_class.getClassLoader().getResources("META-INF/MANIFEST.MF");
        while (resources.hasMoreElements()) {
            Manifest manifest = new Manifest(resources.nextElement().openStream());
            // check that this is your manifest and do what you need or get the next one

            Attributes attr = manifest.getMainAttributes();
            value = attr.getValue(p_key);

            if (value != null) {
                break;
            }
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return value;
}
项目:gemini.blueprint    文件:AbstractOnTheFlyBundleCreatorTests.java   
/**
 * Creates the default manifest in case none if found on the disk. By
 * default, the imports are synthetised based on the test class bytecode.
 * 
 * @return default manifest for the jar created on the fly
 */
protected Manifest createDefaultManifest() {
    Manifest manifest = new Manifest();
    Attributes attrs = manifest.getMainAttributes();

    // manifest versions
    attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    attrs.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");

    String description = getName() + "-" + getClass().getName();
    // name/description
    attrs.putValue(Constants.BUNDLE_NAME, "TestBundle-" + description);
    attrs.putValue(Constants.BUNDLE_SYMBOLICNAME, "TestBundle-" + description);
    attrs.putValue(Constants.BUNDLE_DESCRIPTION, "on-the-fly test bundle");

    // activator
    attrs.putValue(Constants.BUNDLE_ACTIVATOR, JUnitTestActivator.class.getName());

    // add Import-Package entry
    addImportPackage(manifest);

    if (logger.isDebugEnabled()) {
        logger.debug("Created manifest:" + manifest.getMainAttributes().entrySet());
       }
    return manifest;
}
项目:atlas    文件:TPatchTool.java   
/**
 * create manifest for patch file
 *
 * @return
 */
private Manifest createManifest() {
    Manifest manifest = new Manifest();
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (DexPatch)");
    main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
    return manifest;
}
项目:n4js    文件:JarRsrcLoader.java   
private static ManifestInfo getManifestInfo() throws IOException {
    Enumeration<?> resEnum;
    resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
    while (resEnum.hasMoreElements()) {
        try {
            URL url = (URL) resEnum.nextElement();
            InputStream is = url.openStream();
            if (is != null) {
                ManifestInfo result = new ManifestInfo();
                Manifest manifest = new Manifest(is);
                Attributes mainAttribs = manifest.getMainAttributes();
                result.rsrcMainClass = mainAttribs.getValue(JIJConstants.REDIRECTED_MAIN_CLASS_MANIFEST_NAME);
                String rsrcCP = mainAttribs.getValue(JIJConstants.REDIRECTED_CLASS_PATH_MANIFEST_NAME);
                if (rsrcCP == null)
                    rsrcCP = JIJConstants.DEFAULT_REDIRECTED_CLASSPATH;
                result.rsrcClassPath = splitSpaces(rsrcCP);
                if ((result.rsrcMainClass != null) && !result.rsrcMainClass.trim().equals("")) //$NON-NLS-1$
                    return result;
            }
        } catch (Exception e) {
            // Silently ignore wrong manifests on classpath?
        }
    }
    System.err.println(
            "Missing attributes for JarRsrcLoader in Manifest (" + JIJConstants.REDIRECTED_MAIN_CLASS_MANIFEST_NAME //$NON-NLS-1$
                    + ", " + JIJConstants.REDIRECTED_CLASS_PATH_MANIFEST_NAME + ")"); //$NON-NLS-1$ //$NON-NLS-2$
    return null;
}
项目:FApkSigner    文件:ManifestWriter.java   
public static void writeIndividualSection(OutputStream out, String name, Attributes attributes)
        throws IOException {
    writeAttribute(out, "Name", name);

    if (!attributes.isEmpty()) {
        writeAttributes(out, getAttributesSortedByName(attributes));
    }
    writeSectionDelimiter(out);
}
项目:cf-mta-deploy-service    文件:MtaArchiveBuilder.java   
private void prepareResourceEntries(DeploymentDescriptor deploymentDescriptor) throws SLException {
    for (Resource resource : deploymentDescriptor.getResources2_0()) {
        String resourceConfigPath = (String) resource.getParameters().get(SupportedParameters.SERVICE_CONFIG_PATH);
        if (resourceConfigPath != null) {
            prepareFile(resourceConfigPath);

            Attributes attributes = new Attributes();
            attributes.putValue(MtaArchiveHelper.ATTR_MTA_RESOURCE, resource.getName());
            manifestEntries.put(resourceConfigPath, attributes);
        }
    }
}
项目:incubator-netbeans    文件:JPAParseUtils.java   
@Override
public void startElement(String uri, String localName, String qName, org.xml.sax.Attributes attributes) throws SAXException {
    if ("persistence".equals(qName)) { //NOI18N
        String version = attributes.getValue("version"); //NOI18N
        throw new SAXException(ParseUtils.EXCEPTION_PREFIX+(version==null?Persistence.VERSION_2_1:version));
    }
}
项目:incubator-netbeans    文件:PackageAttrsCache.java   
private static String[] extractFromManifest(Manifest man, String path) {
    Attributes spec = man.getAttributes(path);
    Attributes main = man.getMainAttributes();
    String[] arr = new String[7];
    arr[0] = getAttr(spec, main, Attributes.Name.SPECIFICATION_TITLE);
    arr[1] = getAttr(spec, main, Attributes.Name.SPECIFICATION_VERSION);
    arr[2] = getAttr(spec, main, Attributes.Name.SPECIFICATION_VENDOR);
    arr[3] = getAttr(spec, main, Attributes.Name.IMPLEMENTATION_TITLE);
    arr[4] = getAttr(spec, main, Attributes.Name.IMPLEMENTATION_VERSION);
    arr[5] = getAttr(spec, main, Attributes.Name.IMPLEMENTATION_VENDOR);
    arr[6] = getAttr(spec, main, Attributes.Name.SEALED);
    return arr;
}
项目:incubator-netbeans    文件:ModuleData.java   
private String[] computeExported(boolean useOSGi, Collection<String> arr, Attributes attr) {
    if (!useOSGi) {
        return arr.toArray(ZERO_STRING_ARRAY);
    }
    String pkgs = attr.getValue("Export-Package"); // NOI18N
    if (pkgs == null) {
        return arr.toArray(ZERO_STRING_ARRAY);
    }
    StringTokenizer tok = createTokenizer(pkgs); // NOI18N
    while (tok.hasMoreElements()) {
        arr.add(beforeSemicolon(tok));
    }
    return arr.toArray(ZERO_STRING_ARRAY);
}
项目:incubator-netbeans    文件:ModuleData.java   
private String[] computeProvides(
    Module forModule, Attributes attr, boolean verifyCNBs, boolean useOSGi
) throws InvalidException, IllegalArgumentException {
    Set<String> arr = new LinkedHashSet<String>();
    // Token provides
    String providesS = attr.getValue("OpenIDE-Module-Provides"); // NOI18N
    if (providesS != null) {
        StringTokenizer tok = new StringTokenizer(providesS, ", "); // NOI18N
        int expCount = tok.countTokens();
        while (tok.hasMoreTokens()) {
            String provide = tok.nextToken();
            if (provide.indexOf(',') != -1) {
                throw new InvalidException("Illegal code name syntax parsing OpenIDE-Module-Provides: " + provide); // NOI18N
            }
            if (verifyCNBs) {
                Dependency.create(Dependency.TYPE_MODULE, provide);
            }
            if (provide.lastIndexOf('/') != -1) throw new IllegalArgumentException("Illegal OpenIDE-Module-Provides: " + provide); // NOI18N
            arr.add(provide);
        }
        if (arr.size() != expCount) {
            throw new IllegalArgumentException("Duplicate entries in OpenIDE-Module-Provides: " + providesS); // NOI18N
        }
    }
    String[] additionalProvides = forModule.getManager().refineProvides (forModule);
    if (additionalProvides != null) {
        arr.addAll (Arrays.asList (additionalProvides));
    }
    arr.add("cnb." + getCodeNameBase()); // NOI18N
    return computeExported(useOSGi, arr, attr);
}