Example usage for java.util.jar Attributes getValue

List of usage examples for java.util.jar Attributes getValue

Introduction

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

Prototype

public String getValue(Name name) 

Source Link

Document

Returns the value of the specified Attributes.Name, or null if the attribute was not found.

Usage

From source file:com.smash.revolance.ui.model.application.ApplicationFactory.java

private void loadApplication(String appDir, String appId, String impl, String version) throws IOException {
    if (!appDir.isEmpty() && new File(appDir).isDirectory()) {
        Collection<File> files = FileUtils.listFiles(new File(appDir), new String[] { "jar" }, false);

        for (File file : files) {
            JarFile jar = new JarFile(file);
            Manifest manifest = jar.getManifest();
            Attributes attributes = manifest.getMainAttributes();

            String implAttr = attributes.getValue("revolance-ui-explorer-applicationImpl");
            String versionAttr = attributes.getValue("revolance-ui-explorer-applicationVersion");

            if (implAttr.contentEquals(impl) && (versionAttr.contentEquals(version) || version == null)) {
                applicationLoaders.put(getKey(appId, impl, version), new JarClassLoader(file.toURI().toURL()));
            }//  www. ja va  2 s  .c  om
        }

    }
}

From source file:org.owasp.webgoat.application.WebGoatServletListener.java

private void setApplicationVariables(ServletContext context) {
    Application app = Application.getInstance();
    try {/*ww  w  . j  av a2 s  . c o m*/
        InputStream inputStream = context.getResourceAsStream("/META-INF/MANIFEST.MF");
        Manifest manifest = new Manifest(inputStream);
        Attributes attr = manifest.getMainAttributes();
        String name = attr.getValue("Specification-Title");
        String version = attr.getValue("Specification-Version");
        String build = attr.getValue("Implementation-Version");
        app.setName(name);
        app.setVersion(version);
        app.setBuild(build);
    } catch (IOException ioe) {
        context.log("Error setting application variables", ioe);
    }
}

From source file:com.kaylerrenslow.armaDialogCreator.updater.tasks.AdcVersionCheckTask.java

private String getCurrentJarVersion() throws Exception {
    setStatusText("Updater.getting_current_version");
    if (!adcJarSave.exists()) {
        return "";
    }//from   ww  w .  j  a  va  2 s  . co m
    Manifest m = new JarFile(adcJarSave).getManifest();
    Attributes manifestAttributes = m.getMainAttributes();
    return manifestAttributes.getValue("Specification-Version");
}

From source file:com.ikon.util.cl.FilesystemClassLoader.java

/**
 * Get main class name//from   www  .j  av a  2 s  .c o m
 */
@Override
public String getMainClassName() throws IOException {
    log.debug("getMainClassName()");
    File mf = new File(file, "META-INF/MANIFEST.MF");
    FileInputStream fis = null;

    try {
        if (mf.exists() && mf.canRead()) {
            fis = new FileInputStream(mf);
            Manifest manif = new Manifest(fis);
            Attributes attr = manif.getMainAttributes();
            return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
        }
    } finally {
        IOUtils.closeQuietly(fis);
    }

    return null;
}

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

private String findValueInAttribute(Attributes attribute, List<String> priority) {
    if (priority != null) {
        for (String key : priority) {
            String val = attribute.getValue(key);
            if (StringUtils.isNotBlank(val)) {
                return val;
            }//from   www  .ja  v a  2 s  . c  o  m
        }
    }
    return null;
}

From source file:org.nosphere.honker.deptree.DepTreeManifestLoader.java

