List of usage examples for java.util.jar Attributes getValue
public String getValue(Name name)
From source file:org.eclipse.jdt.ls.core.internal.handlers.BundleUtils.java
private static BundleInfo getBundleInfo(String bundleLocation) throws IOException { try (JarFile jarFile = new JarFile(bundleLocation)) { Manifest manifest = jarFile.getManifest(); if (manifest != null) { Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes != null) { String bundleVersion = mainAttributes.getValue(Constants.BUNDLE_VERSION); if (StringUtils.isBlank(bundleVersion)) { return null; }/*from w w w . j a v a2 s . co m*/ String symbolicName = mainAttributes.getValue(Constants.BUNDLE_SYMBOLICNAME); if (StringUtils.isNotBlank(symbolicName) && symbolicName.indexOf(';') >= 0) { symbolicName = symbolicName.substring(0, symbolicName.indexOf(';')); } return new BundleInfo(bundleVersion, symbolicName); } } } return null; }
From source file:org.broadleafcommerce.common.extensibility.InstrumentationRuntimeFactory.java
private static boolean validateAgentJarManifest(File agentJarFile, String agentClassName) { try {/*w w w .j a va 2 s .com*/ JarFile jar = new JarFile(agentJarFile); Manifest manifest = jar.getManifest(); if (manifest == null) { return false; } Attributes attributes = manifest.getMainAttributes(); String ac = attributes.getValue("Agent-Class"); if (ac != null && ac.equals(agentClassName)) { return true; } } catch (Exception e) { if (LOG.isTraceEnabled()) { LOG.trace("Unexpected exception occured.", e); } } return false; }
From source file:org.jahia.data.templates.ModulesPackage.java
private static Set<String> parseDependencies(Attributes manifestAttributes) { Set<String> dependencies = Collections.emptySet(); String dependsValue = manifestAttributes.getValue(Constants.ATTR_NAME_JAHIA_DEPENDS); if (dependsValue != null && dependsValue.length() > 0) { dependencies = new LinkedHashSet<>(); dependencies.addAll(Arrays.asList(StringUtils.split(dependsValue, ", "))); }//from w ww . j a v a2 s. c o m return dependencies; }
From source file:com.sinosoft.one.mvc.scanning.ResourceRef.java
public static ResourceRef toResourceRef(Resource folder) throws IOException { ResourceRef rr = new ResourceRef(folder, null, null); String[] modifiers = null;// w ww.j a v a2 s . com Resource mvcPropertiesResource = rr.getInnerResource("META-INF/mvc.properties"); if (mvcPropertiesResource.exists()) { if (logger.isDebugEnabled()) { logger.debug("found mvc.properties: " + mvcPropertiesResource.getURI()); } InputStream in = mvcPropertiesResource.getInputStream(); rr.properties.load(in); in.close(); String attrValue = rr.properties.getProperty("mvc"); if (attrValue == null) { attrValue = rr.properties.getProperty("Mvc"); } 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("mvc"); if (attrValue == null) { attrValue = attributes.getValue("Mvc"); } 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:com.gzj.tulip.load.ResourceRef.java
public static ResourceRef toResourceRef(Resource folder) throws IOException { ResourceRef rr = new ResourceRef(folder, null, null); String[] modifiers = null;// w w w .ja v a 2 s .c om 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.docx4j.jaxb.Context.java
public static void searchManifestsForJAXBImplementationInfo(ClassLoader loader) { Enumeration resEnum;/*from www . j a va 2 s. c om*/ try { resEnum = loader.getResources(JarFile.MANIFEST_NAME); while (resEnum.hasMoreElements()) { InputStream is = null; try { URL url = (URL) resEnum.nextElement(); // System.out.println("\n\n" + url); is = url.openStream(); if (is != null) { Manifest manifest = new Manifest(is); Attributes mainAttribs = manifest.getMainAttributes(); String impTitle = mainAttribs.getValue("Implementation-Title"); if (impTitle != null && impTitle.contains("JAXB Reference Implementation") || impTitle.contains("org.eclipse.persistence")) { log.info("\n" + url); for (Object key2 : mainAttribs.keySet()) { log.info(key2 + " : " + mainAttribs.getValue((java.util.jar.Attributes.Name) key2)); } } // In 2.1.3, it is in here for (String key : manifest.getEntries().keySet()) { //System.out.println(key); if (key.equals("com.sun.xml.bind.v2.runtime")) { log.info("Found JAXB reference implementation in " + url); mainAttribs = manifest.getAttributes((String) key); for (Object key2 : mainAttribs.keySet()) { log.info(key2 + " : " + mainAttribs.getValue((java.util.jar.Attributes.Name) key2)); } } } } } catch (Exception e) { // Silently ignore // log.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(is); } } } catch (IOException e1) { // Silently ignore // log.error(e1); } }
From source file:org.apache.hadoop.util.TestClasspath.java
/** * Asserts that the specified file is a jar file with a manifest containing a * non-empty classpath attribute.//from w w w . j a v a 2s . c o m * * @param file File to check * @throws IOException if there is an I/O error */ private static void assertJar(File file) throws IOException { JarFile jarFile = null; try { jarFile = new JarFile(file); Manifest manifest = jarFile.getManifest(); assertNotNull(manifest); Attributes mainAttributes = manifest.getMainAttributes(); assertNotNull(mainAttributes); assertTrue(mainAttributes.containsKey(Attributes.Name.CLASS_PATH)); String classPathAttr = mainAttributes.getValue(Attributes.Name.CLASS_PATH); assertNotNull(classPathAttr); assertFalse(classPathAttr.isEmpty()); } finally { // It's too bad JarFile doesn't implement Closeable. if (jarFile != null) { try { jarFile.close(); } catch (IOException e) { LOG.warn("exception closing jarFile: " + jarFile, e); } } } }
From source file:org.hyperic.util.PluginLoader.java
public static String getPluginMainClass(URL url) throws Exception { JarURLConnection jarConn = (JarURLConnection) url.openConnection(); Attributes attrs = jarConn.getMainAttributes(); String pluginName = attrs.getValue(Attributes.Name.MAIN_CLASS); return pluginName; }
From source file:de.uzk.hki.da.utils.Utilities.java
public static String getBuildNumber() { String buildNumber = "fakeBuildNumber"; try {/*from w w w . j av a 2 s . c o m*/ JarFile file = null; Manifest mf = null; file = new JarFile(new File( Utilities.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath())); mf = file.getManifest(); Attributes attr = mf.getMainAttributes(); buildNumber = attr.getValue("buildNumber"); } catch (Exception e) { logger.debug("Can not extract the build number from "); } return buildNumber; }
From source file:org.apache.axiom.util.stax.dialect.StAXDialectDetector.java
private static StAXDialect detectDialectFromJarManifest(URL rootUrl) { Manifest manifest;//from w w w. j a v a 2s . com try { URL metaInfUrl = new URL(rootUrl, "META-INF/MANIFEST.MF"); InputStream is = metaInfUrl.openStream(); try { manifest = new Manifest(is); } finally { is.close(); } } catch (IOException ex) { log.warn("Unable to load manifest for StAX implementation at " + rootUrl); return UnknownStAXDialect.INSTANCE; } Attributes attrs = manifest.getMainAttributes(); String title = attrs.getValue(IMPLEMENTATION_TITLE); String symbolicName = attrs.getValue(BUNDLE_SYMBOLIC_NAME); if (symbolicName != null) { int i = symbolicName.indexOf(';'); if (i != -1) { symbolicName = symbolicName.substring(0, i); } } String vendor = attrs.getValue(IMPLEMENTATION_VENDOR); if (vendor == null) { vendor = attrs.getValue(BUNDLE_VENDOR); } String version = attrs.getValue(IMPLEMENTATION_VERSION); if (version == null) { version = attrs.getValue(BUNDLE_VERSION); } if (log.isDebugEnabled()) { log.debug("StAX implementation at " + rootUrl + " is:\n" + " Title: " + title + "\n" + " Symbolic name: " + symbolicName + "\n" + " Vendor: " + vendor + "\n" + " Version: " + version); } // For the moment, the dialect detection is quite simple, but in the future we will probably // have to differentiate by version number if (vendor != null && vendor.toLowerCase().indexOf("woodstox") != -1) { return WoodstoxDialect.INSTANCE; } else if (title != null && title.indexOf("SJSXP") != -1) { return new SJSXPDialect(false); } else if ("com.bea.core.weblogic.stax".equals(symbolicName)) { // Weblogic's StAX implementation doesn't support CDATA section reporting and there are // a couple of additional test cases (with respect to BEA's reference implementation) // that fail. log.warn("Weblogic's StAX implementation is unsupported and some Axiom features will not work " + "as expected! Please use Woodstox instead."); // This is the best match we can return in this case. return BEADialect.INSTANCE; } else if ("BEA".equals(vendor)) { return BEADialect.INSTANCE; } else if ("com.ibm.ws.prereq.banshee".equals(symbolicName)) { return XLXP2Dialect.INSTANCE; } else { return null; } }