356 "README", 357 "WEB-INF/tags", 358 "p/Type.class", 359 "p/resources/m.properties", 360 "q-/Type.class", // not a legal package name 361 "q-/resources/m/properties"); 362 363 ModuleFinder finder = ModuleFinder.of(m_dir); 364 Optional<ModuleReference> mref = finder.find("m"); 365 assertTrue(mref.isPresent(), "m not found"); 366 367 ModuleDescriptor descriptor = mref.get().descriptor(); 368 369 assertTrue(descriptor.packages().size() == 2); 370 assertTrue(descriptor.packages().contains("p")); 371 assertTrue(descriptor.packages().contains("p.resources")); 372 } 373 374 375 /** 376 * Test ModuleModule with a JAR file containing a .class file in the top 377 * level directory. 378 */ 379 public void testOfOneJarFileWithTopLevelClass() throws Exception { 380 Path dir = Files.createTempDirectory(USER_DIR, "mods"); 381 Path jar = createModularJar(dir.resolve("m.jar"), "m", "Mojo.class"); 382 383 ModuleFinder finder = ModuleFinder.of(jar); 384 try { 385 finder.find("m"); 386 assertTrue(false); 387 } catch (FindException e) { 388 assertTrue(e.getCause() instanceof InvalidModuleDescriptorException); 389 } 390 391 finder = ModuleFinder.of(jar); 392 try { 393 finder.findAll(); 394 assertTrue(false); 395 } catch (FindException e) { 396 assertTrue(e.getCause() instanceof InvalidModuleDescriptorException); 397 } 398 } 399 400 /** 401 * Test ModuleModule with a JAR file containing a .class file in the top 402 * level directory. 403 */ 404 public void testOfOneExplodedModuleWithTopLevelClass() throws Exception { 405 Path dir = Files.createTempDirectory(USER_DIR, "mods"); 406 Path m_dir = createExplodedModule(dir.resolve("m"), "m", "Mojo.class"); 407 408 ModuleFinder finder = ModuleFinder.of(m_dir); 409 try { 410 finder.find("m"); 411 assertTrue(false); 412 } catch (FindException e) { 413 assertTrue(e.getCause() instanceof InvalidModuleDescriptorException); 414 } 415 416 finder = ModuleFinder.of(m_dir); 417 try { 418 finder.findAll(); 419 assertTrue(false); 420 } catch (FindException e) { 421 assertTrue(e.getCause() instanceof InvalidModuleDescriptorException); 422 } 423 } 424 425 426 /** 427 * Test ModuleFinder.of with a path to a file that does not exist. 428 */ 429 public void testOfWithDoesNotExistEntry() throws Exception { 430 Path dir1 = Files.createTempDirectory(USER_DIR, "mods1"); 431 432 Path dir2 = Files.createTempDirectory(USER_DIR, "mods2"); 433 createModularJar(dir2.resolve("m2.jar"), "m2@1.0"); 434 435 Files.delete(dir1); 436 437 ModuleFinder finder = ModuleFinder.of(dir1, dir2); 438 439 assertTrue(finder.find("m2").isPresent()); 440 assertTrue(finder.findAll().size() == 1); 441 assertFalse(finder.find("java.rhubarb").isPresent()); | 356 "README", 357 "WEB-INF/tags", 358 "p/Type.class", 359 "p/resources/m.properties", 360 "q-/Type.class", // not a legal package name 361 "q-/resources/m/properties"); 362 363 ModuleFinder finder = ModuleFinder.of(m_dir); 364 Optional<ModuleReference> mref = finder.find("m"); 365 assertTrue(mref.isPresent(), "m not found"); 366 367 ModuleDescriptor descriptor = mref.get().descriptor(); 368 369 assertTrue(descriptor.packages().size() == 2); 370 assertTrue(descriptor.packages().contains("p")); 371 assertTrue(descriptor.packages().contains("p.resources")); 372 } 373 374 375 /** 376 * Test ModuleFinder with a JAR file containing a .class file in the top 377 * level directory. 378 */ 379 public void testOfOneJarFileWithTopLevelClass() throws Exception { 380 Path dir = Files.createTempDirectory(USER_DIR, "mods"); 381 Path jar = createModularJar(dir.resolve("m.jar"), "m", "Mojo.class"); 382 383 ModuleFinder finder = ModuleFinder.of(jar); 384 try { 385 finder.find("m"); 386 assertTrue(false); 387 } catch (FindException e) { 388 assertTrue(e.getCause() instanceof InvalidModuleDescriptorException); 389 assertTrue(e.getCause().getMessage().contains("Mojo.class")); 390 } 391 392 finder = ModuleFinder.of(jar); 393 try { 394 finder.findAll(); 395 assertTrue(false); 396 } catch (FindException e) { 397 assertTrue(e.getCause() instanceof InvalidModuleDescriptorException); 398 assertTrue(e.getCause().getMessage().contains("Mojo.class")); 399 } 400 } 401 402 /** 403 * Test ModuleFinder with a JAR file containing a .class file in the top 404 * level directory. 405 */ 406 public void testOfOneExplodedModuleWithTopLevelClass() throws Exception { 407 Path dir = Files.createTempDirectory(USER_DIR, "mods"); 408 Path m_dir = createExplodedModule(dir.resolve("m"), "m", "Mojo.class"); 409 410 ModuleFinder finder = ModuleFinder.of(m_dir); 411 try { 412 finder.find("m"); 413 assertTrue(false); 414 } catch (FindException e) { 415 assertTrue(e.getCause() instanceof InvalidModuleDescriptorException); 416 assertTrue(e.getCause().getMessage().contains("Mojo.class")); 417 } 418 419 finder = ModuleFinder.of(m_dir); 420 try { 421 finder.findAll(); 422 assertTrue(false); 423 } catch (FindException e) { 424 assertTrue(e.getCause() instanceof InvalidModuleDescriptorException); 425 assertTrue(e.getCause().getMessage().contains("Mojo.class")); 426 } 427 } 428 429 430 /** 431 * Test ModuleFinder.of with a path to a file that does not exist. 432 */ 433 public void testOfWithDoesNotExistEntry() throws Exception { 434 Path dir1 = Files.createTempDirectory(USER_DIR, "mods1"); 435 436 Path dir2 = Files.createTempDirectory(USER_DIR, "mods2"); 437 createModularJar(dir2.resolve("m2.jar"), "m2@1.0"); 438 439 Files.delete(dir1); 440 441 ModuleFinder finder = ModuleFinder.of(dir1, dir2); 442 443 assertTrue(finder.find("m2").isPresent()); 444 assertTrue(finder.findAll().size() == 1); 445 assertFalse(finder.find("java.rhubarb").isPresent()); |