Search in sources :

Example 41 with Attributes

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

the class DalvikExecTest method test_execCreatedJarWithManifest.

/**
     * This test does quite the same as test_execCreatedJar, but includes a manifest.
     * Note however that the Dalvik JAR format does not require this manifest.
     * We just test whether the manifest is placed correctly within the JAR by
     * dumping its contents read as a simple text resource.
     * No! We can't do that so easily either, as there are other (parent) JARs
     * with a manifest inside, taken with precedence.
     * So we will reopen the JAR as a JarFile and check the manifest
     *  with a top level end-to-end approach.
     */
public void test_execCreatedJarWithManifest() throws IOException, InterruptedException {
    File jarFile = File.createTempFile("cts_dalvikExecTest_", ".jar");
    jarFile.deleteOnExit();
    // Create the manifest:
    Manifest manifest = new Manifest();
    Attributes attrs = manifest.getMainAttributes();
    attrs.put(Attributes.Name.MANIFEST_VERSION, "3.1415962");
    attrs.put(Attributes.Name.MAIN_CLASS, "dalvikExecTest.HelloWorld");
    attrs.put(Attributes.Name.CLASS_PATH, jarFile.getName());
    // Create a JAR output stream on the temp file using the manifest:
    JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(jarFile), manifest);
    // Define the entry for the classes.dex:
    jarOut.putNextEntry(new JarEntry("classes.dex"));
    // Fill in the classes.dex contents, i.e. the Dalvik executable code:
    // (See below for the detailed source code contents.)
    Streams.copy(Support_Resources.getResourceStream("cts_dalvikExecTest_classes.dex"), jarOut);
    // Now add a resource file:
    //
    jarOut.putNextEntry(new JarEntry("dalvikExecTest/myResource"));
    jarOut.write("This Resource contains some text.".getBytes());
    // Close the stream to the completed JAR file.
    jarOut.close();
    // The resulting JAR file contains the classes listed at the end of this text,
    // like the 'cts_dalvikExecTest.jar' as part of the resources, too.
    String res;
    res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.HelloWorld");
    assertEquals("Hello Android World!", "Hello Android World!\n", res);
    res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.ResourceDumper");
    assertTrue("Android Resource Dumper started", res.contains("Android Resource Dumper started"));
    assertTrue("This Resource contains some text.", res.contains("This Resource contains some text."));
    // And now reread the manifest:
    //
    JarFile jarIn = new JarFile(jarFile);
    manifest = jarIn.getManifest();
    attrs = manifest.getMainAttributes();
    assertEquals("MANIFEST_VERSION must match!", "3.1415962", attrs.get(Attributes.Name.MANIFEST_VERSION));
    assertEquals("MAIN_CLASS must match!", "dalvikExecTest.HelloWorld", attrs.get(Attributes.Name.MAIN_CLASS));
    assertEquals("CLASS_PATH must match!", jarFile.getName(), attrs.get(Attributes.Name.CLASS_PATH));
}
Also used : FileOutputStream(java.io.FileOutputStream) Attributes(java.util.jar.Attributes) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 42 with Attributes

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

the class OldAttributesTest method test_putValueLjava_lang_StringLjava_lang_String.

public void test_putValueLjava_lang_StringLjava_lang_String() {
    Attributes b = new Attributes();
    b.put(new Attributes.Name("1"), "one");
    b.putValue("2", "two");
    b.put(new Attributes.Name("3"), "three");
    b.putValue("4", "four");
    assertTrue(a.equals(b));
    try {
        b.putValue(null, "null");
        fail("NullPointerException expected");
    } catch (NullPointerException ee) {
    // expected
    }
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 0x10000; i++) {
        sb.append('3');
    }
    try {
        b.putValue(new String(sb), "wrong name");
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException ee) {
    // expected
    }
}
Also used : Attributes(java.util.jar.Attributes)

Example 43 with Attributes

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

the class OldManifestTest method checkManifest.

private void checkManifest(Manifest manifest) {
    Attributes main = manifest.getMainAttributes();
    assertAttribute(main, "Bundle-Name", "ClientSupport");
    assertAttribute(main, "Bundle-Description", "Provides SessionService, AuthenticationService. Extends RegistryService.");
    assertAttribute(main, "Bundle-Activator", "com.ibm.ive.eccomm.client.support.ClientSupportActivator");
    assertAttribute(main, "Import-Package", "com.ibm.ive.eccomm.client.services.log,com.ibm.ive.eccomm.client.services.registry,com.ibm.ive.eccomm.service.registry; specification-version=1.0.0,com.ibm.ive.eccomm.service.session; specification-version=1.0.0,com.ibm.ive.eccomm.service.framework; specification-version=1.2.0,org.osgi.framework; specification-version=1.0.0,org.osgi.service.log; specification-version=1.0.0,com.ibm.ive.eccomm.flash; specification-version=1.2.0,com.ibm.ive.eccomm.client.xml,com.ibm.ive.eccomm.client.http.common,com.ibm.ive.eccomm.client.http.client");
    assertAttribute(main, "Import-Service", "org.osgi.service.log.LogReaderServiceorg.osgi.service.log.LogService,com.ibm.ive.eccomm.service.registry.RegistryService");
    assertAttribute(main, "Export-Package", "com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.service.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.common; specification-version=1.0.0,com.ibm.ive.eccomm.client.services.registry.store; specification-version=1.0.0");
    assertAttribute(main, "Export-Service", "com.ibm.ive.eccomm.service.authentication.AuthenticationService,com.ibm.ive.eccomm.service.session.SessionService");
    assertAttribute(main, "Bundle-Vendor", "IBM");
    assertAttribute(main, "Bundle-Version", "1.2.0");
}
Also used : Attributes(java.util.jar.Attributes)

Example 44 with Attributes

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

the class OldAttributesTest method setUp.

@Override
protected void setUp() {
    a = new Attributes();
    a.putValue("1", "one");
    a.putValue("2", "two");
    a.putValue("3", "three");
    a.putValue("4", "four");
}
Also used : Attributes(java.util.jar.Attributes)

Example 45 with Attributes

use of java.util.jar.Attributes 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)

Aggregations

Attributes (java.util.jar.Attributes)631 Manifest (java.util.jar.Manifest)358 IOException (java.io.IOException)152 File (java.io.File)143 JarFile (java.util.jar.JarFile)106 URL (java.net.URL)92 Map (java.util.Map)78 InputStream (java.io.InputStream)62 HashMap (java.util.HashMap)62 Jar (aQute.bnd.osgi.Jar)49 Builder (aQute.bnd.osgi.Builder)43 ArrayList (java.util.ArrayList)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)42 Test (org.junit.Test)41 ZipEntry (java.util.zip.ZipEntry)39 FileOutputStream (java.io.FileOutputStream)37 JarOutputStream (java.util.jar.JarOutputStream)36 ByteArrayInputStream (java.io.ByteArrayInputStream)33 FileInputStream (java.io.FileInputStream)33 JarEntry (java.util.jar.JarEntry)32