Example usage for java.util.jar Manifest getMainAttributes

List of usage examples for java.util.jar Manifest getMainAttributes

Introduction

In this page you can find the example usage for java.util.jar Manifest getMainAttributes.

Prototype

public Attributes getMainAttributes() 

Source Link

Document

Returns the main Attributes for the Manifest.

Usage

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

protected String extractValue(Manifest mf, List<String> priority) {
    String val = findValueInAttribute(mf.getMainAttributes(), priority);
    if (StringUtils.isNotBlank(val)) {
        return val;
    }/*from  ww  w . ja va  2  s . c o  m*/
    // prepare the fallback attributes, ordered by name...
    List<String> attributeNames = new ArrayList<String>(mf.getEntries().keySet());
    Collections.sort(attributeNames);

    for (String attributeName : attributeNames) {
        val = findValueInAttribute(mf.getAttributes(attributeName), priority);

        if (StringUtils.isNotBlank(val)) {
            return val;
        }
    }

    return null;
}

From source file:org.eclipse.gemini.blueprint.test.parsing.DifferentParentsInDifferentBundlesTest.java

private String getImportPackage(CaseWithVisibleMethodsBaseTest test) throws Exception {
    Manifest mf = getParsedManifestFor(test);
    String importPackage = mf.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
    // System.out.println("import package value is " + importPackage);
    return importPackage;
}

From source file:org.apache.servicemix.jbi.deployer.handler.JBIDeploymentListener.java

/**
 * Check if the file is a recognized JBI artifact that needs to be
 * processed.//from  w w w .j  a v  a2  s.  com
 *
 * @param artifact the file to check
 * @return <code>true</code> is the file is a JBI artifact that
 *         should be transformed into an OSGi bundle.
 */
public boolean canHandle(File artifact) {
    try {
        // Accept jars and zips
        if (!artifact.getName().endsWith(".zip") && !artifact.getName().endsWith(".jar")) {
            return false;
        }
        JarFile jar = new JarFile(artifact);
        JarEntry entry = jar.getJarEntry(DescriptorFactory.DESCRIPTOR_FILE);
        // Only handle JBI artifacts
        if (entry == null) {
            return false;
        }
        // Only handle non OSGi bundles
        Manifest m = jar.getManifest();
        if (m != null && m.getMainAttributes().getValue(new Attributes.Name("Bundle-SymbolicName")) != null
                && m.getMainAttributes().getValue(new Attributes.Name("Bundle-Version")) != null) {
            return false;
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:fm.last.citrine.web.AdminController.java

@Override
protected void initServletContext(ServletContext servletContext) {
    super.initServletContext(servletContext);
    try {// w  w  w . j a va  2  s.  c o  m
        InputStream inputStream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF");
        Manifest manifest = new Manifest(inputStream);
        Attributes attributes = manifest.getMainAttributes();
        buildVersion = attributes.getValue("Build-Version");
        buildDateTime = attributes.getValue("Build-DateTime");
        log.info("Citrine Build-Version: " + attributes.getValue("Build-Version"));
        log.info("Citrine Build-DateTime: " + attributes.getValue("Build-DateTime"));
    } catch (Exception e) {
        log.error("Error determining build version", e);
    }
}

From source file:ch.ivyteam.ivy.maven.util.ClasspathJar.java

private void writeManifest(String name, ZipOutputStream jarStream, List<String> classpathEntries)
        throws IOException {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    manifest.getMainAttributes().putValue("Name", name);
    if (mainClass != null) {
        manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, mainClass);
    }//from   ww w.jav a 2  s .c  o  m
    if (!classpathEntries.isEmpty()) {
        manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, StringUtils.join(classpathEntries, " "));
    }
    jarStream.putNextEntry(new ZipEntry(MANIFEST_MF));
    manifest.write(jarStream);
}

From source file:com.vmware.vfabric.hyperic.plugin.vfws.BmxResult.java

public Properties parseToProperties() throws IOException {
    InputStream is = _response.getEntity().getContent();
    props = new Properties();

    Manifest manifest = new Manifest(is);
    Attributes attributes = manifest.getMainAttributes();
    if (null == attributes) {
        _log.error("Unable to parse results. No attributes found");
        return null;
    }//from ww  w  .  ja v a2  s.  c  o m

    for (Iterator<Object> it = attributes.keySet().iterator(); it.hasNext();) {
        Name key = (Name) it.next();
        if (key == null) {
            _log.debug("Skipping null key");
            continue;
        }
        Object value = attributes.get(key);
        if (value.getClass() != String.class) {
            _log.error("Attribute value not of class String");
            continue;
        }
        String keyName = key.toString();
        String val = (String) value;
        props.put(keyName, val);
    }
    return props;
}

From source file:de.u808.simpleinquest.web.tags.VersionInfoTag.java

@Override
public void doTag() throws JspException, IOException {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    try {//from w w w.  j a  v  a2s . co m
        String appServerHome = pageContext.getServletContext().getRealPath("/");

        File manifestFile = new File(appServerHome, "META-INF/MANIFEST.MF");

        Manifest mf = new Manifest();
        mf.read(new FileInputStream(manifestFile));

        Attributes atts = mf.getMainAttributes();

        out.println("<span id=\"version\"> (Revision " + atts.getValue("Implementation-Version") + " Build "
                + atts.getValue("Implementation-Build") + " Built-By " + atts.getValue("Built-By")
                + ")</span>");
    } catch (Exception e) {
        log.error("Tag error", e);
    }
}

From source file:org.apache.sling.scripting.sightly.impl.engine.SightlyEngineConfiguration.java

protected void activate(ComponentContext componentContext) {
    InputStream ins = null;//from  ww w .  j  a va 2 s  . co m
    try {
        ins = getClass().getResourceAsStream("/META-INF/MANIFEST.MF");
        if (ins != null) {
            Manifest manifest = new Manifest(ins);
            Attributes attrs = manifest.getMainAttributes();
            String version = attrs.getValue("ScriptEngine-Version");
            if (version != null) {
                engineVersion = version;
            }
            String symbolicName = attrs.getValue("Bundle-SymbolicName");
            if (StringUtils.isNotEmpty(symbolicName)) {
                bundleSymbolicName = symbolicName;
            }
        }
    } catch (IOException ioe) {
    } finally {
        if (ins != null) {
            try {
                ins.close();
            } catch (IOException ignore) {
            }
        }
    }
    Dictionary properties = componentContext.getProperties();
    keepGenerated = PropertiesUtil.toBoolean(properties.get(SCR_PROP_NAME_KEEPGENERATED),
            SCR_PROP_DEFAULT_KEEPGENERATED);
}

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()));
            }/* ww  w  .  j av a 2 s. co m*/
        }

    }
}

From source file:org.easymock.itests.OsgiTest.java

@Override
protected Manifest getManifest() {
    Manifest mf = super.getManifest();

    String imports = mf.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
    imports = imports.replace("org.easymock.internal,", "org.easymock.internal;poweruser=true,");
    imports = imports.replace("org.easymock.internal.matchers,",
            "org.easymock.internal.matchers;poweruser=true,");

    imports += ",org.easymock.cglib.core,org.easymock.cglib.proxy,org.easymock.cglib.reflect,org.easymock.asm";

    mf.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, imports);

    return mf;/*ww  w . j  a va2 s . c  om*/
}