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