List of usage examples for java.util.jar Manifest getMainAttributes
public Attributes getMainAttributes()
From source file:org.carewebframework.api.ManifestIteratorTest.java
@Test public void testIterator() { ManifestIterator manifests = (ManifestIterator) appContext.getBean("manifestIterator"); for (Manifest manifest : manifests) { Attributes attributes = manifest.getMainAttributes(); for (Entry<?, ?> entry : attributes.entrySet()) { Name name = (Name) entry.getKey(); log.info(name + ": " + entry.getValue().toString()); }/* w w w.j a v a 2 s. c o m*/ } }
From source file:strat.mining.stratum.proxy.configuration.ConfigurationManager.java
/** * Return the version of the program/* w w w . jav a 2 s . com*/ * * @return */ public static String getVersion() { if (version == null) { version = "Dev"; Class<Launcher> clazz = Launcher.class; String className = clazz.getSimpleName() + ".class"; String classPath = clazz.getResource(className).toString(); if (classPath.startsWith("jar")) { // Class not from JAR String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; try { Manifest manifest = new Manifest(new URL(manifestPath).openStream()); Attributes attr = manifest.getMainAttributes(); version = attr.getValue("Implementation-Version"); } catch (IOException e) { // Do nothing, just return Unknown as version version = "Unknown"; } } } return version; }
From source file:org.apache.servicemix.war.deployer.WarDeploymentListener.java
public boolean canHandle(File artifact) { try {/*from ww w . j av a2 s. c o m*/ JarFile jar = new JarFile(artifact); JarEntry entry = jar.getJarEntry("WEB-INF/web.xml"); // Only handle WAR artifacts if (entry == null) { return false; } // Only handle non OSGi bundles Manifest m = jar.getManifest(); if (m.getMainAttributes().getValue(new Attributes.Name("Bundle-SymbolicName")) != null && m.getMainAttributes().getValue(new Attributes.Name("Bundle-Version")) != null) { return false; } return true; } catch (Exception e) { return false; } }
From source file:org.sonar.api.utils.ManifestUtilsTest.java
@Test public void singleManifest() throws Exception { Manifest mf = new Manifest(); mf.getMainAttributes().putValue("foo", "bar"); mf.getMainAttributes().putValue("other", "value"); File jar = createJar(mf, "singleManifest.jar"); URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[] { jar })); List<String> values = ManifestUtils.getPropertyValues(classloader, "foo"); assertThat(values.size(), is(1));//w w w . j a va 2 s . co m assertThat(values, hasItem("bar")); }
From source file:org.sonar.api.utils.ManifestUtilsTest.java
@Test public void manyManifests() throws Exception { Manifest mf1 = new Manifest(); mf1.getMainAttributes().putValue("foo", "bar"); File jar1 = createJar(mf1, "manyManifests-one.jar"); Manifest mf2 = new Manifest(); mf2.getMainAttributes().putValue("foo", "otherbar"); File jar2 = createJar(mf2, "manyManifests-two.jar"); URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[] { jar1, jar2 })); List<String> values = ManifestUtils.getPropertyValues(classloader, "foo"); assertThat(values.size(), is(2));/* w w w . j av a 2 s . co m*/ assertThat(values, hasItems("bar", "otherbar")); }
From source file:org.eclipse.gemini.blueprint.test.internal.util.ManifestUtilsTest.java
public void testExportEntries() throws Exception { Manifest mf = new Manifest(); Attributes attrs = mf.getMainAttributes(); String[] packages = new String[] { "foo.bar; version:=1", "bar.foo", "hop.trop" }; attrs.putValue(Constants.EXPORT_PACKAGE, StringUtils.arrayToCommaDelimitedString(packages)); createJar(mf);/*from w w w . j a v a 2s . c om*/ String[] entries = ManifestUtils .determineImportPackages(new Resource[] { storage.getResource(), storage.getResource() }); assertEquals(3, entries.length); ObjectUtils.nullSafeEquals(packages, entries); }
From source file:org.pentaho.webpackage.deployer.WebPackageURLConnectionTest.java
private void verifyManifest(Manifest manifest) { assertTrue(manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME) .startsWith("pentaho-web-package-")); assertTrue(manifest.getMainAttributes().getValue(Constants.PROVIDE_CAPABILITY).startsWith( "org.pentaho.webpackage;name=\"my-simple-module\";version:Version=\"1.4.0\";root=\"/pwp-")); }
From source file:org.sonar.api.utils.ManifestUtilsTest.java
private File createJar(Manifest mf, String name) throws Exception { mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); File file = tempDir.newFile(name); OutputStream out = new JarOutputStream(new FileOutputStream(file), mf); out.flush();//w w w. j a va 2 s . com IOUtils.closeQuietly(out); return file; }
From source file:org.parosproxy.paros.Constant.java
private static String getVersionFromManifest() { Manifest manifest = getManifest(); if (manifest != null) { Attributes attr = manifest.getMainAttributes(); return attr.getValue("Implementation-Version"); } else {// w ww . ja v a 2 s .co m return DEV_VERSION; } }
From source file:org.parosproxy.paros.Constant.java
public static Date getReleaseCreateDate() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Manifest manifest = getManifest(); if (manifest != null) { Attributes attr = manifest.getMainAttributes(); try {//from w w w.j a v a 2 s. c o m return sdf.parse(attr.getValue("Create-Date")); } catch (ParseException e) { // Ignore - treat as undated } } return null; }