41
41
import org .testng .annotations .Test ;
42
42
43
43
import jdk .test .lib .compiler .CompilerUtils ;
44
- import jdk .test .lib .process .OutputAnalyzer ;
45
44
import jdk .test .lib .process .ProcessTools ;
46
45
import jdk .tools .jlink .internal .LinkableRuntimeImage ;
47
46
import tests .Helper ;
@@ -126,30 +125,29 @@ public void testAllModulePath() throws Throwable {
126
125
}
127
126
128
127
/*
129
- * --add-modules ALL-MODULE-PATH with an existing module path and module
130
- * limits applied. Module limit on module from module path.
128
+ * Since ALL-MODULE-PATH does not allow --limit-modules. Add a test that
129
+ * includes just a single module from the module path. This is just for
130
+ * completeness and shows the intended replacement.
131
131
*/
132
132
@ Test
133
- public void testLimitModules () throws Throwable {
133
+ public void testSubsetModules () throws Throwable {
134
134
if (isExplodedJDKImage ()) {
135
135
return ;
136
136
}
137
137
138
138
// create custom image
139
139
Path image = HELPER .createNewImageDir ("image1" );
140
+ // Instead of --add-modules ALL-MODULE-PATH [...] --limit-modules m1 do:
140
141
List <String > opts = List .of ("--module-path" , MODS .toString (),
141
142
"--output" , image .toString (),
142
- "--add-modules" , "ALL-MODULE-PATH" ,
143
- "--limit-modules" , "m1" );
143
+ "--add-modules" , "m1" );
144
144
createImage (image , opts , true /* success */ );
145
145
146
146
checkModules (image , Set .of ("m1" , "java.base" ));
147
147
}
148
148
149
149
/*
150
150
* --add-modules *includes* ALL-MODULE-PATH with an existing module path
151
- * and module limits applied. Module limit on a dependency, but custom
152
- * modules explicitly listed (therefore, expect inclusion of them).
153
151
*/
154
152
@ Test
155
153
public void testAddModules () throws Throwable {
@@ -162,8 +160,7 @@ public void testAddModules() throws Throwable {
162
160
List <String > opts = List .of ("--module-path" , MODS .toString (),
163
161
"--output" , image .toString (),
164
162
"--add-modules" , "m1,test" ,
165
- "--add-modules" , "ALL-MODULE-PATH" ,
166
- "--limit-modules" , "java.base" );
163
+ "--add-modules" , "ALL-MODULE-PATH" );
167
164
createImage (image , opts , true /* success */ );
168
165
169
166
checkModules (image , Set .of ("m1" , "test" , "java.base" ));
@@ -197,7 +194,7 @@ public void modulePathEmpty() throws IOException {
197
194
String strNotExists = "not-exist" ;
198
195
Path notExists = Path .of (strNotExists );
199
196
if (Files .exists (notExists )) {
200
- throw new RuntimeException ("Test setup error, path must not exist!" );
197
+ throw new AssertionError ("Test setup error, path must not exist!" );
201
198
}
202
199
List <String > allArgs = List .of ("--add-modules" , "ALL-MODULE-PATH" ,
203
200
"--module-path" , notExists .toString (),
@@ -210,13 +207,10 @@ public void modulePathEmpty() throws IOException {
210
207
}
211
208
212
209
/*
213
- * --add-modules ALL-MODULE-PATH with an existing module path and module
214
- * limits applied. This case tests a module limit on a dependency, jdk.jfr,
215
- * and *doesn't* list the module explicitly in --add-modules. Therefore,
216
- * expects for the module - on the module path - to not be present.
210
+ * --add-modules ALL-MODULE-PATH with --limit-modules is an error
217
211
*/
218
212
@ Test
219
- public void modulePathWithLimitMods () throws Exception {
213
+ public void testLimitModules () throws Exception {
220
214
if (isExplodedJDKImage ()) {
221
215
return ;
222
216
}
@@ -225,14 +219,13 @@ public void modulePathWithLimitMods() throws Exception {
225
219
Result result = HELPER .generateDefaultJModule (moduleName , "jdk.jfr" );
226
220
Path customModulePath = result .getFile ().getParent ();
227
221
List <String > allArgs = List .of ("--add-modules" , "ALL-MODULE-PATH" ,
228
- "--limit-modules" , "jdk.jfr" , // A dependency of com.baz.runtime
222
+ "--limit-modules" , "jdk.jfr" ,
229
223
"--module-path" , customModulePath .toString (),
230
224
"--output" , targetPath .toString ());
231
- JlinkOutput allOut = createImage (targetPath , allArgs , true /* success */ );
232
- assertTrue (allOut .stdout .isEmpty ());
233
- assertTrue (allOut .stderr .isEmpty ());
234
- Set <String > expected = Set .of ("java.base" , "jdk.jfr" );
235
- verifyListModules (targetPath , expected );
225
+ JlinkOutput allOut = createImage (targetPath , allArgs , false /* success */ );
226
+ String actual = allOut .stdout .trim ();
227
+ String expected = "Error: --limit-modules not allowed with --add-modules ALL-MODULE-PATH" ;
228
+ assertEquals (actual , expected );
236
229
}
237
230
238
231
/*
@@ -252,20 +245,6 @@ private void checkModules(Path image, Set<String> modules) throws Throwable {
252
245
.shouldHaveExitValue (0 );
253
246
}
254
247
255
- /*
256
- * Verify linked modules using java --list-modules
257
- */
258
- private void verifyListModules (Path targetPath , Set <String > expected ) throws Exception {
259
- Path java = findTool (targetPath , "java" );
260
- List <String > listMods = List .of (java .toString (), "--list-modules" );
261
- OutputAnalyzer out = ProcessTools .executeCommand (listMods .toArray (new String [] {}))
262
- .shouldHaveExitValue (0 );
263
- Set <String > actual = out .asLines ().stream ()
264
- .map (s -> { return s .split ("@" )[0 ]; })
265
- .collect (Collectors .toSet ());
266
- assertEquals (actual , expected );
267
- }
268
-
269
248
private Path findTool (Path image , String tool ) {
270
249
String suffix = System .getProperty ("os.name" ).startsWith ("Windows" )
271
250
? ".exe" : "" ;
0 commit comments