use of java.util.jar.Manifest in project byte-buddy by raphw.
the class PackageTypeStrategyManifestReadingTest method testManifestMainAttributesSealed.
@Test
@IntegrationRule.Enforce
public void testManifestMainAttributesSealed() throws Exception {
final Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.SEALED, Boolean.TRUE.toString());
when(classLoader.getResourceAsStream("/META-INF/MANIFEST.MF")).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock invocationOnMock) throws Throwable {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
manifest.write(outputStream);
return new ByteArrayInputStream(outputStream.toByteArray());
}
});
when(sealBaseLocator.findSealBase(classLoader, FOO + "." + BAR + "." + QUX)).thenReturn(url);
PackageDefinitionStrategy packageDefinitionStrategy = new PackageDefinitionStrategy.ManifestReading(sealBaseLocator);
PackageDefinitionStrategy.Definition definition = packageDefinitionStrategy.define(classLoader, FOO + "." + BAR, FOO + "." + BAR + "." + QUX);
assertThat(definition.isDefined(), is(true));
assertThat(definition.getSealBase(), is(url));
verify(sealBaseLocator).findSealBase(classLoader, FOO + "." + BAR + "." + QUX);
verifyNoMoreInteractions(sealBaseLocator);
}
use of java.util.jar.Manifest 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));
}
use of java.util.jar.Manifest in project robovm by robovm.
the class OldManifestTest method test_writeLjava_io_OutputStream.
public void test_writeLjava_io_OutputStream() throws IOException {
byte[] b;
Manifest manifest1 = null;
Manifest manifest2 = null;
try {
manifest1 = new Manifest(new URL(Support_Resources.getURL("manifest/hyts_MANIFEST.MF")).openStream());
} catch (MalformedURLException e) {
fail("Malformed URL");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
manifest1.write(baos);
b = baos.toByteArray();
File f = File.createTempFile("111", "111");
FileOutputStream fos = new FileOutputStream(f);
fos.close();
try {
manifest1.write(fos);
fail("IOException expected");
} catch (IOException e) {
// expected
}
f.delete();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
try {
manifest2 = new Manifest(bais);
} catch (MalformedURLException e) {
fail("Malformed URL");
}
assertTrue(manifest1.equals(manifest2));
}
use of java.util.jar.Manifest in project robovm by robovm.
the class OldManifestTest method test_write_two_versions.
public void test_write_two_versions() throws Exception {
// It's okay to have two versions.
Manifest m1 = new Manifest();
m1.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
m1.getMainAttributes().put(Attributes.Name.SIGNATURE_VERSION, "2.0");
m1.getMainAttributes().putValue("Aardvark-Version", "3.0");
ByteArrayOutputStream os = new ByteArrayOutputStream();
m1.write(os);
// The Manifest-Version takes precedence,
// and the Signature-Version gets no special treatment.
String[] lines = new String(os.toByteArray(), "UTF-8").split("\r\n");
assertEquals("Manifest-Version: 1.0", lines[0]);
assertEquals("Aardvark-Version: 3.0", lines[1]);
assertEquals("Signature-Version: 2.0", lines[2]);
}
use of java.util.jar.Manifest in project robovm by robovm.
the class OldManifestTest method test_clone.
public void test_clone() throws IOException {
Manifest emptyManifest = new Manifest();
Manifest emptyClone = (Manifest) emptyManifest.clone();
assertTrue("Should have no entries", emptyClone.getEntries().isEmpty());
assertTrue("Should have no main attributes", emptyClone.getMainAttributes().isEmpty());
assertEquals(emptyClone, emptyManifest);
assertEquals(emptyManifest.clone().getClass().getName(), "java.util.jar.Manifest");
Manifest manifest = new Manifest(new URL(Support_Resources.getURL("manifest/hyts_MANIFEST.MF")).openStream());
Manifest manifestClone = (Manifest) manifest.clone();
manifestClone.getMainAttributes();
checkManifest(manifestClone);
}
Aggregations