test/langtools/tools/javac/modules/EdgeCases.java
author darcy
Fri, 02 Feb 2018 10:29:25 -0800
changeset 48723 6cb86bf0b51e
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196623: Update JavaBaseTest.java to be version agnostic Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43269
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
     2
 * Copyright (c) 2015, 2017, 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
44451
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
    26
 * @bug 8154283 8167320 8171098 8172809 8173068 8173117 8176045 8177311
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
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    33
 *      jdk.compiler/com.sun.tools.javac.processing
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    34
 *      jdk.compiler/com.sun.tools.javac.util
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    35
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 * @run main EdgeCases
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
44290
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
    39
import java.io.BufferedWriter;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.io.Writer;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.nio.file.Paths;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.HashSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.Objects;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    50
import javax.annotation.processing.AbstractProcessor;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    51
import javax.annotation.processing.RoundEnvironment;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    52
import javax.annotation.processing.SupportedAnnotationTypes;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    53
import javax.annotation.processing.SupportedOptions;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    54
import javax.lang.model.SourceVersion;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
import javax.lang.model.element.Element;
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    56
import javax.lang.model.element.ModuleElement;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    57
import javax.lang.model.element.ModuleElement.RequiresDirective;
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    58
import javax.lang.model.element.PackageElement;
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    59
import javax.lang.model.element.TypeElement;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    60
import javax.lang.model.util.ElementFilter;
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    61
import javax.lang.model.util.Elements;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
import javax.tools.JavaCompiler;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
import javax.tools.JavaFileObject;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
import javax.tools.StandardJavaFileManager;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
import javax.tools.ToolProvider;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
import com.sun.source.tree.CompilationUnitTree;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    68
//import com.sun.source.util.JavacTask; // conflicts with toolbox.JavacTask
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
import com.sun.tools.javac.api.JavacTaskImpl;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
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
    71
import com.sun.tools.javac.code.Symtab;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    73
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    74
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    75
import toolbox.Task;
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
    76
import toolbox.Task.Expect;
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
    77
