< prev index next >

test/tools/javac/modules/XModuleTest.java

Print this page




  95         Path cpClasses = base.resolve("cpClasses");
  96         tb.createDirectories(cpClasses);
  97 
  98         String cpLog = new JavacTask(tb)
  99                 .outdir(cpClasses)
 100                 .files(findJavaFiles(cpSrc))
 101                 .run()
 102                 .writeAll()
 103                 .getOutput(Task.OutputKind.DIRECT);
 104 
 105         if (!cpLog.isEmpty())
 106             throw new Exception("expected output not found: " + cpLog);
 107 
 108         Path src = base.resolve("src");
 109         //note: avoiding use of java.base, as that gets special handling on some places:
 110         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, p.Other { }");
 111         Path classes = base.resolve("classes");
 112         tb.createDirectories(classes);
 113 
 114         String log = new JavacTask(tb)
 115                 .options("-Xmodule:java.compiler", "-classpath", cpClasses.toString())
 116                 .outdir(classes)
 117                 .files(src.resolve("javax/lang/model/element/Extra.java"))
 118                 .run()
 119                 .writeAll()
 120                 .getOutput(Task.OutputKind.DIRECT);
 121 
 122         if (!log.isEmpty())
 123             throw new Exception("expected output not found: " + log);
 124     }
 125 
 126     @Test
 127     public void testNoModuleInfoOnSourcePath(Path base) throws Exception {
 128         //note: avoiding use of java.base, as that gets special handling on some places:
 129         Path src = base.resolve("src");
 130         tb.writeJavaFiles(src,
 131                           "module java.compiler {}",
 132                           "package javax.lang.model.element; public interface Extra { }");
 133         Path classes = base.resolve("classes");
 134         tb.createDirectories(classes);
 135 


 180                 .run(Task.Expect.FAIL)
 181                 .writeAll()
 182                 .getOutputLines(Task.OutputKind.DIRECT);
 183 
 184         List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.classpath",
 185                                               "1 error");
 186 
 187         if (!expected.equals(log))
 188             throw new Exception("expected output not found: " + log);
 189     }
 190 
 191     @Test
 192     public void testModuleSourcePathXModule(Path base) throws Exception {
 193         //note: avoiding use of java.base, as that gets special handling on some places:
 194         Path src = base.resolve("src");
 195         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
 196         Path classes = base.resolve("classes");
 197         tb.createDirectories(classes);
 198 
 199         List<String> log = new JavacTask(tb)
 200                 .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-modulesourcepath", src.toString())
 201                 .outdir(classes)
 202                 .files(findJavaFiles(src))
 203                 .run(Task.Expect.FAIL)
 204                 .writeAll()
 205                 .getOutputLines(Task.OutputKind.DIRECT);
 206 
 207         List<String> expected = Arrays.asList("- compiler.err.xmodule.no.module.sourcepath",
 208                                               "1 error");
 209 
 210         if (!expected.equals(log))
 211             throw new Exception("expected output not found: " + log);
 212     }
 213 
 214     @Test
 215     public void testXModuleTooMany(Path base) throws Exception {
 216         //note: avoiding use of java.base, as that gets special handling on some places:
 217         Path src = base.resolve("src");
 218         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
 219         Path classes = base.resolve("classes");
 220         tb.createDirectories(classes);
 221 
 222         List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
 223                 .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-Xmodule:java.compiler")
 224                 .outdir(classes)
 225                 .files(findJavaFiles(src))
 226                 .run(Task.Expect.FAIL)
 227                 .writeAll()
 228                 .getOutputLines(Task.OutputKind.DIRECT);
 229 
 230         List<String> expected = Arrays.asList("javac: option -Xmodule: can only be specified once",
 231                                               "Usage: javac <options> <source files>",
 232                                               "use -help for a list of possible options");
 233 
 234         if (!expected.equals(log))
 235             throw new Exception("expected output not found: " + log);
 236     }
 237 
 238     @Test
 239     public void testWithModulePath(Path base) throws Exception {
 240         Path modSrc = base.resolve("modSrc");
 241         Path modules = base.resolve("modules");
 242         new ModuleBuilder(tb, "m1")
 243                 .classes("package pkg1; public interface E { }")
 244                 .build(modSrc, modules);
 245 
 246         Path src = base.resolve("src");
 247         tb.writeJavaFiles(src, "package p; interface A extends pkg1.E { }");
 248 
 249         new JavacTask(tb, Task.Mode.CMDLINE)
 250                 .options("-modulepath", modules.toString(),
 251                         "-Xmodule:m1")
 252                 .files(findJavaFiles(src))
 253                 .run()
 254                 .writeAll();
 255 
 256         //checks module bounds still exist
 257         new ModuleBuilder(tb, "m2")
 258                 .classes("package pkg2; public interface D { }")
 259                 .build(modSrc, modules);
 260 
 261         Path src2 = base.resolve("src2");
 262         tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }");
 263 
 264         List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
 265                 .options("-XDrawDiagnostics",
 266                         "-modulepath", modules.toString(),
 267                         "-Xmodule:m1")
 268                 .files(findJavaFiles(src2))
 269                 .run(Task.Expect.FAIL)
 270                 .writeAll()
 271                 .getOutputLines(Task.OutputKind.DIRECT);
 272 
 273         List<String> expected = Arrays.asList("A.java:1:36: compiler.err.doesnt.exist: pkg2",
 274                 "1 error");
 275 
 276         if (!expected.equals(log))
 277             throw new Exception("expected output not found: " + log);
 278     }
 279 
 280     @Test
 281     public void testWithUpgradeModulePath(Path base) throws Exception {
 282         Path modSrc = base.resolve("modSrc");
 283         Path modules = base.resolve("modules");
 284         new ModuleBuilder(tb, "m1")
 285                 .classes("package pkg1; public interface E { }")
 286                 .build(modSrc, modules);
 287 
 288         Path upgrSrc = base.resolve("upgradeSrc");
 289         Path upgrade = base.resolve("upgrade");
 290         new ModuleBuilder(tb, "m1")
 291                 .classes("package pkg1; public interface D { }")
 292                 .build(upgrSrc, upgrade);
 293 
 294         Path src = base.resolve("src");
 295         tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }");
 296 
 297         new JavacTask(tb, Task.Mode.CMDLINE)
 298                 .options("-modulepath", modules.toString(),
 299                         "-upgrademodulepath", upgrade.toString(),
 300                         "-Xmodule:m1")
 301                 .files(findJavaFiles(src))
 302                 .run()
 303                 .writeAll();
 304     }
 305 }


  95         Path cpClasses = base.resolve("cpClasses");
  96         tb.createDirectories(cpClasses);
  97 
  98         String cpLog = new JavacTask(tb)
  99                 .outdir(cpClasses)
 100                 .files(findJavaFiles(cpSrc))
 101                 .run()
 102                 .writeAll()
 103                 .getOutput(Task.OutputKind.DIRECT);
 104 
 105         if (!cpLog.isEmpty())
 106             throw new Exception("expected output not found: " + cpLog);
 107 
 108         Path src = base.resolve("src");
 109         //note: avoiding use of java.base, as that gets special handling on some places:
 110         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, p.Other { }");
 111         Path classes = base.resolve("classes");
 112         tb.createDirectories(classes);
 113 
 114         String log = new JavacTask(tb)
 115                 .options("-Xmodule:java.compiler", "--class-path", cpClasses.toString())
 116                 .outdir(classes)
 117                 .files(src.resolve("javax/lang/model/element/Extra.java"))
 118                 .run()
 119                 .writeAll()
 120                 .getOutput(Task.OutputKind.DIRECT);
 121 
 122         if (!log.isEmpty())
 123             throw new Exception("expected output not found: " + log);
 124     }
 125 
 126     @Test
 127     public void testNoModuleInfoOnSourcePath(Path base) throws Exception {
 128         //note: avoiding use of java.base, as that gets special handling on some places:
 129         Path src = base.resolve("src");
 130         tb.writeJavaFiles(src,
 131                           "module java.compiler {}",
 132                           "package javax.lang.model.element; public interface Extra { }");
 133         Path classes = base.resolve("classes");
 134         tb.createDirectories(classes);
 135 


 180                 .run(Task.Expect.FAIL)
 181                 .writeAll()
 182                 .getOutputLines(Task.OutputKind.DIRECT);
 183 
 184         List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.classpath",
 185                                               "1 error");
 186 
 187         if (!expected.equals(log))
 188             throw new Exception("expected output not found: " + log);
 189     }
 190 
 191     @Test
 192     public void testModuleSourcePathXModule(Path base) throws Exception {
 193         //note: avoiding use of java.base, as that gets special handling on some places:
 194         Path src = base.resolve("src");
 195         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
 196         Path classes = base.resolve("classes");
 197         tb.createDirectories(classes);
 198 
 199         List<String> log = new JavacTask(tb)
 200                 .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "--module-source-path", src.toString())
 201                 .outdir(classes)
 202                 .files(findJavaFiles(src))
 203                 .run(Task.Expect.FAIL)
 204                 .writeAll()
 205                 .getOutputLines(Task.OutputKind.DIRECT);
 206 
 207         List<String> expected = Arrays.asList("- compiler.err.xmodule.no.module.sourcepath",
 208                                               "1 error");
 209 
 210         if (!expected.equals(log))
 211             throw new Exception("expected output not found: " + log);
 212     }
 213 
 214     @Test
 215     public void testXModuleTooMany(Path base) throws Exception {
 216         //note: avoiding use of java.base, as that gets special handling on some places:
 217         Path src = base.resolve("src");
 218         tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
 219         Path classes = base.resolve("classes");
 220         tb.createDirectories(classes);
 221 
 222         List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
 223                 .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-Xmodule:java.compiler")
 224                 .outdir(classes)
 225                 .files(findJavaFiles(src))
 226                 .run(Task.Expect.FAIL)
 227                 .writeAll()
 228                 .getOutputLines(Task.OutputKind.DIRECT);
 229 
 230         List<String> expected = Arrays.asList("javac: option -Xmodule: can only be specified once",
 231                                               "Usage: javac <options> <source files>",
 232                                               "use --help for a list of possible options");
 233 
 234         if (!expected.equals(log))
 235             throw new Exception("expected output not found: " + log);
 236     }
 237 
 238     @Test
 239     public void testWithModulePath(Path base) throws Exception {
 240         Path modSrc = base.resolve("modSrc");
 241         Path modules = base.resolve("modules");
 242         new ModuleBuilder(tb, "m1")
 243                 .classes("package pkg1; public interface E { }")
 244                 .build(modSrc, modules);
 245 
 246         Path src = base.resolve("src");
 247         tb.writeJavaFiles(src, "package p; interface A extends pkg1.E { }");
 248 
 249         new JavacTask(tb, Task.Mode.CMDLINE)
 250                 .options("--module-path", modules.toString(),
 251                         "-Xmodule:m1")
 252                 .files(findJavaFiles(src))
 253                 .run()
 254                 .writeAll();
 255 
 256         //checks module bounds still exist
 257         new ModuleBuilder(tb, "m2")
 258                 .classes("package pkg2; public interface D { }")
 259                 .build(modSrc, modules);
 260 
 261         Path src2 = base.resolve("src2");
 262         tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }");
 263 
 264         List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
 265                 .options("-XDrawDiagnostics",
 266                         "--module-path", modules.toString(),
 267                         "-Xmodule:m1")
 268                 .files(findJavaFiles(src2))
 269                 .run(Task.Expect.FAIL)
 270                 .writeAll()
 271                 .getOutputLines(Task.OutputKind.DIRECT);
 272 
 273         List<String> expected = Arrays.asList("A.java:1:36: compiler.err.doesnt.exist: pkg2",
 274                 "1 error");
 275 
 276         if (!expected.equals(log))
 277             throw new Exception("expected output not found: " + log);
 278     }
 279 
 280     @Test
 281     public void testWithUpgradeModulePath(Path base) throws Exception {
 282         Path modSrc = base.resolve("modSrc");
 283         Path modules = base.resolve("modules");
 284         new ModuleBuilder(tb, "m1")
 285                 .classes("package pkg1; public interface E { }")
 286                 .build(modSrc, modules);
 287 
 288         Path upgrSrc = base.resolve("upgradeSrc");
 289         Path upgrade = base.resolve("upgrade");
 290         new ModuleBuilder(tb, "m1")
 291                 .classes("package pkg1; public interface D { }")
 292                 .build(upgrSrc, upgrade);
 293 
 294         Path src = base.resolve("src");
 295         tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }");
 296 
 297         new JavacTask(tb, Task.Mode.CMDLINE)
 298                 .options("--module-path", modules.toString(),
 299                         "--upgrade-module-path", upgrade.toString(),
 300                         "-Xmodule:m1")
 301                 .files(findJavaFiles(src))
 302                 .run()
 303                 .writeAll();
 304     }
 305 }
< prev index next >