langtools/test/tools/javac/modules/EdgeCases.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
changeset 36526 3b41f1c69604
child 36778 e04318f39f92
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
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) 2015, 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 tests for multi-module mode compilation
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.code
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.compiler/com.sun.tools.javac.main
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 *      jdk.jdeps/com.sun.tools.javap
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 * @build ToolBox ModuleTestBase
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 * @run main EdgeCases
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.io.Writer;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.nio.file.Paths;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.util.HashSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.Objects;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import javax.lang.model.element.Element;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import javax.tools.JavaCompiler;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import javax.tools.JavaFileObject;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import javax.tools.StandardJavaFileManager;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import javax.tools.ToolProvider;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import com.sun.source.tree.CompilationUnitTree;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
import com.sun.source.util.JavacTask;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
import com.sun.tools.javac.api.JavacTaskImpl;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
public class EdgeCases extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        new EdgeCases().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    void testAddExportUndefinedModule(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        tb.writeJavaFiles(src, "package test; import undef.Any; public class Test {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        List<String> log = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                .options("-XaddExports:undef/undef=ALL-UNNAMED", "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                .getOutputLines(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        List<String> expected = Arrays.asList("- compiler.err.cant.find.module: undef",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                                              "Test.java:1:27: compiler.err.doesnt.exist: undef",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                                              "2 errors");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    void testModuleSymbolOutterMostClass(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
            Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
            Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            tb.writeJavaFiles(m1, "module m1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
            JavacTask task = (JavacTask) compiler.getTask(null, fm, null, null, null, files);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            task.analyze();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
            ModuleSymbol msym = (ModuleSymbol) task.getElements().getModuleElement("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            msym.outermostClass();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        }
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
    void testParseEnterAnalyze(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
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
            tb.writeJavaFiles(m1, "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                                  "package p;",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                                  "package p; class T { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
            List<String> options = Arrays.asList("-d", classes.toString(), "-Xpkginfo:always");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
            JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, fm, null, options, null, files);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
            Iterable<? extends CompilationUnitTree> parsed = task.parse();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            Iterable<? extends Element> entered = task.enter(parsed);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
            Iterable<? extends Element> analyzed = task.analyze(entered);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            Iterable<? extends JavaFileObject> generatedFiles = task.generate(analyzed);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
            Set<String> generated = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
            for (JavaFileObject jfo : generatedFiles) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                generated.add(jfo.getName());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            Set<String> expected = new HashSet<>(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                    Arrays.asList(Paths.get("testParseEnterAnalyze", "classes", "p", "package-info.class").toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                                  Paths.get("testParseEnterAnalyze", "classes", "module-info.class").toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                                  Paths.get("testParseEnterAnalyze", "classes", "p", "T.class").toString())
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
            if (!Objects.equals(expected, generated))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                throw new AssertionError("Incorrect generated files: " + generated);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
    void testModuleImplicitModuleBoundaries(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                          "module m1 { exports api1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                          "package api1; public class Api1 { public void call() { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        Path src_m2 = src.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        tb.writeJavaFiles(src_m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                          "module m2 { requires m1; exports api2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                          "package api2; public class Api2 { public static api1.Api1 get() { return null; } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        Path src_m3 = src.resolve("m3");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        tb.writeJavaFiles(src_m3,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                          "module m3 { requires m2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                          "package test; public class Test { { api2.Api2.get().call(); api2.Api2.get().toString(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        String log = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                         "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        if (!log.contains("Test.java:1:52: compiler.err.not.def.access.class.intf.cant.access: call(), api1.Api1") ||
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
            !log.contains("Test.java:1:76: compiler.err.not.def.access.class.intf.cant.access: toString(), java.lang.Object"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
    void testAssignClassToAutomaticModule(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        //check that if a ClassSymbol belongs to an automatic module, it is properly assigned and not
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        //duplicated when being accessed through a classfile.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        Path automaticSrc = base.resolve("automaticSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        tb.writeJavaFiles(automaticSrc, "package api1; public class Api1 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        Path automaticClasses = base.resolve("automaticClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        tb.createDirectories(automaticClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        String automaticLog = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                                .outdir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                                .files(findJavaFiles(automaticSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        if (!automaticLog.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
            throw new Exception("expected output not found: " + automaticLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        Path automaticJar = modulePath.resolve("m1-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        tb.new JarTask(automaticJar)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
          .baseDir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
          .files("api1/Api1.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        Path src_m2 = src.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        tb.writeJavaFiles(src_m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                          "module m2 { requires m1; exports api2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                          "package api2; public class Api2 { public static api1.Api1 get() { return null; } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        Path src_m3 = src.resolve("m3");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        tb.writeJavaFiles(src_m3,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                          "module m3 { requires m1; requires m2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                          "package test; public class Test { { api2.Api2.get(); api1.Api1 a1; } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                .options("-modulepath", modulePath.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                         "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                .files(findJavaFiles(src_m2))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
                .options("-modulepath", modulePath.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
                         "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                .files(findJavaFiles(src_m3))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
    void testEmptyImplicitModuleInfo(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        Files.createDirectories(src_m1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        try (Writer w = Files.newBufferedWriter(src_m1.resolve("module-info.java"))) {}
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                          "package test; public class Test {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                .options("-sourcepath", src_m1.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                         "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                .files(findJavaFiles(src_m1.resolve("test")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
                          "module m1 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                .options("-sourcepath", src_m1.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                .files(findJavaFiles(src_m1.resolve("test")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
}