langtools/test/tools/javac/modules/OutputDirTest.java
changeset 36526 3b41f1c69604
child 36778 e04318f39f92
equal deleted inserted replaced
36525:4caf88912b7f 36526:3b41f1c69604
       
     1 /*
       
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @summary tests for output directory
       
    27  * @library /tools/lib
       
    28  * @modules
       
    29  *      jdk.compiler/com.sun.tools.javac.api
       
    30  *      jdk.compiler/com.sun.tools.javac.main
       
    31  *      jdk.jdeps/com.sun.tools.javap
       
    32  * @build ToolBox ModuleTestBase
       
    33  * @run main OutputDirTest
       
    34  */
       
    35 
       
    36 import java.io.IOException;
       
    37 import java.nio.file.Files;
       
    38 import java.nio.file.Path;
       
    39 import java.nio.file.Paths;
       
    40 
       
    41 public class OutputDirTest extends ModuleTestBase {
       
    42     public static void main(String... args) throws Exception {
       
    43         new OutputDirTest().run();
       
    44     }
       
    45 
       
    46     Path src;
       
    47 
       
    48     void run() throws Exception {
       
    49         tb = new ToolBox();
       
    50 
       
    51         src = Paths.get("src");
       
    52         tb.writeJavaFiles(src.resolve("m"),
       
    53                 "module m { }",
       
    54                 "package p; class C { }");
       
    55 
       
    56         runTests();
       
    57     }
       
    58 
       
    59     @Test
       
    60     void testError(Path base) throws Exception {
       
    61         String log = tb.new JavacTask()
       
    62                 .options("-XDrawDiagnostics",
       
    63                         "-modulesourcepath", src.toString())
       
    64                 .files(findJavaFiles(src))
       
    65                 .run(ToolBox.Expect.FAIL)
       
    66                 .writeAll()
       
    67                 .getOutput(ToolBox.OutputKind.DIRECT);
       
    68 
       
    69         if (!log.contains("- compiler.err.no.output.dir"))
       
    70             throw new Exception("expected output not found");
       
    71     }
       
    72 
       
    73     @Test
       
    74     void testProcOnly(Path base) throws IOException {
       
    75         tb.new JavacTask()
       
    76                 .options("-XDrawDiagnostics",
       
    77                         "-proc:only",
       
    78                         "-modulesourcepath", src.toString())
       
    79                 .files(findJavaFiles(src))
       
    80                 .run(ToolBox.Expect.SUCCESS)
       
    81                 .writeAll();
       
    82     }
       
    83 
       
    84     @Test
       
    85     void testClassOutDir(Path base) throws IOException {
       
    86         Path classes = base.resolve("classes");
       
    87         tb.new JavacTask()
       
    88                 .options("-XDrawDiagnostics",
       
    89                         "-d", classes.toString(),
       
    90                         "-modulesourcepath", src.toString())
       
    91                 .files(findJavaFiles(src))
       
    92                 .run(ToolBox.Expect.SUCCESS)
       
    93                 .writeAll();
       
    94     }
       
    95 
       
    96     @Test
       
    97     void testExplodedOutDir(Path base) throws Exception {
       
    98         Path modSrc = base.resolve("modSrc");
       
    99         tb.writeJavaFiles(modSrc,
       
   100                 "module m1 { exports p; }",
       
   101                 "package p; public class CC { }");
       
   102         Path modClasses = base.resolve("modClasses");
       
   103         Files.createDirectories(modClasses);
       
   104 
       
   105         tb.new JavacTask(ToolBox.Mode.CMDLINE)
       
   106                 .outdir(modClasses)
       
   107                 .files(findJavaFiles(modSrc))
       
   108                 .run()
       
   109                 .writeAll();
       
   110 
       
   111         Path src = base.resolve("src");
       
   112         Path src_m = src.resolve("m");
       
   113         tb.writeJavaFiles(src_m,
       
   114                 "module m { requires m1 ; }",
       
   115                 "class C { }");
       
   116 
       
   117         String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
       
   118                 .outdir(modClasses) // an exploded module
       
   119                 .options("-XDrawDiagnostics",
       
   120                         "-modulesourcepath", src.toString())
       
   121                 .files(findJavaFiles(src))
       
   122                 .run(ToolBox.Expect.FAIL)
       
   123                 .writeAll()
       
   124                 .getOutput(ToolBox.OutputKind.DIRECT);
       
   125 
       
   126         if (!log.contains("- compiler.err.multi-module.outdir.cannot.be.exploded.module: " + modClasses.toString()))
       
   127             throw new Exception("expected output not found");
       
   128     }
       
   129 
       
   130     @Test
       
   131     void testInExplodedOutDir(Path base) throws Exception {
       
   132         Path modSrc = base.resolve("modSrc");
       
   133         tb.writeJavaFiles(modSrc,
       
   134                 "module m1 { exports p; }",
       
   135                 "package p; public class CC { }");
       
   136         Path modClasses = base.resolve("modClasses");
       
   137         Files.createDirectories(modClasses);
       
   138 
       
   139         tb.new JavacTask(ToolBox.Mode.CMDLINE)
       
   140                 .outdir(modClasses)
       
   141                 .files(findJavaFiles(modSrc))
       
   142                 .run()
       
   143                 .writeAll();
       
   144 
       
   145         Path src = base.resolve("src");
       
   146         tb.writeJavaFiles(src,
       
   147                 "module m { requires m1 ; }",
       
   148                 "class C { }");
       
   149 
       
   150         Path classes = modClasses.resolve("m");
       
   151         Files.createDirectories(classes);
       
   152 
       
   153         String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
       
   154                 .outdir(classes) // within an exploded module
       
   155                 .options("-XDrawDiagnostics",
       
   156                         "-Xlint", "-Werror",
       
   157                         "-modulepath", modClasses.toString())
       
   158                 .files(findJavaFiles(src))
       
   159                 .run(ToolBox.Expect.FAIL)
       
   160                 .writeAll()
       
   161                 .getOutput(ToolBox.OutputKind.DIRECT);
       
   162 
       
   163         if (!log.contains("- compiler.warn.outdir.is.in.exploded.module: " + classes.toString()))
       
   164             throw new Exception("expected output not found");
       
   165     }
       
   166 }