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:org.jumpmind.util.AbstractVersion.java

protected Attributes findManifestAttributes() {
    InputStream is = null;//from  w  w  w . j a v a  2 s. c om
    try {
        Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
        while (resources.hasMoreElements()) {
            is = resources.nextElement().openStream();
            Manifest manifest = new Manifest(is);
            Attributes attributes = manifest.getMainAttributes();
            if (getArtifactName().equals(attributes.getValue("Project-Artifact"))) {
                return attributes;
            }
        }
    } catch (IOException e) {
        // nothing to do, really
    } finally {
        IOUtils.closeQuietly(is);
    }
    return null;
}

From source file:org.jumpmind.util.AbstractVersion.java

public long getBuildTime() {
    if (buildTime == -1) {
        Attributes attributes = findManifestAttributes();
        try {/* ww  w.  jav  a 2  s . c  o m*/
            buildTime = Long.parseLong(attributes.getValue("Build-Time").split("-")[0]);
        } catch (Exception e) {
            buildTime = 0;
        }
    }
    return buildTime;
}

From source file:org.jumpmind.util.AbstractVersion.java

public String version() {
    if (version == null) {
        Attributes attributes = findManifestAttributes();
        if (attributes != null) {
            version = attributes.getValue("Build-Version");
        } else {/*from   w w  w.ja  v a 2s. c o  m*/
            File gradleProperties = new File("../symmetric-assemble/gradle.properties");
            if (gradleProperties.exists()) {
                TypedProperties props = new TypedProperties(gradleProperties);
                version = props.get("version");
            } else {
                version = "development";
            }
        }
    }
    return version;
}

From source file:com.mgmtp.perfload.core.console.meta.LtMetaInfoHandler.java

/**
 * Dumps the specified meta information to specified writer.
 * /*from  w  w w  .jav a 2s .  com*/
 * @param metaInfo
 *            the meta information object
 * @param writer
 *            the writer
 */
public void dumpMetaInfo(final LtMetaInfo metaInfo, final Writer writer) {
    PrintWriter pr = new PrintWriter(writer);

    URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
    if (url.getPath().endsWith(".jar")) {
        try {
            JarFile jarFile = new JarFile(toFile(url));
            Manifest mf = jarFile.getManifest();
            Attributes attr = mf.getMainAttributes();
            pr.printf("perfload.implementation.version=%s", attr.getValue("Implementation-Version"));
            pr.println();
            pr.printf("perfload.implementation.date=%s", attr.getValue("Implementation-Date"));
            pr.println();
            pr.printf("perfload.implementation.revision=%s", attr.getValue("Implementation-Revision"));
            pr.println();
        } catch (IOException ex) {
            log.error(ex.getMessage(), ex);
        }
    }

    pr.printf("test.file=%s", metaInfo.getTestplanFileName());
    pr.println();

    pr.printf("test.start=%s", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(metaInfo.getStartTimestamp()));
    pr.println();
    pr.printf("test.finish=%s", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(metaInfo.getFinishTimestamp()));
    pr.println();

    List<Daemon> daemonList = metaInfo.getDaemons();
    Collections.sort(daemonList);

    for (Daemon daemon : daemonList) {
        pr.printf("daemon.%d=%s:%d", daemon.getId(), daemon.getHost(), daemon.getPort());
        pr.println();
    }

    List<String> lpTargets = metaInfo.getLpTargets();
    if (!lpTargets.isEmpty()) {
        Collections.sort(lpTargets);
        pr.printf("targets=%s", on(',').join(lpTargets));
        pr.println();
    }

    List<String> lpOperations = metaInfo.getLpOperations();
    if (!lpOperations.isEmpty()) {
        Collections.sort(lpOperations);
        pr.printf("operations=%s", on(',').join(lpOperations));
        pr.println();
    }

    List<Executions> executionsList = metaInfo.getExecutionsList();
    Collections.sort(executionsList);
    for (Executions executions : executionsList) {
        pr.printf("executions.%s.%s=%d", executions.operation, executions.target, executions.executions);
        pr.println();
    }
}

From source file:com.googlecode.idea.red5.SelectRed5LocationDialog.java

