jdk/test/tools/jar/modularJar/Basic.java
changeset 44267 00898a596f31
parent 43797 dab6fb7f37a3
child 44545 83b611b88ac8
equal deleted inserted replaced
44266:2b9cc0e5e79f 44267:00898a596f31
    37 import java.util.stream.Stream;
    37 import java.util.stream.Stream;
    38 
    38 
    39 import jdk.testlibrary.FileUtils;
    39 import jdk.testlibrary.FileUtils;
    40 import jdk.testlibrary.JDKToolFinder;
    40 import jdk.testlibrary.JDKToolFinder;
    41 import org.testng.annotations.BeforeTest;
    41 import org.testng.annotations.BeforeTest;
       
    42 import org.testng.annotations.DataProvider;
    42 import org.testng.annotations.Test;
    43 import org.testng.annotations.Test;
    43 
    44 
    44 import static java.lang.String.format;
    45 import static java.lang.String.format;
    45 import static java.lang.System.out;
    46 import static java.lang.System.out;
    46 
    47 
    47 /*
    48 /*
    48  * @test
    49  * @test
    49  * @bug 8167328 8171830 8165640 8174248
    50  * @bug 8167328 8171830 8165640 8174248 8176772
    50  * @library /lib/testlibrary
    51  * @library /lib/testlibrary
    51  * @modules jdk.compiler
    52  * @modules jdk.compiler
    52  *          jdk.jartool
    53  *          jdk.jartool
    53  * @build jdk.testlibrary.FileUtils jdk.testlibrary.JDKToolFinder
    54  * @build jdk.testlibrary.FileUtils jdk.testlibrary.JDKToolFinder
    54  * @compile Basic.java
    55  * @compile Basic.java
   752             "-C", modClasses.toString(), "jdk/test/baz/Baz.class",
   753             "-C", modClasses.toString(), "jdk/test/baz/Baz.class",
   753             "-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class")
   754             "-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class")
   754             .assertSuccess();
   755             .assertSuccess();
   755 
   756 
   756 
   757 
   757         for (String option : new String[]  {"--print-module-descriptor", "-d" }) {
   758         for (String option : new String[]  {"--describe-module", "-d" }) {
   758 
   759 
   759             jar(option,
   760             jar(option,
   760                 "--file=" + modularJar.toString())
   761                 "--file=" + modularJar.toString())
   761                 .assertSuccess()
   762                 .assertSuccess()
   762                 .resultChecker(r ->
   763                 .resultChecker(r ->
   799             "-C", modClasses.toString(), "jdk/test/foo/Foo.class")
   800             "-C", modClasses.toString(), "jdk/test/foo/Foo.class")
   800             .assertFailure();
   801             .assertFailure();
   801     }
   802     }
   802 
   803 
   803     @Test
   804     @Test
   804     public void printModuleDescriptorFoo() throws IOException {
   805     public void describeModuleFoo() throws IOException {
   805         Path mp = Paths.get("printModuleDescriptorFoo");
   806         Path mp = Paths.get("describeModuleFoo");
   806         createTestDir(mp);
   807         createTestDir(mp);
   807         Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
   808         Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
   808         Path modularJar = mp.resolve(FOO.moduleName + ".jar");
   809         Path modularJar = mp.resolve(FOO.moduleName + ".jar");
   809 
   810 
   810         jar("--create",
   811         jar("--create",
   813             "--module-version=" + FOO.version,
   814             "--module-version=" + FOO.version,
   814             "--no-manifest",
   815             "--no-manifest",
   815             "-C", modClasses.toString(), ".")
   816             "-C", modClasses.toString(), ".")
   816             .assertSuccess();
   817             .assertSuccess();
   817 
   818 
   818         for (String option : new String[]  {"--print-module-descriptor", "-d" }) {
   819         for (String option : new String[]  {"--describe-module", "-d" }) {
   819             jar(option,
   820             jar(option,
   820                 "--file=" + modularJar.toString())
   821                 "--file=" + modularJar.toString())
   821                 .assertSuccess()
   822                 .assertSuccess()
   822                 .resultChecker(r ->
   823                 .resultChecker(r ->
   823                     assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
   824                     assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
   834             .assertFailure();
   835             .assertFailure();
   835         }
   836         }
   836     }
   837     }
   837 
   838 
   838     @Test
   839     @Test
   839     public void printModuleDescriptorFooFromStdin() throws IOException {
   840     public void describeModuleFooFromStdin() throws IOException {
   840         Path mp = Paths.get("printModuleDescriptorFooFromStdin");
   841         Path mp = Paths.get("describeModuleFooFromStdin");
   841         createTestDir(mp);
   842         createTestDir(mp);
   842         Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
   843         Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
   843         Path modularJar = mp.resolve(FOO.moduleName + ".jar");
   844         Path modularJar = mp.resolve(FOO.moduleName + ".jar");
   844 
   845 
   845         jar("--create",
   846         jar("--create",
   848             "--module-version=" + FOO.version,
   849             "--module-version=" + FOO.version,
   849             "--no-manifest",
   850             "--no-manifest",
   850             "-C", modClasses.toString(), ".")
   851             "-C", modClasses.toString(), ".")
   851             .assertSuccess();
   852             .assertSuccess();
   852 
   853 
   853         for (String option : new String[]  {"--print-module-descriptor", "-d" }) {
   854         for (String option : new String[]  {"--describe-module", "-d" }) {
   854             jarWithStdin(modularJar.toFile(),
   855             jarWithStdin(modularJar.toFile(),
   855                          option)
   856                          option)
   856                          .assertSuccess()
   857                          .assertSuccess()
   857                          .resultChecker(r ->
   858                          .resultChecker(r ->
   858                              assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
   859                              assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
   859                                 "Expected to find ", FOO.moduleName + "@" + FOO.version,
   860                                 "Expected to find ", FOO.moduleName + "@" + FOO.version,
   860                                 " in [", r.output, "]")
   861                                 " in [", r.output, "]")
       
   862                 );
       
   863         }
       
   864     }
       
   865 
       
   866 
       
   867     @DataProvider(name = "autoNames")
       
   868     public Object[][] autoNames() {
       
   869         return new Object[][] {
       
   870             // JAR file name                module-name[@version]
       
   871             { "foo.jar",                    "foo" },
       
   872             { "foo4j.jar",                  "foo4j", },
       
   873             { "foo1.2.3.jar",               "foo" },
       
   874             { "foo-1.2.3.4.jar",            "foo@1.2.3.4" },
       
   875             { "foo-bar.jar",                "foo.bar" },
       
   876             { "foo-1.2-SNAPSHOT.jar",       "foo@1.2-SNAPSHOT" },
       
   877         };
       
   878     }
       
   879 
       
   880     @Test(dataProvider = "autoNames")
       
   881     public void describeAutomaticModule(String jarName, String mid)
       
   882         throws IOException
       
   883     {
       
   884         Path mp = Paths.get("describeAutomaticModule");
       
   885         createTestDir(mp);
       
   886         Path regularJar = mp.resolve(jarName);
       
   887         Path t = Paths.get("t");
       
   888         if (Files.notExists(t))
       
   889             Files.createFile(t);
       
   890 
       
   891         jar("--create",
       
   892             "--file=" + regularJar.toString(),
       
   893             t.toString())
       
   894             .assertSuccess();
       
   895 
       
   896         for (String option : new String[]  {"--describe-module", "-d" }) {
       
   897             jar(option,
       
   898                 "--file=" + regularJar.toString())
       
   899                 .assertSuccess()
       
   900                 .resultChecker(r -> {
       
   901                     assertTrue(r.output.contains("No module descriptor found"));
       
   902                     assertTrue(r.output.contains("Derived automatic module"));
       
   903                     assertTrue(r.output.contains("module " + mid),
       
   904                                "Expected [", "module " + mid,"] in [", r.output, "]");
       
   905                     }
   861                 );
   906                 );
   862         }
   907         }
   863     }
   908     }
   864 
   909 
   865     // -- Infrastructure
   910     // -- Infrastructure