< prev index next >

test/jdk/tools/jar/modularJar/Basic.java

Print this page




  29 import java.util.function.Consumer;
  30 import java.util.jar.JarEntry;
  31 import java.util.jar.JarFile;
  32 import java.util.jar.JarInputStream;
  33 import java.util.jar.Manifest;
  34 import java.util.regex.Pattern;
  35 import java.util.stream.Collectors;
  36 import java.util.stream.Stream;
  37 
  38 import jdk.test.lib.util.FileUtils;
  39 import jdk.test.lib.JDKToolFinder;
  40 import org.testng.annotations.BeforeTest;
  41 import org.testng.annotations.DataProvider;
  42 import org.testng.annotations.Test;
  43 
  44 import static java.lang.String.format;
  45 import static java.lang.System.out;
  46 
  47 /*
  48  * @test
  49  * @bug 8167328 8171830 8165640 8174248 8176772 8196748 8191533
  50  * @library /test/lib
  51  * @modules jdk.compiler
  52  *          jdk.jartool
  53  * @build jdk.test.lib.Platform
  54  *        jdk.test.lib.util.FileUtils
  55  *        jdk.test.lib.JDKToolFinder
  56  * @compile Basic.java
  57  * @run testng Basic
  58  * @summary Tests for plain Modular jars & Multi-Release Modular jars
  59  */
  60 
  61 public class Basic {
  62     static final Path TEST_SRC = Paths.get(System.getProperty("test.src", "."));
  63     static final Path TEST_CLASSES = Paths.get(System.getProperty("test.classes", "."));
  64     static final Path MODULE_CLASSES = TEST_CLASSES.resolve("build");
  65     static final Path MRJAR_DIR = MODULE_CLASSES.resolve("mrjar");
  66 
  67     static final String VM_OPTIONS = System.getProperty("test.vm.opts", "");
  68     static final String TOOL_VM_OPTIONS = System.getProperty("test.tool.vm.opts", "");
  69     static final String JAVA_OPTIONS = System.getProperty("test.java.opts", "");


 861         jar("--create",
 862             "--file=" + modularJar.toString(),
 863             "--main-class=" + FOO.mainClass,
 864             "--module-version=" + FOO.version,
 865             "--no-manifest",
 866             "-C", modClasses.toString(), ".")
 867             .assertSuccess();
 868 
 869         for (String option : new String[]  {"--describe-module", "-d" }) {
 870             jarWithStdin(modularJar.toFile(),
 871                          option)
 872                          .assertSuccess()
 873                          .resultChecker(r ->
 874                              assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
 875                                 "Expected to find ", FOO.moduleName + "@" + FOO.version,
 876                                 " in [", r.output, "]")
 877                 );
 878         }
 879     }
 880 












































 881 
 882     @DataProvider(name = "autoNames")
 883     public Object[][] autoNames() {
 884         return new Object[][] {
 885             // JAR file name                module-name[@version]
 886             { "foo.jar",                    "foo" },
 887             { "foo1.jar",                   "foo1" },
 888             { "foo4j.jar",                  "foo4j", },
 889             { "foo-1.2.3.4.jar",            "foo@1.2.3.4" },
 890             { "foo-bar.jar",                "foo.bar" },
 891             { "foo-1.2-SNAPSHOT.jar",       "foo@1.2-SNAPSHOT" },
 892         };
 893     }
 894 
 895     @Test(dataProvider = "autoNames")
 896     public void describeAutomaticModule(String jarName, String mid)
 897         throws IOException
 898     {
 899         Path mp = Paths.get("describeAutomaticModule");
 900         createTestDir(mp);




  29 import java.util.function.Consumer;
  30 import java.util.jar.JarEntry;
  31 import java.util.jar.JarFile;
  32 import java.util.jar.JarInputStream;
  33 import java.util.jar.Manifest;
  34 import java.util.regex.Pattern;
  35 import java.util.stream.Collectors;
  36 import java.util.stream.Stream;
  37 
  38 import jdk.test.lib.util.FileUtils;
  39 import jdk.test.lib.JDKToolFinder;
  40 import org.testng.annotations.BeforeTest;
  41 import org.testng.annotations.DataProvider;
  42 import org.testng.annotations.Test;
  43 
  44 import static java.lang.String.format;
  45 import static java.lang.System.out;
  46 
  47 /*
  48  * @test
  49  * @bug 8167328 8171830 8165640 8174248 8176772 8196748 8191533 8210454
  50  * @library /test/lib
  51  * @modules jdk.compiler
  52  *          jdk.jartool
  53  * @build jdk.test.lib.Platform
  54  *        jdk.test.lib.util.FileUtils
  55  *        jdk.test.lib.JDKToolFinder
  56  * @compile Basic.java
  57  * @run testng Basic
  58  * @summary Tests for plain Modular jars & Multi-Release Modular jars
  59  */
  60 
  61 public class Basic {
  62     static final Path TEST_SRC = Paths.get(System.getProperty("test.src", "."));
  63     static final Path TEST_CLASSES = Paths.get(System.getProperty("test.classes", "."));
  64     static final Path MODULE_CLASSES = TEST_CLASSES.resolve("build");
  65     static final Path MRJAR_DIR = MODULE_CLASSES.resolve("mrjar");
  66 
  67     static final String VM_OPTIONS = System.getProperty("test.vm.opts", "");
  68     static final String TOOL_VM_OPTIONS = System.getProperty("test.tool.vm.opts", "");
  69     static final String JAVA_OPTIONS = System.getProperty("test.java.opts", "");


 861         jar("--create",
 862             "--file=" + modularJar.toString(),
 863             "--main-class=" + FOO.mainClass,
 864             "--module-version=" + FOO.version,
 865             "--no-manifest",
 866             "-C", modClasses.toString(), ".")
 867             .assertSuccess();
 868 
 869         for (String option : new String[]  {"--describe-module", "-d" }) {
 870             jarWithStdin(modularJar.toFile(),
 871                          option)
 872                          .assertSuccess()
 873                          .resultChecker(r ->
 874                              assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
 875                                 "Expected to find ", FOO.moduleName + "@" + FOO.version,
 876                                 " in [", r.output, "]")
 877                 );
 878         }
 879     }
 880 
 881     /**
 882      * Validate that you can update a jar only specifying --module-version
 883      * @throws IOException
 884      */
 885     @Test
 886     public void updateFooModuleVersion() throws IOException {
 887         Path mp = Paths.get("updateFooModuleVersion");
 888         createTestDir(mp);
 889         Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName);
 890         Path modularJar = mp.resolve(FOO.moduleName + ".jar");
 891         String newFooVersion = "87.0";
 892 
 893         jar("--create",
 894             "--file=" + modularJar.toString(),
 895             "--main-class=" + FOO.mainClass,
 896             "--module-version=" + FOO.version,
 897             "--no-manifest",
 898             "-C", modClasses.toString(), ".")
 899             .assertSuccess();
 900 
 901         jarWithStdin(modularJar.toFile(), "--describe-module")
 902                 .assertSuccess()
 903                 .resultChecker(r ->
 904                         assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version),
 905                                 "Expected to find ", FOO.moduleName + "@" + FOO.version,
 906                                 " in [", r.output, "]")
 907                 );
 908 
 909         jar("--update",
 910             "--file=" + modularJar.toString(),
 911             "--module-version=" + newFooVersion)
 912             .assertSuccess();
 913 
 914         for (String option : new String[]  {"--describe-module", "-d" }) {
 915             jarWithStdin(modularJar.toFile(),
 916                          option)
 917                          .assertSuccess()
 918                          .resultChecker(r ->
 919                              assertTrue(r.output.contains(FOO.moduleName + "@" + newFooVersion),
 920                                 "Expected to find ", FOO.moduleName + "@" + newFooVersion,
 921                                 " in [", r.output, "]")
 922                 );
 923         }
 924     }
 925 
 926     @DataProvider(name = "autoNames")
 927     public Object[][] autoNames() {
 928         return new Object[][] {
 929             // JAR file name                module-name[@version]
 930             { "foo.jar",                    "foo" },
 931             { "foo1.jar",                   "foo1" },
 932             { "foo4j.jar",                  "foo4j", },
 933             { "foo-1.2.3.4.jar",            "foo@1.2.3.4" },
 934             { "foo-bar.jar",                "foo.bar" },
 935             { "foo-1.2-SNAPSHOT.jar",       "foo@1.2-SNAPSHOT" },
 936         };
 937     }
 938 
 939     @Test(dataProvider = "autoNames")
 940     public void describeAutomaticModule(String jarName, String mid)
 941         throws IOException
 942     {
 943         Path mp = Paths.get("describeAutomaticModule");
 944         createTestDir(mp);


< prev index next >