langtools/test/tools/javac/modules/PackageConflictTest.java
changeset 39103 91a64ec5b970
parent 37758 3ecf9b414e05
child 40308 274367a99f98
equal deleted inserted replaced
39102:5a820f7e00b9 39103:91a64ec5b970
   123         }
   123         }
   124     }
   124     }
   125 
   125 
   126     @Test
   126     @Test
   127     public void testSimple2(Path base) throws Exception {
   127     public void testSimple2(Path base) throws Exception {
       
   128         Path modSrc = base.resolve("modSrc");
   128         Path modules = base.resolve("modules");
   129         Path modules = base.resolve("modules");
   129         new ModuleBuilder(tb, "N")
   130         new ModuleBuilder(tb, "N")
   130                 .exports("pack")
   131                 .exports("pack")
   131                 .classes("package pack; public class A { }")
   132                 .classes("package pack; public class A { }")
   132                 .build(modules);
   133                 .build(modules);
   133         new ModuleBuilder(tb, "M")
   134         new ModuleBuilder(tb, "M")
   134                 .requires("N")
   135                 .requires("N")
   135                 .classes("package pack; public class B { pack.A f; }")
   136                 .classes("package pack; public class B { pack.A f; }")
   136                 .write(modules);
   137                 .write(modSrc);
   137 
   138 
   138         String log = new JavacTask(tb)
   139         String log = new JavacTask(tb)
   139                 .options("-XDrawDiagnostics", "-mp", modules.toString())
   140                 .options("-XDrawDiagnostics", "-mp", modules.toString())
   140                 .outdir(Files.createDirectories(base.resolve("classes")))
   141                 .outdir(Files.createDirectories(base.resolve("classes")))
   141                 .files(findJavaFiles(modules.resolve("M")))
   142                 .files(findJavaFiles(modSrc.resolve("M")))
   142                 .run(Task.Expect.FAIL)
   143                 .run(Task.Expect.FAIL)
   143                 .writeAll()
   144                 .writeAll()
   144                 .getOutput(Task.OutputKind.DIRECT);
   145                 .getOutput(Task.OutputKind.DIRECT);
   145 
   146 
   146         if (!log.contains("B.java:1:1: compiler.err.package.in.other.module: N"))
   147         if (!log.contains("B.java:1:1: compiler.err.package.in.other.module: N"))
   147             throw new Exception("expected output not found");
   148             throw new Exception("expected output not found");
   148     }
   149     }
   149 
   150 
   150     @Test
   151     @Test
   151     public void testPrivateConflict(Path base) throws Exception {
   152     public void testPrivateConflict(Path base) throws Exception {
   152         Path modules = base.resolve("modules");
   153         Path modSrc = base.resolve("modSrc");
   153         new ModuleBuilder(tb, "N")
   154         new ModuleBuilder(tb, "N")
   154                 .exports("publ")
   155                 .exports("publ")
   155                 .classes("package pack; public class A { }")
   156                 .classes("package pack; public class A { }")
   156                 .classes("package publ; public class B { }")
   157                 .classes("package publ; public class B { }")
   157                 .write(modules);
   158                 .write(modSrc);
   158         new ModuleBuilder(tb, "M")
   159         new ModuleBuilder(tb, "M")
   159                 .requires("N")
   160                 .requires("N")
   160                 .classes("package pack; public class C { publ.B b; }")
   161                 .classes("package pack; public class C { publ.B b; }")
   161                 .write(modules);
   162                 .write(modSrc);
   162 
   163 
   163         String log = new JavacTask(tb)
   164         String log = new JavacTask(tb)
   164                 .options("-XDrawDiagnostics", "-modulesourcepath", modules + "/*/src")
   165                 .options("-XDrawDiagnostics", "-modulesourcepath", modSrc.toString())
   165                 .outdir(Files.createDirectories(base.resolve("classes")))
   166                 .outdir(Files.createDirectories(base.resolve("classes")))
   166                 .files(findJavaFiles(modules))
   167                 .files(findJavaFiles(modSrc))
   167                 .run(Task.Expect.SUCCESS)
   168                 .run(Task.Expect.SUCCESS)
   168                 .writeAll()
   169                 .writeAll()
   169                 .getOutput(Task.OutputKind.DIRECT);
   170                 .getOutput(Task.OutputKind.DIRECT);
   170 
   171 
   171         if (!log.contains(""))
   172         if (!log.contains(""))
   173 
   174 
   174     }
   175     }
   175 
   176 
   176     @Test
   177     @Test
   177     public void testPrivateConflictOnModulePath(Path base) throws Exception {
   178     public void testPrivateConflictOnModulePath(Path base) throws Exception {
       
   179         Path modSrc = base.resolve("modSrc");
   178         Path modules = base.resolve("modules");
   180         Path modules = base.resolve("modules");
   179         new ModuleBuilder(tb, "N")
   181         new ModuleBuilder(tb, "N")
   180                 .exports("publ")
   182                 .exports("publ")
   181                 .classes("package pack; public class A { }")
   183                 .classes("package pack; public class A { }")
   182                 .classes("package publ; public class B { }")
   184                 .classes("package publ; public class B { }")
   183                 .build(modules);
   185                 .build(modules);
   184         new ModuleBuilder(tb, "M")
   186         new ModuleBuilder(tb, "M")
   185                 .requires("N")
   187                 .requires("N")
   186                 .classes("package pack; public class C { publ.B b; }")
   188                 .classes("package pack; public class C { publ.B b; }")
   187                 .write(modules);
   189                 .write(modSrc);
   188 
   190 
   189         String log = new JavacTask(tb)
   191         String log = new JavacTask(tb)
   190                 .options("-XDrawDiagnostics", "-mp", modules.toString())
   192                 .options("-XDrawDiagnostics", "-mp", modules.toString())
   191                 .outdir(Files.createDirectories(base.resolve("classes")))
   193                 .outdir(Files.createDirectories(base.resolve("classes")))
   192                 .files(findJavaFiles(modules.resolve("M")))
   194                 .files(findJavaFiles(modSrc.resolve("M")))
   193                 .run(Task.Expect.SUCCESS)
   195                 .run(Task.Expect.SUCCESS)
   194                 .writeAll()
   196                 .writeAll()
   195                 .getOutput(Task.OutputKind.DIRECT);
   197                 .getOutput(Task.OutputKind.DIRECT);
   196 
   198 
   197         if (!log.contains(""))
   199         if (!log.contains(""))
   199 
   201 
   200     }
   202     }
   201 
   203 
   202     @Test
   204     @Test
   203     public void testRequiresConflictExports(Path base) throws Exception {
   205     public void testRequiresConflictExports(Path base) throws Exception {
       
   206         Path modSrc = base.resolve("modSrc");
   204         Path modules = base.resolve("modules");
   207         Path modules = base.resolve("modules");
   205         new ModuleBuilder(tb, "M")
   208         new ModuleBuilder(tb, "M")
   206                 .exports("pack")
   209                 .exports("pack")
   207                 .classes("package pack; public class A { }")
   210                 .classes("package pack; public class A { }")
   208                 .build(modules);
   211                 .build(modules);
   212                 .build(modules);
   215                 .build(modules);
   213         new ModuleBuilder(tb, "K")
   216         new ModuleBuilder(tb, "K")
   214                 .requires("M")
   217                 .requires("M")
   215                 .requires("N")
   218                 .requires("N")
   216                 .classes("package pkg; public class C { pack.A a; pack.B b; }")
   219                 .classes("package pkg; public class C { pack.A a; pack.B b; }")
   217                 .write(modules);
   220                 .write(modSrc);
   218 
   221 
   219         List<String> log = new JavacTask(tb)
   222         List<String> log = new JavacTask(tb)
   220                 .options("-XDrawDiagnostics", "-mp", modules.toString())
   223                 .options("-XDrawDiagnostics", "-mp", modules.toString())
   221                 .outdir(Files.createDirectories(base.resolve("classes")))
   224                 .outdir(Files.createDirectories(base.resolve("classes")))
   222                 .files(findJavaFiles(modules.resolve("K")))
   225                 .files(findJavaFiles(modSrc.resolve("K")))
   223                 .run(Task.Expect.FAIL)
   226                 .run(Task.Expect.FAIL)
   224                 .writeAll()
   227                 .writeAll()
   225                 .getOutputLines(Task.OutputKind.DIRECT);
   228                 .getOutputLines(Task.OutputKind.DIRECT);
   226 
   229 
   227         List<String> expected =
   230         List<String> expected =
   230         if (!log.containsAll(expected))
   233         if (!log.containsAll(expected))
   231             throw new Exception("expected output not found");
   234             throw new Exception("expected output not found");
   232     }
   235     }
   233 
   236 
   234     @Test
   237     @Test
   235     public void testQulifiedExportsToDifferentModules(Path base) throws Exception {
   238     public void testQualifiedExportsToDifferentModules(Path base) throws Exception {
   236         Path modules = base.resolve("modules");
   239         Path modSrc = base.resolve("modSrc");
   237         new ModuleBuilder(tb, "U").write(modules);
   240         new ModuleBuilder(tb, "U").write(modSrc);
   238         new ModuleBuilder(tb, "M")
   241         new ModuleBuilder(tb, "M")
   239                 .exports("pkg to U")
   242                 .exports("pkg to U")
   240                 .classes("package pkg; public class A { public static boolean flagM; }")
   243                 .classes("package pkg; public class A { public static boolean flagM; }")
   241                 .write(modules);
   244                 .write(modSrc);
   242         new ModuleBuilder(tb, "N")
   245         new ModuleBuilder(tb, "N")
   243                 .exports("pkg to K")
   246                 .exports("pkg to K")
   244                 .classes("package pkg; public class A { public static boolean flagN; }")
   247                 .classes("package pkg; public class A { public static boolean flagN; }")
   245                 .write(modules);
   248                 .write(modSrc);
   246         ModuleBuilder moduleK = new ModuleBuilder(tb, "K");
   249         ModuleBuilder moduleK = new ModuleBuilder(tb, "K");
   247         moduleK.requires("M")
   250         moduleK.requires("M")
   248                 .requires("N")
   251                 .requires("N")
   249                 .classes("package p; public class DependsOnN { boolean f = pkg.A.flagN; } ")
   252                 .classes("package p; public class DependsOnN { boolean f = pkg.A.flagN; } ")
   250                 .write(modules);
   253                 .write(modSrc);
   251         new JavacTask(tb)
   254         new JavacTask(tb)
   252                 .options("-modulesourcepath", modules + "/*/src")
   255                 .options("-modulesourcepath", modSrc.toString())
   253                 .outdir(Files.createDirectories(base.resolve("classes")))
   256                 .outdir(Files.createDirectories(base.resolve("classes")))
   254                 .files(findJavaFiles(modules.resolve("K")))
   257                 .files(findJavaFiles(modSrc.resolve("K")))
   255                 .run(Task.Expect.SUCCESS)
   258                 .run(Task.Expect.SUCCESS)
   256                 .writeAll();
   259                 .writeAll();
   257 
   260 
   258         //negative case
   261         //negative case
   259         moduleK.classes("package pkg; public class DuplicatePackage { } ")
   262         moduleK.classes("package pkg; public class DuplicatePackage { } ")
   260                 .classes("package p; public class DependsOnM { boolean f = pkg.A.flagM; } ")
   263                 .classes("package p; public class DependsOnM { boolean f = pkg.A.flagM; } ")
   261                 .write(modules);
   264                 .write(modSrc);
   262 
   265 
   263         List<String> output = new JavacTask(tb)
   266         List<String> output = new JavacTask(tb)
   264                 .options("-XDrawDiagnostics",
   267                 .options("-XDrawDiagnostics",
   265                         "-modulesourcepath", modules + "/*/src")
   268                         "-modulesourcepath", modSrc.toString())
   266                 .outdir(Files.createDirectories(base.resolve("classes")))
   269                 .outdir(Files.createDirectories(base.resolve("classes")))
   267                 .files(findJavaFiles(modules.resolve("K")))
   270                 .files(findJavaFiles(modSrc.resolve("K")))
   268                 .run(Task.Expect.FAIL)
   271                 .run(Task.Expect.FAIL)
   269                 .writeAll()
   272                 .writeAll()
   270                 .getOutputLines(Task.OutputKind.DIRECT);
   273                 .getOutputLines(Task.OutputKind.DIRECT);
   271 
   274 
   272         List<String> expected = Arrays.asList(
   275         List<String> expected = Arrays.asList(