langtools/test/tools/javac/modules/XModuleTest.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000 (2016-03-17)
changeset 36526 3b41f1c69604
child 36778 e04318f39f92
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.main
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.jdeps/com.sun.tools.javap
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @build ToolBox ModuleTestBase
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 * @run main XModuleTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
public class XModuleTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
        new XModuleTest().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
    void testCorrectXModule(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        String log = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
                .options("-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    void testSourcePath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        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
    71
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        String log = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
                .options("-Xmodule:java.compiler", "-sourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                .files(src.resolve("javax/lang/model/element/Extra.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
    void testClassPath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        Path cpSrc = base.resolve("cpSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        tb.writeJavaFiles(cpSrc, "package p; public interface Other { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        Path cpClasses = base.resolve("cpClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        tb.createDirectories(cpClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        String cpLog = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                .outdir(cpClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                .files(findJavaFiles(cpSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        if (!cpLog.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
            throw new Exception("expected output not found: " + cpLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, p.Other { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        String log = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                .options("-Xmodule:java.compiler", "-classpath", cpClasses.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                .files(src.resolve("javax/lang/model/element/Extra.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    void testNoModuleInfoOnSourcePath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                          "module java.compiler {}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                          "package javax.lang.model.element; public interface Extra { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        List<String> log = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                .getOutputLines(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        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
   140
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
    void testNoModuleInfoInClassOutput(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        Path srcMod = base.resolve("src-mod");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        tb.writeJavaFiles(srcMod,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                          "module mod {}");
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        String logMod = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .options()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                .files(findJavaFiles(srcMod))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        if (!logMod.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
            throw new Exception("unexpected output found: " + logMod);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                          "package javax.lang.model.element; public interface Extra { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        List<String> log = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                .getOutputLines(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        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
   180
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
    void testModuleSourcePathXModule(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        List<String> log = tb.new JavacTask()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                .getOutputLines(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        List<String> expected = Arrays.asList("- compiler.err.xmodule.no.module.sourcepath",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
    void testXModuleTooMany(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        List<String> log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                .getOutputLines(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        List<String> expected = Arrays.asList("javac: option -Xmodule: can only be specified once",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
                                              "Usage: javac <options> <source files>",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
                                              "use -help for a list of possible options");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
    void testWithModulePath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        Path module = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
                .classes("package pkg1; public interface E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        tb.writeJavaFiles(src, "package p; interface A extends pkg1.E { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                .options("-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                        "-Xmodule:m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                .files(findJavaFiles(src))
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        //checks module bounds still exist
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
        new ModuleBuilder("m2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .classes("package pkg2; public interface D { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
        Path src2 = base.resolve("src2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        List<String> log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
                        "-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                        "-Xmodule:m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
                .files(findJavaFiles(src2))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                .getOutputLines(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
        List<String> expected = Arrays.asList("A.java:1:36: compiler.err.doesnt.exist: pkg2",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
    void testWithUpgradeModulePath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        Path module = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
                .classes("package pkg1; public interface E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
        Path upgrade = base.resolve("upgrade");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
                .classes("package pkg1; public interface D { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
                .build(upgrade);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
                .options("-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
                        "-upgrademodulepath", upgrade.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
                        "-Xmodule:m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
                .files(findJavaFiles(src))
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
}