jdk/test/java/net/URLClassLoader/getresourceasstream/TestDriver.java
author iignatyev
Mon, 12 Jun 2017 12:43:26 -0700
changeset 45467 99c87a16a8e4
parent 45285 7f8db2139152
permissions -rw-r--r--
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45285
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
     1
/*
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
     4
 *
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
     8
 *
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    13
 * accompanied this code).
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    14
 *
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    18
 *
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    21
 * questions.
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    22
 */
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    23
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    24
/**
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    25
 * @test
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    26
 * @bug 5103449
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    27
 * @summary REGRESSION: getResourceAsStream is broken in JDK1.5.0-rc
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    28
 * @library /test/lib
45467
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45285
diff changeset
    29
 * @build jdk.test.lib.Utils
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45285
diff changeset
    30
 *        jdk.test.lib.Asserts
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45285
diff changeset
    31
 *        jdk.test.lib.JDKToolFinder
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45285
diff changeset
    32
 *        jdk.test.lib.JDKToolLauncher
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45285
diff changeset
    33
 *        jdk.test.lib.Platform
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45285
diff changeset
    34
 *        jdk.test.lib.process.*
45285
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    35
 *        Test
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    36
 * @run main/othervm TestDriver
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    37
 */
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    38
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    39
import jdk.test.lib.JDKToolFinder;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    40
import jdk.test.lib.process.ProcessTools;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    41
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    42
import java.io.IOException;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    43
import java.nio.file.Files;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    44
import java.nio.file.Path;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    45
import java.nio.file.Paths;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    46
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    47
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    48
public class TestDriver {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    49
    private static final String ARCHIVE_NAME = "test.jar";
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    50
    private static final String TEST_NAME = "Test";
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    51
    private static final String POLICY_FILE = "policy";
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    52
    public static void main(String[] args)
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    53
            throws Throwable {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    54
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    55
        Path userDir = Paths.get(System.getProperty("user.dir"));
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    56
        String java = JDKToolFinder.getTestJDKTool("java");
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    57
        String basename = userDir.getFileName().toString();
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    58
        setup(userDir);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    59
        ProcessBuilder[] tests = new ProcessBuilder[]{
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    60
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    61
                        java, TEST_NAME, "./" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    62
                ),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    63
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    64
                        java, "-cp", ".",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    65
                        "-Djava.security.policy=file:./policy",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    66
                        "-Djava.security.manager",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    67
                        TEST_NAME, "./" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    68
                ),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    69
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    70
                        java, "-cp", ".",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    71
                        "-Djava.security.policy=file:./policy",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    72
                        "-Djava.security.manager",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    73
                        TEST_NAME, "./" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    74
                ),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    75
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    76
                        java, "-cp", "..",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    77
                        "-Djava.security.policy=file:../policy",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    78
                        "-Djava.security.manager",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    79
                        TEST_NAME, "../" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    80
                ).directory(userDir.resolve("tmp").toFile()),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    81
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    82
                        java, "-cp", basename,
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    83
                        "-Djava.security.policy=file:" + basename + "/policy",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    84
                        "-Djava.security.manager",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    85
                        TEST_NAME, basename + "/" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    86
                ).directory(userDir.resolve("..").toFile())};
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    87
        for (ProcessBuilder test : tests) {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    88
            runTest(test);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    89
        }
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    90
    }
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    91
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    92
    private static void setup(Path userDir) throws IOException {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    93
        Path src = Paths.get(System.getProperty("test.src"));
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    94
        Path testJar = src.resolve(ARCHIVE_NAME);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    95
        Path policy = src.resolve(POLICY_FILE);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    96
        Path testClass = Paths.get(System.getProperty("test.classes"),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    97
                                   TEST_NAME + ".class");
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    98
        Files.copy(testJar, userDir.resolve(ARCHIVE_NAME), REPLACE_EXISTING);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    99
        Files.copy(policy, userDir.resolve(POLICY_FILE), REPLACE_EXISTING);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   100
        Files.copy(testClass, userDir.resolve(TEST_NAME + ".class"),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   101
                   REPLACE_EXISTING);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   102
        Files.createDirectories(userDir.resolve("tmp"));
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   103
    }
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   104
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   105
    private static void runTest(ProcessBuilder pb) throws Exception {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   106
        System.out.println("Testing with command: [" + pb.command() + "]");
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   107
        ProcessTools.executeProcess(pb)
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   108
                    .outputTo(System.out)
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   109
                    .errorTo(System.err)
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   110
                    .shouldHaveExitValue(0);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   111
    }
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   112
}