List of usage examples for java.util.jar Attributes containsKey
public boolean containsKey(Object name)
From source file:org.lockss.plugin.PluginManager.java
/** * Given a file representing a JAR, retrieve a list of available * plugin classes to load./* w w w .j a v a 2 s.com*/ */ private List<String> getJarPluginClasses(File blessedJar) throws IOException { JarFile jar = new JarFile(blessedJar); Manifest manifest = jar.getManifest(); Map entries = manifest.getEntries(); List<String> plugins = new ArrayList<String>(); for (Iterator manIter = entries.keySet().iterator(); manIter.hasNext();) { String key = (String) manIter.next(); Attributes attrs = manifest.getAttributes(key); if (attrs.containsKey(LOADABLE_PLUGIN_ATTR)) { String s = StringUtil.replaceString(key, "/", "."); String pluginName = null; if (StringUtil.endsWithIgnoreCase(key, ".class")) { pluginName = StringUtil.replaceString(s, ".class", ""); log.debug2("Adding '" + pluginName + "' to plugin load list."); plugins.add(pluginName); } else if (StringUtil.endsWithIgnoreCase(key, ".xml")) { pluginName = StringUtil.replaceString(s, ".xml", ""); log.debug2("Adding '" + pluginName + "' to plugin load list."); plugins.add(pluginName); } } } jar.close(); return plugins; }
From source file:org.rhq.plugins.jbossas.util.FileContentDelegate.java
/** * Write the SHA256 to the manifest using the RHQ-Sha256 attribute tag. * * @param deploymentFolder app deployment folder * @param sha SHA256// ww w . jav a2 s. co m * @throws IOException */ private void writeSHAToManifest(File deploymentFolder, String sha) throws IOException { File manifestFile = new File(deploymentFolder, MANIFEST_RELATIVE_PATH); Manifest manifest; if (manifestFile.exists()) { FileInputStream inputStream = new FileInputStream(manifestFile); try { manifest = new Manifest(inputStream); } finally { inputStream.close(); } } else { manifest = new Manifest(); manifestFile.getParentFile().mkdirs(); manifestFile.createNewFile(); } Attributes attribs = manifest.getMainAttributes(); //The main section of the manifest file does not get saved if both of //these two attributes are missing. Please see Attributes implementation. if (!attribs.containsKey(Attributes.Name.MANIFEST_VERSION.toString()) && !attribs.containsKey(Attributes.Name.SIGNATURE_VERSION.toString())) { attribs.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); } attribs.putValue(RHQ_SHA_256, sha); FileOutputStream outputStream = new FileOutputStream(manifestFile); try { manifest.write(outputStream); } finally { outputStream.close(); } }