List of usage examples for java.util.jar Attributes getValue
public String getValue(Name name)
From source file:org.krakenapps.main.Kraken.java
private void setBanner() throws IOException { try {// ww w. j a v a 2 s. com String jarFileName = System.getProperty("java.class.path") .split(System.getProperty("path.separator"))[0]; JarFile jar = new JarFile(jarFileName); Manifest mf = jar.getManifest(); Attributes attrs = mf.getMainAttributes(); BANNER = "Kraken (version " + attrs.getValue("Kraken-Version") + ")"; } catch (FileNotFoundException e) { BANNER = "Kraken (Debug mode)"; } }
From source file:org.hyperic.hq.plugin.jboss7.JBossDetectorBase.java
final String getVersion(Map<String, String> args) { String version = "not found"; File jbossAsServerJar = null; String mp = args.get("mp"); List<String> modulesPAths = Arrays.asList(mp.split(File.pathSeparator)); log.debug("[getVersion] modulesPAths=" + modulesPAths); for (String path : modulesPAths) { Collection<File> files = listFileTree(new File(path)); for (File file : files) { String name = file.getName(); if (name.startsWith("jboss-as-server") && name.endsWith(".jar")) { jbossAsServerJar = file; }/* w w w .java 2s. com*/ } } if (jbossAsServerJar != null) { try { JarFile jarFile = new JarFile(jbossAsServerJar); log.debug("[getVersion] jboss-as-server.jar = '" + jarFile.getName() + "'"); Attributes attributes = jarFile.getManifest().getMainAttributes(); jarFile.close(); version = attributes.getValue("JBossAS-Release-Version"); } catch (IOException e) { log.debug("[getVersion] Error getting JBoss version (" + e + ")", e); } } else { log.debug("[getVersion] 'jboss-as-server.*.jar' not found."); } return version; }
From source file:com.github.lindenb.jvarkit.util.command.CommandFactory.java
private void loadManifest() { try {/*from w w w . j a v a 2s .c om*/ Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");//not '/META-INF' while (resources.hasMoreElements()) { URL url = resources.nextElement(); InputStream in = url.openStream(); if (in == null) { continue; } Manifest m = new Manifest(in); in.close(); in = null; java.util.jar.Attributes attrs = m.getMainAttributes(); if (attrs == null) { continue; } String s = attrs.getValue("Git-Hash"); if (s != null && !s.isEmpty() && !s.contains("$")) //ant failed { this.version = s; } s = attrs.getValue("Compile-Date"); if (s != null && !s.isEmpty()) //ant failed { this.compileDate = s; } } } catch (Exception err) { } }
From source file:com.opengamma.web.WebAbout.java
/** * Gets the OpenGamma version.//from w ww . j av a2 s.c om * @return the version, not null */ public String getOpenGammaBuild() { URL url = ClasspathHelper.forClass(getClass(), getClass().getClassLoader()); if (url != null && url.toString().contains(".jar")) { try { final String part = ClasspathHelper.cleanPath(url); try (JarFile myJar = new JarFile(part)) { final Manifest manifest = myJar.getManifest(); if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); if (attributes != null) { if (attributes.getValue(IMPLEMENTATION_BUILD) != null) { return attributes.getValue(IMPLEMENTATION_BUILD); } } } } } catch (Exception ex) { s_logger.warn(ex.getMessage(), ex); } } return "?"; }
From source file:com.opengamma.web.WebAbout.java
/** * Gets the OpenGamma version./*from w w w.jav a 2 s . co m*/ * @return the version, not null */ public String getOpenGammaVersion() { URL url = ClasspathHelper.forClass(getClass(), getClass().getClassLoader()); if (url != null && url.toString().contains(".jar")) { try { final String part = ClasspathHelper.cleanPath(url); try (JarFile myJar = new JarFile(part)) { final Manifest manifest = myJar.getManifest(); if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); if (attributes != null) { if (attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION) != null) { return attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); } if (attributes.getValue(Attributes.Name.SPECIFICATION_VERSION) != null) { return attributes.getValue(Attributes.Name.SPECIFICATION_VERSION); } } } } } catch (Exception ex) { s_logger.warn(ex.getMessage(), ex); } } else { List<AboutDependency> classpath = getClasspath(); for (AboutDependency depend : classpath) { if ("og-web".equals(depend.getArtifactId())) { return depend.getVersion(); } } } return "?"; }
From source file:com.basistech.bbhmp.RosapiBundleCollectorMojo.java
private boolean isJarFragment(File outputFile) throws MojoExecutionException, MojoFailureException { JarFile jar;/*from www .j a v a 2 s . c o m*/ try { jar = new JarFile(outputFile); } catch (IOException e) { throw new MojoExecutionException( "Failed to open dependency we just copied " + outputFile.getAbsolutePath(), e); } final Manifest manifest; try { manifest = jar.getManifest(); } catch (IOException e) { throw new MojoFailureException( "Failed to read manifest from dependency we just copied " + outputFile.getAbsolutePath(), e); } final Attributes mattr = manifest.getMainAttributes(); // getValue is case-insensitive. String mfVersion = mattr.getValue("Bundle-ManifestVersion"); /* * '2' is the only legitimate bundle manifest version. Version 1 is long obsolete, and not supported * in current containers. There's no plan on the horizon for a version 3. No version at all indicates * that the jar file is not an OSGi bundle at all. */ if (!"2".equals(mfVersion)) { throw new MojoFailureException("Bundle-ManifestVersion is not '2' from dependency we just copied " + outputFile.getAbsolutePath()); } String host = mattr.getValue("Fragment-Host"); return host != null; }
From source file:org.kepler.kar.KARBuilder.java
/** * Prepare the KAR Manifest based on the kar items. * * @param overrideModDeps - Optional override of kar's module dependencies, * set null for normal use.// www . ja v a2 s . c o m * @throws Exception */ private void prepareManifest(String overrideModDeps) throws Exception { _manifest.addMainAttribute(KARFile.LSID.toString(), _karLSID.toString()); if (overrideModDeps == null) { _manifest.addMainAttribute(KARFile.MOD_DEPEND.toString(), ModuleDependencyUtil.buildModuleDependenciesString()); } else { //System.out.println("KARBuilder prepareManifest using overrideModDeps:"+overrideModDeps); _manifest.addMainAttribute(KARFile.MOD_DEPEND.toString(), overrideModDeps); } // add all the KAREntry attributes to the KARManifest Vector<KAREntry> toRemove = new Vector<KAREntry>(1); for (KAREntry ke : _karItems.keySet()) { Attributes atts = ke.getAttributes(); // Check required attributes String entryLSID = atts.getValue(KAREntry.LSID); String entryType = atts.getValue(KAREntry.TYPE); String entryHandler = atts.getValue(KAREntry.HANDLER); if (entryLSID == null || entryType == null || entryHandler == null) { log.warn(ke.getName() + " KAREntry did not have an LSID, Type, or Handler attribute. KAREntry removed."); toRemove.add(ke); } else { // add all attributes of the karentry to the manifest for (Object att : atts.keySet()) { if (att instanceof Name) { Name attName = (Name) att; String attValue = atts.getValue(attName); _manifest.addEntryAttribute(ke, attName.toString(), attValue); } } } } if (toRemove.size() > 0) { for (KAREntry ke : toRemove) { _karItemLSIDs.remove(ke.getLSID()); _karItems.remove(ke); } } }
From source file:com.github.wolf480pl.mias4j.util.AbstractTransformingClassLoader.java
protected Package definePackage(String name, Manifest man, URL codeSourceURL) { String path = toInternalName(name) + "/"; Attributes attr = man.getAttributes(path); String specTitle = null;//ww w .j ava 2s. co m String specVersion = null; String specVendor = null; String implTitle = null; String implVersion = null; String implVendor = null; String sealed = null; if (attr != null) { specTitle = attr.getValue(Name.SPECIFICATION_TITLE); specVersion = attr.getValue(Name.SPECIFICATION_VERSION); specVendor = attr.getValue(Name.SPECIFICATION_VENDOR); implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE); implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION); implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR); sealed = attr.getValue(Name.SEALED); } attr = man.getMainAttributes(); if (attr != null) { if (specTitle != null) { specTitle = attr.getValue(Name.SPECIFICATION_TITLE); } if (specVersion != null) { specVersion = attr.getValue(Name.SPECIFICATION_VERSION); } if (specVendor != null) { specVendor = attr.getValue(Name.SPECIFICATION_VENDOR); } if (implTitle != null) { implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE); } if (implVersion != null) { implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION); } if (implVendor != null) { implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR); } if (sealed != null) { sealed = attr.getValue(Name.SEALED); } } return definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealed.equalsIgnoreCase("true") ? codeSourceURL : null); }
From source file:org.moe.cli.ParameterParserTest.java
@Test public void linkUniversalLibrary() throws Exception { File project = tmpDir.newFolder(); File outputJar = new File(project, "TestLib.jar"); // prepare file with ldFlags String flags = "-lTestLibrary"; File ldFlags = new File(project, "ldflags"); ldFlags.createNewFile();//from ww w . j a v a 2 s .co m PrintWriter write = new PrintWriter(ldFlags); write.print(flags); write.close(); ClassLoader cl = this.getClass().getClassLoader(); URL library = cl.getResource("natives/universal/libTestLibrary.a"); URL headersURL = cl.getResource("natives/Headers/TestFramework.h"); File headers = new File(headersURL.getPath()); URL bundle = cl.getResource("moe_logo.png"); CommandLine argc = parseArgs(new String[] { "--library", library.getPath(), "--headers", headers.getParentFile().getPath(), "--package-name", "org", "--output-file-path", outputJar.getPath(), "--ld-flags", ldFlags.getPath(), "--bundle", bundle.getPath() }); IExecutor executor = ExecutorManager.getExecutorByParams(argc); assertNotNull(executor); assertTrue(executor instanceof ThirdPartyLibraryLinkExecutor); // generate binding & prepare output jar executor.execute(); // check output jar file existence assertTrue(outputJar.exists()); JarFile jarFile = new JarFile(outputJar); Manifest manifest = jarFile.getManifest(); Attributes attributes = manifest.getMainAttributes(); String manifestLDFlags = attributes.getValue("MOE_CUSTOM_LINKER_FLAGS"); Set<String> realLDFlags = new HashSet<String>(Arrays.asList(flags.split(";"))); realLDFlags.add("-ObjC"); assertEquals(realLDFlags, new HashSet<String>(Arrays.asList(manifestLDFlags.split(";")))); String manifestSimFramework = attributes.getValue("MOE_ThirdpartyFramework_universal"); assertEquals(manifestSimFramework, "./lib/libTestLibrary.a"); String manifestBundle = attributes.getValue("MOE_BUNDLE_FILE_RESOURCES"); assertEquals(manifestBundle, "./bundle/moe_logo.png;"); assertNotNull(jarFile.getEntry("bundle/moe_logo.png")); assertNotNull(jarFile.getEntry("lib/libTestLibrary.a")); jarFile.close(); }
From source file:org.moe.cli.ParameterParserTest.java
@Test public void linkFramework() throws Exception { File project = tmpDir.newFolder(); File outputJar = new File(project, "TestFramework.jar"); // prepare file with ldFlags String flags = "-framework TestFramework"; File ldFlags = new File(project, "ldflags"); ldFlags.createNewFile();/* ww w . jav a 2 s . c o m*/ PrintWriter write = new PrintWriter(ldFlags); write.print(flags); write.close(); ClassLoader cl = this.getClass().getClassLoader(); URL simFramework = cl.getResource("natives/device/TestFramework.framework"); URL devFramework = cl.getResource("natives/simulator/TestFramework.framework"); URL bundle = cl.getResource("moe_logo.png"); CommandLine argc = parseArgs(new String[] { "--framework", String.format("%s:%s", simFramework.getPath(), devFramework.getPath()), "--package-name", "org", "--output-file-path", outputJar.getPath(), "--ld-flags", ldFlags.getPath(), "--bundle", bundle.getPath() }); IExecutor executor = ExecutorManager.getExecutorByParams(argc); assertNotNull(executor); assertTrue(executor instanceof ThirdPartyFrameworkLinkExecutor); // generate binding & prepare output jar executor.execute(); // check output jar file existence assertTrue(outputJar.exists()); JarFile jarFile = new JarFile(outputJar); Manifest manifest = jarFile.getManifest(); Attributes attributes = manifest.getMainAttributes(); String manifestLDFlags = attributes.getValue("MOE_CUSTOM_LINKER_FLAGS"); assertEquals(flags + ";", manifestLDFlags); String manifestBundle = attributes.getValue("MOE_BUNDLE_FILE_RESOURCES"); assertEquals(manifestBundle, "./bundle/moe_logo.png;"); String manifestFramework = attributes.getValue("MOE_ThirdpartyFramework_ios_simulator"); assertEquals(manifestFramework, "./lib/iphonesimulator/TestFramework.framework"); String manifestDevFramework = attributes.getValue("MOE_ThirdpartyFramework_ios_device"); assertEquals(manifestDevFramework, "./lib/iphoneos/TestFramework.framework"); assertNotNull(jarFile.getEntry("bundle/moe_logo.png")); assertNotNull(jarFile.getEntry("lib/iphonesimulator/TestFramework.framework")); assertNotNull(jarFile.getEntry("lib/iphoneos/TestFramework.framework")); jarFile.close(); }