Example usage for java.util.jar JarFile getManifest

List of usage examples for java.util.jar JarFile getManifest

Introduction

In this page you can find the example usage for java.util.jar JarFile getManifest.

Prototype

public Manifest getManifest() throws IOException 

Source Link

Document

Returns the jar file manifest, or null if none.

Usage

From source file:de.metanome.backend.algorithm_loading.AlgorithmFinder.java

/**
 * Finds out which subclass of Algorithm is implemented by the source code in the
 * algorithmJarFile./*from   ww  w .j  a  va  2s. co m*/
 *
 * @param algorithmJarFile the algorithm's jar file
 * @return the interfaces of the algorithm implementation in algorithmJarFile
 * @throws java.io.IOException if the algorithm jar file could not be opened
 * @throws java.lang.ClassNotFoundException if the algorithm contains a not supported interface
 */
public Set<Class<?>> getAlgorithmInterfaces(File algorithmJarFile) throws IOException, ClassNotFoundException {
    JarFile jar = new JarFile(algorithmJarFile);

    Manifest man = jar.getManifest();
    Attributes attr = man.getMainAttributes();
    String className = attr.getValue(bootstrapClassTagName);

    URL[] url = { algorithmJarFile.toURI().toURL() };
    ClassLoader loader = new URLClassLoader(url, Algorithm.class.getClassLoader());

    Class<?> algorithmClass;
    try {
        algorithmClass = Class.forName(className, false, loader);
    } catch (ClassNotFoundException e) {
        System.out.println("Could not find class " + className);
        return new HashSet<>();
    } finally {
        jar.close();
    }

    return new HashSet<>(ClassUtils.getAllInterfaces(algorithmClass));
}

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

private DepTreeData.Manifest loadFromZip(File zipFile) throws IOException {
    JarFile jar = null;
    try {/*  w  w w .  j  av  a2 s .  c  o m*/
        jar = new JarFile(zipFile);
        Manifest mf = jar.getManifest();
        if (mf == null) {
            return DepTreeData.Manifest.EMPTY;
        }
        return loadData(mf);
    } finally {
        if (jar != null) {
            try {
                jar.close();
            } catch (IOException ignored) {
                // Ignored
            }
        }
    }
}

From source file:org.pentaho.webpackage.deployer.archive.impl.WebPackageURLConnectionTest.java

@Test
public void testTgzFileWithPackageJson() throws Exception {
    JarFile jarFile = getDeployedJar(getResourceUrl("/my-simple-module-1.4.0.tgz"));

    Manifest manifest = jarFile.getManifest();

    verifyManifest(manifest, "my-simple-module", "1.4.0");
}

From source file:org.pentaho.webpackage.deployer.archive.impl.WebPackageURLConnectionTest.java

@Test
public void testZipFileWithPackageJson() throws Exception {
    JarFile jarFile = getDeployedJar(getResourceUrl("/my-simple-module-1.4.0.zip"));

    Manifest manifest = jarFile.getManifest();

    verifyManifest(manifest, "my-simple-module", "1.4.0");
}

From source file:com.npower.dm.msm.JADCreator.java

public Manifest getJADManufest(File file, String jarURL) throws IOException {
    //JarInputStream jarIn = new JarInputStream(in);
    JarFile jar = new JarFile(file);
    Manifest srcManifest = jar.getManifest();
    /*/*from  www .  j  a  v a2s .  c  o  m*/
    {
      Attributes attrs = srcManifest.getMainAttributes();
      for (Object akey: attrs.keySet()) {
          Object ov = attrs.get(akey);
          System.out.println(akey + ": " + ov);
      }
    }
    */
    Manifest manifest = new Manifest(srcManifest);
    manifest.getMainAttributes().put(new Attributes.Name("MIDlet-Jar-URL"), jarURL);
    manifest.getMainAttributes().put(new Attributes.Name("MIDlet-Jar-Size"), Long.toString(file.length()));
    return manifest;
}

From source file:org.pentaho.webpackage.deployer.WebPackageURLConnectionTest.java

@Test
public void testTgzFileWithPackageJson() throws Exception {
    JarFile jarFile = getDeployedJar(new File("src/test/resources/my-simple-module-1.4.0.tgz").toURI().toURL());

    Manifest manifest = jarFile.getManifest();

    verifyManifest(manifest);/*from ww w.j a  v  a2  s  .co  m*/
}

From source file:org.pentaho.webpackage.deployer.WebPackageURLConnectionTest.java

@Test
public void testZipFileWithPackageJson() throws Exception {
    JarFile jarFile = getDeployedJar(new File("src/test/resources/my-simple-module-1.4.0.zip").toURI().toURL());

    Manifest manifest = jarFile.getManifest();

    verifyManifest(manifest);//from www  .  j av a2  s  .  c  o m
}

From source file:org.nuxeo.osgi.application.BundleWalker.java

@Override
public int visitFile(File file) {
    // System.out.println("###### Processing file: "+file);
    // first check if this is a possible bundle
    String fileName = file.getName();
    if (patterns != null) {
        if (!acceptFile(fileName, patterns)) {
            // System.out.println("###### Ignoring file based on name: "+file);
            return FileWalker.CONTINUE;
        }/*from ww  w.  ja va 2s  .  c o  m*/
    }
    // check if this is an OSGi bundle
    try {
        JarFile jarFile = new JarFile(file);
        if (jarFile.getManifest() == null) {
            // System.out.println("###### No manifest found: "+file);
            return FileWalker.CONTINUE;
        }
        BundleFile bundleFile = new JarBundleFile(jarFile);
        if (bundleFile.getSymbolicName() != null) {
            // System.out.println("###### Bundle symbolic name: "+bundleFile.getSymbolicName());

            // notify the callback about the new bundle
            callback.visitBundle(bundleFile);
        } else {
            // notify the callback about the new jar
            callback.visitJar(bundleFile);
        }
    } catch (IOException e) {
        // ignore
    }
    return FileWalker.CONTINUE;
}

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

private String getVersion() {
    String home = homeDir.getText();
    if (home.length() == 0) {
        return EMPTY;
    }/*from w  ww .  j  a  va 2s.co m*/
    @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:com.mgmtp.perfload.core.console.meta.LtMetaInfoHandler.java

/**
 * Dumps the specified meta information to specified writer.
 * //w ww .  ja  v a  2s.c o m
 * @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();
    }
}