private String getVersion() {
    String home = homeDir.getText();
    if (home.length() == 0) {
        return EMPTY;
    }//ww w  .java 2  s  .  c  om
    @NonNls
    final String pathToRed5Jar = new StringBuilder().append(home).append(separator).append("red5.jar")
            .toString();
    File red5 = new File(pathToRed5Jar);
    if (red5.exists()) {
        try {
            JarFile jar = new JarFile(pathToRed5Jar);
            Manifest manifest = jar.getManifest();
            Attributes attrs = manifest.getAttributes("");
            if (attrs != null) {
                String version = attrs.getValue("Red5-Version");
                if (version.startsWith("0.7")) {
                    logger.debug("Setting to version 0.7.");
                    return VERSION_DOT_SEVEN;
                } else if (version.startsWith("0.6")) {
                    logger.debug("Setting to version 0.6.");
                    return VERSION_DOT_SIX;
                }
            }
        } catch (IOException e) {
            logger.error("No version found! Returning the default.");
        }
    }
    return VERSION_DOT_EIGHT;
}

From source file:org.kuali.student.common.util.ManifestInspector.java

/**
 * Examine the manifest provided for build information. Returns null if manifest is null
 *///w w  w .j a  v  a2s .com
protected BuildInformation getBuildInformation(Manifest manifest) {
    // No Manifest is available
    if (manifest == null) {
        return null;
    }

    // Extract the attributes
    Attributes attributes = manifest.getMainAttributes();

    // Manifest attributes containing the build information
    String name = attributes.getValue(BUNDLE_NAME);
    String version = attributes.getValue(BUNDLE_VERSION);
    String buildNumber = attributes.getValue(BUNDLE_BUILD_NUMBER);
    String timestamp = attributes.getValue(BUNDLE_TIMESTAMP);

    // Create and populate a BuildInformation object
    BuildInformation bi = new BuildInformation();
    bi.setName(name);
    bi.setVersion(version);
    bi.setBuildNumber(buildNumber);
    bi.setTimestamp(timestamp);
    return bi;
}

From source file:com.liferay.ide.project.core.modules.ServiceWrapperCommand.java

private void _getServiceWrapperList(Map<String, String[]> wrapperMap, String name,
        JarInputStream jarInputStream) {
    if (name.endsWith("ServiceWrapper.class") && !name.contains("$")) {
        name = name.replaceAll("\\\\", ".").replaceAll("/", ".");

        name = name.substring(0, name.lastIndexOf("."));

        Attributes mainAttributes = jarInputStream.getManifest().getMainAttributes();

        String bundleName = mainAttributes.getValue("Bundle-SymbolicName");
        String version = mainAttributes.getValue("Bundle-Version");

        String group = "";

        if (bundleName.equals("com.liferay.portal.kernel")) {
            group = "com.liferay.portal";
        } else {/*from w w w  . j ava  2s .  co m*/
            int ordinalIndexOf = StringUtils.ordinalIndexOf(bundleName, ".", 2);

            if (ordinalIndexOf != -1) {
                group = bundleName.substring(0, ordinalIndexOf);
            }
        }

        wrapperMap.put(name, new String[] { group, bundleName, version });
    }
}

From source file:hudson.plugins.simpleupdatesite.HPI.java

public String getBuiltBy(Attributes attributes) throws IOException {
    return attributes.getValue("Built-By");
}

From source file:org.sonar.updatecenter.common.PluginManifest.java

private void loadManifest(Manifest manifest) {
    Attributes attributes = manifest.getMainAttributes();
    this.key = attributes.getValue(KEY);
    this.mainClass = attributes.getValue(MAIN_CLASS);
    this.name = attributes.getValue(NAME);
    this.description = attributes.getValue(DESCRIPTION);
    this.license = attributes.getValue(LICENSE);
    this.organization = attributes.getValue(ORGANIZATION);
    this.organizationUrl = attributes.getValue(ORGANIZATION_URL);
    this.version = attributes.getValue(VERSION);
    this.homepage = attributes.getValue(HOMEPAGE);
    this.termsConditionsUrl = attributes.getValue(TERMS_CONDITIONS_URL);
    this.sonarVersion = attributes.getValue(SONAR_VERSION);
    this.issueTrackerUrl = attributes.getValue(ISSUE_TRACKER_URL);
    this.buildDate = toDate(attributes.getValue(BUILD_DATE), true);

    String deps = attributes.getValue(DEPENDENCIES);
    this.dependencies = StringUtils.split(StringUtils.defaultString(deps), ' ');
}

From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginOSGiManifestTest.java

private String valueFor(final String prefix) throws IOException {
    if (!manifestFile.exists()) {
        return null;
    }/*from www  .java 2s  .c  o m*/

    FileInputStream manifestInputStream = new FileInputStream(manifestFile);
    Manifest manifest = new Manifest(manifestInputStream);
    Attributes entries = manifest.getMainAttributes();

    return entries.getValue(prefix);
}