langtools/test/tools/javac/modules/XModuleTest.java
author jjg
Thu, 03 Nov 2016 13:59:15 -0700
changeset 41938 8e66bf10fcec
parent 41932 b23b4712933b
child 43138 680d378b9d64
permissions -rw-r--r--
8167975: align javac --add-* modules options with launcher Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary tests for multi-module mode compilation
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *      jdk.compiler/com.sun.tools.javac.api
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.code
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.compiler/com.sun.tools.javac.main
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    32
 *      jdk.compiler/com.sun.tools.javac.processing
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 * @run main XModuleTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.List;
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    40
import java.util.Set;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    42
import javax.annotation.processing.AbstractProcessor;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    43
import javax.annotation.processing.RoundEnvironment;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    44
import javax.annotation.processing.SupportedAnnotationTypes;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    45
import javax.lang.model.SourceVersion;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    46
import javax.lang.model.element.ModuleElement;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    47
import javax.lang.model.element.TypeElement;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    48
import javax.lang.model.util.Elements;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    49
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    50
import com.sun.tools.javac.code.Symtab;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    51
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    52
import toolbox.JavacTask;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    53
import toolbox.ModuleBuilder;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    54
import toolbox.Task;
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
    55
import toolbox.Task.Expect;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    56
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
public class XModuleTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        new XModuleTest().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    64
    public void testCorrectXModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    71
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                .options("-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    77
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    84
    public void testSourcePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, Other { }", "package javax.lang.model.element; interface Other { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    91
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                .options("-Xmodule:java.compiler", "-sourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                .files(src.resolve("javax/lang/model/element/Extra.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    97
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   104
    public void testClassPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        Path cpSrc = base.resolve("cpSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        tb.writeJavaFiles(cpSrc, "package p; public interface Other { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        Path cpClasses = base.resolve("cpClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        tb.createDirectories(cpClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   110
        String cpLog = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                .outdir(cpClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                .files(findJavaFiles(cpSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   115
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        if (!cpLog.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            throw new Exception("expected output not found: " + cpLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, p.Other { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   126
        List<String> log = new JavacTask(tb)
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   127
                .options("-Xmodule:java.compiler",
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   128
                         "--class-path", cpClasses.toString(),
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   129
                         "-XDrawDiagnostics")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                .files(src.resolve("javax/lang/model/element/Extra.java"))
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   132
                .run(Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                .writeAll()
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   134
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   136
        List<String> expectedOut = Arrays.asList(
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   137
                "Extra.java:1:76: compiler.err.doesnt.exist: p",
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   138
                "1 error"
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   139
        );
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   140
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   141
        if (!expectedOut.equals(log))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   146
    public void testNoModuleInfoOnSourcePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                          "module java.compiler {}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                          "package javax.lang.model.element; public interface Extra { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   155
        List<String> log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   159
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   161
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.sourcepath",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   171
    public void testNoModuleInfoInClassOutput(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        Path srcMod = base.resolve("src-mod");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        tb.writeJavaFiles(srcMod,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                          "module mod {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   179
        String logMod = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                .options()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                .files(findJavaFiles(srcMod))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   185
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        if (!logMod.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            throw new Exception("unexpected output found: " + logMod);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                          "package javax.lang.model.element; public interface Extra { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   195
        List<String> log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   199
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   201
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.classpath",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   211
    public void testModuleSourcePathXModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   218
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   219
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   222
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   224
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   226
        List<String> expected = Arrays.asList("- compiler.err.xmodule.no.module.sourcepath");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   233
    public void testXModuleTooMany(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   240
        List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   244
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   246
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        List<String> expected = Arrays.asList("javac: option -Xmodule: can only be specified once",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                                              "Usage: javac <options> <source files>",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   250
                                              "use --help for a list of possible options");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   257
    public void testWithModulePath(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   258
        Path modSrc = base.resolve("modSrc");
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   259
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   260
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                .classes("package pkg1; public interface E { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   262
                .build(modSrc, modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        tb.writeJavaFiles(src, "package p; interface A extends pkg1.E { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   267
        new JavacTask(tb, Task.Mode.CMDLINE)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   268
                .options("--module-path", modules.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                        "-Xmodule:m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        //checks module bounds still exist
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   275
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                .classes("package pkg2; public interface D { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   277
                .build(modSrc, modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        Path src2 = base.resolve("src2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
        tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   282
        List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   284
                        "--module-path", modules.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
                        "-Xmodule:m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
                .files(findJavaFiles(src2))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   287
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   289
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
41932
b23b4712933b 8169074: Build is failing after JDK-8166538
jlahoda
parents: 41931
diff changeset
   291
        List<String> expected = Arrays.asList("A.java:1:36: compiler.err.doesnt.exist: pkg2",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
            throw new Exception("expected output not found: " + log);
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
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   299
    public void testWithUpgradeModulePath(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   300
        Path modSrc = base.resolve("modSrc");
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   301
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   302
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
                .classes("package pkg1; public interface E { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   304
                .build(modSrc, modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   306
        Path upgrSrc = base.resolve("upgradeSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
        Path upgrade = base.resolve("upgrade");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   308
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
                .classes("package pkg1; public interface D { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   310
                .build(upgrSrc, upgrade);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
        tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   315
        new JavacTask(tb, Task.Mode.CMDLINE)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   316
                .options("--module-path", modules.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   317
                        "--upgrade-module-path", upgrade.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
                        "-Xmodule:m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
    }
40768
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   323
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   324
    @Test
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   325
    public void testUnnamedIsolation(Path base) throws Exception {
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   326
        //note: avoiding use of java.base, as that gets special handling on some places:
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   327
        Path sourcePath = base.resolve("source-path");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   328
        tb.writeJavaFiles(sourcePath, "package src; public class Src {}");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   329
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   330
        Path classPathSrc = base.resolve("class-path-src");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   331
        tb.writeJavaFiles(classPathSrc, "package cp; public class CP { }");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   332
        Path classPath = base.resolve("classPath");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   333
        tb.createDirectories(classPath);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   334
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   335
        String cpLog = new JavacTask(tb)
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   336
                .outdir(classPath)
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   337
                .files(findJavaFiles(classPathSrc))
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   338
                .run()
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   339
                .writeAll()
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   340
                .getOutput(Task.OutputKind.DIRECT);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   341
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   342
        if (!cpLog.isEmpty())
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   343
            throw new Exception("expected output not found: " + cpLog);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   344
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   345
        Path modulePathSrc = base.resolve("module-path-src");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   346
        tb.writeJavaFiles(modulePathSrc,
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   347
                          "module m {}",
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   348
                          "package m; public class M {}");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   349
        Path modulePath = base.resolve("modulePath");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   350
        tb.createDirectories(modulePath.resolve("m"));
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   351
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   352
        String modLog = new JavacTask(tb)
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   353
                .outdir(modulePath.resolve("m"))
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   354
                .files(findJavaFiles(modulePathSrc))
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   355
                .run()
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   356
                .writeAll()
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   357
                .getOutput(Task.OutputKind.DIRECT);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   358
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   359
        if (!modLog.isEmpty())
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   360
            throw new Exception("expected output not found: " + modLog);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   361
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   362
        Path src = base.resolve("src");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   363
        tb.writeJavaFiles(src, "package m; public class Extra { }");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   364
        Path classes = base.resolve("classes");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   365
        tb.createDirectories(classes);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   366
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   367
        String log = new JavacTask(tb)
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   368
                .options("-Xmodule:m",
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   369
                         "--class-path", classPath.toString(),
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   370
                         "--source-path", sourcePath.toString(),
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   371
                         "--module-path", modulePath.toString(),
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   372
                         "--processor-path", System.getProperty("test.classes"),
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   373
                         "-XDaccessInternalAPI=true",
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   374
                         "-processor", CheckModuleContentProcessing.class.getName())
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   375
                .outdir(classes)
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   376
                .files(findJavaFiles(sourcePath))
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   377
                .run()
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   378
                .writeAll()
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   379
                .getOutput(Task.OutputKind.DIRECT);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   380
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   381
        if (!log.isEmpty())
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   382
            throw new Exception("expected output not found: " + log);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   383
    }
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   384
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   385
    @SupportedAnnotationTypes("*")
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   386
    public static final class CheckModuleContentProcessing extends AbstractProcessor {
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   387
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   388
        @Override
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   389
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   390
            Symtab syms = Symtab.instance(((JavacProcessingEnvironment) processingEnv).getContext());
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   391
            Elements elements = processingEnv.getElementUtils();
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   392
            ModuleElement unnamedModule = syms.unnamedModule;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   393
            ModuleElement mModule = elements.getModuleElement("m");
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   394
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   395
            assertNonNull("mModule found", mModule);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   396
            assertNonNull("src.Src from m", elements.getTypeElement(mModule, "src.Src"));
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   397
            assertNull("cp.CP not from m", elements.getTypeElement(mModule, "cp.CP"));
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   398
            assertNull("src.Src not from unnamed", elements.getTypeElement(unnamedModule, "src.Src"));
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   399
            assertNonNull("cp.CP from unnamed", elements.getTypeElement(unnamedModule, "cp.CP"));
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   400
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   401
            return false;
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   402
        }
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   403
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   404
        @Override
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   405
        public SourceVersion getSupportedSourceVersion() {
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   406
            return SourceVersion.latest();
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   407
        }
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   408
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   409
        private static void assertNonNull(String msg, Object val) {
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   410
            if (val == null) {
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   411
                throw new AssertionError(msg);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   412
            }
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   413
        }
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   414
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   415
        private static void assertNull(String msg, Object val) {
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   416
            if (val != null) {
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   417
                throw new AssertionError(msg);
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   418
            }
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   419
        }
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   420
    }
8b6a878d8773 8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents: 40604
diff changeset
   421
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   422
}