25 * @test |
25 * @test |
26 * @summary Basic test of jlink to create jmods and images |
26 * @summary Basic test of jlink to create jmods and images |
27 * @author Andrei Eremeev |
27 * @author Andrei Eremeev |
28 * @library /lib/testlibrary |
28 * @library /lib/testlibrary |
29 * @modules java.base/jdk.internal.module |
29 * @modules java.base/jdk.internal.module |
30 * jdk.jlink/jdk.tools.jlink.internal |
30 * jdk.jlink |
31 * jdk.jlink/jdk.tools.jmod |
|
32 * jdk.compiler |
31 * jdk.compiler |
33 * @build jdk.testlibrary.ProcessTools |
32 * @build jdk.testlibrary.ProcessTools |
34 * jdk.testlibrary.OutputAnalyzer |
33 * jdk.testlibrary.OutputAnalyzer |
35 * JarUtils CompilerUtils |
34 * JarUtils CompilerUtils |
36 * @run main BasicTest |
35 * @run main BasicTest |
42 import java.nio.file.Path; |
41 import java.nio.file.Path; |
43 import java.nio.file.Paths; |
42 import java.nio.file.Paths; |
44 import java.util.ArrayList; |
43 import java.util.ArrayList; |
45 import java.util.Collections; |
44 import java.util.Collections; |
46 import java.util.List; |
45 import java.util.List; |
|
46 import java.util.spi.ToolProvider; |
47 |
47 |
48 import jdk.testlibrary.OutputAnalyzer; |
48 import jdk.testlibrary.OutputAnalyzer; |
49 import jdk.testlibrary.ProcessTools; |
49 import jdk.testlibrary.ProcessTools; |
50 |
50 |
51 public class BasicTest { |
51 public class BasicTest { |
|
52 static final ToolProvider JMOD_TOOL = ToolProvider.findFirst("jmod") |
|
53 .orElseThrow(() -> |
|
54 new RuntimeException("jmod tool not found") |
|
55 ); |
|
56 |
|
57 static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink") |
|
58 .orElseThrow(() -> |
|
59 new RuntimeException("jlink tool not found") |
|
60 ); |
52 |
61 |
53 private final Path jdkHome = Paths.get(System.getProperty("test.jdk")); |
62 private final Path jdkHome = Paths.get(System.getProperty("test.jdk")); |
54 private final Path jdkMods = jdkHome.resolve("jmods"); |
63 private final Path jdkMods = jdkHome.resolve("jmods"); |
55 private final Path testSrc = Paths.get(System.getProperty("test.src")); |
64 private final Path testSrc = Paths.get(System.getProperty("test.src")); |
56 private final Path src = testSrc.resolve("src"); |
65 private final Path src = testSrc.resolve("src"); |
108 Collections.addAll(args, |
117 Collections.addAll(args, |
109 "--module-path", jdkMods + File.pathSeparator + jmods, |
118 "--module-path", jdkMods + File.pathSeparator + jmods, |
110 "--add-modules", modName, |
119 "--add-modules", modName, |
111 "--output", image.toString()); |
120 "--output", image.toString()); |
112 Collections.addAll(args, options); |
121 Collections.addAll(args, options); |
113 int rc = jdk.tools.jlink.internal.Main.run(args.toArray(new String[args.size()]), new PrintWriter(System.out)); |
122 |
|
123 PrintWriter pw = new PrintWriter(System.out); |
|
124 int rc = JLINK_TOOL.run(pw, pw, args.toArray(new String[args.size()])); |
114 if (rc != 0) { |
125 if (rc != 0) { |
115 throw new AssertionError("Jlink failed: rc = " + rc); |
126 throw new AssertionError("Jlink failed: rc = " + rc); |
116 } |
127 } |
117 } |
128 } |
118 |
129 |
119 private void runJmod(String cp, String modName) { |
130 private void runJmod(String cp, String modName) { |
120 int rc = jdk.tools.jmod.Main.run(new String[] { |
131 int rc = JMOD_TOOL.run(System.out, System.out, new String[] { |
121 "create", |
132 "create", |
122 "--class-path", cp, |
133 "--class-path", cp, |
123 "--module-version", "1.0", |
134 "--module-version", "1.0", |
124 "--main-class", "jdk.test.Test", |
135 "--main-class", "jdk.test.Test", |
125 jmods.resolve(modName + ".jmod").toString(), |
136 jmods.resolve(modName + ".jmod").toString(), |
126 }, System.out); |
137 }); |
127 if (rc != 0) { |
138 if (rc != 0) { |
128 throw new AssertionError("Jmod failed: rc = " + rc); |
139 throw new AssertionError("Jmod failed: rc = " + rc); |
129 } |
140 } |
130 } |
141 } |
131 } |
142 } |