List of usage examples for java.util.jar Manifest Manifest
public Manifest(Manifest man)
From source file:org.echocat.nodoodle.NodoodleInformationFactory.java
public Manifest getManifest() { final Manifest manifest; final URL manifestUrl = findManifestUrl(); if (manifestUrl != null) { try {//from w ww.j a v a 2s . com final InputStream is = manifestUrl.openStream(); try { manifest = new Manifest(is); } finally { IOUtils.closeQuietly(is); } } catch (IOException e) { throw new RuntimeException("Could not read manifest from " + manifestUrl + ".", e); } } else { manifest = null; } return manifest; }
From source file:com.vmware.vfabric.hyperic.plugin.vfws.BmxResult.java
public Properties parseToProperties() throws IOException { InputStream is = _response.getEntity().getContent(); props = new Properties(); Manifest manifest = new Manifest(is); Attributes attributes = manifest.getMainAttributes(); if (null == attributes) { _log.error("Unable to parse results. No attributes found"); return null; }/*from www . ja v a 2 s . c om*/ for (Iterator<Object> it = attributes.keySet().iterator(); it.hasNext();) { Name key = (Name) it.next(); if (key == null) { _log.debug("Skipping null key"); continue; } Object value = attributes.get(key); if (value.getClass() != String.class) { _log.error("Attribute value not of class String"); continue; } String keyName = key.toString(); String val = (String) value; props.put(keyName, val); } return props; }
From source file:pl.otros.logview.VersionUtil.java
/** * Check version of running application. Version is read from /META-INF/MANIFEST.MF file * * @return currently running version// www.j a va 2 s.co m * @throws IOException */ public static String getRunningVersion() throws IOException { LOGGER.info("Checking running version"); String result = ""; Enumeration<URL> resources = VersionUtil.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { URL url = resources.nextElement(); if (url.toString().contains("OtrosLogViewer")) { InputStream inputStream = url.openStream(); try { Manifest manifest = new Manifest(inputStream); result = manifest.getMainAttributes().getValue(IMPLEMENTATION_VERSION); LOGGER.info("Running version is " + result); } finally { IOUtils.closeQuietly(inputStream); } } } return result; }
From source file:org.openhab.tools.analysis.checkstyle.RequireBundleCheck.java
@Override protected void processFiltered(File file, FileText fileText) { try {//from w ww. j a v a 2 s. c o m // We use Manifest class here instead of ManifestParser, // because it is easier to get the content of the headers // in the MANIFEST.MF Manifest manifest = new Manifest(new FileInputStream(file)); Attributes attributes = manifest.getMainAttributes(); String fragmentHost = attributes.getValue(FRAGMENT_HOST_HEADER_NAME); String bundleSymbolicName = attributes.getValue(BUNDLE_SYMBOLIC_NAME_HEADER_NAME); boolean testBundle = false; if (StringUtils.isNotBlank(fragmentHost) && StringUtils.isNotBlank(bundleSymbolicName)) { testBundle = bundleSymbolicName.startsWith(fragmentHost) && bundleSymbolicName.substring(fragmentHost.length()).startsWith(".test"); } String requireBundleHeaderValue = attributes.getValue(REQUIRE_BUNDLE_HEADER_NAME); if (requireBundleHeaderValue != null && !testBundle) { int lineNumber = findLineNumberSafe(fileText, requireBundleHeaderValue, 0, REQUIRE_BUNDLE_HEADER_NAME + " header line number not found."); log(lineNumber, "The MANIFEST.MF file must not contain any Require-Bundle entries. " + "Instead, Import-Package must be used."); } else if (requireBundleHeaderValue != null && testBundle) { String[] bundleNames = requireBundleHeaderValue.split(","); for (String bundleName : bundleNames) { if (!allowedRequireBundles.contains(bundleName)) { int lineNumber = findLineNumberSafe(fileText, requireBundleHeaderValue, 0, "Header value not found."); log(lineNumber, "The MANIFEST.MF file of a test fragment must not contain Require-Bundle entries other than " + getAllowedBundlesString() + "."); break; } } } } catch ( FileNotFoundException e) { logger.error("An exception was thrown while trying to open the file " + file.getPath(), e); } catch (IOException e) { logger.error("An exception was thrown while trying to read the file " + file.getPath(), e); } }
From source file:org.ow2.chameleon.core.utils.BundleHelper.java
private static boolean isExplodedBundle(File directory) { if (!directory.isDirectory()) { return false; }/*from w w w. j ava 2s .com*/ File manifestFile = new File(directory, MANIFEST); if (!manifestFile.exists()) { return false; } FileInputStream stream = null; try { stream = new FileInputStream(manifestFile); Manifest manifest = new Manifest(stream); return manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME) != null; } catch (IOException e) { LoggerFactory.getLogger(BundleHelper.class).error( "Cannot check if the directory {} is a bundle, " + "cannot read the manifest file", directory.getName(), e); return false; } finally { IOUtils.closeQuietly(stream); } }
From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginOSGiManifest.java
private void updateManifest(String symbolicName, String classPath, String bundleActivator) throws IOException { try (FileInputStream manifestInputStream = new FileInputStream(manifestLocation)) { Manifest manifest = new Manifest(manifestInputStream); Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes.containsKey(new Attributes.Name(BUNDLE_SYMBOLICNAME))) { descriptor.markAsInvalid(Arrays.asList( "Plugin JAR is invalid. MANIFEST.MF already contains header: " + BUNDLE_SYMBOLICNAME), null);//from www. j ava2 s . c o m return; } mainAttributes.put(new Attributes.Name(BUNDLE_SYMBOLICNAME), symbolicName); mainAttributes.put(new Attributes.Name(BUNDLE_CLASSPATH), classPath); mainAttributes.put(new Attributes.Name(BUNDLE_ACTIVATOR), bundleActivator); descriptor.updateBundleInformation(symbolicName, classPath, bundleActivator); try (FileOutputStream manifestOutputStream = new FileOutputStream(manifestLocation)) { manifest.write(manifestOutputStream); } } }
From source file:adalid.util.info.JavaInfo.java
public static void printManifestInfo(String extension, boolean details, URL url) throws IOException { InputStream stream = url.openStream(); if (stream == null) { return;//w w w. java 2 s . c o m } // String file = url.getFile(); String path = StringUtils.removeEndIgnoreCase(url.getPath(), "!/" + JarFile.MANIFEST_NAME); String name = StringUtils.substringAfterLast(path, "/"); Manifest manifest = new Manifest(stream); if (!extensionNameMatches(manifest, extension)) { return; } // out.println(file); printManifestInfo(path, name, details, manifest); }
From source file:com.commercehub.dropwizard.BuildInfoServlet.java
@Override public void init(ServletConfig config) { objectWriter = new ObjectMapper().writer(); cacheControl = new CacheControl(); cacheControl.setMustRevalidate(true); cacheControl.setNoCache(true);/* w w w . j a va 2s .c o m*/ cacheControl.setNoStore(true); // cache build information manifestAttributes = new Properties(); ImmutableSet<String> attributeBlacklist = getAttributeBlacklist(config); try { Enumeration<URL> resources = getClass().getClassLoader().getResources(JarFile.MANIFEST_NAME); if (resources != null) { while (resources.hasMoreElements()) { Manifest manifest = new Manifest(resources.nextElement().openStream()); Attributes attributes = manifest.getMainAttributes(); for (Object key : attributes.keySet()) { Attributes.Name attrName = (Attributes.Name) key; if (!attributeBlacklist.contains(attrName.toString())) { manifestAttributes.setProperty(attrName.toString(), attributes.getValue(attrName)); } } } } } catch (IOException e) { log.warn("Unable to retrieve build info", e); } }
From source file:com.ericsson.eiffel.remrem.generate.EiffelRemremControllerIntegrationTest.java
public static String getMessagingVersion() { Enumeration resEnum;/*from w ww.j a v a 2 s. c o m*/ try { resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME); while (resEnum.hasMoreElements()) { try { URL url = (URL) resEnum.nextElement(); if (url.getPath().contains("eiffel-remrem-semantics")) { InputStream is = url.openStream(); if (is != null) { Manifest manifest = new Manifest(is); Attributes mainAttribs = manifest.getMainAttributes(); String version = mainAttribs.getValue("semanticsVersion"); if (version != null) { return version; } } } } catch (Exception e) { // Silently ignore wrong manifests on classpath? } } } catch (IOException e1) { // Silently ignore wrong manifests on classpath? } return null; }