author | mchung |
Wed, 04 Jan 2017 09:50:21 -0800 | |
changeset 42993 | d761de69e27f |
parent 42170 | 0bb91d845f04 |
child 45393 | de4e1efc8eec |
permissions | -rw-r--r-- |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
1 |
/* |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
4 |
* |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
8 |
* |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
13 |
* accompanied this code). |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
14 |
* |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
18 |
* |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
21 |
* questions. |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
22 |
*/ |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
23 |
|
42170
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
24 |
import java.io.BufferedWriter; |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
25 |
import java.nio.file.Files; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
26 |
import java.nio.file.Path; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
27 |
import java.nio.file.Paths; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
28 |
import java.util.ArrayList; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
29 |
import java.util.List; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
30 |
import java.util.Map; |
42170
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
31 |
import java.util.spi.ToolProvider; |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
32 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
33 |
import jdk.testlibrary.OutputAnalyzer; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
34 |
import org.testng.annotations.BeforeTest; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
35 |
import org.testng.annotations.DataProvider; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
36 |
import org.testng.annotations.Test; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
37 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
38 |
import static org.testng.Assert.assertTrue; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
39 |
import static jdk.testlibrary.ProcessTools.*; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
40 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
41 |
/** |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
42 |
* @test |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
43 |
* @bug 8168205 |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
44 |
* @summary Test the default class path if -Djava.class.path is set |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
45 |
* @library /lib/testlibrary |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
46 |
* @modules jdk.compiler |
42170
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
47 |
* jdk.jartool |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
48 |
* @build CompilerUtils jdk.testlibrary.* |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
49 |
* @run testng JavaClassPathTest |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
50 |
*/ |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
51 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
52 |
public class JavaClassPathTest { |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
53 |
private static final Path SRC_DIR = Paths.get(System.getProperty("test.src"), |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
54 |
"src"); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
55 |
private static final Path MODS_DIR = Paths.get("mods"); |
42170
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
56 |
private static final Path LIB_DIR = Paths.get("lib"); |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
57 |
private static final String TEST_MODULE = "m"; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
58 |
private static final String TEST_MAIN = "jdk.test.Main"; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
59 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
60 |
@BeforeTest |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
61 |
public void setup() throws Exception { |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
62 |
boolean compiled = CompilerUtils.compile(SRC_DIR.resolve(TEST_MODULE), |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
63 |
MODS_DIR.resolve(TEST_MODULE)); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
64 |
assertTrue(compiled, "module " + TEST_MODULE + " did not compile"); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
65 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
66 |
// add the class and a resource to the current working directory |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
67 |
Path file = Paths.get("jdk/test/Main.class"); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
68 |
Files.createDirectories(file.getParent()); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
69 |
Files.copy(MODS_DIR.resolve(TEST_MODULE).resolve(file), file); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
70 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
71 |
Path res = Paths.get("jdk/test/res.properties"); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
72 |
Files.createFile(res); |
42170
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
73 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
74 |
ToolProvider jartool = ToolProvider.findFirst("jar").orElseThrow( |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
75 |
() -> new RuntimeException("jar tool not found") |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
76 |
); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
77 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
78 |
Path jarfile = LIB_DIR.resolve("m.jar"); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
79 |
Files.createDirectories(LIB_DIR); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
80 |
assertTrue(jartool.run(System.out, System.err, "cfe", |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
81 |
jarfile.toString(), TEST_MAIN, |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
82 |
file.toString()) == 0); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
83 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
84 |
Path manifest = LIB_DIR.resolve("manifest"); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
85 |
try (BufferedWriter writer = Files.newBufferedWriter(manifest)) { |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
86 |
writer.write("CLASS-PATH: lib/m.jar"); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
87 |
} |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
88 |
jarfile = LIB_DIR.resolve("m1.jar"); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
89 |
assertTrue(jartool.run(System.out, System.err, "cfme", |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
90 |
jarfile.toString(), manifest.toString(), TEST_MAIN, |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
91 |
file.toString()) == 0); |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
92 |
} |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
93 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
94 |
@DataProvider(name = "classpath") |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
95 |
public Object[][] classpath() { |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
96 |
return new Object[][]{ |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
97 |
// true indicates that class path default to current working directory |
42993
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
98 |
{ List.of(), "." }, |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
99 |
{ List.of("-cp", ""), "" }, |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
100 |
{ List.of("-cp", "."), "." }, |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
101 |
{ List.of("-Djava.class.path"), "." }, |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
102 |
{ List.of("-Djava.class.path="), "" }, |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
103 |
{ List.of("-Djava.class.path=."), "." }, |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
104 |
}; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
105 |
} |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
106 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
107 |
@Test(dataProvider = "classpath") |
42993
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
108 |
public void testUnnamedModule(List<String> options, String expected) |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
109 |
throws Throwable |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
110 |
{ |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
111 |
List<String> args = new ArrayList<>(options); |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
112 |
args.add(TEST_MAIN); |
42170
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
113 |
args.add(Boolean.toString(true)); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
114 |
args.add(expected); |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
115 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
116 |
assertTrue(execute(args).getExitValue() == 0); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
117 |
} |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
118 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
119 |
@DataProvider(name = "moduleAndClassPath") |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
120 |
public Object[][] moduleAndClassPath() { |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
121 |
return new Object[][]{ |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
122 |
// true indicates that class path default to current working directory |
42170
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
123 |
{ "", "" }, |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
124 |
{ "-Djava.class.path", "" }, |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
125 |
{ "-Djava.class.path=", "" }, |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
126 |
}; |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
127 |
} |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
128 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
129 |
@Test(dataProvider = "moduleAndClassPath") |
42170
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
130 |
public void testNamedModule(String option, String expected) throws Throwable { |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
131 |
List<String> args = new ArrayList<>(); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
132 |
if (!option.isEmpty()) { |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
133 |
args.add(option); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
134 |
} |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
135 |
args.add("--module-path"); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
136 |
args.add(MODS_DIR.toString()); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
137 |
args.add("-m"); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
138 |
args.add(TEST_MODULE + "/" + TEST_MAIN); |
42170
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
139 |
// not default to CWD |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
140 |
args.add(Boolean.toString(false)); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
141 |
args.add(expected); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
142 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
143 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
144 |
assertTrue(execute(args).getExitValue() == 0); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
145 |
} |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
146 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
147 |
@Test |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
148 |
public void testClassPath() throws Throwable { |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
149 |
List<String> args = new ArrayList<>(); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
150 |
args.add("-Djava.class.path=."); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
151 |
args.add("--module-path"); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
152 |
args.add(MODS_DIR.toString()); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
153 |
args.add("-m"); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
154 |
args.add(TEST_MODULE + "/" + TEST_MAIN); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
155 |
args.add(Boolean.toString(true)); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
156 |
args.add("."); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
157 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
158 |
assertTrue(execute(args).getExitValue() == 0); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
159 |
} |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
160 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
161 |
@Test |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
162 |
public void testJAR() throws Throwable { |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
163 |
String jarfile = LIB_DIR.resolve("m.jar").toString(); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
164 |
List<String> args = new ArrayList<>(); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
165 |
args.add("-jar"); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
166 |
args.add(jarfile); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
167 |
args.add(Boolean.toString(false)); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
168 |
args.add(jarfile); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
169 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
170 |
assertTrue(execute(args).getExitValue() == 0); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
171 |
} |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
172 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
173 |
/* |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
174 |
* Test CLASS-PATH attribute in manifest |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
175 |
*/ |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
176 |
@Test |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
177 |
public void testClassPathAttribute() throws Throwable { |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
178 |
String jarfile = LIB_DIR.resolve("m1.jar").toString(); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
179 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
180 |
List<String> args = new ArrayList<>(); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
181 |
args.add("-jar"); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
182 |
args.add(jarfile); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
183 |
args.add(Boolean.toString(false)); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
184 |
args.add(jarfile); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
185 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
186 |
assertTrue(execute(args).getExitValue() == 0); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
187 |
|
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
188 |
args.clear(); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
189 |
args.add("-cp"); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
190 |
args.add(jarfile); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
191 |
args.add(TEST_MAIN); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
192 |
args.add(Boolean.toString(false)); |
0bb91d845f04
8169909: java agent fails to add to class path when the initial module is a named module
mchung
parents:
41814
diff
changeset
|
193 |
args.add(jarfile); |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
194 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
195 |
assertTrue(execute(args).getExitValue() == 0); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
196 |
} |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
197 |
|
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
198 |
private OutputAnalyzer execute(List<String> options) throws Throwable { |
42993
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
199 |
ProcessBuilder pb = createJavaProcessBuilder( |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
200 |
options.stream() |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
201 |
.map(this::autoQuote) |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
202 |
.toArray(String[]::new) |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
203 |
); |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
204 |
|
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
205 |
Map<String,String> env = pb.environment(); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
206 |
// remove CLASSPATH environment variable |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
207 |
String value = env.remove("CLASSPATH"); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
208 |
return executeCommand(pb) |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
209 |
.outputTo(System.out) |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
210 |
.errorTo(System.out); |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
211 |
} |
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
212 |
|
42993
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
213 |
private static final boolean IS_WINDOWS |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
214 |
= System.getProperty("os.name").startsWith("Windows"); |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
215 |
|
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
216 |
/* |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
217 |
* Autoquote empty string argument on Windows |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
218 |
*/ |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
219 |
private String autoQuote(String arg) { |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
220 |
if (IS_WINDOWS && arg.isEmpty()) { |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
221 |
return "\"\""; |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
222 |
} |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
223 |
return arg; |
d761de69e27f
8172215: java launcher no longer accepts -cp "" empty string
mchung
parents:
42170
diff
changeset
|
224 |
} |
41814
a0333150713e
8168205: Should not default class path to CWD if -cp is not specified but -m is specified
mchung
parents:
diff
changeset
|
225 |
} |