Example usage for java.util.jar Manifest getAttributes

List of usage examples for java.util.jar Manifest getAttributes

Introduction

In this page you can find the example usage for java.util.jar Manifest getAttributes.

Prototype

public Attributes getAttributes(String name) 

Source Link

Document

Returns the Attributes for the specified entry name.

Usage

From source file:org.apache.hive.beeline.BeeLine.java

String getManifestAttribute(String name) {
    try {/*from   ww  w .  j  a  v  a2 s  . c  o m*/
        Manifest m = getManifest();
        if (m == null) {
            return "??";
        }

        Attributes attrs = m.getAttributes("beeline");
        if (attrs == null) {
            return "???";
        }

        String val = attrs.getValue(name);
        if (val == null || "".equals(val)) {
            return "????";
        }

        return val;
    } catch (Exception e) {
        e.printStackTrace(errorStream);
        return "?????";
    }
}

From source file:org.docx4j.jaxb.Context.java

public static void searchManifestsForJAXBImplementationInfo(ClassLoader loader) {
    Enumeration resEnum;//from ww  w.  j a  v  a  2 s.  c  o m
    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.echocat.nodoodle.classloading.FileClassLoader.java

private boolean isSealed(String name, Manifest man) {
    final String path = name.replace('.', '/').concat("/");
    Attributes attr = man.getAttributes(path);
    String sealed = null;// ww w  . j a va  2  s.  c om
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}

From source file:org.echocat.nodoodle.classloading.FileClassLoader.java

/**
 * This is a copy of {@link URLClassLoader#getPermissions(CodeSource)}.
 *
 * Defines a new package by name in this ClassLoader. The attributes contained in the specified Manifest will be used to obtain package version and sealing
 * information. For sealed packages, the additional URL specifies the code source URL from which the package was loaded.
 *
 * @param name the package name/*from   w ww .  j  a v a2  s .c  o m*/
 * @param man the Manifest containing package version and sealing information
 * @param url the code source url for the package, or null if none
 * @return the newly defined Package object
 * @throws IllegalArgumentException if the package name duplicates an existing package either in this class loader or one of its ancestors
 */
protected Package definePackage(String name, Manifest man, URL url) throws IllegalArgumentException {
    final String path = name.replace('.', '/').concat("/");
    String specTitle = null;
    String specVersion = null;
    String specVendor = null;
    String implTitle = null;
    String implVersion = null;
    String implVendor = null;
    String sealed = null;
    URL sealBase = null;

    Attributes attr = man.getAttributes(path);
    if (attr != null) {
        specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
        specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
        specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
        implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
        implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
        implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
        sealed = attr.getValue(Name.SEALED);
    }
    attr = man.getMainAttributes();
    if (attr != null) {
        if (specTitle == null) {
            specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
        }
        if (specVersion == null) {
            specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
        }
        if (specVendor == null) {
            specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
        }
        if (implTitle == null) {
            implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
        }
        if (implVersion == null) {
            implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
        }
        if (implVendor == null) {
            implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
        }
        if (sealed == null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    if ("true".equalsIgnoreCase(sealed)) {
        sealBase = url;
    }
    return definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor,
            sealBase);
}

From source file:org.jboss.windup.decorator.archive.ManifestDecorator.java

protected String extractValue(Manifest mf, List<String> priority) {
    String val = findValueInAttribute(mf.getMainAttributes(), priority);
    if (StringUtils.isNotBlank(val)) {
        return val;
    }//w  w w .ja  v a  2  s.c o m
    // prepare the fallback attributes, ordered by name...
    List<String> attributeNames = new ArrayList<String>(mf.getEntries().keySet());
    Collections.sort(attributeNames);

    for (String attributeName : attributeNames) {
        val = findValueInAttribute(mf.getAttributes(attributeName), priority);

        if (StringUtils.isNotBlank(val)) {
            return val;
        }
    }

    return null;
}

From source file:org.jboss.windup.decorator.archive.ManifestVersionMapperDecorator.java

protected boolean matchesAll(Manifest mf) {
    boolean matched = false;

    // check the main attributes....
    matched = matchAttributes(mf.getMainAttributes());

    // if this doesn't match the main attributes, go through attribute groups trying to match.
    if (!matched) {
        // prepare the fallback attributes, ordered by name...
        List<String> attributeNames = new ArrayList<String>(mf.getEntries().keySet());
        Collections.sort(attributeNames);

        for (String attributeName : attributeNames) {
            matched = matchAttributes(mf.getAttributes(attributeName));

            if (matched) {
                return true;
            }//from   w  w w .  ja v a2s  .co m
        }
    }

    return matched;
}

From source file:org.lockss.plugin.PluginManager.java

/**
 * Given a file representing a JAR, retrieve a list of available
 * plugin classes to load.//  w  ww .java2  s .c o m
 */
private List<String> getJarPluginClasses(File blessedJar) throws IOException {
    JarFile jar = new JarFile(blessedJar);
    Manifest manifest = jar.getManifest();
    Map entries = manifest.getEntries();
    List<String> plugins = new ArrayList<String>();

    for (Iterator manIter = entries.keySet().iterator(); manIter.hasNext();) {
        String key = (String) manIter.next();

        Attributes attrs = manifest.getAttributes(key);

        if (attrs.containsKey(LOADABLE_PLUGIN_ATTR)) {
            String s = StringUtil.replaceString(key, "/", ".");

            String pluginName = null;

            if (StringUtil.endsWithIgnoreCase(key, ".class")) {
                pluginName = StringUtil.replaceString(s, ".class", "");
                log.debug2("Adding '" + pluginName + "' to plugin load list.");
                plugins.add(pluginName);
            } else if (StringUtil.endsWithIgnoreCase(key, ".xml")) {
                pluginName = StringUtil.replaceString(s, ".xml", "");
                log.debug2("Adding '" + pluginName + "' to plugin load list.");
                plugins.add(pluginName);
            }
        }

    }

    jar.close();

    return plugins;
}

From source file:org.pentaho.reporting.libraries.base.versioning.VersionHelper.java

/**
 * Looks up the attributes for the given module specified by <code>name</code> in the given Manifest.
 *
 * @param props the manifest where to search for the attributes.
 * @param name  the name of the module.//  w ww.  j a  v  a2s . c  om
 * @return the attributes for the module or the main attributes if the jar contains no such module.
 */
private Attributes getAttributes(final Manifest props, final String name) {
    final Attributes attributes = props.getAttributes(name);
    if (attributes == null) {
        return props.getMainAttributes();
    }
    return attributes;
}

From source file:org.pepstock.jem.gwt.server.listeners.StartUp.java

/**
 * Set the jem Version//from   w  ww. j a va  2  s  .  c  o  m
 * 
 * @param contextPath
 */
private void setJemVersion(ServletContext context) {
    // reads manifest file for searching version of JEM
    InputStream fis = null;
    try {
        fis = context.getResourceAsStream(MANIFEST_FILE);
        if (fis == null) {
            throw new FileNotFoundException(MANIFEST_FILE);
        }
        Manifest manifest = new Manifest(fis);
        // gets JEM vrsion
        Attributes at = manifest.getAttributes(ConfigKeys.JEM_MANIFEST_SECTION);
        String jemVersion = at.getValue(ConfigKeys.JEM_MANIFEST_VERSION);
        // saves JEM version
        if (jemVersion != null) {
            SharedObjects.getInstance().setJemVersion(jemVersion);
        }
    } catch (FileNotFoundException e) {
        // to ignore stack trace
        LogAppl.getInstance().ignore(e.getMessage(), e);
        LogAppl.getInstance().emit(NodeMessage.JEMC184W);
    } catch (IOException e) {
        // to ignore stack trace
        LogAppl.getInstance().ignore(e.getMessage(), e);
        LogAppl.getInstance().emit(NodeMessage.JEMC184W);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
                LogAppl.getInstance().ignore(e.getMessage(), e);
            }
        }
    }

}

From source file:test.BuilderTest.java

/**
 * Check if we can create digests/* w w  w. ja v  a2  s  .  c  om*/
 * 
 * @throws Exception
 */

public static void testDigests() throws Exception {
    Builder b = new Builder();
    try {
        b.addClasspath(IO.getFile(new File(""), "jar/osgi.jar"));
        b.setExportPackage("org.osgi.framework");
        b.setProperty(Constants.DIGESTS, "MD5, SHA1");
        Jar jar = b.build();
        assertTrue(b.check());
        File f = File.createTempFile("test", ".jar");
        jar.write(f);

        Jar other = new Jar(f);
        Manifest manifest = other.getManifest();
        assertNotNull(manifest);
        Attributes attrs = manifest.getAttributes("org/osgi/framework/BundleActivator.class");
        assertNotNull(attrs);
        assertEquals("RTRhr3kadnulINegRhpmog==", attrs.getValue("MD5-Digest"));
        assertEquals("BfVfpnE3Srx/0UWwtzNecrAGf8A=", attrs.getValue("SHA-Digest"));
        other.close();
    } finally {
        b.close();
    }
}