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