Search in sources :

Example 61 with Manifest

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

the class OldURLClassLoaderTest method test_definePackage.

public void test_definePackage() throws MalformedURLException {
    Manifest manifest = new Manifest();
    URL[] u = new URL[0];
    TestURLClassLoader tucl = new TestURLClassLoader(u);
    URL[] urls = { new URL("http://foo.com/foo"), new URL("jar:file://foo.jar!/foo.c"), new URL("ftp://foo1/foo2/foo.c"), new URL("file://new/package/name/"), null };
    String packageName = "new.package.name";
    for (int i = 0; i < urls.length; i++) {
        Package pack = tucl.definePackage(packageName + i, manifest, urls[i]);
        assertEquals(packageName + i, pack.getName());
        assertNull("Implementation Title is not null", pack.getImplementationTitle());
        assertNull("Implementation Vendor is not null", pack.getImplementationVendor());
        assertNull("Implementation Version is not null.", pack.getImplementationVersion());
    }
    try {
        tucl.definePackage(packageName + "0", manifest, null);
        fail("IllegalArgumentException was not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
}
Also used : Manifest(java.util.jar.Manifest) URL(java.net.URL)

Example 62 with Manifest

use of java.util.jar.Manifest in project bazel by bazelbuild.

the class SingleJar method createManifest.

/**
   * Creates a manifest and returns an input stream for its contents.
   */
private InputStream createManifest() throws IOException {
    Manifest manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    attributes.put(new Attributes.Name("Created-By"), "blaze-singlejar");
    if (mainClass != null) {
        attributes.put(Attributes.Name.MAIN_CLASS, mainClass);
    }
    if (extraManifestContent != null) {
        ByteArrayInputStream in = new ByteArrayInputStream(extraManifestContent.getBytes("UTF8"));
        manifest.read(in);
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    manifest.write(out);
    return new ByteArrayInputStream(out.toByteArray());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Attributes(java.util.jar.Attributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest)

Example 63 with Manifest

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

the class DefaultManifest method writeTo.

@Deprecated
@Override
public DefaultManifest writeTo(Writer writer) {
    SingleMessageLogger.nagUserOfDeprecated("Manifest.writeTo(Writer)", "Please use Manifest.writeTo(Object) instead");
    try {
        Manifest javaManifest = generateJavaManifest(getEffectiveManifest());
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        javaManifest.write(buffer);
        String manifestContent = buffer.toString(DEFAULT_CONTENT_CHARSET);
        if (!DEFAULT_CONTENT_CHARSET.equals(contentCharset)) {
            // Convert the UTF-8 manifest bytes to the requested content charset
            manifestContent = new String(manifestContent.getBytes(contentCharset), contentCharset);
        }
        writer.write(manifestContent);
        writer.flush();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return this;
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Manifest(java.util.jar.Manifest)

Example 64 with Manifest

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

the class JarUtil method getManifestKey.

public static String getManifestKey(String jar, String key) {
    String version = null;
    try {
        JarFile jarFile = new JarFile(jar);
        Manifest manifest = jarFile.getManifest();
        if (manifest != null) {
            Attributes attributes = manifest.getMainAttributes();
            version = attributes.getValue(key);
        }
    } catch (IOException e) {
        LOG.error("Exception while trying to read Go-Version from " + jar + ":" + e.toString());
    }
    return version;
}
Also used : Attributes(java.util.jar.Attributes) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest)

Example 65 with Manifest

use of java.util.jar.Manifest in project bazel by bazelbuild.

the class JarCreator method manifestContent.

private byte[] manifestContent() throws IOException {
    Manifest manifest;
    if (manifestFile != null) {
        FileInputStream in = new FileInputStream(manifestFile);
        manifest = new Manifest(in);
    } else {
        manifest = new Manifest();
    }
    Attributes attributes = manifest.getMainAttributes();
    attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    Attributes.Name createdBy = new Attributes.Name("Created-By");
    if (attributes.getValue(createdBy) == null) {
        attributes.put(createdBy, "blaze");
    }
    if (mainClass != null) {
        attributes.put(Attributes.Name.MAIN_CLASS, mainClass);
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    manifest.write(out);
    return out.toByteArray();
}
Also used : Attributes(java.util.jar.Attributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) FileInputStream(java.io.FileInputStream)

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