Example usage for java.util.jar Attributes.Name toString

List of usage examples for java.util.jar Attributes.Name toString

Introduction

In this page you can find the example usage for java.util.jar Attributes.Name toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:ezbake.deployer.utilities.VersionHelper.java

private static String getVersionFromManifest(File artifact) throws IOException {
    String versionNumber = null;/*www  .  j av a2s . co  m*/
    try (JarFile jar = new JarFile(artifact)) {
        Manifest manifest = jar.getManifest();
        Attributes attributes = manifest.getMainAttributes();
        if (attributes != null) {
            for (Object o : attributes.keySet()) {
                Attributes.Name key = (Attributes.Name) o;
                String keyword = key.toString();
                if (keyword.equals("Implementation-Version") || keyword.equals("Bundle-Version")) {
                    versionNumber = (String) attributes.get(key);
                    break;
                }
            }
        }
    }
    return versionNumber;
}

From source file:com.commercehub.dropwizard.BuildInfoServlet.java

@Override
public void init(ServletConfig config) {
    objectWriter = new ObjectMapper().writer();

    cacheControl = new CacheControl();
    cacheControl.setMustRevalidate(true);
    cacheControl.setNoCache(true);/*from w w w  . j a va  2 s.c  o m*/
    cacheControl.setNoStore(true);

    // cache build information
    manifestAttributes = new Properties();
    ImmutableSet<String> attributeBlacklist = getAttributeBlacklist(config);
    try {
        Enumeration<URL> resources = getClass().getClassLoader().getResources(JarFile.MANIFEST_NAME);
        if (resources != null) {
            while (resources.hasMoreElements()) {
                Manifest manifest = new Manifest(resources.nextElement().openStream());
                Attributes attributes = manifest.getMainAttributes();
                for (Object key : attributes.keySet()) {
                    Attributes.Name attrName = (Attributes.Name) key;
                    if (!attributeBlacklist.contains(attrName.toString())) {
                        manifestAttributes.setProperty(attrName.toString(), attributes.getValue(attrName));
                    }
                }
            }
        }
    } catch (IOException e) {
        log.warn("Unable to retrieve build info", e);
    }
}

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;
            }//from  w w  w .ja  v a 2  s. c  om
        }
    }
    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;

}