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