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.s4i.feature.FeatureMojo.java

private static String getBundleSymbolicName(Attributes attrs) {
    String name = attrs.getValue("Bundle-SymbolicName");
    if (name == null)
        return null;

    StringTokenizer token = new StringTokenizer(name, ";");
    return token.nextToken().trim();
}

From source file:net.minecraftforge.fml.relauncher.libraries.LibraryManager.java

private static Artifact readArtifact(Repository repo, Attributes meta) {
    String timestamp = meta.getValue(TIMESTAMP);
    if (timestamp != null)
        timestamp = SnapshotJson.TIMESTAMP.format(new Date(Long.parseLong(timestamp)));

    return new Artifact(repo, meta.getValue(MAVEN_ARTIFACT), timestamp);
}

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

private static String getVersionFromManifest(String path) throws IOException {
    String manifestPath = path.substring(0, path.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
    Manifest manifest = new Manifest(new URL(manifestPath).openStream());
    Attributes attr = manifest.getMainAttributes();
    return attr.getValue("version");
}

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

/**
 * Calculates the value and set the Require-Capability manifest attribute.
 *
 * @param moduleId the ID of the module/*from www  .  ja va 2 s . c o m*/
 * @param atts the manifest attributes
 */
private static void populateRequireCapabilities(String moduleId, Attributes atts) {
    List<String> caps = getRequireCapabilities(moduleId, atts.getValue(ATTR_NAME_JAHIA_DEPENDS));
    if (caps.size() > 0) {
        StringBuilder require = new StringBuilder();
        String existingRequireValue = atts.getValue(ATTR_NAME_REQUIRE_CAPABILITY);
        if (StringUtils.isNotEmpty(existingRequireValue)) {
            require.append(existingRequireValue);
        }
        for (String cap : caps) {
            if (require.length() > 0) {
                require.append(",");
            }
            require.append(cap);
        }
        atts.put(ATTR_NAME_REQUIRE_CAPABILITY, require.toString());
    }
}

From source file:org.kepler.kar.KAREntry.java

/**
 * @param atts//  ww  w  .  ja  va 2s.c o m
 * @return
 */
public static Vector<KeplerLSID> parseLsidDependencies(Attributes atts) {

    Vector<KeplerLSID> depList = new Vector<KeplerLSID>(2);
    if (atts == null)
        return depList;

    String ld = atts.getValue(KAREntry.LSID_DEPENDENCIES);
    if (ld == null) {
        return depList;
    }

    StringTokenizer st = new StringTokenizer(ld, ":");
    while (st.hasMoreTokens()) {
        try {
            String lsidStr = st.nextToken() + ":" + st.nextToken() + ":" + st.nextToken() + ":" + st.nextToken()
                    + ":" + st.nextToken() + ":" + st.nextToken();
            KeplerLSID lsid = new KeplerLSID(lsidStr);
            depList.add(lsid);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return depList;
}

From source file:org.ebayopensource.turmeric.tools.codegen.util.ClassPathUtil.java

private static List<File> getJarClassPathRefs(File file) {
    List<File> refs = new ArrayList<File>();

    JarFile jar = null;/*  w w  w . java2 s  .  c o m*/
    try {
        jar = new JarFile(file);
        Manifest manifest = jar.getManifest();
        if (manifest == null) {
            // No manifest, no classpath.
            return refs;
        }

        Attributes attrs = manifest.getMainAttributes();
        if (attrs == null) {
            /*
             * No main attributes. (not sure how that's possible, but we can skip this jar)
             */
            return refs;
        }
        String classPath = attrs.getValue(Attributes.Name.CLASS_PATH);
        if (CodeGenUtil.isEmptyString(classPath)) {
            return refs;
        }

        String parentDir = FilenameUtils.getFullPath(file.getAbsolutePath());
        File possible;
        for (String path : StringUtils.splitStr(classPath, ' ')) {
            possible = new File(path);

            if (!possible.isAbsolute()) {
                // relative path?
                possible = new File(FilenameUtils.normalize(parentDir + path));
            }

            if (!refs.contains(possible)) {
                refs.add(possible);
            }
        }
    } catch (IOException e) {
        LOG.log(Level.WARNING, "Unable to load/read/parse Jar File: " + file.getAbsolutePath(), e);
    } finally {
        CodeGenUtil.closeQuietly(jar);
    }

    return refs;
}

From source file:org.orbisgis.core.plugin.BundleTools.java

/**
 * Parse a Manifest in order to extract Exported Package
 * @param manifest//from ww w .ja v  a 2  s. c o  m
 * @param packages
 * @throws IOException
 */
public static BundleReference parseManifest(Manifest manifest, List<PackageDeclaration> packages)
        throws IOException {
    Attributes attributes = manifest.getMainAttributes();
    String exports = attributes.getValue(Constants.EXPORT_PACKAGE);
    String versionProperty = attributes.getValue(Constants.BUNDLE_VERSION_ATTRIBUTE);
    Version version = null;
    if (versionProperty != null) {
        version = new Version(versionProperty);
    }
    String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
    org.apache.felix.framework.Logger logger = new org.apache.felix.framework.Logger();
    // Use Apache Felix to parse the Manifest Export header
    List<BundleCapability> exportsCapability = ManifestParser.parseExportHeader(logger, null, exports, "0",
            new Version(0, 0, 0));
    for (BundleCapability bc : exportsCapability) {
        Map<String, Object> attr = bc.getAttributes();
        // If the package contain a package name and a package version
        if (attr.containsKey(PACKAGE_NAMESPACE)) {
            Version packageVersion = new Version(0, 0, 0);
            if (attr.containsKey(Constants.VERSION_ATTRIBUTE)) {
                packageVersion = (Version) attr.get(Constants.VERSION_ATTRIBUTE);
            }
            if (packageVersion.getMajor() != 0 || packageVersion.getMinor() != 0
                    || packageVersion.getMicro() != 0) {
                packages.add(new PackageDeclaration((String) attr.get(PACKAGE_NAMESPACE), packageVersion));
            } else {
                // No version, take the bundle version
                packages.add(new PackageDeclaration((String) attr.get(PACKAGE_NAMESPACE), version));
            }
        }
    }
    return new BundleReference(symbolicName, version);
}

From source file:org.pepstock.jem.node.NodeInfoUtility.java

/**
 * Extracts from manifest file the attribute passed by argument 
 * @param what name of attribute to get//from  w  w  w  .  j ava  2s. c o m
 * @return attribute value or null, if doesn't exist
 */
public static String getManifestAttribute(String what) {
    JarFile jarFile = null;
    try {
        // gets JAR file
        jarFile = new JarFile(new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()));

        // gets attributes
        Attributes at = (Attributes) jarFile.getManifest().getAttributes(ConfigKeys.JEM_MANIFEST_SECTION);
        // gets version
        return at.getValue(ConfigKeys.JEM_MANIFEST_VERSION);
    } catch (IOException e) {
        // ignore the stack trace
        LogAppl.getInstance().ignore(e.getMessage(), e);
        LogAppl.getInstance().emit(NodeMessage.JEMC184W);
    } catch (URISyntaxException e) {
        // ignore the stack trace
        LogAppl.getInstance().ignore(e.getMessage(), e);
        LogAppl.getInstance().emit(NodeMessage.JEMC184W);
    } finally {
        if (jarFile != null) {
            try {
                jarFile.close();
            } catch (IOException e) {
                // debug
                LogAppl.getInstance().debug(e.getMessage(), e);
            }
        }
    }
    return null;
}

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

/**
 * Calculates the value and set the Provide-Capability manifest attribute and modifies it.
 *
 * @param moduleId the ID of the module.
 * @param atts the manifest attributes/*from w  ww  .j  av a2s  . com*/
 */
private static void populateProvideCapabilities(String moduleId, Attributes atts) {
    StringBuilder provide = new StringBuilder();
    String existingProvideValue = atts.getValue(ATTR_NAME_PROVIDE_CAPABILITY);
    if (StringUtils.isNotEmpty(existingProvideValue)) {
        provide.append(existingProvideValue).append(",");
    }
    provide.append(buildClauseProvideCapability(moduleId));
    String bundleName = atts.getValue(ATTR_NAME_BUNDLE_NAME);
    if (StringUtils.isNotEmpty(bundleName)) {
        provide.append(",").append(buildClauseProvideCapability(bundleName));
    }
    atts.put(ATTR_NAME_PROVIDE_CAPABILITY, provide.toString());
}

From source file:edu.stanford.epad.common.plugins.impl.ClassFinderTestUtils.java

/**
 * //from   w  w w.java 2  s  .  c om
 * @param clazz Class
 * @return String
 */
public static String readJarManifestForClass(Class<?> clazz) {
    StringBuilder sb = new StringBuilder();
    InputStream manifestInputStream = null;

    try {

        String className = clazz.getSimpleName() + ".class";
        String classPath = clazz.getResource(className).toString();
        if (!classPath.startsWith("jar")) {
            // Class not from JAR
            return "Class " + className + " not from jar file.";
        }

        String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
        manifestInputStream = new URL(manifestPath).openStream();
        Manifest manifest = new Manifest(manifestInputStream);
        Attributes attr = manifest.getMainAttributes();
        // String value = attr.getValue("Manifest-Version");

        Set<Object> keys = attr.keySet();
        for (Object currKey : keys) {
            String currValue = attr.getValue(currKey.toString());
            if (currValue != null) {
                sb.append(currKey.toString()).append(" : ").append(currValue).append("\n");
            } else {
                sb.append(currKey.toString()).append(": Didn't have a value");
            }
        }
    } catch (Exception e) {
        logger.warning("Failed to read manifest for " + clazz.getSimpleName(), e);
    } finally {
        IOUtils.closeQuietly(manifestInputStream);
    }
    return sb.toString();
}