langtools/test/tools/javac/modules/GraphsTest.java
changeset 39103 91a64ec5b970
parent 37758 3ecf9b414e05
child 40308 274367a99f98
equal deleted inserted replaced
39102:5a820f7e00b9 39103:91a64ec5b970
    71      *
    71      *
    72      */
    72      */
    73     @Test
    73     @Test
    74     public void diamond(Path base) throws Exception {
    74     public void diamond(Path base) throws Exception {
    75 
    75 
       
    76         Path modSrc = Files.createDirectories(base.resolve("modSrc"));
    76         Path modules = Files.createDirectories(base.resolve("modules"));
    77         Path modules = Files.createDirectories(base.resolve("modules"));
    77 
    78 
    78         new ModuleBuilder(tb, "J")
    79         new ModuleBuilder(tb, "J")
    79                 .exports("openJ")
    80                 .exports("openJ")
    80                 .classes("package openJ; public class J { }")
    81                 .classes("package openJ; public class J { }")
    92         new ModuleBuilder(tb, "O")
    93         new ModuleBuilder(tb, "O")
    93                 .exports("openO")
    94                 .exports("openO")
    94                 .requiresPublic("J", jarModules)
    95                 .requiresPublic("J", jarModules)
    95                 .classes("package openO; public class O { openJ.J j; }")
    96                 .classes("package openO; public class O { openJ.J j; }")
    96                 .classes("package closedO; public class O { }")
    97                 .classes("package closedO; public class O { }")
    97                 .build(modules);
    98                 .build(modSrc, modules);
    98         new ModuleBuilder(tb, "N")
    99         new ModuleBuilder(tb, "N")
    99                 .requiresPublic("O", modules, jarModules)
   100                 .requiresPublic("O", modules, jarModules)
   100                 .exports("openN")
   101                 .exports("openN")
   101                 .classes("package openN; public class N { }")
   102                 .classes("package openN; public class N { }")
   102                 .classes("package closedN; public class N { }")
   103                 .classes("package closedN; public class N { }")
   103                 .build(modules);
   104                 .build(modSrc, modules);
   104         new ModuleBuilder(tb, "L")
   105         new ModuleBuilder(tb, "L")
   105                 .requiresPublic("O", modules, jarModules)
   106                 .requiresPublic("O", modules, jarModules)
   106                 .exports("openL")
   107                 .exports("openL")
   107                 .classes("package openL; public class L { }")
   108                 .classes("package openL; public class L { }")
   108                 .classes("package closedL; public class L { }")
   109                 .classes("package closedL; public class L { }")
   109                 .build(modules);
   110                 .build(modSrc, modules);
   110         ModuleBuilder m = new ModuleBuilder(tb, "M");
   111         ModuleBuilder m = new ModuleBuilder(tb, "M");
   111         //positive case
   112         //positive case
   112         Path positiveSrc = m
   113         Path positiveSrc = m
   113                 .requires("N", modules)
   114                 .requires("N", modules)
   114                 .requires("L", modules)
   115                 .requires("L", modules)
   138                 "Negative.java:1:69: compiler.err.doesnt.exist: closedL");
   139                 "Negative.java:1:69: compiler.err.doesnt.exist: closedL");
   139         if (!log.containsAll(expected)) {
   140         if (!log.containsAll(expected)) {
   140             throw new Exception("Expected output not found");
   141             throw new Exception("Expected output not found");
   141         }
   142         }
   142         //multi module mode
   143         //multi module mode
   143         m.write(modules);
   144         m.write(modSrc);
   144         List<String> out = new JavacTask(tb)
   145         List<String> out = new JavacTask(tb)
   145                 .options("-XDrawDiagnostics",
   146                 .options("-XDrawDiagnostics",
   146                         "-modulesourcepath", modules + "/*/src",
   147                         "-modulesourcepath", modSrc.toString(),
   147                         "-mp", jarModules.toString()
   148                         "-mp", jarModules.toString()
   148                 )
   149                 )
   149                 .outdir(Files.createDirectories(base.resolve("negative")))
   150                 .outdir(Files.createDirectories(base.resolve("negative")))
   150                 .files(findJavaFiles(modules))
   151                 .files(findJavaFiles(modSrc))
   151                 .run(Task.Expect.FAIL)
   152                 .run(Task.Expect.FAIL)
   152                 .writeAll()
   153                 .writeAll()
   153                 .getOutputLines(Task.OutputKind.DIRECT);
   154                 .getOutputLines(Task.OutputKind.DIRECT);
   154         expected = Arrays.asList(
   155         expected = Arrays.asList(
   155                 "Negative.java:1:43: compiler.err.not.def.access.package.cant.access: closedO.O, closedO",
   156                 "Negative.java:1:43: compiler.err.not.def.access.package.cant.access: closedO.O, closedO",
   177     +-------------+        |                    |        +---------------+
   178     +-------------+        |                    |        +---------------+
   178                            +--------------------+
   179                            +--------------------+
   179     */
   180     */
   180     @Test
   181     @Test
   181     public void reexportOfQualifiedExport(Path base) throws Exception {
   182     public void reexportOfQualifiedExport(Path base) throws Exception {
   182         Path modules = base.resolve("modules");
   183         Path modSrc = base.resolve("modSrc");
   183         new ModuleBuilder(tb, "M")
   184         new ModuleBuilder(tb, "M")
   184                 .requiresPublic("N")
   185                 .requiresPublic("N")
   185                 .write(modules);
   186                 .write(modSrc);
   186         new ModuleBuilder(tb, "N")
   187         new ModuleBuilder(tb, "N")
   187                 .exportsTo("pack", "M")
   188                 .exportsTo("pack", "M")
   188                 .classes("package pack; public class Clazz { }")
   189                 .classes("package pack; public class Clazz { }")
   189                 .write(modules);
   190                 .write(modSrc);
   190         new ModuleBuilder(tb, "L")
   191         new ModuleBuilder(tb, "L")
   191                 .requires("M")
   192                 .requires("M")
   192                 .classes("package p; public class A { A(pack.Clazz cl){} } ")
   193                 .classes("package p; public class A { A(pack.Clazz cl){} } ")
   193                 .write(modules);
   194                 .write(modSrc);
   194         String log = new JavacTask(tb)
   195         String log = new JavacTask(tb)
   195                 .options("-XDrawDiagnostics",
   196                 .options("-XDrawDiagnostics",
   196                         "-modulesourcepath", modules + "/*/src")
   197                         "-modulesourcepath", modSrc.toString())
   197                 .outdir(Files.createDirectories(base.resolve("negative")))
   198                 .outdir(Files.createDirectories(base.resolve("negative")))
   198                 .files(findJavaFiles(modules))
   199                 .files(findJavaFiles(modSrc))
   199                 .run(Task.Expect.FAIL)
   200                 .run(Task.Expect.FAIL)
   200                 .writeAll()
   201                 .writeAll()
   201                 .getOutput(Task.OutputKind.DIRECT);
   202                 .getOutput(Task.OutputKind.DIRECT);
   202 
   203 
   203         String expected = "A.java:1:35: compiler.err.not.def.access.package.cant.access: pack.Clazz, pack";
   204         String expected = "A.java:1:35: compiler.err.not.def.access.package.cant.access: pack.Clazz, pack";