langtools/test/tools/javac/modules/ModuleSourcePathTest.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
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 -modulesourcepath
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 ModuleSourcePathTest
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.io.File;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.io.IOException;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.nio.file.Paths;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.stream.Collectors;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.stream.Stream;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
public class ModuleSourcePathTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    public static final char PATH_SEP = File.pathSeparatorChar;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
        ModuleSourcePathTest t = new ModuleSourcePathTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    void testSourcePathConflict(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        Path sp = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        Path msp = base.resolve("srcmodules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                        "-sourcepath", sp.toString().replace('/', File.separatorChar),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                        "-modulesourcepath", msp.toString().replace('/', File.separatorChar),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
                        "dummyClass")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        if (!log.contains("cannot specify both -sourcepath and -modulesourcepath"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
            throw new Exception("expected diagnostic not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
    void testUnnormalizedPath1(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        tb.writeJavaFiles(src_m1, "module m1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                        "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
                .files(prefixAll(findJavaFiles(src), Paths.get("./")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    void testUnnormalizedPath2(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        tb.writeJavaFiles(src_m1, "module m1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                        "-modulesourcepath", "./" + src)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
    private Path[] prefixAll(Path[] paths, Path prefix) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        return Stream.of(paths)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                .map(prefix::resolve)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                .collect(Collectors.toList())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                .toArray(new Path[paths.length]);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
    void regularBraces(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        generateModules(base, "src1", "src2/inner_dir");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                        "-modulesourcepath", base + "/{src1,src2/inner_dir}")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                .files(base.resolve("src1/m0/pkg0/A.java"), base.resolve("src2/inner_dir/m1/pkg1/A.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        checkFiles(modules.resolve("m0/pkg0/A.class"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                modules.resolve("m1/pkg1/A.class"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                modules.resolve("m0/module-info.class"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                modules.resolve("m1/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
    void mismatchedBraces(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        final List<String> sourcePaths = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                "{",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                "}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                "}{",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                "./}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
                ".././{./",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                "src{}}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                "{{}{}}{}}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                "src/{a,b}/{",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                "src/{a,{,{}}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
                "{.,..{}/src",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
                "*}{",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                "{}*}"
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        );
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        for (String sourcepath : sourcePaths) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
            String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                    .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                            "-modulesourcepath", sourcepath.replace('/', File.separatorChar))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                    .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                    .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                    .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
            if (!log.contains("- compiler.err.illegal.argument.for.option: -modulesourcepath, mismatched braces"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                throw new Exception("expected output for path [" + sourcepath + "] not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
    void deepBraces(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        String[] modulePaths = {"src/src1",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
                "src/src2",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                "src/src3",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                "src/srcB/src1",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                "src/srcB/src2/srcXX",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                "src/srcB/src2/srcXY",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                "src/srcC/src1",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                "src/srcC/src2/srcXX",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                "src/srcC/src2/srcXY"};
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
        generateModules(base, modulePaths);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                        "-modulesourcepath",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                        base + "/{src/{{src1,src2,src3},{srcB,srcC}/{src1,src2/srcX{X,Y}/}},.}"
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                                .replace('/', File.separatorChar))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                .files(findJavaFiles(base.resolve(modulePaths[modulePaths.length - 1])))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        for (int i = 0; i < modulePaths.length; i++) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
            checkFiles(modules.resolve("m" + i + "/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        checkFiles(modules.resolve("m8/pkg8/A.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
    void fileInPath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        tb.writeJavaFiles(src.resolve("kettle$"), "module kettle$ { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        tb.writeFile(base.resolve("dummy.txt"), "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
                        "-modulesourcepath", base + "/{dummy.txt,src}")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                .files(src.resolve("kettle$/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        checkFiles(modules.resolve("kettle$/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        checkFiles(modules.resolve("kettle$/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
    void noAlternative(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        tb.writeJavaFiles(src.resolve("kettle$"), "module kettle$ { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
                        "-modulesourcepath", base + "/{src}")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
                .files(src.resolve("kettle$/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        checkFiles(modules.resolve("kettle$/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
        checkFiles(modules.resolve("kettle$/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
    void noChoice(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        tb.writeJavaFiles(base.resolve("kettle$"), "module kettle$ { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                        "-modulesourcepath", base + "/{}")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                .files(base.resolve("kettle$/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        checkFiles(modules.resolve("kettle$/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
        checkFiles(modules.resolve("kettle$/module-info.class"));
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
    void nestedModules(Path src) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        Path carModule = src.resolve("car");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        tb.writeJavaFiles(carModule, "module car { }", "package light; class Headlight { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        tb.writeJavaFiles(carModule.resolve("engine"), "module engine { }", "package flat; class Piston { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        final Path modules = src.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                        "-modulesourcepath", "{" + src + "," + src + "/car}")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
        checkFiles(modules.resolve("car/light/Headlight.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
        checkFiles(modules.resolve("engine/flat/Piston.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
    void relativePaths(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        tb.writeJavaFiles(src.resolve("kettle"), "module kettle { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
                        "-modulesourcepath", base + "/src/./../src")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
                .files(src.resolve("kettle/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        checkFiles(modules.resolve("kettle/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
        checkFiles(modules.resolve("kettle/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
    void duplicatePaths(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
        tb.writeJavaFiles(src.resolve("m1"), "module m1 { }", "package a; class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
                        "-modulesourcepath", base + "/{src,src,src}")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
                .files(src.resolve("m1/a/A.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
        checkFiles(modules.resolve("m1/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
    void notExistentPaths(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
        tb.writeJavaFiles(base.resolve("m1"), "module m1 { requires m0; }", "package a; class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
                        "-modulesourcepath", base + "/not_exist" + PATH_SEP + base + "/{not_exist,}")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
                .files(base.resolve("m1/a/A.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        if (!log.contains("compiler.err.module.not.found: m0"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
            throw new Exception("expected output for not existent module source path not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
    void notExistentPathShouldBeSkipped(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
        tb.writeJavaFiles(base.resolve("m1"), "module m1 { }", "package a; class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
                        "-modulesourcepath", base + "{/not_exist,/}")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
                .files(base.resolve("m1/a/A.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   345
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
        checkFiles(modules.resolve("m1/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
    void commas(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
        tb.writeJavaFiles(src.resolve("m1"), "module m1 { }", "package a; class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   355
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   356
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
                        "-modulesourcepath", base + "/{,{,,,,src,,,}}")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
                .files(src.resolve("m1/a/A.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   364
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
        checkFiles(modules.resolve("m1/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   369
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
    void asterisk(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   372
        tb.writeJavaFiles(base.resolve("kettle").resolve("classes"), "module kettle { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   378
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   379
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                        "-modulesourcepath", base + "/*/classes/")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   381
                .files(base.resolve("kettle/classes/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
        checkFiles(modules.resolve("kettle/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
        checkFiles(modules.resolve("kettle/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   388
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   389
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   390
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   391
    void asteriskInDifferentSets(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   392
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   393
        final Path module = src.resolve("kettle");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
        tb.writeJavaFiles(module.resolve("classes"), "module kettle { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
        tb.writeJavaFiles(module.resolve("gensrc"), "package model; class Java { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
        tb.writeJavaFiles(module.resolve("special/classes"), "package gas; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   399
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   401
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   403
                        "-modulesourcepath", src + "{/*/gensrc/,/*/classes/}" + PATH_SEP
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
                                + src + "/*/special/classes")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   405
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   407
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   409
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   410
        checkFiles(modules.resolve("kettle/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   411
        checkFiles(modules.resolve("kettle/gas/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
        checkFiles(modules.resolve("kettle/model/Java.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   413
        checkFiles(modules.resolve("kettle/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   415
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
    void asteriskIllegalUse(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   418
        final List<String> sourcePaths = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
                "*",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   420
                "**",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   421
                "***",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   422
                "*.*",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
                ".*",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   424
                "*.",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   425
                "src/*/*/",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   426
                "{*,*}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   427
                "src/module*/"
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   428
        );
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   429
        for (String sourcepath : sourcePaths) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   430
            String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   431
                    .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   432
                            "-modulesourcepath", sourcepath.replace('/', File.separatorChar))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   433
                    .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   434
                    .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   435
                    .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   436
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   437
            if (!log.contains("- compiler.err.illegal.argument.for.option: -modulesourcepath, illegal use of *"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   438
                throw new Exception("expected output for path [" + sourcepath + "] not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   439
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   440
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   441
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   442
    private void generateModules(Path base, String... paths) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   443
        for (int i = 0; i < paths.length; i++) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   444
            String moduleName = "m" + i;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   445
            String dependency = i > 0 ? "requires m" + (i - 1) + ";" : "";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   446
            tb.writeJavaFiles(base.resolve(paths[i]).resolve(moduleName),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   447
                    "module " + moduleName + " { " + dependency + " }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   448
                    "package pkg" + i + "; class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   449
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   450
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   451
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   452
    private void checkFiles(Path... files) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   453
        for (Path file : files) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   454
            if (!Files.exists(file)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   455
                throw new Exception("File not exists: " + file);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   456
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   457
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   458
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   459
}