langtools/test/tools/javac/modules/ModulesAndClassPathTest.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 37758 3ecf9b414e05
child 42822 a84956e7ee4d
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary Ensure named modules cannot refer to classpath types.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /tools/lib
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.api
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    30
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 * @run main ModulesAndClassPathTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.io.File;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import javax.annotation.processing.AbstractProcessor;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import javax.annotation.processing.RoundEnvironment;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import javax.annotation.processing.SupportedAnnotationTypes;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import javax.lang.model.element.TypeElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    46
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    47
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    48
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    49
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
public class ModulesAndClassPathTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        new ModulesAndClassPathTest().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    57
    public void testModulesAndClassPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        Path jar = prepareTestJar(base);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                          "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
                          "package impl; public class Impl { api.Api api; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    71
        List<String> modLog = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    72
                                .options("--class-path", jar.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                                         "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
                                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
                                .files(findJavaFiles(moduleSrc))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    76
                                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    78
                                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        List<String> expected = Arrays.asList("Impl.java:1:38: compiler.err.doesnt.exist: api",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        if (!expected.equals(modLog)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            throw new Exception("unexpected output: " + modLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    87
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    88
          .options("--class-path", jar.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    89
                   "--add-reads", "m1=ALL-UNNAMED")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
          .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
          .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    94
          .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    96
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    97
          .options("--class-path", jar.toString() + File.pathSeparator + System.getProperty("test.classes"),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    98
                   "--add-reads", "m1=ALL-UNNAMED",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                   "-processor", ProcessorImpl.class.getName())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
          .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
          .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   104
          .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   108
    public void testImplicitSourcePathModuleInfo(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        Path jar = prepareTestJar(base);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                          "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                          "package impl; public class Impl { api.Api api; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   122
        List<String> modLog = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   123
                                .options("--class-path", jar.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                                         "-sourcepath", m1.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                                         "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                                .files(m1.resolve("impl").resolve("Impl.java"))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   128
                                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   130
                                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        List<String> expected = Arrays.asList("Impl.java:1:38: compiler.err.doesnt.exist: api",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        if (!expected.equals(modLog)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            throw new Exception("unexpected output: " + modLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   141
    public void testModuleInfoFromOutput(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        Path jar = prepareTestJar(base);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                          "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                          "package impl; public class Impl { api.Api api; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   155
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   156
          .options("--class-path", jar.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                   "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
          .files(m1.resolve("module-info.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
          .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   162
          .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   164
        List<String> modLog = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   165
                                .options("--class-path", jar.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                                         "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
                                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                                .files(m1.resolve("impl").resolve("Impl.java"))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   169
                                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   171
                                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        List<String> expected = Arrays.asList("Impl.java:1:38: compiler.err.doesnt.exist: api",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        if (!expected.equals(modLog)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
            throw new Exception("unexpected output: " + modLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
    private Path prepareTestJar(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        Path legacySrc = base.resolve("legacy-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        tb.writeJavaFiles(legacySrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                          "package api; public abstract class Api {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        Path legacyClasses = base.resolve("legacy-classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        Files.createDirectories(legacyClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   188
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                .options()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                .outdir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                .files(findJavaFiles(legacySrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   194
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        if (!log.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
            throw new Exception("unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        Path lib = base.resolve("lib");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        Files.createDirectories(lib);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        Path jar = lib.resolve("test-api-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   206
        new JarTask(tb, jar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
          .baseDir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
          .files("api/Api.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        return jar;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
    public static class ProcessorImpl extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   223
    public void testClassOutputVisibleForIncrementalCompilation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                          "module m1 { exports impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                          "package impl; public class Impl { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                          "package src; public class Src { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                          "package test; public class TestCP extends impl.Impl { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                          "package test; public class TestSP extends src.Src { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   238
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
          .files(m1.resolve("impl").resolve("Impl.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
          .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   243
          .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   245
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
          .files(m1.resolve("module-info.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
          .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   250
          .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   252
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
          .files(m1.resolve("test").resolve("TestCP.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
          .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   257
          .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   259
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
          .options("-sourcepath", m1.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
          .files(m1.resolve("test").resolve("TestSP.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
          .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   265
          .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
}