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