Search in sources :

Example 76 with Manifest

use of java.util.jar.Manifest in project robovm by robovm.

the class OldManifestTest method test_ConstructorLjava_util_jar_Manifest.

public void test_ConstructorLjava_util_jar_Manifest() {
    // Test for method java.util.jar.Manifest()
    Manifest emptyManifest = new Manifest();
    Manifest emptyClone = new Manifest(emptyManifest);
    assertTrue("Should have no entries", emptyClone.getEntries().isEmpty());
    assertTrue("Should have no main attributes", emptyClone.getMainAttributes().isEmpty());
    assertEquals(emptyClone, emptyManifest);
    assertEquals(emptyClone, emptyManifest.clone());
}
Also used : Manifest(java.util.jar.Manifest)

Example 77 with Manifest

use of java.util.jar.Manifest in project uavstack by uavorg.

the class FastClasspathScanner method addClasspathElement.

/**
 * Add a classpath element.
 */
private void addClasspathElement(String pathElement) {
    if (!pathElement.isEmpty()) {
        final File pathElementFile = new File(pathElement);
        if (pathElementFile.exists()) {
            // Canonicalize path so that we don't get stuck in a redirect loop due to softlinks
            String canonicalPath;
            try {
                canonicalPath = pathElementFile.getCanonicalPath();
            } catch (IOException e) {
                canonicalPath = pathElement;
            } catch (SecurityException e) {
                canonicalPath = pathElement;
            }
            if (classpathElementsSet.add(canonicalPath)) {
                // This is the first time this classpath element has been encountered
                if (verbose) {
                    Log.log("Found classpath element: " + pathElement);
                }
                classpathElements.add(pathElementFile);
                // we recursively call addClasspathElement if needed each time a jar is encountered.
                if (pathElementFile.isFile() && isJar(pathElement)) {
                    String manifestUrlStr = "jar:file:" + pathElement + "!/META-INF/MANIFEST.MF";
                    InputStream stream = null;
                    try {
                        stream = new URL(manifestUrlStr).openStream();
                        // Look for Class-Path keys within manifest files
                        Manifest manifest = new Manifest(stream);
                        String manifestClassPath = manifest.getMainAttributes().getValue("Class-Path");
                        if (manifestClassPath != null && !manifestClassPath.isEmpty()) {
                            if (verbose) {
                                Log.log("Found Class-Path entry in " + manifestUrlStr + ": " + manifestClassPath);
                            }
                            // Class-Path elements are space-delimited
                            for (String manifestClassPathElement : manifestClassPath.split(" ")) {
                                // Resolve Class-Path elements relative to the parent jar's containing directory
                                String manifestClassPathElementAbsolute = new File(pathElementFile.getParent(), manifestClassPathElement).getPath();
                                addClasspathElement(manifestClassPathElementAbsolute);
                            }
                        }
                    } catch (IOException e) {
                    // Jar does not contain a manifest
                    } finally /**
                     *************************** Alex Modified START ****************************
                     */
                    {
                        try {
                            if (stream != null) {
                                stream.close();
                            }
                        } catch (IOException e) {
                        }
                    }
                /**
                 *************************** XiaoSong Modified END ****************************
                 */
                }
            }
        } else if (verbose) {
            Log.log("Classpath element does not exist: " + pathElement);
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) ZipFile(java.util.zip.ZipFile) File(java.io.File) URL(java.net.URL)

Example 78 with Manifest

use of java.util.jar.Manifest in project graal by graphik-team.

the class Apps method printVersion.

public static void printVersion(String applicationName) {
    Manifest manifest;
    InputStream is;
    Attributes att;
    URL pathToManifest;
    String version;
    String vendor;
    String buildDate;
    // GET DATA
    try {
        pathToManifest = new URL(getPathToManifest());
        is = pathToManifest.openStream();
        manifest = new Manifest(is);
        att = manifest.getMainAttributes();
        version = att.getValue("Specification-Version");
        vendor = att.getValue("Specification-Vendor");
        buildDate = att.getValue("Built-On");
        is.close();
    } catch (IOException ex) {
        version = vendor = buildDate = "?";
    }
    // PRINT DATA
    System.out.print(applicationName);
    System.out.print(" version \"");
    System.out.print(version);
    System.out.println("\"");
    System.out.print("Built on ");
    System.out.println(buildDate);
    System.out.print("Produced by ");
    System.out.println(vendor);
}
Also used : InputStream(java.io.InputStream) Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) URL(java.net.URL)

Example 79 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class BundleTransformer method canHandle.

public boolean canHandle(File artifact) {
    JarFile jar = null;
    try {
        // Handle OSGi bundles with the default deployer
        String name = artifact.getName();
        if (!artifact.canRead() || name.endsWith(".txt") || name.endsWith(".xml") || name.endsWith(".properties") || name.endsWith(".cfg")) {
            // exception in the log
            return false;
        }
        jar = new JarFile(artifact);
        Manifest m = jar.getManifest();
        if (m != null && m.getMainAttributes().getValue(new Attributes.Name("Bundle-SymbolicName")) != null) {
            return true;
        }
    } catch (Exception e) {
    // Ignore
    } finally {
        if (jar != null) {
            try {
                jar.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
    return false;
}
Also used : Attributes(java.util.jar.Attributes) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) IOException(java.io.IOException)

Example 80 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class DPSigner method sign.

public void sign(DeploymentPackageBuilder builder, PrivateKey privKey, X509Certificate cert, OutputStream os) throws Exception {
    Manifest manifest = builder.createManifest();
    List<ArtifactData> artifacts = builder.getArtifactList();
    sign(manifest, artifacts, privKey, cert, os);
}
Also used : Manifest(java.util.jar.Manifest)

Aggregations

Manifest (java.util.jar.Manifest)1226 Attributes (java.util.jar.Attributes)392 File (java.io.File)391 IOException (java.io.IOException)336 JarFile (java.util.jar.JarFile)231 InputStream (java.io.InputStream)184 URL (java.net.URL)177 JarOutputStream (java.util.jar.JarOutputStream)145 FileOutputStream (java.io.FileOutputStream)131 Test (org.junit.Test)129 FileInputStream (java.io.FileInputStream)119 Jar (aQute.bnd.osgi.Jar)105 JarInputStream (java.util.jar.JarInputStream)104 Builder (aQute.bnd.osgi.Builder)99 ZipEntry (java.util.zip.ZipEntry)99 ByteArrayOutputStream (java.io.ByteArrayOutputStream)96 JarEntry (java.util.jar.JarEntry)96 ByteArrayInputStream (java.io.ByteArrayInputStream)93 ArrayList (java.util.ArrayList)83 Map (java.util.Map)83