/** * tests case when Main-Class is not in the zip launched but in another zip referenced by * Class-Path * * @throws Exception in case of troubles */ public void test_main_class_in_another_zip() throws Exception { File fooZip = File.createTempFile("hyts_", ".zip"); File barZip = File.createTempFile("hyts_", ".zip"); fooZip.deleteOnExit(); barZip.deleteOnExit(); // create the manifest Manifest man = new Manifest(); Attributes att = man.getMainAttributes(); att.put(Attributes.Name.MANIFEST_VERSION, "1.0"); att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo"); att.put(Attributes.Name.CLASS_PATH, fooZip.getName()); File resources = Support_Resources.createTempFolder(); ZipOutputStream zoutFoo = new ZipOutputStream(new FileOutputStream(fooZip)); zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class")); zoutFoo.write(getResource(resources, "hyts_Foo.ser")); zoutFoo.close(); ZipOutputStream zoutBar = new ZipOutputStream(new FileOutputStream(barZip)); zoutBar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF")); man.write(zoutBar); zoutBar.putNextEntry(new ZipEntry("foo/bar/execjartest/Bar.class")); zoutBar.write(getResource(resources, "hyts_Bar.ser")); zoutBar.close(); String[] args = new String[] {"-jar", barZip.getAbsolutePath()}; // execute the JAR and read the result String res = Support_Exec.execJava(args, null, false); assertTrue("Error executing JAR : result returned was incorrect.", res.startsWith("FOOBAR")); }
public void test_1562() throws Exception { Manifest man = new Manifest(); Attributes att = man.getMainAttributes(); att.put(Attributes.Name.MANIFEST_VERSION, "1.0"); att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo"); File outputZip = File.createTempFile("hyts_", ".zip"); outputZip.deleteOnExit(); ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(outputZip)); File resources = Support_Resources.createTempFolder(); for (String zipClass : new String[] {"Foo", "Bar"}) { zout.putNextEntry(new ZipEntry("foo/bar/execjartest/" + zipClass + ".class")); zout.write(getResource(resources, "hyts_" + zipClass + ".ser")); } zout.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF")); man.write(zout); zout.close(); // set up the VM parameters String[] args = new String[] {"-jar", outputZip.getAbsolutePath()}; // execute the JAR and read the result String res = Support_Exec.execJava(args, null, false); assertTrue("Error executing ZIP : result returned was incorrect.", res.startsWith("FOOBAR")); }
@Override protected void setUp() { resources = Support_Resources.createTempFolder(); resPath = resources.toString(); if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') resPath = resPath.substring(1); }
/** * tests Class-Path entry in manifest * * @throws Exception in case of troubles */ public void test_zip_class_path() throws Exception { File fooZip = File.createTempFile("hyts_", ".zip"); File barZip = File.createTempFile("hyts_", ".zip"); fooZip.deleteOnExit(); barZip.deleteOnExit(); // create the manifest Manifest man = new Manifest(); Attributes att = man.getMainAttributes(); att.put(Attributes.Name.MANIFEST_VERSION, "1.0"); att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo"); att.put(Attributes.Name.CLASS_PATH, barZip.getName()); File resources = Support_Resources.createTempFolder(); ZipOutputStream zoutFoo = new ZipOutputStream(new FileOutputStream(fooZip)); zoutFoo.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF")); man.write(zoutFoo); zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class")); zoutFoo.write(getResource(resources, "hyts_Foo.ser")); zoutFoo.close(); ZipOutputStream zoutBar = new ZipOutputStream(new FileOutputStream(barZip)); zoutBar.putNextEntry(new ZipEntry("foo/bar/execjartest/Bar.class")); zoutBar.write(getResource(resources, "hyts_Bar.ser")); zoutBar.close(); String[] args = new String[] {"-jar", fooZip.getAbsolutePath()}; // execute the JAR and read the result String res = Support_Exec.execJava(args, null, false); assertTrue("Error executing JAR : result returned was incorrect.", res.startsWith("FOOBAR")); // rewrite manifest so it contains not only reference to bar but useless entries as well att.put(Attributes.Name.CLASS_PATH, "xx yy zz " + barZip.getName()); zoutFoo = new ZipOutputStream(new FileOutputStream(fooZip)); zoutFoo.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF")); man.write(zoutFoo); zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class")); zoutFoo.write(getResource(resources, "hyts_Foo.ser")); zoutFoo.close(); // execute the JAR and read the result res = Support_Exec.execJava(args, null, false); assertTrue("Error executing JAR : result returned was incorrect.", res.startsWith("FOOBAR")); // play with relative file names - put relative path as ../<parent dir name>/xx.zip att.put( Attributes.Name.CLASS_PATH, ".." + File.separator + barZip.getParentFile().getName() + File.separator + barZip.getName()); zoutFoo = new ZipOutputStream(new FileOutputStream(fooZip)); zoutFoo.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF")); man.write(zoutFoo); zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class")); zoutFoo.write(getResource(resources, "hyts_Foo.ser")); zoutFoo.close(); // execute the ZIP and read the result res = Support_Exec.execJava(args, null, false); assertTrue("Error executing JAR : result returned was incorrect.", res.startsWith("FOOBAR")); }
@Override protected void setUp() { resources = Support_Resources.createTempFolder(); }