List of usage examples for java.util.jar Manifest getMainAttributes
public Attributes getMainAttributes()
From source file:org.sablo.specification.WebComponentPackage.java
/** * @param manifest//from ww w. j av a 2 s. c o m * @return */ public static String getPackageName(Manifest manifest) { String bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLIC_NAME); if (bundleName != null && bundleName.indexOf(';') > 0) { return bundleName.substring(0, bundleName.indexOf(';')).trim(); } return bundleName; }
From source file:org.apache.oozie.action.hadoop.SparkMain.java
private static String getJarVersion(File jarFile) throws IOException { @SuppressWarnings("resource") Manifest manifest = new JarFile(jarFile).getManifest(); return manifest.getMainAttributes().getValue("Specification-Version"); }
From source file:sx.blah.discord.modules.ModuleLoader.java
/** * Gets the <code>Module-Requires</code> attribute list from the given jar file manifest. * * @param file The jar file to extract the manifest attribute from. * @return The value of the attribute./*w w w . j av a2 s .c o m*/ * @throws IOException If the jar file read operation fails. */ private static String[] getModuleRequires(File file) throws IOException { JarFile jarFile = new JarFile(file); Manifest manifest = jarFile.getManifest(); Attributes.Name moduleRequiresLower = new Attributes.Name("module-requires"); //TODO remove Attributes.Name moduleRequiresUpper = new Attributes.Name("Module-Requires"); if (manifest != null && manifest.getMainAttributes() != null //TODO remove && manifest.getMainAttributes().containsKey(moduleRequiresLower)) { String value = manifest.getMainAttributes().getValue(moduleRequiresLower); Discord4J.LOGGER.warn(LogMarkers.MODULES, "File {} uses the 'module-requires' attribute instead of 'Module-Requires', please rename the attribute!", file.getName()); return value.contains(";") ? value.split(";") : new String[] { value }; } else if (manifest != null && manifest.getMainAttributes() != null && manifest.getMainAttributes().containsKey(moduleRequiresUpper)) { String value = manifest.getMainAttributes().getValue(moduleRequiresUpper); return value.contains(";") ? value.split(";") : new String[] { value }; } else { return new String[0]; } }
From source file:org.sablo.specification.WebComponentPackage.java
public static String getPackageDisplayname(Manifest manifest) { if (manifest == null) return null; return manifest.getMainAttributes().getValue(BUNDLE_NAME); }
From source file:org.apache.sling.testing.mock.sling.NodeTypeDefinitionScanner.java
/** * Find all node type definition classpath paths by searching all MANIFEST.MF files in the classpath and reading * the paths from the "Sling-Nodetypes" entry. * The order of the paths from each entry is preserved, but the overall order when multiple bundles define such an entry * is not deterministic and may not be correct according to the dependencies between the node type definitions. * @return List of node type definition class paths *///from w w w . java2 s. c om private static List<String> findeNodeTypeDefinitions() { List<String> nodeTypeDefinitions = new ArrayList<String>(); try { Enumeration<URL> resEnum = NodeTypeDefinitionScanner.class.getClassLoader() .getResources(JarFile.MANIFEST_NAME); while (resEnum.hasMoreElements()) { try { URL url = (URL) resEnum.nextElement(); InputStream is = url.openStream(); if (is != null) { try { Manifest manifest = new Manifest(is); Attributes mainAttribs = manifest.getMainAttributes(); String nodeTypeDefinitionList = mainAttribs.getValue("Sling-Nodetypes"); String[] nodeTypeDefinitionArray = StringUtils.split(nodeTypeDefinitionList, ","); if (nodeTypeDefinitionArray != null) { for (String nodeTypeDefinition : nodeTypeDefinitionArray) { if (!StringUtils.isBlank(nodeTypeDefinition)) { nodeTypeDefinitions.add(StringUtils.trim(nodeTypeDefinition)); } } } } finally { is.close(); } } } catch (Throwable ex) { log.warn("Unable to read JAR manifest.", ex); } } } catch (IOException ex2) { log.warn("Unable to read JAR manifests.", ex2); } return nodeTypeDefinitions; }
From source file:org.orbisgis.framework.BundleTools.java
/** * Parse a Manifest in order to extract Exported Package * @param manifest Jar Manifest//from w w w .ja v a2 s.com * @param packages package array or null * @throws IOException */ public static BundleReference parseManifest(Manifest manifest, List<PackageDeclaration> packages) throws IOException { Attributes attributes = manifest.getMainAttributes(); String exports = attributes.getValue(Constants.EXPORT_PACKAGE); String versionProperty = attributes.getValue(Constants.BUNDLE_VERSION_ATTRIBUTE); Version version = null; if (versionProperty != null) { version = new Version(versionProperty); } String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME); if (packages != null) { org.apache.felix.framework.Logger logger = new org.apache.felix.framework.Logger(); // Use Apache Felix to parse the Manifest Export header List<BundleCapability> exportsCapability = ManifestParser.parseExportHeader(logger, null, exports, "0", new Version(0, 0, 0)); for (BundleCapability bc : exportsCapability) { Map<String, Object> attr = bc.getAttributes(); // If the package contain a package name and a package version if (attr.containsKey(PACKAGE_NAMESPACE)) { Version packageVersion = new Version(0, 0, 0); if (attr.containsKey(Constants.VERSION_ATTRIBUTE)) { packageVersion = (Version) attr.get(Constants.VERSION_ATTRIBUTE); } if (packageVersion.getMajor() != 0 || packageVersion.getMinor() != 0 || packageVersion.getMicro() != 0) { packages.add(new PackageDeclaration((String) attr.get(PACKAGE_NAMESPACE), packageVersion)); } else { // No version, take the bundle version packages.add(new PackageDeclaration((String) attr.get(PACKAGE_NAMESPACE), version)); } } } } return new BundleReference(symbolicName, version); }
From source file:umbrella.Umbrella.java
/** * Builds an analyzer instance based on a jar file. * @param file The jar file.// w w w . ja va 2s . c om * @param relativePath A relative path which is prepended to all elements. * @return The analyzer. * @throws IOException Occurs if reading any class path element is not possible. */ public static Analyzer getAnalyzer(@NonNull JarFile file, @NonNull String relativePath) throws IOException { // fix relative path if (relativePath == null) relativePath = ""; // grab manifest Manifest manifest = file.getManifest(); // log getLogger().debug("Searching for class-path information within the jar ..."); // get class path String classPath = manifest.getMainAttributes().getValue("Class-Path"); // search Class-Path attribute if (classPath == null) return null; // create basic analyzer Analyzer analyzer = new Analyzer(); // reset analyzer analyzer.reset(); // append all elements for (String element : Splitter.on(' ').omitEmptyStrings().splitToList(classPath)) { // create file File elementFile = new File(relativePath + element); // log getLogger().debug("Adding \"" + element + "\" to the analyzer class path."); // add adapter analyzer.addAdapter((elementFile.isDirectory() ? new ExplodedAnalyzerAdapter(elementFile) : new JarAnalyzerAdapter(new JarFile(elementFile)))); } // return finished analyzer instance return analyzer; }
From source file:org.apache.sling.testing.clients.osgi.OsgiConsoleClient.java
/** * Get the symbolic name from a bundle file * @param bundleFile//from ww w. j av a2 s.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; }
From source file:org.apache.sling.testing.clients.osgi.OsgiConsoleClient.java
/** * Get the version form a bundle file//from w w w .ja v a 2s. com * @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:ar.edu.taco.TacoMain.java
/** * //from w ww. j a v a 2s .c o m */ private static String getManifestAttribute(Name name) { String manifestAttributeValue = "Undefined"; try { String jarFileName = System.getProperty("java.class.path") .split(System.getProperty("path.separator"))[0]; JarFile jar = new JarFile(jarFileName); Manifest manifest = jar.getManifest(); Attributes mainAttributes = manifest.getMainAttributes(); manifestAttributeValue = mainAttributes.getValue(name); jar.close(); } catch (IOException e) { } return manifestAttributeValue; }