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:jenkins.security.ClassFilterImpl.java

private static boolean isPluginManifest(Manifest mf) {
    Attributes attr = mf.getMainAttributes();
    return attr.getValue("Short-Name") != null
            && (attr.getValue("Plugin-Version") != null || attr.getValue("Jenkins-Version") != null)
            || "true".equals(attr.getValue("Jenkins-ClassFilter-Whitelisted"));
}

From source file:edu.cmu.tetrad.cli.util.Args.java

public static void showHelp(String algorithmName, Options options) {
    StringBuilder sb = new StringBuilder("java -jar");
    try {//  w  w w .j a  v a  2 s. c o  m
        JarFile jarFile = new JarFile(Args.class.getProtectionDomain().getCodeSource().getLocation().getPath(),
                true);
        Manifest manifest = jarFile.getManifest();
        Attributes attributes = manifest.getMainAttributes();
        String artifactId = attributes.getValue("Implementation-Title");
        String version = attributes.getValue("Implementation-Version");
        sb.append(String.format(" %s-%s.jar", artifactId, version));
    } catch (IOException exception) {
        sb.append(" causal-cmd.jar");
    }
    sb.append(" --algorithm ");
    sb.append(algorithmName);

    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(-1);
    formatter.printHelp(sb.toString(), options, true);
}

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

private static void validate(Attributes mainAttributes) {
    checkArgument(mainAttributes.containsKey(new Name(PACKAGE_FORMAT_VERSION_ATTRIBUTE_NAME)),
            "manifest does not contain required DAR attribute '%s'", PACKAGE_FORMAT_VERSION_ATTRIBUTE_NAME);
    checkArgument(/*from   ww  w .j a  v  a  2s  . co m*/
            mainAttributes.getValue(PACKAGE_FORMAT_VERSION_ATTRIBUTE_NAME)
                    .equals(SUPPORTED_PACKAGE_FORMAT_VERSION),
            "unsupported package format version '%s', only '%s' supported",
            mainAttributes.getValue(PACKAGE_FORMAT_VERSION_ATTRIBUTE_NAME), SUPPORTED_PACKAGE_FORMAT_VERSION);
    checkArgument(mainAttributes.containsKey(new Name(APPLICATION_ATTRIBUTE_NAME)),
            "manifest does not contain required DAR attribute '%s'", APPLICATION_ATTRIBUTE_NAME);
    checkArgument(mainAttributes.containsKey(new Name(VERSION_ATTRIBUTE_NAME)),
            "manifest does not contain required DAR attribute '%s'", VERSION_ATTRIBUTE_NAME);
}

From source file:io.selendroid.builder.SelendroidServerBuilder.java

public static String getJarVersionNumber() {
    Class clazz = SelendroidStandaloneDriver.class;
    String className = clazz.getSimpleName() + ".class";
    String classPath = clazz.getResource(className).toString();
    if (!classPath.startsWith("jar")) {
        // Class not from JAR
        return "dev";
    }/*  w ww .j a  v  a  2  s.  c o  m*/
    String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
    Manifest manifest = null;
    try {
        manifest = new Manifest(new URL(manifestPath).openStream());
    } catch (Exception e) {
        return "";
    }
    Attributes attr = manifest.getMainAttributes();
    String value = attr.getValue("version");
    return value;
}

From source file:org.asoem.greyfish.cli.GreyfishCLIApplication.java

private static Optional<String> getCommitHash(final Class<?> clazz) {
    try {/*  w  w w.j a  va 2 s. co  m*/
        final JarFile jarFile = Resources.getJarFile(clazz);
        final Manifest manifest = jarFile.getManifest();
        final Attributes attr = manifest.getMainAttributes();
        return Optional.of(attr.getValue("Git-Commit-Hash"));
    } catch (IOException e) {
        throw new IOError(e);
    } catch (UnsupportedOperationException e) {
        return Optional.absent();
    }
}

From source file:com.arcusys.liferay.vaadinplugin.util.ControlPanelPortletUtil.java

private static String getManifestAttribute(JarFile jarFile, String versionAttribute) throws IOException {
    Manifest manifest = jarFile.getManifest();
    if (manifest == null) {
        return null;
    }/* ww w .  j  ava 2s  .  com*/
    Attributes attr = manifest.getMainAttributes();
    String bundleName = attr.getValue("Bundle-Name");
    if (bundleName != null) {
        return attr.getValue(versionAttribute);
    }

    return null;
}

From source file:com.arcusys.liferay.vaadinplugin.util.ControlPanelPortletUtil.java

private static String getManifestAttributeForVaadin6(JarFile jarFile, String versionAttribute)
        throws IOException {
    Manifest manifest = jarFile.getManifest();
    if (manifest == null) {
        return null;
    }//from   w  w  w  .  j av a2  s  .  c om
    Attributes attr = manifest.getMainAttributes();
    String bundleName = attr.getValue("Bundle-Name");
    if (bundleName != null && bundleName.equals("Vaadin")) {
        return attr.getValue(versionAttribute);
    }

    return null;
}

From source file:org.s4i.feature.FeatureMojo.java

private static String getBundleVersion(Attributes attrs) {
    return attrs.getValue("Bundle-Version");
}

From source file:org.s4i.feature.FeatureMojo.java

private static boolean isFragment(Attributes attrs) {
    return attrs.getValue("Fragment-Host") != null;
}

From source file:org.jahia.services.modulemanager.util.ModuleUtils.java

/**
 * Checks if the artifact manifest requires adjustments in the capability headers w.r.t. module dependencies.
 *
 * @param atts the manifest attributes to be checked
 *
 * @return <code>true</code> if the artifact manifest requires adjustments in the capability headers w.r.t. module dependencies;
 *         <code>false</code> if it already contains that info
 *//*w w w .  j  av  a 2 s. co m*/
public static boolean requiresTransformation(Attributes atts) {
    return !StringUtils.contains(atts.getValue(ATTR_NAME_PROVIDE_CAPABILITY),
            OSGI_CAPABILITY_MODULE_DEPENDENCIES) && !atts.containsKey(ATTR_NAME_FRAGMENT_HOST);
}