equal
deleted
inserted
replaced
24 /** |
24 /** |
25 * @test |
25 * @test |
26 * @bug 8159596 |
26 * @bug 8159596 |
27 * @library /lib/testlibrary |
27 * @library /lib/testlibrary |
28 * @modules jdk.compiler |
28 * @modules jdk.compiler |
29 * jdk.jartool/sun.tools.jar |
29 * jdk.jartool |
30 * @build DryRunTest CompilerUtils jdk.testlibrary.ProcessTools |
30 * @build DryRunTest CompilerUtils jdk.testlibrary.ProcessTools |
31 * @run testng DryRunTest |
31 * @run testng DryRunTest |
32 * @summary Test java --dry-run |
32 * @summary Test java --dry-run |
33 */ |
33 */ |
34 |
34 |
35 import java.io.File; |
35 import java.io.File; |
36 import java.io.IOException; |
36 import java.io.IOException; |
37 import java.nio.file.Files; |
37 import java.nio.file.Files; |
38 import java.nio.file.Path; |
38 import java.nio.file.Path; |
39 import java.nio.file.Paths; |
39 import java.nio.file.Paths; |
|
40 import java.util.spi.ToolProvider; |
40 |
41 |
41 import jdk.testlibrary.ProcessTools; |
42 import jdk.testlibrary.ProcessTools; |
42 |
43 |
43 import org.testng.annotations.BeforeTest; |
44 import org.testng.annotations.BeforeTest; |
44 import org.testng.annotations.Test; |
45 import org.testng.annotations.Test; |
76 "--module-source-path", SRC_DIR.toString())); |
77 "--module-source-path", SRC_DIR.toString())); |
77 |
78 |
78 Files.createDirectories(LIBS_DIR); |
79 Files.createDirectories(LIBS_DIR); |
79 |
80 |
80 // create JAR files with no module-info.class |
81 // create JAR files with no module-info.class |
81 assertTrue(jar(M_MODULE, "p/Lib.class")); |
82 assertTrue(jar(M_MODULE, "p/Lib.class") == 0); |
82 assertTrue(jar(TEST_MODULE, "jdk/test/Main.class")); |
83 assertTrue(jar(TEST_MODULE, "jdk/test/Main.class") == 0); |
83 } |
84 } |
84 |
85 |
85 /** |
86 /** |
86 * Execute "java" with the given arguments, returning the exit code. |
87 * Execute "java" with the given arguments, returning the exit code. |
87 */ |
88 */ |
195 // resolution failure |
196 // resolution failure |
196 int exitValue = exec("--dry-run", "--module-path", subdir, "-m", mid); |
197 int exitValue = exec("--dry-run", "--module-path", subdir, "-m", mid); |
197 assertTrue(exitValue != 0); |
198 assertTrue(exitValue != 0); |
198 } |
199 } |
199 |
200 |
200 private static boolean jar(String name, String entries) throws IOException { |
201 private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar") |
|
202 .orElseThrow(() -> |
|
203 new RuntimeException("jar tool not found") |
|
204 ); |
|
205 |
|
206 private static int jar(String name, String entries) throws IOException { |
201 Path jar = LIBS_DIR.resolve(name + ".jar"); |
207 Path jar = LIBS_DIR.resolve(name + ".jar"); |
202 |
208 |
203 // jar --create ... |
209 // jar --create ... |
204 String classes = MODS_DIR.resolve(name).toString(); |
210 String classes = MODS_DIR.resolve(name).toString(); |
205 String[] args = { |
211 String[] args = { |
206 "--create", |
212 "--create", |
207 "--file=" + jar, |
213 "--file=" + jar, |
208 "-C", classes, entries |
214 "-C", classes, entries |
209 }; |
215 }; |
210 boolean success |
216 return JAR_TOOL.run(System.out, System.out, args); |
211 = new sun.tools.jar.Main(System.out, System.out, "jar").run(args); |
|
212 return success; |
|
213 } |
217 } |
214 } |
218 } |