454 finder.find("java.rhubarb");
455 assertTrue(false);
456 } catch (FindException e) {
457 // expected
458 }
459
460 finder = ModuleFinder.of(mod);
461 try {
462 finder.findAll();
463 assertTrue(false);
464 } catch (FindException e) {
465 // expected
466 }
467 }
468
469
470 /**
471 * Test ModuleFinder.of with a file path to a directory containing a file
472 * that will not be recognized as a module.
473 */
474 public void testOfWithUnrecognizedEntryInDirectory() throws Exception {
475 Path dir = Files.createTempDirectory(USER_DIR, "mods");
476 Files.createTempFile(dir, "m", ".junk");
477
478 ModuleFinder finder = ModuleFinder.of(dir);
479 try {
480 finder.find("java.rhubarb");
481 assertTrue(false);
482 } catch (FindException e) {
483 // expected
484 }
485
486 finder = ModuleFinder.of(dir);
487 try {
488 finder.findAll();
489 assertTrue(false);
490 } catch (FindException e) {
491 // expected
492 }
493 }
494
495
496 /**
497 * Test ModuleFinder.of with a file path to a directory containing a file
498 * starting with ".", the file should be ignored.
499 */
500 public void testOfWithHiddenEntryInDirectory() throws Exception {
501 Path dir = Files.createTempDirectory(USER_DIR, "mods");
502 Files.createTempFile(dir, ".marker", "");
503
504 ModuleFinder finder = ModuleFinder.of(dir);
505 assertFalse(finder.find("java.rhubarb").isPresent());
506
507 finder = ModuleFinder.of(dir);
508 assertTrue(finder.findAll().isEmpty());
509 }
510
511
512 /**
513 * Test ModuleFinder.of with a directory that contains two
514 * versions of the same module
515 */
516 public void testOfDuplicateModulesInDirectory() throws Exception {
517 Path dir = Files.createTempDirectory(USER_DIR, "mods");
518 createModularJar(dir.resolve("m1@1.0.jar"), "m1");
519 createModularJar(dir.resolve("m1@2.0.jar"), "m1");
520
521 ModuleFinder finder = ModuleFinder.of(dir);
522 try {
523 finder.find("m1");
524 assertTrue(false);
525 } catch (FindException expected) { }
526
527 finder = ModuleFinder.of(dir);
528 try {
731 }
732
733
734 /**
735 * Parses a string of the form {@code name[@version]} and returns a
736 * ModuleDescriptor with that name and version. The ModuleDescriptor
737 * will have a requires on java.base.
738 */
739 static ModuleDescriptor newModuleDescriptor(String mid) {
740 String mn;
741 String vs;
742 int i = mid.indexOf("@");
743 if (i == -1) {
744 mn = mid;
745 vs = null;
746 } else {
747 mn = mid.substring(0, i);
748 vs = mid.substring(i+1);
749 }
750 ModuleDescriptor.Builder builder
751 = ModuleDescriptor.module(mn).requires("java.base");
752 if (vs != null)
753 builder.version(vs);
754 return builder.build();
755 }
756
757 /**
758 * Creates an exploded module in the given directory and containing a
759 * module descriptor with the given module name/version.
760 */
761 static Path createExplodedModule(Path dir, String mid, String... entries)
762 throws Exception
763 {
764 ModuleDescriptor descriptor = newModuleDescriptor(mid);
765 Files.createDirectories(dir);
766 Path mi = dir.resolve("module-info.class");
767 try (OutputStream out = Files.newOutputStream(mi)) {
768 ModuleInfoWriter.write(descriptor, out);
769 }
770
771 for (String entry : entries) {
|
454 finder.find("java.rhubarb");
455 assertTrue(false);
456 } catch (FindException e) {
457 // expected
458 }
459
460 finder = ModuleFinder.of(mod);
461 try {
462 finder.findAll();
463 assertTrue(false);
464 } catch (FindException e) {
465 // expected
466 }
467 }
468
469
470 /**
471 * Test ModuleFinder.of with a file path to a directory containing a file
472 * that will not be recognized as a module.
473 */
474 public void testOfWithUnrecognizedEntryInDirectory1() throws Exception {
475 Path dir = Files.createTempDirectory(USER_DIR, "mods");
476 Files.createTempFile(dir, "m", ".junk");
477
478 ModuleFinder finder = ModuleFinder.of(dir);
479 assertFalse(finder.find("java.rhubarb").isPresent());
480
481 finder = ModuleFinder.of(dir);
482 assertTrue(finder.findAll().isEmpty());
483 }
484
485
486 /**
487 * Test ModuleFinder.of with a file path to a directory containing a file
488 * that will not be recognized as a module.
489 */
490 public void testOfWithUnrecognizedEntryInDirectory2() throws Exception {
491 Path dir = Files.createTempDirectory(USER_DIR, "mods");
492 createModularJar(dir.resolve("m1.jar"), "m1");
493 Files.createTempFile(dir, "m2", ".junk");
494
495 ModuleFinder finder = ModuleFinder.of(dir);
496 assertTrue(finder.find("m1").isPresent());
497 assertFalse(finder.find("m2").isPresent());
498
499 finder = ModuleFinder.of(dir);
500 assertTrue(finder.findAll().size() == 1);
501 }
502
503
504 /**
505 * Test ModuleFinder.of with a directory that contains two
506 * versions of the same module
507 */
508 public void testOfDuplicateModulesInDirectory() throws Exception {
509 Path dir = Files.createTempDirectory(USER_DIR, "mods");
510 createModularJar(dir.resolve("m1@1.0.jar"), "m1");
511 createModularJar(dir.resolve("m1@2.0.jar"), "m1");
512
513 ModuleFinder finder = ModuleFinder.of(dir);
514 try {
515 finder.find("m1");
516 assertTrue(false);
517 } catch (FindException expected) { }
518
519 finder = ModuleFinder.of(dir);
520 try {
723 }
724
725
726 /**
727 * Parses a string of the form {@code name[@version]} and returns a
728 * ModuleDescriptor with that name and version. The ModuleDescriptor
729 * will have a requires on java.base.
730 */
731 static ModuleDescriptor newModuleDescriptor(String mid) {
732 String mn;
733 String vs;
734 int i = mid.indexOf("@");
735 if (i == -1) {
736 mn = mid;
737 vs = null;
738 } else {
739 mn = mid.substring(0, i);
740 vs = mid.substring(i+1);
741 }
742 ModuleDescriptor.Builder builder
743 = ModuleDescriptor.newModule(mn).requires("java.base");
744 if (vs != null)
745 builder.version(vs);
746 return builder.build();
747 }
748
749 /**
750 * Creates an exploded module in the given directory and containing a
751 * module descriptor with the given module name/version.
752 */
753 static Path createExplodedModule(Path dir, String mid, String... entries)
754 throws Exception
755 {
756 ModuleDescriptor descriptor = newModuleDescriptor(mid);
757 Files.createDirectories(dir);
758 Path mi = dir.resolve("module-info.class");
759 try (OutputStream out = Files.newOutputStream(mi)) {
760 ModuleInfoWriter.write(descriptor, out);
761 }
762
763 for (String entry : entries) {
|