List of usage examples for java.util.jar JarFile getManifest
public Manifest getManifest() throws IOException
From source file:org.araqne.pkg.PackageManagerService.java
private Version getBundleVersion(File file) { JarFile jar = null; try {/*from w ww. jav a 2 s . co m*/ jar = new JarFile(file); Attributes attrs = jar.getManifest().getMainAttributes(); return new Version(attrs.getValue("Bundle-Version")); } catch (IOException e) { logger.error("package manager: bundle version not found", e); return null; } finally { if (jar != null) try { jar.close(); } catch (IOException e) { } } }
From source file:org.araqne.pkg.PackageManagerService.java
private String getBundleSymbolicName(File file) { JarFile jar = null; try {/*from w w w.j av a 2s. co m*/ jar = new JarFile(file); Attributes attrs = jar.getManifest().getMainAttributes(); // metadata can be added followed by semicolon (e.g. ;singleton) return attrs.getValue("Bundle-SymbolicName").split(";")[0].trim(); } catch (IOException e) { logger.error("package manager: symbolic name not found", e); return null; } finally { if (jar != null) try { jar.close(); } catch (IOException e) { } } }
From source file:hudson.ClassicPluginStrategy.java
@Override public String getShortName(File archive) throws IOException { Manifest manifest;/*from w w w .j ava2s . co m*/ if (isLinked(archive)) { manifest = loadLinkedManifest(archive); } else { JarFile jf = new JarFile(archive, false); try { manifest = jf.getManifest(); } finally { jf.close(); } } return PluginWrapper.computeShortName(manifest, archive.getName()); }
From source file:org.apache.sling.maven.bundlesupport.AbstractBundleInstallMojo.java
/** * Get the manifest from the File./*from w ww. j a v a 2s .com*/ * @param bundleFile The bundle jar * @return The manifest. * @throws IOException */ protected Manifest getManifest(final File bundleFile) throws IOException { JarFile file = null; try { file = new JarFile(bundleFile); return file.getManifest(); } finally { if (file != null) { try { file.close(); } catch (IOException ignore) { } } } }
From source file:org.jahia.utils.maven.plugin.DeployMojo.java
private boolean isJahiaModuleBundle(File file) { if (!file.exists()) { return false; }// w w w.j av a 2 s . c om // check the manifest JarFile jar = null; try { jar = new JarFile(file, false); return jar.getManifest().getMainAttributes().containsKey(new Attributes.Name("Jahia-Module-Type")); } catch (IOException e) { getLog().error(e); } finally { if (jar != null) { try { jar.close(); } catch (IOException e) { getLog().warn(e); } } } return false; }
From source file:org.ops4j.pax.runner.platform.internal.PlatformImpl.java
/** * Validate that the file is an valid bundle. * A valid bundle will be a loadable jar file that has manifest and the manifest contains at least an entry for * Bundle-SymboliName or Bundle-Name (R3). * * @param url original url from where the bundle was created. * @param file file to be validated/* w w w . j a v a2 s .co m*/ * * @throws PlatformException if the jar is not a valid bundle */ void validateBundle(final URL url, final File file) throws PlatformException { String bundleSymbolicName = null; String bundleName = null; JarFile jar = null; try { // verify that is a valid jar. Do not verify that is signed (the false param). jar = new JarFile(file, false); final Manifest manifest = jar.getManifest(); if (manifest == null) { throw new PlatformException("[" + url + "] is not a valid bundle"); } bundleSymbolicName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); bundleName = manifest.getMainAttributes().getValue(Constants.BUNDLE_NAME); } catch (IOException e) { throw new PlatformException("[" + url + "] is not a valid bundle", e); } finally { if (jar != null) { try { jar.close(); } catch (IOException ignore) { // just ignore as this is less probably to happen. } } } if (bundleSymbolicName == null && bundleName == null) { throw new PlatformException("[" + url + "] is not a valid bundle"); } }
From source file:org.ops4j.pax.runner.platform.internal.PlatformImpl.java
/** * Determine name to be used for caching on local file system. * * @param file file to be validated * @param defaultBundleSymbolicName default bundle symbolic name to be used if manifest does not have a bundle * symbolic name * * @return file name based on bundle symbolic name and version *///from ww w . j a v a 2 s . co m String determineCachingName(final File file, final String defaultBundleSymbolicName) { String bundleSymbolicName = null; String bundleVersion = null; JarFile jar = null; try { // verify that is a valid jar. Do not verify that is signed (the false param). jar = new JarFile(file, false); final Manifest manifest = jar.getManifest(); if (manifest != null) { bundleSymbolicName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); bundleVersion = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION); } } catch (IOException ignore) { // just ignore } finally { if (jar != null) { try { jar.close(); } catch (IOException ignore) { // just ignore as this is less probably to happen. } } } if (bundleSymbolicName == null) { bundleSymbolicName = defaultBundleSymbolicName; } else { // remove directives like "; singleton:=true" int semicolonPos = bundleSymbolicName.indexOf(";"); if (semicolonPos > 0) { bundleSymbolicName = bundleSymbolicName.substring(0, semicolonPos); } } if (bundleVersion == null) { bundleVersion = "0.0.0"; } return bundleSymbolicName + "_" + bundleVersion + ".jar"; }
From source file:massbank.admin.VersionManager.java
/** * jart@Co?[W?//from w w w. java 2 s.c o m * @param path t@CpX * @return o?[W? */ private VersionInfo getVerJarFile(String path) { VersionInfo verInfo = null; try { // }jtFXgo?[W? JarFile jar = new JarFile(new File(path)); Manifest manifest = jar.getManifest(); Attributes attributes = manifest.getMainAttributes(); String item1 = attributes.getValue("Implementation-Version"); if (item1 == null) { item1 = "-"; } // Xy?[X?o?[Wt?o String[] item2 = item1.trim().split(" "); String ver = item2[0]; String date = "-"; if (item2.length > 1) { date = item2[1]; } verInfo = new VersionInfo(null, ver, date); } catch (Exception e) { e.printStackTrace(); } return verInfo; }
From source file:org.fusesource.mop.MOP.java
protected void setClassNameFromExecutableJar(List<File> dependencies) throws Exception, UsageException { // now lets figure out the className from the manifest // lets assume that the first file in the dependency list is usually the one we want to execute for (File file : dependencies) { JarFile jar = new JarFile(file); Manifest manifest = jar.getManifest(); if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); if (attributes != null) { //debug("file " + file + " has main attributes: " + new HashMap(attributes)); className = attributes.getValue(Attributes.Name.MAIN_CLASS); if (className != null && className.length() > 0) { className = className.trim(); if (className.length() > 0) { break; }/*w w w .j ava2 s .c o m*/ } } else { LOG.debug("file " + file + " has no manifest main attributes: " + attributes); } } else { LOG.debug("file " + file + " has no manifest"); } } if (className == null) { throw new Exception("No Main-Class attribute could be found in the dependent jars!"); } }
From source file:runtime.starter.MPJRun.java
/** * Parses the input .../*from www . j av a 2s . co m*/ */ private void processInput(String args[]) { if (args.length < 1) { printUsage(); System.exit(0); } boolean parallelProgramNotYetEncountered = true; for (int i = 0; i < args.length; i++) { if (args[i].equals("-np")) { try { nprocs = new Integer(args[i + 1]).intValue(); if (nprocs < 1) { System.out.println("Number of Processes should be equal to or greater than 1"); System.out.println("exiting ..."); System.exit(0); } } catch (NumberFormatException e) { nprocs = Runtime.getRuntime().availableProcessors(); } i++; } else if (args[i].equals("-h")) { printUsage(); System.exit(0); } else if (args[i].equals("-dport")) { D_SER_PORT = new Integer(args[i + 1]).intValue(); i++; } else if (args[i].equals("-dev")) { deviceName = args[i + 1]; i++; if (!(deviceName.equals("niodev") || deviceName.equals("hybdev") || deviceName.equals("mxdev") || deviceName.equals("multicore"))) { System.out.println("MPJ Express currently does not support the <" + deviceName + "> device."); System.out.println( "Possible options are niodev, hybdev, mxdev, native, and " + "multicore devices."); System.out.println("exiting ..."); System.exit(0); } } else if (args[i].equals("-machinesfile")) { machinesFile = args[i + 1]; i++; } else if (args[i].equals("-wdir")) { wdir = args[i + 1]; i++; } else if (args[i].equals("-psl")) { psl = new Integer(args[i + 1]).intValue(); i++; } else if (args[i].equals("-mxboardnum")) { mxBoardNum = new Integer(args[i + 1]).intValue(); i++; } else if (args[i].equals("-cp") | args[i].equals("-classpath")) { jvmArgs.add("-cp"); jvmArgs.add(args[i + 1]); i++; } else if (args[i].equals("-jar")) { File tFile = new File(args[i + 1]); String absJarPath = tFile.getAbsolutePath(); if (tFile.exists()) { applicationClassPathEntry = new String(absJarPath); try { JarFile jarFile = new JarFile(absJarPath); Attributes attr = jarFile.getManifest().getMainAttributes(); className = attr.getValue(Attributes.Name.MAIN_CLASS); } catch (IOException ioe) { ioe.printStackTrace(); } parallelProgramNotYetEncountered = false; i++; } else { throw new MPJRuntimeException("mpjrun cannot find the jar file <" + args[i + 1] + ">. Make sure this is the right path."); } } else if (args[i].equals("-src")) { this.zippedSource = true; } else if (args[i].equals("-debug")) { DEBUG_PORT = new Integer(args[i + 1]).intValue(); i++; ADEBUG = true; } else if (args[i].equals("-profile")) { APROFILE = true; } else { // these are JVM options .. if (parallelProgramNotYetEncountered) { if (args[i].startsWith("-")) { jvmArgs.add(args[i]); } else { // This code takes care of executing class files // directly .... // although does not look like it .... applicationClassPathEntry = System.getProperty("user.dir"); className = args[i]; parallelProgramNotYetEncountered = false; } } // these have to be app arguments ... else { appArgs.add(args[i]); } } } jArgs = jvmArgs.toArray(new String[0]); aArgs = appArgs.toArray(new String[0]); if (DEBUG && logger.isDebugEnabled()) { logger.debug("###########################"); logger.debug("-dport: <" + D_SER_PORT + ">"); logger.debug("-np: <" + nprocs + ">"); logger.debug("$MPJ_HOME: <" + mpjHomeDir + ">"); logger.debug("-dir: <" + wdir + ">"); logger.debug("-dev: <" + deviceName + ">"); logger.debug("-psl: <" + psl + ">"); logger.debug("jvmArgs.length: <" + jArgs.length + ">"); logger.debug("className : <" + className + ">"); logger.debug("applicationClassPathEntry : <" + applicationClassPathEntry + ">"); for (int i = 0; i < jArgs.length; i++) { if (DEBUG && logger.isDebugEnabled()) logger.debug(" jvmArgs[" + i + "]: <" + jArgs[i] + ">"); } if (DEBUG && logger.isDebugEnabled()) logger.debug("appArgs.length: <" + aArgs.length + ">"); for (int i = 0; i < aArgs.length; i++) { if (DEBUG && logger.isDebugEnabled()) logger.debug(" appArgs[" + i + "]: <" + aArgs[i] + ">"); } if (DEBUG && logger.isDebugEnabled()) logger.debug("###########################"); } }