private DepTreeData.Manifest loadData(java.util.jar.Manifest mf) {
    Attributes attr = mf.getMainAttributes();
    String name = attr.getValue("Bundle-Name");
    if (name == null) {
        name = attr.getValue("Implementation-Title");
    }/* w w w.  ja va 2 s.  com*/
    if (name == null) {
        name = attr.getValue("Bundle-SymbolicName");
    }
    String version = attr.getValue("Bundle-Version");
    if (version == null) {
        version = attr.getValue("Implementation-Version");
    }
    if (version == null) {
        version = attr.getValue("Specification-Version");
    }
    String vendor = attr.getValue("Bundle-Vendor");
    if (vendor == null) {
        vendor = attr.getValue("Implementation-Vendor");
    }
    String url = attr.getValue("Bundle-DocURL");
    String license = attr.getValue("Bundle-License");
    if (license != null && license.contains(";")) {
        String[] licenseItems = license.split(";");
        for (String licenseItem : licenseItems) {
            String trimmed = licenseItem.trim();
            if (!trimmed.contains("=")) {
                license = trimmed;
                break;
            }
            if (trimmed.startsWith("link=")) {
                trimmed = trimmed.substring(5, trimmed.length());
                if (trimmed.startsWith("\"") || trimmed.startsWith("'")) {
                    trimmed = trimmed.substring(1, trimmed.length() - 1);
                }
                license = trimmed;
                break;
            }
        }
    }
    return new DepTreeData.Manifest(name, version, vendor, url, license);
}

From source file:com.xebialabs.deployit.cli.ext.mustachify.dar.DarManifestParser.java

private static DarManifest parse(Manifest manifest) {
    Attributes mainAttributes = manifest.getMainAttributes();
    validate(mainAttributes);//  w  ww. j  a va2s  .  c o m

    Iterable<DarManifestEntry> darEntries = filter(transform(manifest.getEntries().entrySet(),
            new Function<Entry<String, Attributes>, DarManifestEntry>() {
                @Override
                public DarManifestEntry apply(Entry<String, Attributes> input) {
                    String entryName = input.getKey();
                    Attributes entryAttributes = input.getValue();
                    return (DarManifestEntry.isDarEntry(entryName, entryAttributes)
                            ? DarManifestEntry.fromEntryAttributes(entryName, entryAttributes)
                            : DarManifestEntry.NULL);
                }
            }), not(new Predicate<Object>() {
                @Override
                public boolean apply(Object input) {
                    return (input == DarManifestEntry.NULL);
                }
            }));
    return new DarManifest(mainAttributes.getValue(APPLICATION_ATTRIBUTE_NAME),
            mainAttributes.getValue(VERSION_ATTRIBUTE_NAME), copyOf(darEntries));
}

From source file:eu.chocolatejar.eclipse.plugin.cleaner.Main.java

/**
 * Read version from jar manifest, if it fails the exception is swallow and
 * empty string is returned//w ww . j a  va 2  s .com
 */
private String getImplementationVersion() {
    try {
        URLClassLoader cl = (URLClassLoader) Main.class.getClassLoader();
        URL url = cl.findResource("META-INF/MANIFEST.MF");
        Manifest manifest = new Manifest(url.openStream());
        Attributes mainAttribs = manifest.getMainAttributes();
        String version = mainAttribs.getValue("Implementation-Version");
        if (version != null) {
            return version;
        }
    } catch (Exception e) {
        logger.trace("Unable to read a manifest version of this program.", e);
    }
    return "X.X.X.X";
}

From source file:org.cleverbus.core.common.version.impl.ManifestVersionInfoSource.java

private String getVersion(Attributes attrs) {
    String title = attrs.getValue(ATTR_VERSION);
    if (title == null) {
        title = attrs.getValue(ATTR_BUNDLE_VERSION);
    }/*from w w w.j a  v a  2 s . c o  m*/
    return title;
}

From source file:org.cleverbus.core.common.version.impl.ManifestVersionInfoSource.java

private String getTitle(Attributes attrs) {
    String title = attrs.getValue(ATTR_TITLE);
    if (title == null) {
        title = attrs.getValue(ATTR_BUNDLE_NAME);
    }//from  w w  w.j a v  a2s.  co m
    return title;
}