1 /*
  2  * Copyright (c) 2017, 2024, 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 5103449
 27  * @summary REGRESSION: getResourceAsStream is broken in JDK1.5.0-rc
 28  * @library /test/lib
 29  * @build jdk.test.lib.Utils
 30  *        jdk.test.lib.Asserts
 31  *        jdk.test.lib.JDKToolFinder
 32  *        jdk.test.lib.JDKToolLauncher
 33  *        jdk.test.lib.Platform
 34  *        jdk.test.lib.process.*
 35  *        Test
 36  * @run main/othervm TestDriver
 37  */
 38 
 39 import jdk.test.lib.process.ProcessTools;
 40 
 41 import java.io.IOException;
 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     private static final String ARCHIVE_NAME = "test.jar";
 49     private static final String TEST_NAME = "Test";
 50     private static final String POLICY_FILE = "policy";
 51     public static void main(String[] args)
 52             throws Throwable {
 53 
 54         Path userDir = Paths.get(System.getProperty("user.dir"));
 55         String basename = userDir.getFileName().toString();
 56         setup(userDir);
 57         ProcessBuilder[] tests = new ProcessBuilder[]{
 58                 ProcessTools.createTestJavaProcessBuilder(
 59                         TEST_NAME,
 60                         "./" + ARCHIVE_NAME
 61                 ),
 62                 ProcessTools.createTestJavaProcessBuilder(
 63                         "-cp", ".",
 64                         "-Djava.security.policy=file:./policy",
 65                         "-Djava.security.manager",
 66                         TEST_NAME, "./" + ARCHIVE_NAME
 67                 ),
 68                 ProcessTools.createTestJavaProcessBuilder(
 69                         "-cp", ".",
 70                         "-Djava.security.policy=file:./policy",
 71                         "-Djava.security.manager",
 72                         TEST_NAME, "./" + ARCHIVE_NAME
 73                 ),
 74                 ProcessTools.createTestJavaProcessBuilder(
 75                         "-cp", "..",
 76                         "-Djava.security.policy=file:../policy",
 77                         "-Djava.security.manager",
 78                         TEST_NAME, "../" + ARCHIVE_NAME
 79                 ).directory(userDir.resolve("tmp").toFile()),
 80                 ProcessTools.createTestJavaProcessBuilder(
 81                         "-cp", basename,
 82                         "-Djava.security.policy=file:" + basename + "/policy",
 83                         "-Djava.security.manager",
 84                         TEST_NAME, basename + "/" + ARCHIVE_NAME
 85                 ).directory(userDir.resolve("..").toFile())};
 86         for (ProcessBuilder test : tests) {
 87             runTest(test);
 88         }
 89     }
 90 
 91     private static void setup(Path userDir) throws IOException {
 92         Path src = Paths.get(System.getProperty("test.src"));
 93         Path testJar = src.resolve(ARCHIVE_NAME);
 94         Path policy = src.resolve(POLICY_FILE);
 95         Path testClass = Paths.get(System.getProperty("test.classes"),
 96                                    TEST_NAME + ".class");
 97         Files.copy(testJar, userDir.resolve(ARCHIVE_NAME), REPLACE_EXISTING);
 98         Files.copy(policy, userDir.resolve(POLICY_FILE), REPLACE_EXISTING);
 99         Files.copy(testClass, userDir.resolve(TEST_NAME + ".class"),
100                    REPLACE_EXISTING);
101         Files.createDirectories(userDir.resolve("tmp"));
102     }
103 
104     private static void runTest(ProcessBuilder pb) throws Exception {
105         System.out.println("Testing with command: [" + pb.command() + "]");
106         ProcessTools.executeProcess(pb)
107                     .outputTo(System.out)
108                     .errorTo(System.err)
109                     .shouldHaveExitValue(0);
110     }
111 }