langtools/test/tools/javac/modules/XModuleTest.java
changeset 37758 3ecf9b414e05
parent 36778 e04318f39f92
child 39103 91a64ec5b970
equal deleted inserted replaced
37757:f38cc75b6fa0 37758:3ecf9b414e05
    26  * @summary tests for multi-module mode compilation
    26  * @summary tests for multi-module mode compilation
    27  * @library /tools/lib
    27  * @library /tools/lib
    28  * @modules
    28  * @modules
    29  *      jdk.compiler/com.sun.tools.javac.api
    29  *      jdk.compiler/com.sun.tools.javac.api
    30  *      jdk.compiler/com.sun.tools.javac.main
    30  *      jdk.compiler/com.sun.tools.javac.main
    31  * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
    31  * @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase
    32  * @run main XModuleTest
    32  * @run main XModuleTest
    33  */
    33  */
    34 
    34 
    35 import java.nio.file.Path;
    35 import java.nio.file.Path;
    36 import java.util.Arrays;
    36 import java.util.Arrays;
    37 import java.util.List;
    37 import java.util.List;
    38 
    38 
    39 import toolbox.JavacTask;
    39 import toolbox.JavacTask;
       
    40 import toolbox.ModuleBuilder;
    40 import toolbox.Task;
    41 import toolbox.Task;
       
    42 import toolbox.TestRunner;
    41 import toolbox.ToolBox;
    43 import toolbox.ToolBox;
    42 
    44 
    43 public class XModuleTest extends ModuleTestBase {
    45 public class XModuleTest extends ModuleTestBase {
    44 
    46 
    45     public static void main(String... args) throws Exception {
    47     public static void main(String... args) throws Exception {
    46         new XModuleTest().runTests();
    48         new XModuleTest().runTests();
    47     }
    49     }
    48 
    50 
    49     @Test
    51     @Test
    50     void testCorrectXModule(Path base) throws Exception {
    52     public void testCorrectXModule(Path base) throws Exception {
    51         //note: avoiding use of java.base, as that gets special handling on some places:
    53         //note: avoiding use of java.base, as that gets special handling on some places:
    52         Path src = base.resolve("src");
    54         Path src = base.resolve("src");
    53         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
    55         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
    54         Path classes = base.resolve("classes");
    56         Path classes = base.resolve("classes");
    55         tb.createDirectories(classes);
    57         tb.createDirectories(classes);
    65         if (!log.isEmpty())
    67         if (!log.isEmpty())
    66             throw new Exception("expected output not found: " + log);
    68             throw new Exception("expected output not found: " + log);
    67     }
    69     }
    68 
    70 
    69     @Test
    71     @Test
    70     void testSourcePath(Path base) throws Exception {
    72     public void testSourcePath(Path base) throws Exception {
    71         //note: avoiding use of java.base, as that gets special handling on some places:
    73         //note: avoiding use of java.base, as that gets special handling on some places:
    72         Path src = base.resolve("src");
    74         Path src = base.resolve("src");
    73         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, Other { }", "package javax.lang.model.element; interface Other { }");
    75         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, Other { }", "package javax.lang.model.element; interface Other { }");
    74         Path classes = base.resolve("classes");
    76         Path classes = base.resolve("classes");
    75         tb.createDirectories(classes);
    77         tb.createDirectories(classes);
    85         if (!log.isEmpty())
    87         if (!log.isEmpty())
    86             throw new Exception("expected output not found: " + log);
    88             throw new Exception("expected output not found: " + log);
    87     }
    89     }
    88 
    90 
    89     @Test
    91     @Test
    90     void testClassPath(Path base) throws Exception {
    92     public void testClassPath(Path base) throws Exception {
    91         Path cpSrc = base.resolve("cpSrc");
    93         Path cpSrc = base.resolve("cpSrc");
    92         tb.writeJavaFiles(cpSrc, "package p; public interface Other { }");
    94         tb.writeJavaFiles(cpSrc, "package p; public interface Other { }");
    93         Path cpClasses = base.resolve("cpClasses");
    95         Path cpClasses = base.resolve("cpClasses");
    94         tb.createDirectories(cpClasses);
    96         tb.createDirectories(cpClasses);
    95 
    97 
   120         if (!log.isEmpty())
   122         if (!log.isEmpty())
   121             throw new Exception("expected output not found: " + log);
   123             throw new Exception("expected output not found: " + log);
   122     }
   124     }
   123 
   125 
   124     @Test
   126     @Test
   125     void testNoModuleInfoOnSourcePath(Path base) throws Exception {
   127     public void testNoModuleInfoOnSourcePath(Path base) throws Exception {
   126         //note: avoiding use of java.base, as that gets special handling on some places:
   128         //note: avoiding use of java.base, as that gets special handling on some places:
   127         Path src = base.resolve("src");
   129         Path src = base.resolve("src");
   128         tb.writeJavaFiles(src,
   130         tb.writeJavaFiles(src,
   129                           "module java.compiler {}",
   131                           "module java.compiler {}",
   130                           "package javax.lang.model.element; public interface Extra { }");
   132                           "package javax.lang.model.element; public interface Extra { }");
   145         if (!expected.equals(log))
   147         if (!expected.equals(log))
   146             throw new Exception("expected output not found: " + log);
   148             throw new Exception("expected output not found: " + log);
   147     }
   149     }
   148 
   150 
   149     @Test
   151     @Test
   150     void testNoModuleInfoInClassOutput(Path base) throws Exception {
   152     public void testNoModuleInfoInClassOutput(Path base) throws Exception {
   151         //note: avoiding use of java.base, as that gets special handling on some places:
   153         //note: avoiding use of java.base, as that gets special handling on some places:
   152         Path srcMod = base.resolve("src-mod");
   154         Path srcMod = base.resolve("src-mod");
   153         tb.writeJavaFiles(srcMod,
   155         tb.writeJavaFiles(srcMod,
   154                           "module mod {}");
   156                           "module mod {}");
   155         Path classes = base.resolve("classes");
   157         Path classes = base.resolve("classes");
   185         if (!expected.equals(log))
   187         if (!expected.equals(log))
   186             throw new Exception("expected output not found: " + log);
   188             throw new Exception("expected output not found: " + log);
   187     }
   189     }
   188 
   190 
   189     @Test
   191     @Test
   190     void testModuleSourcePathXModule(Path base) throws Exception {
   192     public void testModuleSourcePathXModule(Path base) throws Exception {
   191         //note: avoiding use of java.base, as that gets special handling on some places:
   193         //note: avoiding use of java.base, as that gets special handling on some places:
   192         Path src = base.resolve("src");
   194         Path src = base.resolve("src");
   193         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
   195         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
   194         Path classes = base.resolve("classes");
   196         Path classes = base.resolve("classes");
   195         tb.createDirectories(classes);
   197         tb.createDirectories(classes);
   208         if (!expected.equals(log))
   210         if (!expected.equals(log))
   209             throw new Exception("expected output not found: " + log);
   211             throw new Exception("expected output not found: " + log);
   210     }
   212     }
   211 
   213 
   212     @Test
   214     @Test
   213     void testXModuleTooMany(Path base) throws Exception {
   215     public void testXModuleTooMany(Path base) throws Exception {
   214         //note: avoiding use of java.base, as that gets special handling on some places:
   216         //note: avoiding use of java.base, as that gets special handling on some places:
   215         Path src = base.resolve("src");
   217         Path src = base.resolve("src");
   216         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
   218         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
   217         Path classes = base.resolve("classes");
   219         Path classes = base.resolve("classes");
   218         tb.createDirectories(classes);
   220         tb.createDirectories(classes);
   232         if (!expected.equals(log))
   234         if (!expected.equals(log))
   233             throw new Exception("expected output not found: " + log);
   235             throw new Exception("expected output not found: " + log);
   234     }
   236     }
   235 
   237 
   236     @Test
   238     @Test
   237     void testWithModulePath(Path base) throws Exception {
   239     public void testWithModulePath(Path base) throws Exception {
   238         Path module = base.resolve("modules");
   240         Path module = base.resolve("modules");
   239         new ModuleBuilder("m1")
   241         new ModuleBuilder(tb, "m1")
   240                 .classes("package pkg1; public interface E { }")
   242                 .classes("package pkg1; public interface E { }")
   241                 .build(module);
   243                 .build(module);
   242 
   244 
   243         Path src = base.resolve("src");
   245         Path src = base.resolve("src");
   244         tb.writeJavaFiles(src, "package p; interface A extends pkg1.E { }");
   246         tb.writeJavaFiles(src, "package p; interface A extends pkg1.E { }");
   249                 .files(findJavaFiles(src))
   251                 .files(findJavaFiles(src))
   250                 .run()
   252                 .run()
   251                 .writeAll();
   253                 .writeAll();
   252 
   254 
   253         //checks module bounds still exist
   255         //checks module bounds still exist
   254         new ModuleBuilder("m2")
   256         new ModuleBuilder(tb, "m2")
   255                 .classes("package pkg2; public interface D { }")
   257                 .classes("package pkg2; public interface D { }")
   256                 .build(module);
   258                 .build(module);
   257 
   259 
   258         Path src2 = base.resolve("src2");
   260         Path src2 = base.resolve("src2");
   259         tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }");
   261         tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }");
   273         if (!expected.equals(log))
   275         if (!expected.equals(log))
   274             throw new Exception("expected output not found: " + log);
   276             throw new Exception("expected output not found: " + log);
   275     }
   277     }
   276 
   278 
   277     @Test
   279     @Test
   278     void testWithUpgradeModulePath(Path base) throws Exception {
   280     public void testWithUpgradeModulePath(Path base) throws Exception {
   279         Path module = base.resolve("modules");
   281         Path module = base.resolve("modules");
   280         new ModuleBuilder("m1")
   282         new ModuleBuilder(tb, "m1")
   281                 .classes("package pkg1; public interface E { }")
   283                 .classes("package pkg1; public interface E { }")
   282                 .build(module);
   284                 .build(module);
   283 
   285 
   284         Path upgrade = base.resolve("upgrade");
   286         Path upgrade = base.resolve("upgrade");
   285         new ModuleBuilder("m1")
   287         new ModuleBuilder(tb, "m1")
   286                 .classes("package pkg1; public interface D { }")
   288                 .classes("package pkg1; public interface D { }")
   287                 .build(upgrade);
   289                 .build(upgrade);
   288 
   290 
   289         Path src = base.resolve("src");
   291         Path src = base.resolve("src");
   290         tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }");
   292         tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }");