81
82 @Test(expectedExceptions = UnsupportedOperationException.class)
83 public void testCloseFileSystem() throws Exception {
84 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
85 fs.close(); // should throw UOE
86 }
87
88 @Test
89 public void testNewFileSystem() throws Exception {
90 FileSystem theFileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
91 Map<String, ?> env = Collections.emptyMap();
92 try (FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), env)) {
93 checkFileSystem(fs);
94 assertTrue(fs != theFileSystem);
95 }
96 }
97
98 @DataProvider(name = "knownClassFiles")
99 private Object[][] knownClassFiles() {
100 return new Object[][] {
101 { "/java.base/java/lang/Object.class" },
102 { "java.base/java/lang/Object.class" },
103 };
104 }
105
106 @Test(dataProvider = "knownClassFiles")
107 public void testKnownClassFiles(String path) throws Exception {
108 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
109 Path classFile = fs.getPath(path);
110
111 assertTrue(Files.isRegularFile(classFile));
112 assertTrue(Files.size(classFile) > 0L);
113
114 // check magic number
115 try (InputStream in = Files.newInputStream(classFile)) {
116 int magic = new DataInputStream(in).readInt();
117 assertEquals(magic, 0xCAFEBABE);
118 }
119 }
120
121 @DataProvider(name = "knownDirectories")
122 private Object[][] knownDirectories() {
123 return new Object[][] {
124 { "/" },
125 { "." },
126 { "./" },
127 { "/." },
128 { "/./" },
129 { "/java.base/.." },
130 { "/java.base/../" },
131 { "/java.base/../." },
132 { "/java.base" },
133 { "/java.base/java/lang" },
134 { "java.base/java/lang" },
135 { "/java.base/java/lang/" },
136 { "java.base/java/lang/" }
137 };
138 }
139
140 @Test(dataProvider = "knownDirectories")
141 public void testKnownDirectories(String path) throws Exception {
142 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
143 Path dir = fs.getPath(path);
144
145 assertTrue(Files.isDirectory(dir));
146
147 // directory should not be empty
148 try (Stream<Path> stream = Files.list(dir)) {
149 assertTrue(stream.count() > 0L);
150 }
151 try (Stream<Path> stream = Files.walk(dir)) {
152 assertTrue(stream.count() > 0L);
153 }
154 }
155
156 @DataProvider(name = "topLevelPkgDirs")
191 });
192 }
193 }
194
195 @Test
196 public void testDirectoryNames() throws Exception {
197 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
198 Path top = fs.getPath("/");
199 // check that directory names do not have trailing '/' char
200 try (Stream<Path> stream = Files.walk(top)) {
201 stream.skip(1).filter(Files::isDirectory).forEach(path -> {
202 assertFalse(path.toString().endsWith("/"));
203 });
204 }
205 }
206
207 @DataProvider(name = "pathPrefixs")
208 private Object[][] pathPrefixes() {
209 return new Object[][] {
210 { "/" },
211 { "java.base/java/lang" },
212 { "./java.base/java/lang" },
213 { "/java.base/java/lang" },
214 { "/./java.base/java/lang" },
215 { "java.base/java/lang/" },
216 { "./java.base/java/lang/" },
217 { "/./java.base/java/lang/" },
218 };
219 }
220
221 @Test(dataProvider = "pathPrefixes")
222 public void testParentInDirList(String dir) throws Exception {
223 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
224 Path base = fs.getPath(dir);
225 try (DirectoryStream<Path> stream = Files.newDirectoryStream(base)) {
226 for (Path entry: stream) {
227 assertTrue( entry.getParent().equals(base) );
228 }
229 }
230 }
231
232 @DataProvider(name = "dirStreamStringFilterData")
233 private Object[][] dirStreamStringFilterData() {
234 return new Object[][] {
235 { "/java.base/java/lang", "/reflect" },
236 { "/java.base/java/lang", "/Object.class" },
237 { "/java.base/java/util", "/stream" },
238 { "/java.base/java/util", "/List.class" },
239 };
240 }
241
242 @Test(dataProvider = "dirStreamStringFilterData")
243 public void testDirectoryStreamStringFilter(String dir, String filter) throws Exception {
244 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
245 Path base = fs.getPath(dir);
246 try (DirectoryStream<Path> stream =
247 Files.newDirectoryStream(base, p->!p.toString().endsWith(filter))) {
248 for (Path entry: stream) {
249 assertFalse(entry.toString().contains(filter),
250 "filtered path seen: " + filter);
251 }
252 }
253
254 // make sure without filter, we do see that matching entry!
255 boolean seen = false;
256 try (DirectoryStream<Path> stream = Files.newDirectoryStream(base)) {
257 for (Path entry: stream) {
258 if (entry.toString().endsWith(filter)) {
259 seen = true;
260 break;
261 }
262 }
263 }
264
265 assertTrue(seen, "even without filter " + filter + " is missing");
266 }
267
268 @DataProvider(name = "dirStreamFilterData")
269 private Object[][] dirStreamFilterData() {
270 return new Object[][] {
271 {
272 "/",
273 (DirectoryStream.Filter<Path>)(Files::isDirectory),
274 "isDirectory"
275 },
276 {
277 "/java.base/java/lang",
278 (DirectoryStream.Filter<Path>)(Files::isRegularFile),
279 "isFile"
280 }
281 };
282 }
283
284 @Test(dataProvider = "dirStreamFilterData")
285 private void testDirectoryStreamFilter(String dir, DirectoryStream.Filter filter,
286 String name) throws Exception {
287 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
288 Path base = fs.getPath(dir);
289 try (DirectoryStream<Path> stream = Files.newDirectoryStream(base, filter)) {
290 for (Path entry: stream) {
291 assertTrue(filter.accept(entry), "filtered path seen: " + name);
292 }
293 }
294
295 // make sure without filter, we do see that matching entry!
296 boolean seen = false;
297 try (DirectoryStream<Path> stream = Files.newDirectoryStream(base)) {
305
306 assertTrue(seen, "even without filter " + name + " is missing");
307 }
308
309 @Test
310 private void testDirectoryStreamIterator() throws Exception {
311 // run the tests with null filter (no filter)
312 dirStreamIteratorTest(null);
313 // run the same tests with trivial "accept all" filter
314 dirStreamIteratorTest(p->true);
315 // two other non-trivial ones
316 dirStreamIteratorTest(Files::isDirectory);
317 dirStreamIteratorTest(Files::isRegularFile);
318 }
319
320 private void dirStreamIteratorTest(DirectoryStream.Filter<Path> filter)
321 throws Exception {
322 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
323 // This test assumes at least there are two elements in "java/lang"
324 // package with any filter passed. don't change to different path here!
325 Path dir = fs.getPath("/java.base/java/lang");
326 try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
327 Iterator<Path> itr = stream.iterator();
328 itr.hasNext();
329 Path path1 = itr.next();
330 // missing second hasNext call
331 Path path2 = itr.next();
332 assertNotEquals(path1, path2);
333 }
334
335 try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
336 Iterator<Path> itr = stream.iterator();
337 // no hasNext calls at all
338 Path path1 = itr.next();
339 Path path2 = itr.next();
340 assertNotEquals(path1, path2);
341 }
342
343 int numEntries = 0;
344 try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
345 Iterator<Path> itr = stream.iterator();
362 Iterator<Path> itr = stream.iterator();
363 // any number of hasNext should definitely stay at first element
364 for (int i = 0; i < 2*numEntries; i++) {
365 itr.hasNext();
366 }
367
368 for (int j = 0; j < numEntries; j++) {
369 itr.next();
370 }
371 // exactly count number of entries!
372 assertFalse(itr.hasNext());
373 }
374 }
375
376 @DataProvider(name = "hiddenPaths")
377 private Object[][] hiddenPaths() {
378 return new Object[][] {
379 { "/META-INF" },
380 { "/META-INF/services" },
381 { "/META-INF/services/java.nio.file.spi.FileSystemProvider" },
382 { "/java.base/packages.offsets" },
383 { "/java.instrument/packages.offsets" },
384 { "/jdk.zipfs/packages.offsets" },
385 { "/java/lang" },
386 { "/java/util" },
387 };
388 }
389
390 @Test(dataProvider = "hiddenPaths")
391 public void testHiddenPathsNotExposed(String path) throws Exception {
392 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
393 assertTrue(Files.notExists(fs.getPath(path)), path + " should not exist");
394 }
395
396 @DataProvider(name = "pathGlobPatterns")
397 private Object[][] pathGlobPatterns() {
398 return new Object[][] {
399 { "/*", "/java.base", true },
400 { "/*", "/java.base/java", false },
401 { "/j*", "/java.base", true },
402 { "/J*", "/java.base", false },
403 { "**.class", "/java.base/java/lang/Object.class", true },
404 { "**.java", "/java.base/java/lang/Object.class", false },
405 { "**java/*", "/java.base/java/lang", true },
406 { "**java/lang/ref*", "/java.base/java/lang/reflect", true },
407 { "**java/lang/ref*", "/java.base/java/lang/ref", true },
408 { "**java/lang/ref?", "/java.base/java/lang/ref", false },
409 { "**java/lang/{ref,refl*}", "/java.base/java/lang/ref", true },
410 { "**java/lang/{ref,refl*}", "/java.base/java/lang/reflect", true },
411 { "**java/[a-u]?*/*.class", "/java.base/java/util/Map.class", true },
412 { "**java/util/[a-z]*.class", "/java.base/java/util/TreeMap.class", false },
413 };
414 }
415
416 @Test(dataProvider = "pathGlobPatterns")
417 public void testGlobPathMatcher(String pattern, String path,
418 boolean expectMatch) throws Exception {
419 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
420 PathMatcher pm = fs.getPathMatcher("glob:" + pattern);
421 Path p = fs.getPath(path);
422 assertTrue(Files.exists(p), path);
423 assertTrue(!(pm.matches(p) ^ expectMatch),
424 p + (expectMatch? " should match " : " should not match ") +
425 pattern);
426 }
427
428 @DataProvider(name = "pathRegexPatterns")
429 private Object[][] pathRegexPatterns() {
430 return new Object[][] {
431 { "/.*", "/java.base", true },
432 { "/[^/]*", "/java.base/java", false },
433 { "/j.*", "/java.base", true },
434 { "/J.*", "/java.base", false },
435 { ".*\\.class", "/java.base/java/lang/Object.class", true },
436 { ".*\\.java", "/java.base/java/lang/Object.class", false },
437 { ".*java/.*", "/java.base/java/lang", true },
438 { ".*java/lang/ref.*", "/java.base/java/lang/reflect", true },
439 { ".*java/lang/ref.*", "/java.base/java/lang/ref", true },
440 { ".*/java/lang/ref.+", "/java.base/java/lang/ref", false },
441 { ".*/java/lang/(ref|refl.*)", "/java.base/java/lang/ref", true },
442 { ".*/java/lang/(ref|refl.*)", "/java.base/java/lang/reflect", true },
443 { ".*/java/[a-u]?.*/.*\\.class", "/java.base/java/util/Map.class", true },
444 { ".*/java/util/[a-z]*\\.class", "/java.base/java/util/TreeMap.class", false },
445 };
446 }
447
448 @Test(dataProvider = "pathRegexPatterns")
449 public void testRegexPathMatcher(String pattern, String path,
450 boolean expectMatch) throws Exception {
451 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
452 PathMatcher pm = fs.getPathMatcher("regex:" + pattern);
453 Path p = fs.getPath(path);
454 assertTrue(Files.exists(p), path);
455 assertTrue(!(pm.matches(p) ^ expectMatch),
456 p + (expectMatch? " should match " : " should not match ") +
457 pattern);
458 }
459 }
|
81
82 @Test(expectedExceptions = UnsupportedOperationException.class)
83 public void testCloseFileSystem() throws Exception {
84 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
85 fs.close(); // should throw UOE
86 }
87
88 @Test
89 public void testNewFileSystem() throws Exception {
90 FileSystem theFileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
91 Map<String, ?> env = Collections.emptyMap();
92 try (FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), env)) {
93 checkFileSystem(fs);
94 assertTrue(fs != theFileSystem);
95 }
96 }
97
98 @DataProvider(name = "knownClassFiles")
99 private Object[][] knownClassFiles() {
100 return new Object[][] {
101 { "/modules/java.base/java/lang/Object.class" },
102 { "modules/java.base/java/lang/Object.class" },
103 };
104 }
105
106 @Test(dataProvider = "knownClassFiles")
107 public void testKnownClassFiles(String path) throws Exception {
108 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
109 Path classFile = fs.getPath(path);
110
111 assertTrue(Files.isRegularFile(classFile));
112 assertTrue(Files.size(classFile) > 0L);
113
114 // check magic number
115 try (InputStream in = Files.newInputStream(classFile)) {
116 int magic = new DataInputStream(in).readInt();
117 assertEquals(magic, 0xCAFEBABE);
118 }
119 }
120
121 @DataProvider(name = "knownDirectories")
122 private Object[][] knownDirectories() {
123 return new Object[][] {
124 { "/" },
125 { "." },
126 { "./" },
127 { "/." },
128 { "/./" },
129 { "/modules/java.base/.." },
130 { "/modules/java.base/../" },
131 { "/modules/java.base/../." },
132 { "/modules/java.base" },
133 { "/modules/java.base/java/lang" },
134 { "modules/java.base/java/lang" },
135 { "/modules/java.base/java/lang/" },
136 { "modules/java.base/java/lang/" }
137 };
138 }
139
140 @Test(dataProvider = "knownDirectories")
141 public void testKnownDirectories(String path) throws Exception {
142 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
143 Path dir = fs.getPath(path);
144
145 assertTrue(Files.isDirectory(dir));
146
147 // directory should not be empty
148 try (Stream<Path> stream = Files.list(dir)) {
149 assertTrue(stream.count() > 0L);
150 }
151 try (Stream<Path> stream = Files.walk(dir)) {
152 assertTrue(stream.count() > 0L);
153 }
154 }
155
156 @DataProvider(name = "topLevelPkgDirs")
191 });
192 }
193 }
194
195 @Test
196 public void testDirectoryNames() throws Exception {
197 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
198 Path top = fs.getPath("/");
199 // check that directory names do not have trailing '/' char
200 try (Stream<Path> stream = Files.walk(top)) {
201 stream.skip(1).filter(Files::isDirectory).forEach(path -> {
202 assertFalse(path.toString().endsWith("/"));
203 });
204 }
205 }
206
207 @DataProvider(name = "pathPrefixs")
208 private Object[][] pathPrefixes() {
209 return new Object[][] {
210 { "/" },
211 { "modules/java.base/java/lang" },
212 { "./modules/java.base/java/lang" },
213 { "/modules/java.base/java/lang" },
214 { "/./modules/java.base/java/lang" },
215 { "modules/java.base/java/lang/" },
216 { "./modules/java.base/java/lang/" },
217 { "/./modules/java.base/java/lang/" },
218 };
219 }
220
221 // @Test(dataProvider = "pathPrefixes")
222 public void testParentInDirList(String dir) throws Exception {
223 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
224 Path base = fs.getPath(dir);
225 try (DirectoryStream<Path> stream = Files.newDirectoryStream(base)) {
226 for (Path entry: stream) {
227 assertTrue( entry.getParent().equals(base),
228 base.toString() + "-> " + entry.toString() );
229 }
230 }
231 }
232
233 @DataProvider(name = "dirStreamStringFilterData")
234 private Object[][] dirStreamStringFilterData() {
235 return new Object[][] {
236 { "/modules/java.base/java/lang", "/reflect" },
237 { "/modules/java.base/java/lang", "/Object.class" },
238 { "/modules/java.base/java/util", "/stream" },
239 { "/modules/java.base/java/util", "/List.class" },
240 };
241 }
242
243 @Test(dataProvider = "dirStreamStringFilterData")
244 public void testDirectoryStreamStringFilter(String dir, String filter) throws Exception {
245 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
246 Path base = fs.getPath(dir);
247 try (DirectoryStream<Path> stream =
248 Files.newDirectoryStream(base, p->!p.toString().endsWith(filter))) {
249 for (Path entry: stream) {
250 assertFalse(entry.toString().contains(filter),
251 "filtered path seen: " + filter);
252 }
253 }
254
255 // make sure without filter, we do see that matching entry!
256 boolean seen = false;
257 try (DirectoryStream<Path> stream = Files.newDirectoryStream(base)) {
258 for (Path entry: stream) {
259 if (entry.toString().endsWith(filter)) {
260 seen = true;
261 break;
262 }
263 }
264 }
265
266 assertTrue(seen, "even without filter " + filter + " is missing");
267 }
268
269 @DataProvider(name = "dirStreamFilterData")
270 private Object[][] dirStreamFilterData() {
271 return new Object[][] {
272 {
273 "/",
274 (DirectoryStream.Filter<Path>)(Files::isDirectory),
275 "isDirectory"
276 },
277 {
278 "/modules/java.base/java/lang",
279 (DirectoryStream.Filter<Path>)(Files::isRegularFile),
280 "isFile"
281 }
282 };
283 }
284
285 @Test(dataProvider = "dirStreamFilterData")
286 private void testDirectoryStreamFilter(String dir, DirectoryStream.Filter filter,
287 String name) throws Exception {
288 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
289 Path base = fs.getPath(dir);
290 try (DirectoryStream<Path> stream = Files.newDirectoryStream(base, filter)) {
291 for (Path entry: stream) {
292 assertTrue(filter.accept(entry), "filtered path seen: " + name);
293 }
294 }
295
296 // make sure without filter, we do see that matching entry!
297 boolean seen = false;
298 try (DirectoryStream<Path> stream = Files.newDirectoryStream(base)) {
306
307 assertTrue(seen, "even without filter " + name + " is missing");
308 }
309
310 @Test
311 private void testDirectoryStreamIterator() throws Exception {
312 // run the tests with null filter (no filter)
313 dirStreamIteratorTest(null);
314 // run the same tests with trivial "accept all" filter
315 dirStreamIteratorTest(p->true);
316 // two other non-trivial ones
317 dirStreamIteratorTest(Files::isDirectory);
318 dirStreamIteratorTest(Files::isRegularFile);
319 }
320
321 private void dirStreamIteratorTest(DirectoryStream.Filter<Path> filter)
322 throws Exception {
323 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
324 // This test assumes at least there are two elements in "java/lang"
325 // package with any filter passed. don't change to different path here!
326 Path dir = fs.getPath("/modules/java.base/java/lang");
327 try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
328 Iterator<Path> itr = stream.iterator();
329 itr.hasNext();
330 Path path1 = itr.next();
331 // missing second hasNext call
332 Path path2 = itr.next();
333 assertNotEquals(path1, path2);
334 }
335
336 try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
337 Iterator<Path> itr = stream.iterator();
338 // no hasNext calls at all
339 Path path1 = itr.next();
340 Path path2 = itr.next();
341 assertNotEquals(path1, path2);
342 }
343
344 int numEntries = 0;
345 try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
346 Iterator<Path> itr = stream.iterator();
363 Iterator<Path> itr = stream.iterator();
364 // any number of hasNext should definitely stay at first element
365 for (int i = 0; i < 2*numEntries; i++) {
366 itr.hasNext();
367 }
368
369 for (int j = 0; j < numEntries; j++) {
370 itr.next();
371 }
372 // exactly count number of entries!
373 assertFalse(itr.hasNext());
374 }
375 }
376
377 @DataProvider(name = "hiddenPaths")
378 private Object[][] hiddenPaths() {
379 return new Object[][] {
380 { "/META-INF" },
381 { "/META-INF/services" },
382 { "/META-INF/services/java.nio.file.spi.FileSystemProvider" },
383 { "/modules/java.base/packages.offsets" },
384 { "/modules/java.instrument/packages.offsets" },
385 { "/modules/jdk.zipfs/packages.offsets" },
386 { "/java/lang" },
387 { "/java/util" },
388 };
389 }
390
391 @Test(dataProvider = "hiddenPaths")
392 public void testHiddenPathsNotExposed(String path) throws Exception {
393 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
394 assertTrue(Files.notExists(fs.getPath(path)), path + " should not exist");
395 }
396
397 @DataProvider(name = "pathGlobPatterns")
398 private Object[][] pathGlobPatterns() {
399 return new Object[][] {
400 { "/modules/*", "/modules/java.base", true },
401 { "/modules/*", "/modules/java.base/java", false },
402 { "/modules/j*", "/modules/java.base", true },
403 { "/modules/J*", "/modules/java.base", false },
404 { "**.class", "/modules/java.base/java/lang/Object.class", true },
405 { "**.java", "/modules/java.base/java/lang/Object.class", false },
406 { "**java/*", "/modules/java.base/java/lang", true },
407 { "**java/lang/ref*", "/modules/java.base/java/lang/reflect", true },
408 { "**java/lang/ref*", "/modules/java.base/java/lang/ref", true },
409 { "**java/lang/ref?", "/modules/java.base/java/lang/ref", false },
410 { "**java/lang/{ref,refl*}", "/modules/java.base/java/lang/ref", true },
411 { "**java/lang/{ref,refl*}", "/modules/java.base/java/lang/reflect", true },
412 { "**java/[a-u]?*/*.class", "/modules/java.base/java/util/Map.class", true },
413 { "**java/util/[a-z]*.class", "/modules/java.base/java/util/TreeMap.class", false },
414 };
415 }
416
417 @Test(dataProvider = "pathGlobPatterns")
418 public void testGlobPathMatcher(String pattern, String path,
419 boolean expectMatch) throws Exception {
420 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
421 PathMatcher pm = fs.getPathMatcher("glob:" + pattern);
422 Path p = fs.getPath(path);
423 assertTrue(Files.exists(p), path);
424 assertTrue(!(pm.matches(p) ^ expectMatch),
425 p + (expectMatch? " should match " : " should not match ") +
426 pattern);
427 }
428
429 @DataProvider(name = "pathRegexPatterns")
430 private Object[][] pathRegexPatterns() {
431 return new Object[][] {
432 { "/modules/.*", "/modules/java.base", true },
433 { "/modules/[^/]*", "/modules/java.base/java", false },
434 { "/modules/j.*", "/modules/java.base", true },
435 { "/modules/J.*", "/modules/java.base", false },
436 { ".*\\.class", "/modules/java.base/java/lang/Object.class", true },
437 { ".*\\.java", "/modules/java.base/java/lang/Object.class", false },
438 { ".*java/.*", "/modules/java.base/java/lang", true },
439 { ".*java/lang/ref.*", "/modules/java.base/java/lang/reflect", true },
440 { ".*java/lang/ref.*", "/modules/java.base/java/lang/ref", true },
441 { ".*/java/lang/ref.+", "/modules/java.base/java/lang/ref", false },
442 { ".*/java/lang/(ref|refl.*)", "/modules/java.base/java/lang/ref", true },
443 { ".*/java/lang/(ref|refl.*)", "/modules/java.base/java/lang/reflect", true },
444 { ".*/java/[a-u]?.*/.*\\.class", "/modules/java.base/java/util/Map.class", true },
445 { ".*/java/util/[a-z]*\\.class", "/modules/java.base/java/util/TreeMap.class", false },
446 };
447 }
448
449 @Test(dataProvider = "pathRegexPatterns")
450 public void testRegexPathMatcher(String pattern, String path,
451 boolean expectMatch) throws Exception {
452 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
453 PathMatcher pm = fs.getPathMatcher("regex:" + pattern);
454 Path p = fs.getPath(path);
455 assertTrue(Files.exists(p), path);
456 assertTrue(!(pm.matches(p) ^ expectMatch),
457 p + (expectMatch? " should match " : " should not match ") +
458 pattern);
459 }
460
461 @Test
462 public void testPackagesAndModules() throws Exception {
463 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
464 assertTrue(Files.isDirectory(fs.getPath("/packages")));
465 assertTrue(Files.isDirectory(fs.getPath("/modules")));
466 }
467
468 @DataProvider(name = "packagesSubDirs")
469 private Object[][] packagesSubDirs() {
470 return new Object[][] {
471 { "java.lang" },
472 { "java.util" },
473 { "java.nio" },
474 { "jdk.nashorn.api.scripting" }
475 };
476 }
477
478 @Test(dataProvider = "packagesSubDirs")
479 public void testPackagesSubDirs(String pkg) throws Exception {
480 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
481 assertTrue(Files.isDirectory(fs.getPath("/packages/" + pkg)),
482 pkg + " missing");
483 }
484
485 @DataProvider(name = "packagesLinks")
486 private Object[][] packagesLinks() {
487 return new Object[][] {
488 { "/packages/java.lang/java.base" },
489 { "/packages/java.lang/java.instrument" },
490 { "/packages/java/java.base" },
491 { "/packages/java/java.instrument" },
492 { "/packages/java/java.rmi" },
493 { "/packages/java/java.sql" },
494 { "/packages/javax/java.base" },
495 { "/packages/javax/java.sql" },
496 { "/packages/javax/java.xml" },
497 { "/packages/javax/java.management" },
498 { "/packages/java.util/java.base" },
499 { "/packages/jdk.nashorn.api.scripting/jdk.scripting.nashorn" },
500 };
501 }
502
503 @Test(dataProvider = "packagesLinks")
504 public void testPackagesLinks(String link) throws Exception {
505 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
506 Path path = fs.getPath(link);
507 assertTrue(Files.exists(path), link + " missing");
508 assertTrue(Files.isSymbolicLink(path), path + " is not a link");
509 path = Files.readSymbolicLink(path);
510 assertEquals(path.toString(), "/modules" + link.substring(link.lastIndexOf("/")));
511 }
512
513 @DataProvider(name = "modulesSubDirs")
514 private Object[][] modulesSubDirs() {
515 return new Object[][] {
516 { "java.base" },
517 { "java.sql" },
518 { "jdk.scripting.nashorn" },
519 };
520 }
521
522 @Test(dataProvider = "modulesSubDirs")
523 public void testModulesSubDirs(String module) throws Exception {
524 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
525 Path path = fs.getPath("/modules/" + module);
526 assertTrue(Files.isDirectory(path), module + " missing");
527 assertTrue(!Files.isSymbolicLink(path), path + " is a link");
528 }
529
530 @DataProvider(name="linkChases")
531 private Object[][] linkChases() {
532 return new Object[][] {
533 { "/modules/java.base/java/lang" },
534 { "/modules/java.base/java/util/Vector.class" },
535 { "/modules/jdk.scripting.nashorn/jdk/nashorn" },
536 { "/packages/java.lang/java.base/java/lang" },
537 { "/packages/java.util/java.base/java/util/Vector.class" },
538 };
539 }
540
541 @Test(dataProvider = "linkChases")
542 public void testLinkChases(String link) throws Exception {
543 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
544 Path path = fs.getPath(link);
545 assertTrue(Files.exists(path), link);
546 }
547
548 @Test
549 public void testSymlinkDirList() throws Exception {
550 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
551 Path path = fs.getPath("/packages/java.lang/java.base");
552 assertTrue(Files.isSymbolicLink(path));
553 assertTrue(Files.isDirectory(path));
554
555 boolean javaSeen = false, javaxSeen = false;
556 try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
557 for (Path p : stream) {
558 String str = p.toString();
559 if (str.endsWith("/java")) {
560 javaSeen = true;
561 } else if (str.endsWith("javax")) {
562 javaxSeen = true;
563 }
564 }
565 }
566 assertTrue(javaSeen);
567 assertTrue(javaxSeen);
568 }
569
570 @Test
571 public void testPackagesSubDirList() throws Exception {
572 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
573 String pathName = "/packages/javax.annotation";
574 Path path = fs.getPath(pathName);
575 boolean seenJavaCompiler = false, seenAnnotationsCommon = false;
576 try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
577 for (Path p : stream) {
578 String str = p.toString();
579 if (str.equals(pathName + "/java.compiler")) {
580 seenJavaCompiler = true;
581 } else if (str.equals(pathName + "/java.annotations.common")) {
582 seenAnnotationsCommon = true;
583 }
584 }
585 }
586 assertTrue(seenJavaCompiler);
587 assertTrue(seenAnnotationsCommon);
588 }
589
590 @Test
591 public void testRootDirList() throws Exception {
592 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
593 Path path = fs.getPath("/");
594 // check /packages and /modules are not repeated
595 // and seen once.
596 boolean packages = false, modules = false;
597 try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
598 for (Path p : stream) {
599 String str = p.toString();
600 switch (str) {
601 case "/packages":
602 assertFalse(packages, "/packages repeated");
603 packages = true;
604 break;
605 case "/modules":
606 assertFalse(modules, "/modules repeated");
607 modules = true;
608 break;
609 }
610 }
611 }
612 assertTrue(packages, "/packages missing in / list!");
613 assertTrue(modules, "/modules missing in / list!");
614 }
615 }
|