1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 4361044 4388202 4418643 4523159 4730642 27 * @library /test/lib 28 * /lib/testlibrary 29 * @modules jdk.compiler 30 * @build src.test.src.TestDriver JarUtils 31 * jdk.test.lib.CompilerUtils 32 * jdk.test.lib.JDKToolFinder 33 * jdk.test.lib.process.* 34 * @summary various resource and classloading bugs related to jar files 35 * @run main/othervm TestDriver 36 */ 37 38 import jdk.test.lib.JDKToolFinder; 39 import jdk.test.lib.process.ProcessTools; 40 41 import java.io.File; 42 import java.nio.file.Files; 43 import java.nio.file.Path; 44 import java.nio.file.Paths; 45 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; 46 47 public class TestDriver { 48 public static void main(String[] args) throws Throwable { 49 Path srcDir = Paths.get(System.getProperty("test.src")); 50 Path targetDir = Paths.get(System.getProperty("user.dir")); 51 Path jar1SrcDir = srcDir.resolve("src").resolve("jar1"); 52 Path jar1TargetDir = targetDir.resolve("jar1"); 53 Path ectJar1Dir = srcDir.resolve("etc").resolve("jar1"); 54 Path jarFile = targetDir.resolve("jar1.jar"); 55 Path[] files= new Path[] { 56 Paths.get("res1.txt"), Paths.get("jar1", "bundle.properties") 57 }; 58 59 // Copy files to target directory and change permission 60 for (Path file : files) { 61 Path dest = jar1TargetDir.resolve(file); 62 Files.createDirectories(dest.getParent()); 63 Files.copy(ectJar1Dir.resolve(file), dest, REPLACE_EXISTING); 64 } 65 66 // Compile and build jar1.jar 67 ProcessTools.executeCommand("chmod", "-R", "u+w", "./jar1") 68 .outputTo(System.out) 69 .errorTo(System.out) 70 .shouldHaveExitValue(0); 71 CompilerUtils.compile(jar1SrcDir, jar1TargetDir); 72 JarUtils.createJarFile(jarFile, jar1TargetDir); 73 74 // Compile test files 75 CompilerUtils.compile(srcDir.resolve("src").resolve("test"), targetDir); 76 77 // Run tests 78 String java = JDKToolFinder.getTestJDKTool("java"); 79 String cp = targetDir.toString() + File.pathSeparator + jarFile; 80 String[] tests = new String[]{"TestBug4361044", "TestBug4523159"}; 81 for (String test : tests) { 82 ProcessTools.executeCommand(java, "-cp", cp, test) 83 .outputTo(System.out) 84 .errorTo(System.out) 85 .shouldHaveExitValue(0); 86 } 87 } 88 }