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:ru.codeinside.gses.webui.utils.JarParseUtils.java
public static boolean isOsgiComponent(JarInputStream jarStream) { Attributes mainAttributes = jarStream.getManifest().getMainAttributes(); String serviceComponent = mainAttributes.getValue("Service-Component"); String exportPackage = mainAttributes.getValue("Export-Package"); String importPackage = mainAttributes.getValue("Import-Package"); return StringUtils.isNotEmpty(serviceComponent) && StringUtils.isNotEmpty(exportPackage) && StringUtils.isNotEmpty(importPackage); }
From source file:com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.java
private static void assertMainClass(final String jarFile, final String mainClass) throws Exception { JarInputStream jarStream = null; try {/* w w w . ja va 2 s . c o m*/ jarStream = new JarInputStream(new FileInputStream(jarFile)); final Manifest manifest = jarStream.getManifest(); final Attributes attrs = manifest.getMainAttributes(); assertEquals("Maven plugin must also provide and main class in manifest", mainClass, attrs.getValue("Main-Class")); } finally { IOUtils.closeQuietly(jarStream); } }
From source file:org.talend.designer.maven.utils.ClasspathsJarGenerator.java
public static String getClasspathFromManifest(Property property) throws Exception { String jarLocation = getJarLocation(property); JarInputStream stream = null; try {/*from w w w . j a va2 s . co m*/ stream = new JarInputStream(new FileInputStream(jarLocation)); Manifest manifest = stream.getManifest(); String classpath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH); return classpath; } finally { if (stream != null) { stream.close(); } } }
From source file:org.eclipse.gemini.blueprint.test.internal.util.jar.JarUtils.java
/** * Read the manifest for a given stream. The stream will be wrapped in a * JarInputStream and closed after the manifest was read. * // w w w . j a v a 2 s .co m * @param stream * @return */ public static Manifest getManifest(InputStream stream) { JarInputStream myStream = null; try { myStream = new JarInputStream(stream); return myStream.getManifest(); } catch (IOException ioex) { // just ignore it } finally { closeStream(myStream); } // return (man != null ? man : new Manifest()); return null; }
From source file:com.redhat.victims.plugin.ant.FileStub.java
/** * Creates metadata from a given jar file. * /*from w w w . j a v a 2 s . c o m*/ * @param jar * file containing a manifest * @return Metadata containing extracted information from manifest file. * @throws FileNotFoundException * @throws VictimsException */ public static Metadata getMeta(File jar) throws FileNotFoundException, VictimsException { if (!jar.getAbsolutePath().endsWith(".jar")) return null; JarInputStream jis = null; try { jis = new JarInputStream(new FileInputStream(jar)); Manifest mf = jis.getManifest(); jis.close(); if (mf != null) return Metadata.fromManifest(mf); } catch (IOException io) { throw new VictimsException(String.format("Could not open file: %s", jar.getName()), io); } finally { IOUtils.closeQuietly(jis); } return null; }
From source file:org.bndtools.rt.repository.server.RepositoryResourceComponent.java
private static Manifest readManifest(InputStream stream) throws IOException { if (!stream.markSupported()) throw new IOException("Stream must support mark/reset"); stream.mark(100000);// www.j a v a 2 s .c o m try { @SuppressWarnings("resource") JarInputStream jarStream = new JarInputStream(stream); return jarStream.getManifest(); } finally { stream.reset(); } }
From source file:org.hecl.jarhack.JarHack.java
/** * The <code>substHecl</code> method takes the filenames of two * .jar's - one as input, the second as output, in addition to the * name of the application. Where it counts, the old name (Hecl, * usually) is overridden with the new name, and the new .jar file * is written to the specified outfile. Via the iconname argument * it is also possible to specify a new icon file to use. * * @param infile a <code>FileInputStream</code> value * @param outfile a <code>String</code> value * @param newname a <code>String</code> value * @param iconname a <code>String</code> value * @exception IOException if an error occurs *///from w ww . ja v a 2 s .c om public static void substHecl(InputStream infile, String outfile, String newname, String iconname, String scriptfile) throws IOException { JarInputStream jif = new JarInputStream(infile); Manifest mf = jif.getManifest(); Attributes attrs = mf.getMainAttributes(); Set keys = attrs.keySet(); Iterator it = keys.iterator(); while (it.hasNext()) { Object key = it.next(); Object value = attrs.get(key); String keyname = key.toString(); /* These are the three cases that interest us in * particular, where we need to make changes. */ if (keyname.equals("MIDlet-Name")) { attrs.putValue(keyname, newname); } else if (keyname.equals("MIDlet-1")) { String valuestr = value.toString(); /* FIXME - the stringsplit method is used for older * versions of GCJ. Once newer versions are common, * it can go away. Or not - it works just fine. */ String properties[] = stringsplit(valuestr, ", "); attrs.putValue(keyname, newname + ", " + properties[1] + ", " + properties[2]); } else if (keyname.equals("MicroEdition-Configuration")) { cldcversion = value.toString(); } else if (keyname.equals("MicroEdition-Profile")) { midpversion = value.toString(); } else if (keyname.equals("MIDlet-Jar-URL")) { attrs.put(key, newname + ".jar"); } } JarOutputStream jof = new JarOutputStream(new FileOutputStream(outfile), mf); byte[] buf = new byte[4096]; /* Go through the various entries. */ JarEntry entry; int read; while ((entry = jif.getNextJarEntry()) != null) { /* Don't copy the manifest file. */ if ("META-INF/MANIFEST.MF".equals(entry.getName())) continue; /* Insert our own icon */ if (iconname != null && "Hecl.png".equals(entry.getName())) { jof.putNextEntry(new JarEntry("Hecl.png")); FileInputStream inf = new FileInputStream(iconname); while ((read = inf.read(buf)) != -1) { jof.write(buf, 0, read); } inf.close(); } /* Insert our own copy of the script file. */ else if ("script.hcl".equals(entry.getName())) { jof.putNextEntry(new JarEntry("script.hcl")); FileInputStream inf = new FileInputStream(scriptfile); while ((read = inf.read(buf)) != -1) { jof.write(buf, 0, read); } inf.close(); } else { /* Otherwise, just copy the entry. */ jof.putNextEntry(entry); while ((read = jif.read(buf)) != -1) { jof.write(buf, 0, read); } } jof.closeEntry(); } jof.flush(); jof.close(); jif.close(); }
From source file:org.apache.catalina.util.ExtensionValidator.java
/** * Return the Manifest from a jar file or war file * * @param inStream Input stream to a WAR or JAR file * @return The WAR's or JAR's manifest/* w w w.j a v a 2 s . c o m*/ */ private static Manifest getManifest(InputStream inStream) throws IOException { Manifest manifest = null; JarInputStream jin = null; try { jin = new JarInputStream(inStream); manifest = jin.getManifest(); jin.close(); jin = null; } finally { if (jin != null) { try { jin.close(); } catch (Throwable t) { // Ignore } } } return manifest; }
From source file:org.springframework.data.hadoop.mapreduce.ExecutionUtils.java
static String mainClass(Resource jar) throws IOException { JarInputStream jis = new JarInputStream(jar.getInputStream()); try {/* ww w. j a v a 2s. c o m*/ Manifest mf = jis.getManifest(); if (mf != null) { String main = mf.getMainAttributes().getValue("Main-Class"); if (StringUtils.hasText(main)) { return main.replace("/", "."); } } return null; } finally { IOUtils.closeStream(jis); } }
From source file:org.apache.sling.testing.clients.osgi.OsgiConsoleClient.java
/** * Get the symbolic name from a bundle file * @param bundleFile//from w w w .j a v a2s. c om * @return * @throws IOException */ public static String getBundleSymbolicName(File bundleFile) throws IOException { String name = 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()); } name = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); } finally { jis.close(); } return name; }