langtools/test/tools/javac/modules/OutputDirTest.java
changeset 36778 e04318f39f92
parent 36526 3b41f1c69604
child 37758 3ecf9b414e05
equal deleted inserted replaced
36777:28d33fb9097f 36778:e04318f39f92
    26  * @summary tests for output directory
    26  * @summary tests for output directory
    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  *      jdk.jdeps/com.sun.tools.javap
    31  * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
    32  * @build ToolBox ModuleTestBase
       
    33  * @run main OutputDirTest
    32  * @run main OutputDirTest
    34  */
    33  */
    35 
    34 
    36 import java.io.IOException;
    35 import java.io.IOException;
    37 import java.nio.file.Files;
    36 import java.nio.file.Files;
    38 import java.nio.file.Path;
    37 import java.nio.file.Path;
    39 import java.nio.file.Paths;
    38 import java.nio.file.Paths;
       
    39 
       
    40 import toolbox.JavacTask;
       
    41 import toolbox.Task;
       
    42 import toolbox.ToolBox;
    40 
    43 
    41 public class OutputDirTest extends ModuleTestBase {
    44 public class OutputDirTest extends ModuleTestBase {
    42     public static void main(String... args) throws Exception {
    45     public static void main(String... args) throws Exception {
    43         new OutputDirTest().run();
    46         new OutputDirTest().run();
    44     }
    47     }
    56         runTests();
    59         runTests();
    57     }
    60     }
    58 
    61 
    59     @Test
    62     @Test
    60     void testError(Path base) throws Exception {
    63     void testError(Path base) throws Exception {
    61         String log = tb.new JavacTask()
    64         String log = new JavacTask(tb)
    62                 .options("-XDrawDiagnostics",
    65                 .options("-XDrawDiagnostics",
    63                         "-modulesourcepath", src.toString())
    66                         "-modulesourcepath", src.toString())
    64                 .files(findJavaFiles(src))
    67                 .files(findJavaFiles(src))
    65                 .run(ToolBox.Expect.FAIL)
    68                 .run(Task.Expect.FAIL)
    66                 .writeAll()
    69                 .writeAll()
    67                 .getOutput(ToolBox.OutputKind.DIRECT);
    70                 .getOutput(Task.OutputKind.DIRECT);
    68 
    71 
    69         if (!log.contains("- compiler.err.no.output.dir"))
    72         if (!log.contains("- compiler.err.no.output.dir"))
    70             throw new Exception("expected output not found");
    73             throw new Exception("expected output not found");
    71     }
    74     }
    72 
    75 
    73     @Test
    76     @Test
    74     void testProcOnly(Path base) throws IOException {
    77     void testProcOnly(Path base) throws IOException {
    75         tb.new JavacTask()
    78         new JavacTask(tb)
    76                 .options("-XDrawDiagnostics",
    79                 .options("-XDrawDiagnostics",
    77                         "-proc:only",
    80                         "-proc:only",
    78                         "-modulesourcepath", src.toString())
    81                         "-modulesourcepath", src.toString())
    79                 .files(findJavaFiles(src))
    82                 .files(findJavaFiles(src))
    80                 .run(ToolBox.Expect.SUCCESS)
    83                 .run(Task.Expect.SUCCESS)
    81                 .writeAll();
    84                 .writeAll();
    82     }
    85     }
    83 
    86 
    84     @Test
    87     @Test
    85     void testClassOutDir(Path base) throws IOException {
    88     void testClassOutDir(Path base) throws IOException {
    86         Path classes = base.resolve("classes");
    89         Path classes = base.resolve("classes");
    87         tb.new JavacTask()
    90         new JavacTask(tb)
    88                 .options("-XDrawDiagnostics",
    91                 .options("-XDrawDiagnostics",
    89                         "-d", classes.toString(),
    92                         "-d", classes.toString(),
    90                         "-modulesourcepath", src.toString())
    93                         "-modulesourcepath", src.toString())
    91                 .files(findJavaFiles(src))
    94                 .files(findJavaFiles(src))
    92                 .run(ToolBox.Expect.SUCCESS)
    95                 .run(Task.Expect.SUCCESS)
    93                 .writeAll();
    96                 .writeAll();
    94     }
    97     }
    95 
    98 
    96     @Test
    99     @Test
    97     void testExplodedOutDir(Path base) throws Exception {
   100     void testExplodedOutDir(Path base) throws Exception {
   100                 "module m1 { exports p; }",
   103                 "module m1 { exports p; }",
   101                 "package p; public class CC { }");
   104                 "package p; public class CC { }");
   102         Path modClasses = base.resolve("modClasses");
   105         Path modClasses = base.resolve("modClasses");
   103         Files.createDirectories(modClasses);
   106         Files.createDirectories(modClasses);
   104 
   107 
   105         tb.new JavacTask(ToolBox.Mode.CMDLINE)
   108         new JavacTask(tb, Task.Mode.CMDLINE)
   106                 .outdir(modClasses)
   109                 .outdir(modClasses)
   107                 .files(findJavaFiles(modSrc))
   110                 .files(findJavaFiles(modSrc))
   108                 .run()
   111                 .run()
   109                 .writeAll();
   112                 .writeAll();
   110 
   113 
   112         Path src_m = src.resolve("m");
   115         Path src_m = src.resolve("m");
   113         tb.writeJavaFiles(src_m,
   116         tb.writeJavaFiles(src_m,
   114                 "module m { requires m1 ; }",
   117                 "module m { requires m1 ; }",
   115                 "class C { }");
   118                 "class C { }");
   116 
   119 
   117         String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
   120         String log = new JavacTask(tb, Task.Mode.CMDLINE)
   118                 .outdir(modClasses) // an exploded module
   121                 .outdir(modClasses) // an exploded module
   119                 .options("-XDrawDiagnostics",
   122                 .options("-XDrawDiagnostics",
   120                         "-modulesourcepath", src.toString())
   123                         "-modulesourcepath", src.toString())
   121                 .files(findJavaFiles(src))
   124                 .files(findJavaFiles(src))
   122                 .run(ToolBox.Expect.FAIL)
   125                 .run(Task.Expect.FAIL)
   123                 .writeAll()
   126                 .writeAll()
   124                 .getOutput(ToolBox.OutputKind.DIRECT);
   127                 .getOutput(Task.OutputKind.DIRECT);
   125 
   128 
   126         if (!log.contains("- compiler.err.multi-module.outdir.cannot.be.exploded.module: " + modClasses.toString()))
   129         if (!log.contains("- compiler.err.multi-module.outdir.cannot.be.exploded.module: " + modClasses.toString()))
   127             throw new Exception("expected output not found");
   130             throw new Exception("expected output not found");
   128     }
   131     }
   129 
   132 
   134                 "module m1 { exports p; }",
   137                 "module m1 { exports p; }",
   135                 "package p; public class CC { }");
   138                 "package p; public class CC { }");
   136         Path modClasses = base.resolve("modClasses");
   139         Path modClasses = base.resolve("modClasses");
   137         Files.createDirectories(modClasses);
   140         Files.createDirectories(modClasses);
   138 
   141 
   139         tb.new JavacTask(ToolBox.Mode.CMDLINE)
   142         new JavacTask(tb, Task.Mode.CMDLINE)
   140                 .outdir(modClasses)
   143                 .outdir(modClasses)
   141                 .files(findJavaFiles(modSrc))
   144                 .files(findJavaFiles(modSrc))
   142                 .run()
   145                 .run()
   143                 .writeAll();
   146                 .writeAll();
   144 
   147 
   148                 "class C { }");
   151                 "class C { }");
   149 
   152 
   150         Path classes = modClasses.resolve("m");
   153         Path classes = modClasses.resolve("m");
   151         Files.createDirectories(classes);
   154         Files.createDirectories(classes);
   152 
   155 
   153         String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
   156         String log = new JavacTask(tb, Task.Mode.CMDLINE)
   154                 .outdir(classes) // within an exploded module
   157                 .outdir(classes) // within an exploded module
   155                 .options("-XDrawDiagnostics",
   158                 .options("-XDrawDiagnostics",
   156                         "-Xlint", "-Werror",
   159                         "-Xlint", "-Werror",
   157                         "-modulepath", modClasses.toString())
   160                         "-modulepath", modClasses.toString())
   158                 .files(findJavaFiles(src))
   161                 .files(findJavaFiles(src))
   159                 .run(ToolBox.Expect.FAIL)
   162                 .run(Task.Expect.FAIL)
   160                 .writeAll()
   163                 .writeAll()
   161                 .getOutput(ToolBox.OutputKind.DIRECT);
   164                 .getOutput(Task.OutputKind.DIRECT);
   162 
   165 
   163         if (!log.contains("- compiler.warn.outdir.is.in.exploded.module: " + classes.toString()))
   166         if (!log.contains("- compiler.warn.outdir.is.in.exploded.module: " + classes.toString()))
   164             throw new Exception("expected output not found");
   167             throw new Exception("expected output not found");
   165     }
   168     }
   166 }
   169 }