langtools/test/tools/javac/modules/EdgeCases.java
author jlahoda
Tue, 11 Oct 2016 10:31:10 +0200
changeset 41516 0a5838f027a4
parent 41254 08f8dbf7741e
child 41931 d7c9720c4223
permissions -rw-r--r--
8167320: Trying to document only java.base causes a NPE in javac Summary: Ensure ModuleSymbol.getDirectives completes the Symbol Reviewed-by: ksrini, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
36526
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
41516
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
    26
 * @bug 8154283 8167320
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @summary tests for multi-module mode compilation
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.compiler/com.sun.tools.javac.code
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 *      jdk.compiler/com.sun.tools.javac.main
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase
36526
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;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    54
//import com.sun.source.util.JavacTask; // conflicts with toolbox.JavacTask
36526
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;
41516
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
    57
import com.sun.tools.javac.code.Symtab;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    59
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    60
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    61
import toolbox.Task;
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
    62
import toolbox.Task.Expect;
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
    63
import toolbox.Task.OutputKind;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    64
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
public class EdgeCases extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        new EdgeCases().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
    72
    public void testAddExportUndefinedModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        tb.writeJavaFiles(src, "package test; import undef.Any; public class Test {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    78
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    79
                .options("--add-exports", "undef/undef=ALL-UNNAMED", "-XDrawDiagnostics")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    82
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    84
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        List<String> expected = Arrays.asList("- compiler.err.cant.find.module: undef",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                                              "Test.java:1:27: compiler.err.doesnt.exist: undef",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                                              "2 errors");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
    95
    public void testModuleSymbolOutterMostClass(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
            Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
            tb.writeJavaFiles(m1, "module m1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc));
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   104
            com.sun.source.util.JavacTask task =
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   105
                (com.sun.source.util.JavacTask) compiler.getTask(null, fm, null, null, null, files);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
            task.analyze();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
            ModuleSymbol msym = (ModuleSymbol) task.getElements().getModuleElement("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
            msym.outermostClass();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   116
    public void testParseEnterAnalyze(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
            Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
            Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            tb.writeJavaFiles(m1, "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                                  "package p;",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                                  "package p; class T { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
            List<String> options = Arrays.asList("-d", classes.toString(), "-Xpkginfo:always");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
            JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, fm, null, options, null, files);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
            Iterable<? extends CompilationUnitTree> parsed = task.parse();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            Iterable<? extends Element> entered = task.enter(parsed);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            Iterable<? extends Element> analyzed = task.analyze(entered);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            Iterable<? extends JavaFileObject> generatedFiles = task.generate(analyzed);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            Set<String> generated = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
            for (JavaFileObject jfo : generatedFiles) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                generated.add(jfo.getName());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            Set<String> expected = new HashSet<>(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                    Arrays.asList(Paths.get("testParseEnterAnalyze", "classes", "p", "package-info.class").toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                                  Paths.get("testParseEnterAnalyze", "classes", "module-info.class").toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                                  Paths.get("testParseEnterAnalyze", "classes", "p", "T.class").toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            );
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            if (!Objects.equals(expected, generated))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                throw new AssertionError("Incorrect generated files: " + generated);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   154
    public void testModuleImplicitModuleBoundaries(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                          "module m1 { exports api1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                          "package api1; public class Api1 { public void call() { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        Path src_m2 = src.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        tb.writeJavaFiles(src_m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
                          "module m2 { requires m1; exports api2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
                          "package api2; public class Api2 { public static api1.Api1 get() { return null; } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        Path src_m3 = src.resolve("m3");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        tb.writeJavaFiles(src_m3,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                          "module m3 { requires m2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
                          "package test; public class Test { { api2.Api2.get().call(); api2.Api2.get().toString(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   171
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   173
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   176
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   178
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        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
   181
            !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
   182
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   186
    public void testAssignClassToAutomaticModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        //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
   188
        //duplicated when being accessed through a classfile.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        Path automaticSrc = base.resolve("automaticSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        tb.writeJavaFiles(automaticSrc, "package api1; public class Api1 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        Path automaticClasses = base.resolve("automaticClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        tb.createDirectories(automaticClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   194
        String automaticLog = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                                .outdir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                                .files(findJavaFiles(automaticSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   199
                                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
        if (!automaticLog.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
            throw new Exception("expected output not found: " + automaticLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        Path automaticJar = modulePath.resolve("m1-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   210
        new JarTask(tb, automaticJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
          .baseDir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
          .files("api1/Api1.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        Path src_m2 = src.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        tb.writeJavaFiles(src_m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                          "module m2 { requires m1; exports api2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                          "package api2; public class Api2 { public static api1.Api1 get() { return null; } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        Path src_m3 = src.resolve("m3");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        tb.writeJavaFiles(src_m3,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
                          "module m3 { requires m1; requires m2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                          "package test; public class Test { { api2.Api2.get(); api1.Api1 a1; } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   227
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   228
                .options("--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   229
                         "--module-source-path", src.toString())
36526
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_m2))
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
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   235
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   236
                .options("--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   237
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                .files(findJavaFiles(src_m3))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   245
    public void testEmptyImplicitModuleInfo(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        Files.createDirectories(src_m1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        try (Writer w = Files.newBufferedWriter(src_m1.resolve("module-info.java"))) {}
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                          "package test; public class Test {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   255
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   256
                .options("--source-path", src_m1.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                         "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                .files(findJavaFiles(src_m1.resolve("test")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   260
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                          "module m1 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   266
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   267
                .options("--source-path", src_m1.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                .files(findJavaFiles(src_m1.resolve("test")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   275
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   276
    public void testClassPackageClash(Path base) throws Exception {
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   277
        Path src = base.resolve("src");
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   278
        Path src_m1 = src.resolve("m1");
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   279
        tb.writeJavaFiles(src_m1,
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   280
                          "module m1 { exports test.m1; }",
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   281
                          "package test.m1;\n" +
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   282
                          "public class Test {}\n");
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   283
        Path src_m2 = src.resolve("m2");
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   284
        tb.writeJavaFiles(src_m2,
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   285
                          "module m2 { requires m1; }",
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   286
                          "package test;\n" +
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   287
                          "public class m1 {}\n");
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   288
        Path classes = base.resolve("classes");
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   289
        tb.createDirectories(classes);
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   290
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   291
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   292
                .options("--module-source-path", src.toString(),
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   293
                         "-XDrawDiagnostics")
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   294
                .outdir(classes)
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   295
                .files(findJavaFiles(src))
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   296
                .run(Task.Expect.FAIL)
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   297
                .writeAll()
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   298
                .getOutputLines(Task.OutputKind.DIRECT);
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   299
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   300
        List<String> expected = Arrays.asList(
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   301
            "m1.java:2:8: compiler.err.clash.with.pkg.of.same.name: kindname.class, test.m1",
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   302
            "1 error"
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   303
        );
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   304
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   305
        if (!expected.equals(log)) {
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   306
            throw new IllegalStateException(log.toString());
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   307
        }
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   308
    }
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   309
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   310
    @Test
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   311
    public void testImplicitJavaBase(Path base) throws Exception {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   312
        Path src = base.resolve("src");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   313
        Path src_java_base = src.resolve("java.base");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   314
        Files.createDirectories(src_java_base);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   315
        tb.writeJavaFiles(src_java_base, "module java.base { exports java.lang; }");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   316
        tb.writeJavaFiles(src_java_base,
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   317
                          "package java.lang; public class Object {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   318
        Path classes = base.resolve("classes");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   319
        tb.createDirectories(classes);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   320
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   321
        //module-info from source:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   322
        new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   323
            .options("-sourcepath", src_java_base.toString())
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   324
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   325
            .files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   326
            .run()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   327
            .writeAll();
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   328
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   329
        //module-info from class:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   330
        if (!Files.exists(classes.resolve("module-info.class"))) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   331
            throw new AssertionError("module-info.class not created!");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   332
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   333
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   334
        new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   335
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   336
            .files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   337
            .run()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   338
            .writeAll();
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   339
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   340
        //broken module-info.class:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   341
        Files.newOutputStream(classes.resolve("module-info.class")).close();
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   342
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   343
        List<String> log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   344
            .options("-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   345
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   346
            .files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   347
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   348
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   349
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   350
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   351
        List<String> expected = Arrays.asList(
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   352
                "- compiler.err.cant.access: <error>.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.illegal.start.of.class.file))",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   353
                "1 error");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   354
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   355
        if (!expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   356
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   357
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   358
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   359
        //broken module-info.java:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   360
        Files.delete(classes.resolve("module-info.class"));
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   361
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   362
        try (Writer out = Files.newBufferedWriter(src_java_base.resolve("module-info.java"))) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   363
            out.write("class Broken {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   364
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   365
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   366
        log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   367
            .options("-sourcepath", src_java_base.toString(),
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   368
                                "-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   369
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   370
            .files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   371
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   372
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   373
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   374
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   375
        expected = Arrays.asList("X");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   376
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   377
        if (expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   378
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   379
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   380
    }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   381
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   382
    @Test
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   383
    public void testModuleInfoNameMismatchSource(Path base) throws Exception {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   384
        Path src = base.resolve("src");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   385
        Path m1 = src.resolve("m1");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   386
        Files.createDirectories(m1);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   387
        tb.writeJavaFiles(m1, "module other { }",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   388
                              "package test; public class Test {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   389
        Path classes = base.resolve("classes");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   390
        tb.createDirectories(classes);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   391
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   392
        List<String> log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   393
            .options("--module-source-path", src.toString(),
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   394
                     "-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   395
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   396
            .files(findJavaFiles(m1.resolve("test").resolve("Test.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   397
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   398
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   399
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   400
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   401
        List<String> expected = Arrays.asList(
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   402
                "module-info.java:1:1: compiler.err.module.name.mismatch: other, m1",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   403
                "- compiler.err.cant.access: m1.module-info, (compiler.misc.cant.resolve.modules)",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   404
                "2 errors");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   405
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   406
        if (!expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   407
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   408
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   409
    }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   410
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   411
    @Test
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   412
    public void testModuleInfoNameMismatchClass(Path base) throws Exception {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   413
        Path src = base.resolve("src");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   414
        Files.createDirectories(src);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   415
        tb.writeJavaFiles(src, "module other { }",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   416
                               "package test; public class Test {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   417
        Path classes = base.resolve("classes");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   418
        Path m1Classes = classes.resolve("m1");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   419
        tb.createDirectories(m1Classes);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   420
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   421
        new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   422
            .outdir(m1Classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   423
            .files(findJavaFiles(src))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   424
            .run()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   425
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   426
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   427
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   428
        Path src2 = base.resolve("src2");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   429
        Files.createDirectories(src2);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   430
        tb.writeJavaFiles(src2, "module use { requires m1; }");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   431
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   432
        Path classes2 = base.resolve("classes2");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   433
        tb.createDirectories(classes2);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   434
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   435
        List<String> log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   436
            .options("--module-path", classes.toString(),
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   437
                     "-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   438
            .outdir(classes2)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   439
            .files(findJavaFiles(src2))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   440
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   441
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   442
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   443
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   444
        List<String> expected = Arrays.asList(
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   445
                "- compiler.err.cant.access: m1.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.name.mismatch: other, m1))",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   446
                "1 error");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   447
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   448
        if (!expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   449
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   450
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   451
    }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   452
41516
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   453
    @Test
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   454
    public void testGetDirectivesComplete(Path base) throws Exception {
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   455
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   456
        JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, null, null, null, null, null);
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   457
        Symtab syms = Symtab.instance(task.getContext());
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   458
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   459
        syms.java_base.getDirectives();
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   460
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   461
}