List of usage examples for java.util.jar JarInputStream getManifest
public Manifest getManifest()
Manifest
for this JAR file, or null
if none. From source file:org.apache.sling.testing.clients.osgi.OsgiConsoleClient.java
/** * Get the version form a bundle file//from ww w . j a va 2 s .co m * @param bundleFile * @return * @throws IOException */ public static String getBundleVersionFromFile(File bundleFile) throws IOException { String version = null; final JarInputStream jis = new JarInputStream(new FileInputStream(bundleFile)); try { final Manifest m = jis.getManifest(); if (m == null) { throw new IOException("Manifest is null in " + bundleFile.getAbsolutePath()); } version = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION); } finally { jis.close(); } return version; }
From source file:org.apache.sling.osgi.obr.Resource.java
public static Resource create(URL file) throws IOException { JarInputStream jar = null; try {//from w ww. j a v a2 s . c o m URLConnection conn = file.openConnection(); jar = new JarInputStream(conn.getInputStream()); Manifest manifest = jar.getManifest(); if (manifest == null) { throw new IOException(file + " is not a valid JAR file: Manifest not first entry"); } return new Resource(file, manifest.getMainAttributes(), conn.getContentLength()); } finally { IOUtils.closeQuietly(jar); } }
From source file:org.pentaho.webpackage.deployer.WebPackageURLConnectionTest.java
@Test public void testClosingStream() throws IOException { WebPackageURLConnection connection = new WebPackageURLConnection( new File("src/test/resources/my-simple-module-1.4.0.zip").toURI().toURL()); connection.connect();//from www . j a v a2 s .c om InputStream inputStream = connection.getInputStream(); JarInputStream jar = new JarInputStream(inputStream); jar.getManifest(); jar.close(); try { connection.transform_thread.get(); } catch (Exception exception) { fail("Thread failed to execute transform() method: " + exception.getMessage()); } }
From source file:org.pentaho.webpackage.deployer.archive.impl.WebPackageURLConnectionTest.java
@Test public void testClosingStream() throws IOException { WebPackageURLConnection connection = new WebPackageURLConnection( getResourceUrl("/my-simple-module-1.4.0.zip")); connection.connect();//from w w w . j a va 2 s. c o m InputStream inputStream = connection.getInputStream(); JarInputStream jar = new JarInputStream(inputStream); jar.getManifest(); jar.close(); try { connection.transform_thread.get(); } catch (Exception exception) { fail("Thread failed to execute transform() method: " + exception.getMessage()); } }
From source file:org.apache.brooklyn.rt.felix.EmbeddedFelixFrameworkTest.java
@Test public void testReadKnownManifest() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_OSGI_ENTITIES_PATH); InputStream in = this.getClass().getResourceAsStream(BROOKLYN_TEST_OSGI_ENTITIES_PATH); JarInputStream jarIn = new JarInputStream(in); ManifestHelper helper = ManifestHelper.forManifest(jarIn.getManifest()); jarIn.close();/*from w w w. j a v a 2s .co m*/ Assert.assertEquals(helper.getVersion().toString(), "0.1.0"); Assert.assertTrue(helper.getExportedPackages().contains("org.apache.brooklyn.test.osgi.entities")); }
From source file:org.chtijbug.drools.platform.runtime.utils.Xsd2JarTransformerTestCase.java
@Test public void should_get_all_expected_entries_from_generated_jar_file() throws IOException { Xsd2JarTransformer toTest = new Xsd2JarTransformer(); URL xsdFile = this.getClass().getResource("/model.xsd"); InputStream modelJarStream = toTest.transformXsd2Jar("org.pymma.drools", new File(xsdFile.getFile())); File modelJarFile = File.createTempFile("model", ".jar"); IOUtils.copy(modelJarStream, FileUtils.openOutputStream(modelJarFile)); JarInputStream inputStream = new JarInputStream(FileUtils.openInputStream(modelJarFile)); assertThat(inputStream.getManifest()).isNotNull(); List<ZipEntry> allJarEntries = new ArrayList<ZipEntry>(); ZipEntry entry;//w w w. ja v a2 s. c o m while ((entry = inputStream.getNextEntry()) != null) allJarEntries.add(entry); assertThat(allJarEntries).hasSize(5); }
From source file:org.apache.hadoop.util.TestJarFinder.java
@Test public void testNoManifest() throws Exception { File dir = GenericTestUtils.getTestDir(TestJarFinder.class.getName() + "-testNoManifest"); delete(dir);// w ww .j a v a 2 s .co m dir.mkdirs(); File propsFile = new File(dir, "props.properties"); Writer writer = new FileWriter(propsFile); new Properties().store(writer, ""); writer.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream zos = new JarOutputStream(baos); JarFinder.jarDir(dir, "", zos); JarInputStream jis = new JarInputStream(new ByteArrayInputStream(baos.toByteArray())); Assert.assertNotNull(jis.getManifest()); jis.close(); }
From source file:org.apache.hadoop.hbase.mapreduce.hadoopbackport.TestJarFinder.java
@Test public void testNoManifest() throws Exception { File dir = new File(System.getProperty("test.build.dir", "target/test-dir"), TestJarFinder.class.getName() + "-testNoManifest"); delete(dir);//from ww w. j a v a2 s .com dir.mkdirs(); File propsFile = new File(dir, "props.properties"); Writer writer = new FileWriter(propsFile); new Properties().store(writer, ""); writer.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream zos = new JarOutputStream(baos); JarFinder.jarDir(dir, "", zos); JarInputStream jis = new JarInputStream(new ByteArrayInputStream(baos.toByteArray())); Assert.assertNotNull(jis.getManifest()); jis.close(); }
From source file:org.apache.hadoop.util.TestJarFinder.java
@Test public void testExistingManifest() throws Exception { File dir = GenericTestUtils.getTestDir(TestJarFinder.class.getName() + "-testExistingManifest"); delete(dir);/*from w w w.j a v a2s . c o m*/ dir.mkdirs(); File metaInfDir = new File(dir, "META-INF"); metaInfDir.mkdirs(); File manifestFile = new File(metaInfDir, "MANIFEST.MF"); Manifest manifest = new Manifest(); OutputStream os = new FileOutputStream(manifestFile); manifest.write(os); os.close(); File propsFile = new File(dir, "props.properties"); Writer writer = new FileWriter(propsFile); new Properties().store(writer, ""); writer.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream zos = new JarOutputStream(baos); JarFinder.jarDir(dir, "", zos); JarInputStream jis = new JarInputStream(new ByteArrayInputStream(baos.toByteArray())); Assert.assertNotNull(jis.getManifest()); jis.close(); }
From source file:com.thoughtworks.go.domain.materials.tfs.TfsSDKCommandBuilderTest.java
private String implementationVersionFromManifrest(URL log4jJarFromClasspath) throws IOException { JarInputStream in = new JarInputStream(log4jJarFromClasspath.openStream()); ByteArrayOutputStream out = new ByteArrayOutputStream(); in.getManifest().write(out); out.close();/*from ww w . j a v a 2 s . co m*/ List<String> lines = IOUtils.readLines(new ByteArrayInputStream(out.toByteArray())); for (String line : lines) { if (line.startsWith("Implementation-Version")) { return line.split(":")[1].trim(); } } return null; }