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