List of usage examples for java.util.jar JarFile getManifest
public Manifest getManifest() throws IOException
From source file:com.gzj.tulip.load.ResourceRef.java
public static ResourceRef toResourceRef(Resource folder) throws IOException { ResourceRef rr = new ResourceRef(folder, null, null); String[] modifiers = null;//from ww w . j ava 2 s .c o m Resource rosePropertiesResource = rr.getInnerResource("META-INF/rose.properties"); if (rosePropertiesResource.exists()) { if (logger.isDebugEnabled()) { logger.debug("found rose.properties: " + rosePropertiesResource.getURI()); } InputStream in = rosePropertiesResource.getInputStream(); rr.properties.load(in); in.close(); String attrValue = rr.properties.getProperty("rose"); if (attrValue == null) { attrValue = rr.properties.getProperty("Rose"); } if (attrValue != null) { modifiers = StringUtils.split(attrValue, ", ;\n\r\t"); if (logger.isDebugEnabled()) { logger.debug("modifiers[by properties][" + rr.getResource().getURI() + "]=" + Arrays.toString(modifiers)); } } } // if (modifiers == null) { if (!"jar".equals(rr.getProtocol())) { modifiers = new String[] { "**" }; if (logger.isDebugEnabled()) { logger.debug("modifiers[by default][" + rr.getResource().getURI() + "]=" + Arrays.toString(modifiers)); } } else { JarFile jarFile = new JarFile(rr.getResource().getFile()); Manifest manifest = jarFile.getManifest(); if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); String attrValue = attributes.getValue("rose"); if (attrValue == null) { attrValue = attributes.getValue("Rose"); } if (attrValue != null) { modifiers = StringUtils.split(attrValue, ", ;\n\r\t"); if (logger.isDebugEnabled()) { logger.debug("modifiers[by manifest.mf][" + rr.getResource().getURI() + "]=" + Arrays.toString(modifiers)); } } } } } rr.setModifiers(modifiers); return rr; }
From source file:org.sonar.updatecenter.deprecated.Plugin.java
public static Plugin extractMetadata(File file) throws IOException { JarFile jar = new JarFile(file); ZipEntry entry = jar.getEntry("META-INF/MANIFEST.MF"); long timestamp = entry.getTime(); Manifest manifest = jar.getManifest(); jar.close();//from w ww. java 2 s .c o m Attributes attributes = manifest.getMainAttributes(); String pluginKey = attributes.getValue("Plugin-Key"); Plugin plugin = new Plugin(pluginKey); plugin.setName(attributes.getValue("Plugin-Name")); plugin.setVersion(attributes.getValue("Plugin-Version")); plugin.setRequiredSonarVersion(attributes.getValue("Sonar-Version")); plugin.setHomepage(attributes.getValue("Plugin-Homepage")); plugin.setDate(timestamp); return plugin; }
From source file:org.commonjava.web.test.fixture.JarKnockouts.java
public static File rewriteJar(final File source, final File targetDir, final Set<JarKnockouts> jarKnockouts) throws IOException { final JarKnockouts allKnockouts = new JarKnockouts(); for (final JarKnockouts jk : jarKnockouts) { allKnockouts.knockoutPaths(jk.getKnockedOutPaths()); }/* w w w. ja v a 2 s . c o m*/ targetDir.mkdirs(); final File target = new File(targetDir, source.getName()); JarFile in = null; JarOutputStream out = null; try { in = new JarFile(source); final BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(target)); out = new JarOutputStream(fos, in.getManifest()); final Enumeration<JarEntry> entries = in.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); if (!allKnockouts.knockout(entry.getName())) { final InputStream stream = in.getInputStream(entry); out.putNextEntry(entry); copy(stream, out); out.closeEntry(); } } } finally { closeQuietly(out); if (in != null) { try { in.close(); } catch (final IOException e) { } } } return target; }
From source file:hudson.plugins.simpleupdatesite.HPI.java
public static HPI loadHPI(File file) throws IOException { JarFile jarFile = new JarFile(file); try {// w ww . ja va2s. c om ZipEntry entry = jarFile.getEntry("META-INF/MANIFEST.MF"); HPI hpi = new HPI(); hpi.init(jarFile.getManifest().getMainAttributes(), entry.getTime()); return hpi; } finally { jarFile.close(); } }
From source file:org.asoem.greyfish.cli.GreyfishCLIApplication.java
private static Optional<String> getCommitHash(final Class<?> clazz) { try {//ww w.ja va 2 s. co m final JarFile jarFile = Resources.getJarFile(clazz); final Manifest manifest = jarFile.getManifest(); final Attributes attr = manifest.getMainAttributes(); return Optional.of(attr.getValue("Git-Commit-Hash")); } catch (IOException e) { throw new IOError(e); } catch (UnsupportedOperationException e) { return Optional.absent(); } }
From source file:com.arcusys.liferay.vaadinplugin.util.ControlPanelPortletUtil.java
private static String getManifestAttribute(JarFile jarFile, String versionAttribute) throws IOException { Manifest manifest = jarFile.getManifest(); if (manifest == null) { return null; }//from w w w . j a v a2s.c o m Attributes attr = manifest.getMainAttributes(); String bundleName = attr.getValue("Bundle-Name"); if (bundleName != null) { return attr.getValue(versionAttribute); } return null; }
From source file:com.arcusys.liferay.vaadinplugin.util.ControlPanelPortletUtil.java
private static String getManifestAttributeForVaadin6(JarFile jarFile, String versionAttribute) throws IOException { Manifest manifest = jarFile.getManifest(); if (manifest == null) { return null; }/*from ww w .ja va 2 s . com*/ Attributes attr = manifest.getMainAttributes(); String bundleName = attr.getValue("Bundle-Name"); if (bundleName != null && bundleName.equals("Vaadin")) { return attr.getValue(versionAttribute); } return null; }
From source file:org.openanzo.client.cli.CommandLineInterface.java
private static String determineVersion() throws URISyntaxException, IOException { String version = null;//from ww w. j a va2s.c o m if (CommandLineInterface.class.getProtectionDomain() != null && CommandLineInterface.class.getProtectionDomain().getCodeSource() != null && CommandLineInterface.class.getProtectionDomain().getCodeSource().getLocation() != null) { ProtectionDomain domain = CommandLineInterface.class.getProtectionDomain(); CodeSource source = domain.getCodeSource(); URL location = source.getLocation(); if (location != null) { File file = new File(location.toURI()); if (file.exists()) { JarFile jar = new JarFile(file); version = jar.getManifest().getMainAttributes().getValue("Bundle-Version"); if (version == null) { version = jar.getManifest().getMainAttributes().getValue("Implementation-Build"); } } } } if (version == null) { version = CommandLineInterface.class.getPackage().getImplementationVersion(); } return version; }
From source file:org.orbisgis.core.plugin.BundleTools.java
private static BundleReference parseJarManifest(File jarFilePath, List<PackageDeclaration> packages) throws IOException { JarFile jar = new JarFile(jarFilePath); return parseManifest(jar.getManifest(), packages); }
From source file:org.wso2.carbon.wsdl2code.POMGenerator.java
public static String getVersion(String artifact) throws Exception { java.io.File file = new java.io.File(artifact); java.util.jar.JarFile jar = new java.util.jar.JarFile(file); java.util.jar.Manifest manifest = jar.getManifest(); String versionNumber = ""; java.util.jar.Attributes attributes = manifest.getMainAttributes(); if (attributes != null) { java.util.Iterator it = attributes.keySet().iterator(); while (it.hasNext()) { java.util.jar.Attributes.Name key = (java.util.jar.Attributes.Name) it.next(); String keyword = key.toString(); if (keyword.equals("Implementation-Version") || keyword.equals("Bundle-Version")) { versionNumber = (String) attributes.get(key); break; }//w w w. jav a2s . com } } jar.close(); if (versionNumber != null && !versionNumber.equals("")) { return versionNumber; } //if manifest does not contain version number it had to be extracted from the file name String fileName = file.getName().substring(0, file.getName().lastIndexOf(".")); if (fileName.contains(".")) { String majorVersion = fileName.substring(0, fileName.indexOf(".")); String minorVersion = fileName.substring(fileName.indexOf(".")); int delimiter = majorVersion.lastIndexOf("-"); if (majorVersion.indexOf("_") > delimiter) delimiter = majorVersion.indexOf("_"); majorVersion = majorVersion.substring(delimiter + 1, fileName.indexOf(".")); versionNumber = majorVersion + minorVersion; } return versionNumber; }