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