jdk/test/java/net/URLClassLoader/getresourceasstream/TestDriver.java
author xiaofeya
Tue, 30 May 2017 07:03:33 -0700
changeset 45285 7f8db2139152
child 45467 99c87a16a8e4
permissions -rw-r--r--
8166139: Refactor java/net shell cases to java Reviewed-by: chegar, rriggs
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
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    29
 * @build jdk.test.lib.JDKToolFinder
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    30
 *        jdk.test.lib.process.ProcessTools
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    31
 *        Test
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    32
 * @run main/othervm TestDriver
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    33
 */
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    34
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    35
import jdk.test.lib.JDKToolFinder;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    36
import jdk.test.lib.process.ProcessTools;
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
import java.io.IOException;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    39
import java.nio.file.Files;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    40
import java.nio.file.Path;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    41
import java.nio.file.Paths;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    42
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    43
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    44
public class TestDriver {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    45
    private static final String ARCHIVE_NAME = "test.jar";
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    46
    private static final String TEST_NAME = "Test";
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    47
    private static final String POLICY_FILE = "policy";
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    48
    public static void main(String[] args)
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    49
            throws Throwable {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    50
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    51
        Path userDir = Paths.get(System.getProperty("user.dir"));
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    52
        String java = JDKToolFinder.getTestJDKTool("java");
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    53
        String basename = userDir.getFileName().toString();
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    54
        setup(userDir);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    55
        ProcessBuilder[] tests = new ProcessBuilder[]{
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    56
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    57
                        java, TEST_NAME, "./" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    58
                ),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    59
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    60
                        java, "-cp", ".",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    61
                        "-Djava.security.policy=file:./policy",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    62
                        "-Djava.security.manager",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    63
                        TEST_NAME, "./" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    64
                ),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    65
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    66
                        java, "-cp", ".",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    67
                        "-Djava.security.policy=file:./policy",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    68
                        "-Djava.security.manager",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    69
                        TEST_NAME, "./" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    70
                ),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    71
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    72
                        java, "-cp", "..",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    73
                        "-Djava.security.policy=file:../policy",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    74
                        "-Djava.security.manager",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    75
                        TEST_NAME, "../" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    76
                ).directory(userDir.resolve("tmp").toFile()),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    77
                new ProcessBuilder(
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    78
                        java, "-cp", basename,
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    79
                        "-Djava.security.policy=file:" + basename + "/policy",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    80
                        "-Djava.security.manager",
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    81
                        TEST_NAME, basename + "/" + ARCHIVE_NAME
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    82
                ).directory(userDir.resolve("..").toFile())};
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    83
        for (ProcessBuilder test : tests) {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    84
            runTest(test);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    85
        }
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    86
    }
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    87
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    88
    private static void setup(Path userDir) throws IOException {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    89
        Path src = Paths.get(System.getProperty("test.src"));
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    90
        Path testJar = src.resolve(ARCHIVE_NAME);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    91
        Path policy = src.resolve(POLICY_FILE);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    92
        Path testClass = Paths.get(System.getProperty("test.classes"),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    93
                                   TEST_NAME + ".class");
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    94
        Files.copy(testJar, userDir.resolve(ARCHIVE_NAME), REPLACE_EXISTING);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    95
        Files.copy(policy, userDir.resolve(POLICY_FILE), REPLACE_EXISTING);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    96
        Files.copy(testClass, userDir.resolve(TEST_NAME + ".class"),
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    97
                   REPLACE_EXISTING);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    98
        Files.createDirectories(userDir.resolve("tmp"));
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
    99
    }
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   100
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   101
    private static void runTest(ProcessBuilder pb) throws Exception {
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   102
        System.out.println("Testing with command: [" + pb.command() + "]");
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   103
        ProcessTools.executeProcess(pb)
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   104
                    .outputTo(System.out)
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   105
                    .errorTo(System.err)
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   106
                    .shouldHaveExitValue(0);
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   107
    }
7f8db2139152 8166139: Refactor java/net shell cases to java
xiaofeya
parents:
diff changeset
   108
}