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 * @modules jdk.compiler 29 * @build jdk.test.lib.compiler.CompilerUtils 30 * jdk.test.lib.Utils 31 * jdk.test.lib.Asserts 32 * jdk.test.lib.JDKToolFinder 33 * jdk.test.lib.JDKToolLauncher 34 * jdk.test.lib.Platform 35 * jdk.test.lib.process.* 36 * jdk.test.lib.util.JarUtils 37 * src.test.src.TestDriver 38 * @summary various resource and classloading bugs related to jar files 39 * @run main/othervm TestDriver 40 */ 41 42 import jdk.test.lib.JDKToolFinder; 43 import jdk.test.lib.compiler.CompilerUtils; 44 import jdk.test.lib.process.ProcessTools; 45 import jdk.test.lib.util.JarUtils; 46 47 import java.io.File; 48 import java.nio.file.Files; 49 import java.nio.file.Path; 50 import java.nio.file.Paths; 51 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; 52 53 public class TestDriver { 54 public static void main(String[] args) throws Throwable { 55 Path srcDir = Paths.get(System.getProperty("test.src")); 56 Path targetDir = Paths.get(System.getProperty("user.dir")); 57 Path jar1SrcDir = srcDir.resolve("src").resolve("jar1"); 58 Path jar1TargetDir = targetDir.resolve("jar1"); 59 Path ectJar1Dir = srcDir.resolve("etc").resolve("jar1"); 60 Path jarFile = targetDir.resolve("jar1.jar"); 61 Path[] files= new Path[] { 62 Paths.get("res1.txt"), Paths.get("jar1", "bundle.properties") 63 }; 64 65 // Copy files to target directory and change permission 66 for (Path file : files) { 67 Path dest = jar1TargetDir.resolve(file); 68 Files.createDirectories(dest.getParent()); 69 Files.copy(ectJar1Dir.resolve(file), dest, REPLACE_EXISTING); 70 } 71 72 // Compile and build jar1.jar 73 ProcessTools.executeCommand("chmod", "-R", "u+w", "./jar1") 74 .outputTo(System.out) 75 .errorTo(System.out) 76 .shouldHaveExitValue(0); 77 CompilerUtils.compile(jar1SrcDir, jar1TargetDir); 78 JarUtils.createJarFile(jarFile, jar1TargetDir); 79 80 // Compile test files 81 CompilerUtils.compile(srcDir.resolve("src").resolve("test"), targetDir); 82 83 // Run tests 84 String java = JDKToolFinder.getTestJDKTool("java"); 85 String cp = targetDir.toString() + File.pathSeparator + jarFile; 86 String[] tests = new String[]{"TestBug4361044", "TestBug4523159"}; 87 for (String test : tests) { 88 ProcessTools.executeCommand(java, "-cp", cp, test) 89 .outputTo(System.out) 90 .errorTo(System.out) 91 .shouldHaveExitValue(0); 92 } 93 } 94 }