import toolbox.Task.OutputKind;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    78
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
public class EdgeCases extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        new EdgeCases().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
    86
    public void testAddExportUndefinedModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        Path src = base.resolve("src");
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
    88
        tb.writeJavaFiles(src, "package test; import undefPackage.Any; public class Test {}");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    92
        List<String> log = new JavacTask(tb)
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
    93
                .options("--add-exports", "undefModule/undefPackage=ALL-UNNAMED",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
    94
                         "-XDrawDiagnostics")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    97
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    99
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   101
        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
   102
                                              "Test.java:1:34: compiler.err.doesnt.exist: undefPackage",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   103
                                              "1 error", "1 warning");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   110
    public void testModuleSymbolOutterMostClass(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
            Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   114
            Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   116
            tb.writeJavaFiles(m1, "module m1x { }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc));
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   119
            com.sun.source.util.JavacTask task =
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   120
                (com.sun.source.util.JavacTask) compiler.getTask(null, fm, null, null, null, files);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            task.analyze();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   124
            ModuleSymbol msym = (ModuleSymbol) task.getElements().getModuleElement("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            msym.outermostClass();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   131
    public void testParseEnterAnalyze(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   135
            Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   137
            tb.writeJavaFiles(m1, "module m1x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                                  "package p;",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                                  "package p; class T { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
            Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            List<String> options = Arrays.asList("-d", classes.toString(), "-Xpkginfo:always");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
            JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, fm, null, options, null, files);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            Iterable<? extends CompilationUnitTree> parsed = task.parse();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
            Iterable<? extends Element> entered = task.enter(parsed);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            Iterable<? extends Element> analyzed = task.analyze(entered);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
            Iterable<? extends JavaFileObject> generatedFiles = task.generate(analyzed);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
            Set<String> generated = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
            for (JavaFileObject jfo : generatedFiles) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                generated.add(jfo.getName());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            Set<String> expected = new HashSet<>(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                    Arrays.asList(Paths.get("testParseEnterAnalyze", "classes", "p", "package-info.class").toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                                  Paths.get("testParseEnterAnalyze", "classes", "module-info.class").toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                                  Paths.get("testParseEnterAnalyze", "classes", "p", "T.class").toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
            );
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
            if (!Objects.equals(expected, generated))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                throw new AssertionError("Incorrect generated files: " + generated);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   169
    public void testModuleImplicitModuleBoundaries(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   171
        Path src_m1 = src.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        tb.writeJavaFiles(src_m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   173
                          "module m1x { exports api1; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                          "package api1; public class Api1 { public void call() { } }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   175
        Path src_m2 = src.resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        tb.writeJavaFiles(src_m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   177
                          "module m2x { requires m1x; exports api2; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                          "package api2; public class Api2 { public static api1.Api1 get() { return null; } }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   179
        Path src_m3 = src.resolve("m3x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        tb.writeJavaFiles(src_m3,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   181
                          "module m3x { requires m2x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                          "package test; public class Test { { api2.Api2.get().call(); api2.Api2.get().toString(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   186
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   188
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   191
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   193
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42822
diff changeset
   195
        if (!log.contains("Test.java:1:52: compiler.err.not.def.access.class.intf.cant.access.reason: call(), api1.Api1, api1, (compiler.misc.not.def.access.does.not.read: m3x, api1, m1x)") ||
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
            !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
   197
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   201
    public void testAssignClassToAutomaticModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        //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
   203
        //duplicated when being accessed through a classfile.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        Path automaticSrc = base.resolve("automaticSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        tb.writeJavaFiles(automaticSrc, "package api1; public class Api1 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        Path automaticClasses = base.resolve("automaticClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        tb.createDirectories(automaticClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   209
        String automaticLog = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                                .outdir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                                .files(findJavaFiles(automaticSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
                                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   214
                                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        if (!automaticLog.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
            throw new Exception("expected output not found: " + automaticLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   223
        Path automaticJar = modulePath.resolve("a-1.0.jar");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   225
        new JarTask(tb, automaticJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
          .baseDir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
          .files("api1/Api1.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   231
        Path src_m2 = src.resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        tb.writeJavaFiles(src_m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   233
                          "module m2x { requires a; exports api2; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                          "package api2; public class Api2 { public static api1.Api1 get() { return null; } }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   235
        Path src_m3 = src.resolve("m3x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        tb.writeJavaFiles(src_m3,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   237
                          "module m3x { requires a; requires m2x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
                          "package test; public class Test { { api2.Api2.get(); api1.Api1 a1; } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   242
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   243
                .options("--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   244
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                .files(findJavaFiles(src_m2))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   250
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   251
                .options("--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   252
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
                .files(findJavaFiles(src_m3))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   260
    public void testEmptyImplicitModuleInfo(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   262
        Path src_m1 = src.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        Files.createDirectories(src_m1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        try (Writer w = Files.newBufferedWriter(src_m1.resolve("module-info.java"))) {}
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                          "package test; public class Test {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   270
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   271
                .options("--source-path", src_m1.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                         "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                .files(findJavaFiles(src_m1.resolve("test")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   275
                .run(Task.Expect.FAIL)
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   276
                .writeAll()
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   277
                .getOutputLines(OutputKind.DIRECT);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   278
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   279
        List<String> expected = Arrays.asList(
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   280
                "- compiler.err.cant.access: module-info, (compiler.misc.bad.source.file.header: module-info.java, (compiler.misc.file.does.not.contain.module))",
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   281
                "1 error");
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   282
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   283
        if (!expected.equals(log)) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   284
            throw new AssertionError("Unexpected output: " + log);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   285
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        tb.writeJavaFiles(src_m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   288
                          "module m1x {}");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   290
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   291
                .options("--source-path", src_m1.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
                .files(findJavaFiles(src_m1.resolve("test")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   299
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   300
    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
   301
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   302
        Path src_m1 = src.resolve("m1x");
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   303
        tb.writeJavaFiles(src_m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   304
                          "module m1x { exports test.m1x; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   305
                          "package test.m1x;\n" +
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   306
                          "public class Test {}\n");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   307
        Path src_m2 = src.resolve("m2x");
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   308
        tb.writeJavaFiles(src_m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   309
                          "module m2x { requires m1x; }",
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   310
                          "package test;\n" +
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   311
                          "public class m1x {}\n");
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   312
        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
   313
        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
   314
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   315
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   316
                .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
   317
                         "-XDrawDiagnostics")
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   318
                .outdir(classes)
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   319
                .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
   320
                .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
   321
                .writeAll()
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   322
                .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
   323
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   324
        List<String> expected = Arrays.asList(
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   325
            "m1x.java:2:8: compiler.err.clash.with.pkg.of.same.name: kindname.class, test.m1x",
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   326
            "1 error"
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   327
        );
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   328
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   329
        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
   330
            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
   331
        }
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   332
    }
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   333
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   334
    @Test
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   335
    public void testImplicitJavaBase(Path base) throws Exception {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   336
        Path src = base.resolve("src");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   337
        Path src_java_base = src.resolve("java.base");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   338
        Files.createDirectories(src_java_base);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   339
        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
   340
        tb.writeJavaFiles(src_java_base,
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   341
                          "package java.lang; public class Object {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   342
        Path classes = base.resolve("classes");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   343
        tb.createDirectories(classes);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   344
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   345
        //module-info from source:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   346
        new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   347
            .options("-sourcepath", src_java_base.toString())
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   348
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   349
            .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
   350
            .run()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   351
            .writeAll();
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   352
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   353
        //module-info from class:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   354
        if (!Files.exists(classes.resolve("module-info.class"))) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   355
            throw new AssertionError("module-info.class not created!");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   356
        }
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
        new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   359
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   360
            .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
   361
            .run()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   362
            .writeAll();
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   363
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   364
        //broken module-info.class:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   365
        Files.newOutputStream(classes.resolve("module-info.class")).close();
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
        List<String> log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   368
            .options("-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
        List<String> expected = Arrays.asList(
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   376
                "- 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
   377
                "1 error");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   378
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   379
        if (!expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   380
            throw new AssertionError("Unexpected output: " + log);
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
        //broken module-info.java:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   384
        Files.delete(classes.resolve("module-info.class"));
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   385
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   386
        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
   387
            out.write("class Broken {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   388
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   389
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   390
        log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   391
            .options("-sourcepath", src_java_base.toString(),
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   392
                                "-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   393
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   394
            .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
   395
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   396
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   397
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   398
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   399
        expected = Arrays.asList("X");
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
        if (expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   402
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   403
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   404
    }
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
    @Test
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   407
    public void testModuleInfoNameMismatchSource(Path base) throws Exception {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   408
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   409
        Path m1 = src.resolve("m1x");
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   410
        Files.createDirectories(m1);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   411
        tb.writeJavaFiles(m1, "module other { }",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   412
                              "package test; public class Test {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   413
        Path classes = base.resolve("classes");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   414
        tb.createDirectories(classes);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   415
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   416
        List<String> log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   417
            .options("--module-source-path", src.toString(),
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   418
                     "-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   419
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   420
            .files(findJavaFiles(m1.resolve("test").resolve("Test.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   421
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   422
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   423
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   424
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   425
        List<String> expected = Arrays.asList(
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   426
                "module-info.java:1:1: compiler.err.module.name.mismatch: other, m1x",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   427
                "- compiler.err.cant.access: m1x.module-info, (compiler.misc.cant.resolve.modules)",
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   428
                "2 errors");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   429
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   430
        if (!expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   431
            throw new AssertionError("Unexpected output: " + log);
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
    }
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
    @Test
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   436
    public void testModuleInfoNameMismatchClass(Path base) throws Exception {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   437
        Path src = base.resolve("src");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   438
        Files.createDirectories(src);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   439
        tb.writeJavaFiles(src, "module other { }",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   440
                               "package test; public class Test {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   441
        Path classes = base.resolve("classes");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   442
        Path m1Classes = classes.resolve("m1x");
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   443
        tb.createDirectories(m1Classes);
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
        new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   446
            .outdir(m1Classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   447
            .files(findJavaFiles(src))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   448
            .run()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   449
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   450
            .getOutputLines(OutputKind.DIRECT);
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
        Path src2 = base.resolve("src2");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   453
        Files.createDirectories(src2);
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   454
        tb.writeJavaFiles(src2, "module use { requires m1x; }");
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   455
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   456
        Path classes2 = base.resolve("classes2");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   457
        tb.createDirectories(classes2);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   458
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   459
        List<String> log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   460
            .options("--module-path", classes.toString(),
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   461
                     "-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   462
            .outdir(classes2)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   463
            .files(findJavaFiles(src2))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   464
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   465
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   466
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   467
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   468
        List<String> expected = Arrays.asList(
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   469
                "- compiler.err.cant.access: m1x.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.name.mismatch: other, m1x))",
45910
c7092e4591b2 8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents: 45687
diff changeset
   470
                "module-info.java:1:1: compiler.err.module.not.found: m1x",
c7092e4591b2 8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents: 45687
diff changeset
   471
                "2 errors");
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   472
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   473
        if (!expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   474
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   475
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   476
    }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   477
41516
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   478
    @Test
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   479
    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
   480
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   481
        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
   482
        Symtab syms = Symtab.instance(task.getContext());
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   483
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   484
        syms.java_base.getDirectives();
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   485
    }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   486
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   487
    @Test
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   488
    public void testPackageInModuleInfo(Path base) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   489
        Path src = base.resolve("src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   490
        Files.createDirectories(src);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   491
        tb.writeJavaFiles(src, "package p; module foo { }");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   492
        Path classes = base.resolve("classes");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   493
        tb.createDirectories(classes);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   494
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   495
        List<String> log = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   496
            .options("-XDrawDiagnostics", "-XDshould-stop.ifError=FLOW")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   497
            .outdir(classes)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   498
            .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   499
            .run(Expect.FAIL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   500
            .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   501
            .getOutputLines(OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   502
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   503
        List<String> expected = Arrays.asList(
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   504
                "module-info.java:1:1: compiler.err.no.pkg.in.module-info.java",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   505
                "1 error");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   506
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   507
        if (!expected.equals(log)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   508
            throw new AssertionError("Unexpected output: " + log);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   509
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   510
    }
43269
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   511
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   512
    @Test
43272
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   513
    public void testInvisibleClassVisiblePackageClash(Path base) throws Exception {
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   514
        Path src = base.resolve("src");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   515
        Path src_m1 = src.resolve("m1x");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   516
        tb.writeJavaFiles(src_m1,
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   517
                          "module m1x { }",
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   518
                          "package m1x;\n" +
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   519
                          "import m1x.a.*; public class Test { A a; }\n",
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   520
                          "package m1x.a;\n" +
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   521
                          "public class A { }\n");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   522
        Path src_m2 = src.resolve("m2x");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   523
        tb.writeJavaFiles(src_m2,
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   524
                          "module m2x { }",
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   525
                          "package m1x;\n" +
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   526
                          "public class a { public static class A { } }\n");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   527
        Path classes = base.resolve("classes");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   528
        tb.createDirectories(classes);
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   529
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   530
        new JavacTask(tb)
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   531
            .options("--module-source-path", src.toString(),
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   532
                     "-XDrawDiagnostics")
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   533
            .outdir(classes)
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   534
            .files(findJavaFiles(src))
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   535
            .run()
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   536
            .writeAll();
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   537
    }
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   538
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   539
    @Test
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   540
    public void testStripUnknownRequired(Path base) throws Exception {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   541
        Path src = base.resolve("src");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   542
        Path src_m1 = src.resolve("m1x");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   543
        tb.writeJavaFiles(src_m1,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   544
                          "module m1x { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   545
        Path src_m2 = src.resolve("m2x");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   546
        tb.writeJavaFiles(src_m2,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   547
                          "module m2x { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   548
        Path src_m3 = src.resolve("m3x");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   549
        tb.writeJavaFiles(src_m3,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   550
                          "module m3x { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   551
        Path src_m4 = src.resolve("m4x");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   552
        tb.writeJavaFiles(src_m4,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   553
                          "module m4x { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   554
        Path src_test = src.resolve("test");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   555
        tb.writeJavaFiles(src_test,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   556
                          "module test { requires m1x; requires m2x; requires java.base; requires m3x; requires m4x; }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   557
        Path src_compile = src.resolve("compile");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   558
        tb.writeJavaFiles(src_compile,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   559
                          "module compile { exports p to test; }",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   560
                          "package p; public class Test { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   561
        Path classes = base.resolve("classes");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   562
        tb.createDirectories(classes);
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   563
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   564
        List<String> log = new JavacTask(tb)
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   565
                .options("-processor", ListRequires.class.getName(),
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   566
                         "--module-source-path", src.toString(),
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   567
                         "--limit-modules", "compile",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   568
                         "-XDaccessInternalAPI=true")
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   569
                .outdir(classes)
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   570
                .files(findJavaFiles(src_compile))
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   571
                .run(Expect.FAIL)
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   572
                .writeAll()
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   573
                .getOutputLines(Task.OutputKind.STDOUT);
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   574
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   575
        List<String> expected = Arrays.asList(
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   576
                "from directives:",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   577
                "java.base",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   578
                "from requires:",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   579
                "java.base"
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   580
        );
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   581
        if (!Objects.equals(log, expected))
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   582
            throw new AssertionError("Unexpected output: " + log);
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   583
    }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   584
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   585
    @SupportedAnnotationTypes("*")
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   586
    @SupportedOptions("expectedEnclosedElements")
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   587
    public static final class ListRequires extends AbstractProcessor {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   588
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   589
        private int round;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   590
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   591
        @Override
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   592
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   593
            if (round++ == 0) {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   594
                ModuleElement compileE = processingEnv.getElementUtils().getModuleElement("compile");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   595
                ModuleElement testE = ElementFilter.exportsIn(compileE.getDirectives()).get(0).getTargetModules().get(0);
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   596
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   597
                System.out.println("from directives:");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   598
                for (RequiresDirective rd : ElementFilter.requiresIn(testE.getDirectives())) {
45687
07463ccee73b 8163989: Clarify ModuleElement spec
darcy
parents: 44451
diff changeset
   599
                    System.out.println(rd.getDependency().getQualifiedName());
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   600
                }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   601
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   602
                System.out.println("from requires:");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   603
                for (RequiresDirective rd : ((ModuleSymbol) testE).requires) {
45687
07463ccee73b 8163989: Clarify ModuleElement spec
darcy
parents: 44451
diff changeset
   604
                    System.out.println(rd.getDependency().getQualifiedName());
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   605
                }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   606
            }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   607
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   608
            return false;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   609
        }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   610
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   611
        @Override
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   612
        public SourceVersion getSupportedSourceVersion() {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   613
            return SourceVersion.latest();
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   614
        }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   615
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   616
    }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   617
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   618
    @Test
43269
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   619
    public void testOnDemandCompletionModuleInfoJava(Path base) throws Exception {
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   620
        Path src = base.resolve("src");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   621
        Path src_m1 = src.resolve("m1x");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   622
        tb.writeJavaFiles(src_m1,
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   623
                          "@Deprecated module m1x { }");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   624
        Path src_m2 = src.resolve("m2x");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   625
        tb.writeJavaFiles(src_m2,
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   626
                          "module m2x { requires m1x; }");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   627
        Path src_m3 = src.resolve("m3x");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   628
        tb.writeJavaFiles(src_m3,
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   629
                          "module m3x { requires m2x; requires m1x; }");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   630
        Path classes = base.resolve("classes");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   631
        tb.createDirectories(classes);
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   632
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   633
        List<String> log;
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   634
        List<String> expected;
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   635
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   636
        log = new JavacTask(tb)
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   637
                .options("--module-source-path", src.toString())
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   638
                .outdir(classes)
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   639
                .files(findJavaFiles(src_m1))
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   640
                .run()
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   641
                .writeAll()
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   642
                .getOutputLines(Task.OutputKind.DIRECT);
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   643
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   644
        expected = Arrays.asList("");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   645
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   646
        if (!expected.equals(log)) {
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   647
            throw new IllegalStateException(log.toString());
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   648
        }
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   649
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   650
        log = new JavacTask(tb)
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   651
                .options("--module-source-path", src.toString(),
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   652
                         "-XDrawDiagnostics",
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   653
                         "-Xlint:deprecation")
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   654
                .outdir(classes)
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   655
                .files(findJavaFiles(src_m3))
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   656
                .run()
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   657
                .writeAll()
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   658
                .getOutputLines(Task.OutputKind.DIRECT);
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   659
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   660
        expected = Arrays.asList(
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   661
                "module-info.java:1:23: compiler.warn.has.been.deprecated.module: m1x",
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   662
                "module-info.java:1:37: compiler.warn.has.been.deprecated.module: m1x",
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   663
                "2 warnings"
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   664
        );
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   665
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   666
        if (!expected.equals(log)) {
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   667
            throw new IllegalStateException(log.toString());
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   668
        }
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   669
    }
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   670
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   671
    @Test
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   672
    public void testUnnamedPackage(Path base) throws Exception {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   673
        List<String> out;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   674
        List<String> expected;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   675
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   676
        //-source 8:
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   677
        Path src8 = base.resolve("src8");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   678
        Files.createDirectories(src8);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   679
        tb.writeJavaFiles(src8,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   680
                          "package test; public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   681
        Path classes = base.resolve("classes");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   682
        tb.createDirectories(classes);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   683
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   684
        out = new JavacTask(tb)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   685
                .options("--source-path", src8.toString(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   686
                         "-processor", UnnamedPackageProcessor.class.getName(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   687
                         "-source", "8")
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   688
                .outdir(classes)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   689
                .files(findJavaFiles(src8))
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   690
                .run()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   691
                .writeAll()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   692
                .getOutputLines(OutputKind.STDOUT);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   693
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   694
        expected = Arrays.asList("noModule");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   695
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   696
        if (!expected.equals(out)) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   697
            throw new AssertionError("Unexpected output: " + out);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   698
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   699
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   700
        //-source 9, unnamed:
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   701
        Path srcUnnamed = base.resolve("srcUnnamed");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   702
        Files.createDirectories(srcUnnamed);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   703
        tb.writeJavaFiles(srcUnnamed,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   704
                          "public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   705
        Path classesUnnamed = base.resolve("classesUnnamed");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   706
        tb.createDirectories(classesUnnamed);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   707
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   708
        out = new JavacTask(tb)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   709
                .options("--source-path", srcUnnamed.toString(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   710
                         "-processor", UnnamedPackageProcessor.class.getName())
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   711
                .outdir(classesUnnamed)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   712
                .files(findJavaFiles(srcUnnamed))
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   713
                .run()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   714
                .writeAll()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   715
                .getOutputLines(OutputKind.STDOUT);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   716
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   717
        expected = Arrays.asList("unnamedModule");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   718
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   719
        if (!expected.equals(out)) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   720
            throw new AssertionError("Unexpected output: " + out);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   721
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   722
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   723
        //-source 9, named:
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   724
        Path srcNamed = base.resolve("srcNamed");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   725
        Files.createDirectories(srcNamed);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   726
        tb.writeJavaFiles(srcNamed,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   727
                          "module m {}",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   728
                          "public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   729
        Path classesNamed = base.resolve("classesNamed");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   730
        tb.createDirectories(classesNamed);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   731
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   732
        out = new JavacTask(tb)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   733
                .options("--source-path", srcNamed.toString(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   734
                         "-classpath", "",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   735
                         "-processorpath", System.getProperty("test.class.path"),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   736
                         "-processor", UnnamedPackageProcessor.class.getName())
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   737
                .outdir(classesNamed)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   738
                .files(findJavaFiles(srcNamed))
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   739
                .run()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   740
                .writeAll()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   741
                .getOutputLines(OutputKind.STDOUT);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   742
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   743
        expected = Arrays.asList("m");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   744
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   745
        if (!expected.equals(out)) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   746
            throw new AssertionError("Unexpected output: " + out);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   747
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   748
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   749
        //-source 9, conflict:
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   750
        Path srcNamed2 = base.resolve("srcNamed2");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   751
        Path srcNamed2m1 = srcNamed2.resolve("m1x");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   752
        Files.createDirectories(srcNamed2m1);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   753
        tb.writeJavaFiles(srcNamed2m1,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   754
                          "module m1x {}",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   755
                          "public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   756
        Path srcNamed2m2 = srcNamed2.resolve("m2x");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   757
        Files.createDirectories(srcNamed2m2);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   758
        tb.writeJavaFiles(srcNamed2m2,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   759
                          "module m2x {}",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   760
                          "public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   761
        Path classesNamed2 = base.resolve("classesNamed2");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   762
        tb.createDirectories(classesNamed2);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   763
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   764
        out = new JavacTask(tb)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   765
                .options("--module-source-path", srcNamed2.toString(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   766
                         "-classpath", "",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   767
                         "-processorpath", System.getProperty("test.class.path"),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   768
                         "-processor", UnnamedPackageProcessor.class.getName(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   769
                         "-XDshould-stop.ifError=FLOW")
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   770
                .outdir(classesNamed2)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   771
                .files(findJavaFiles(srcNamed2))
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   772
                .run(Expect.FAIL)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   773
                .writeAll()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   774
                .getOutputLines(OutputKind.STDOUT);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   775
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   776
        expected = Arrays.asList("null",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   777
                                 "m1x: true",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   778
                                 "m2x: true");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   779
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   780
        if (!expected.equals(out)) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   781
            throw new AssertionError("Unexpected output: " + out);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   782
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   783
    }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   784
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   785
    @SupportedAnnotationTypes("*")
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   786
    public static final class UnnamedPackageProcessor extends AbstractProcessor {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   787
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   788
        int round = 0;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   789
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   790
        @Override
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   791
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   792
            if (round++ != 0)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   793
                return false;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   794
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   795
            Elements elements = processingEnv.getElementUtils();
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   796
            PackageElement pe = elements.getPackageElement("");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   797
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   798
            if (pe == null) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   799
                System.out.println("null");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   800
            } else {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   801
                ModuleElement mod = (ModuleElement) pe.getEnclosingElement();
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   802
                if (mod == null) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   803
                    System.out.println("noModule");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   804
                } else if (mod.isUnnamed()) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   805
                    System.out.println("unnamedModule");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   806
                } else {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   807
                    System.out.println(mod);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   808
                }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   809
            }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   810
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   811
            ModuleElement m1x = elements.getModuleElement("m1x");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   812
            ModuleElement m2x = elements.getModuleElement("m2x");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   813
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   814
            if (m1x != null && m2x != null) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   815
                System.out.println("m1x: " + (elements.getPackageElement(m1x, "") != null));
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   816
                System.out.println("m2x: " + (elements.getPackageElement(m2x, "") != null));
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   817
            }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   818
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   819
            return false;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   820
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   821
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   822
    }
44290
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   823
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   824
    @Test
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   825
    public void testEmptyInExportedPackage(Path base) throws Exception {
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   826
        Path src = base.resolve("src");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   827
        Path m = src.resolve("m");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   828
        tb.writeJavaFiles(m,
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   829
                          "module m { exports api; }");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   830
        Path apiFile = m.resolve("api").resolve("Api.java");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   831
        Files.createDirectories(apiFile.getParent());
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   832
        try (BufferedWriter w = Files.newBufferedWriter(apiFile)) {
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   833
            w.write("//no package decl");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   834
        }
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   835
        Path classes = base.resolve("classes");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   836
        tb.createDirectories(classes);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   837
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   838
        List<String> log;
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   839
        List<String> expected =
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   840
                Arrays.asList("module-info.java:1:20: compiler.err.package.empty.or.not.found: api",
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   841
                              "1 error");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   842
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   843
        System.err.println("file explicitly specified:");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   844
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   845
        log = new JavacTask(tb)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   846
            .options("-XDrawDiagnostics",
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   847
                     "--module-source-path", src.toString())
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   848
            .outdir(classes)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   849
            .files(findJavaFiles(src))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   850
            .run(Task.Expect.FAIL)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   851
            .writeAll()
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   852
            .getOutputLines(Task.OutputKind.DIRECT);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   853
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   854
        if (!expected.equals(log))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   855
            throw new Exception("expected output not found: " + log);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   856
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   857
        System.err.println("file not specified:");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   858
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   859
        tb.cleanDirectory(classes);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   860
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   861
        log = new JavacTask(tb)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   862
            .options("-XDrawDiagnostics",
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   863
                     "--module-source-path", src.toString())
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   864
            .outdir(classes)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   865
            .files(findJavaFiles(m.resolve("module-info.java")))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   866
            .run(Task.Expect.FAIL)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   867
            .writeAll()
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   868
            .getOutputLines(Task.OutputKind.DIRECT);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   869
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   870
        if (!expected.equals(log))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   871
            throw new Exception("expected output not found: " + log);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   872
    }
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   873
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   874
    @Test
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   875
    public void testJustPackageInExportedPackage(Path base) throws Exception {
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   876
        Path src = base.resolve("src");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   877
        Path m = src.resolve("m");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   878
        tb.writeJavaFiles(m,
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   879
                          "module m { exports api; }");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   880
        Path apiFile = m.resolve("api").resolve("Api.java");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   881
        Files.createDirectories(apiFile.getParent());
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   882
        try (BufferedWriter w = Files.newBufferedWriter(apiFile)) {
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   883
            w.write("package api;");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   884
        }
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   885
        Path classes = base.resolve("classes");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   886
        tb.createDirectories(classes);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   887
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   888
        System.err.println("file explicitly specified:");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   889
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   890
        new JavacTask(tb)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   891
            .options("-XDrawDiagnostics",
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   892
                     "--module-source-path", src.toString())
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   893
            .outdir(classes)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   894
            .files(findJavaFiles(src))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   895
            .run()
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   896
            .writeAll();
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   897
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   898
        System.err.println("file not specified:");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   899
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   900
        tb.cleanDirectory(classes);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   901
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   902
        new JavacTask(tb)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   903
            .options("-XDrawDiagnostics",
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   904
                     "--module-source-path", src.toString())
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   905
            .outdir(classes)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   906
            .files(findJavaFiles(m.resolve("module-info.java")))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   907
            .run()
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   908
            .writeAll();
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   909
    }
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   910
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   911
    @Test
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   912
    public void testWrongPackageInExportedPackage(Path base) throws Exception {
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   913
        Path src = base.resolve("src");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   914
        Path m = src.resolve("m");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   915
        tb.writeJavaFiles(m,
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   916
                          "module m { exports api; }");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   917
        Path apiFile = m.resolve("api").resolve("Api.java");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   918
        Files.createDirectories(apiFile.getParent());
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   919
        try (BufferedWriter w = Files.newBufferedWriter(apiFile)) {
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   920
            w.write("package impl; public class Api { }");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   921
        }
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   922
        Path classes = base.resolve("classes");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   923
        tb.createDirectories(classes);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   924
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   925
        List<String> log;
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   926
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   927
        List<String> expected =
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   928
                Arrays.asList("module-info.java:1:20: compiler.err.package.empty.or.not.found: api",
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   929
                              "1 error");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   930
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   931
        System.err.println("file explicitly specified:");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   932
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   933
        log = new JavacTask(tb)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   934
                .options("-XDrawDiagnostics",
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   935
                         "--module-source-path", src.toString())
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   936
                .outdir(classes)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   937
                .files(findJavaFiles(src))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   938
                .run(Task.Expect.FAIL)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   939
                .writeAll()
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   940
                .getOutputLines(Task.OutputKind.DIRECT);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   941
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   942
        if (!expected.equals(log))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   943
            throw new Exception("expected output not found: " + log);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   944
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   945
        System.err.println("file not specified:");
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   946
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   947
        tb.cleanDirectory(classes);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   948
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   949
        log = new JavacTask(tb)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   950
                .options("-XDrawDiagnostics",
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   951
                         "--module-source-path", src.toString())
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   952
                .outdir(classes)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   953
                .files(findJavaFiles(m.resolve("module-info.java")))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   954
                .run(Task.Expect.FAIL)
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   955
                .writeAll()
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   956
                .getOutputLines(Task.OutputKind.DIRECT);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   957
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   958
        if (!expected.equals(log))
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   959
            throw new Exception("expected output not found: " + log);
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   960
    }
202973b2d1ae 8176045: No compile error when a package is not declared
jlahoda
parents: 44289
diff changeset
   961
44451
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   962
    @Test
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   963
    public void testDependOnUnnamedAccessibility(Path base) throws Exception {
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   964
        Path unnamedSrc = base.resolve("unnamed-src");
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   965
        tb.writeJavaFiles(unnamedSrc,
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   966
                          "package p1; public class First { public static p2.Second get() { return null; } }",
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   967
                          "package p2; public class Second { public void test() { } }");
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   968
        Path unnamedClasses = base.resolve("unnamed-classes");
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   969
        tb.createDirectories(unnamedClasses);
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   970
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   971
        System.err.println("compiling unnamed sources:");
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   972
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   973
        new JavacTask(tb)
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   974
                .outdir(unnamedClasses)
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   975
                .files(findJavaFiles(unnamedSrc))
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   976
                .run()
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   977
                .writeAll();
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   978
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   979
        //test sources:
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   980
        Path src = base.resolve("src");
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   981
        Path m = src.resolve("m");
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   982
        tb.writeJavaFiles(m,
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   983
                          "module m { }",
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   984
                          "package p; public class Test { { p1.First.get().test(); } }");
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   985
        Path classes = base.resolve("classes");
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   986
        tb.createDirectories(classes);
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   987
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   988
        System.err.println("compiling test module:");
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   989
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   990
        new JavacTask(tb)
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   991
            .options("-classpath", unnamedClasses.toString(),
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   992
                     "--add-reads", "m=ALL-UNNAMED")
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   993
            .outdir(classes)
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   994
            .files(findJavaFiles(src))
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   995
            .run()
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   996
            .writeAll();
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   997
    }
1619c00af9df 8177311: Denied access when named module accesses unreferences package from the unnamed module
jlahoda
parents: 44290
diff changeset
   998
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   999
}