langtools/test/tools/javac/modules/ModuleSourcePathTest.java
author jjg
Mon, 17 Apr 2017 14:16:07 -0700
changeset 44690 aec722d1b538
parent 42822 a84956e7ee4d
permissions -rw-r--r--
8178509: MODULE_SOURCE_PATH: Implement missing methods 8178493: StandardJavaFileManager: Clarify/document the use of IllegalStateException Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
40599
be40838eb215 8164887: update tests to remove use of old-style options
jjg
parents: 40308
diff changeset
    26
 * @summary tests for --module-source-path
36526
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;
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
    40
import java.util.ArrayList;
36526
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
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
    46
import javax.tools.JavaCompiler;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
    47
import javax.tools.JavaFileManager.Location;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
    48
import javax.tools.StandardJavaFileManager;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
    49
import javax.tools.StandardLocation;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
    50
import javax.tools.ToolProvider;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
    51
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    52
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    53
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    54
import toolbox.ToolBox;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    55
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
public class ModuleSourcePathTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    public static final char PATH_SEP = File.pathSeparatorChar;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        ModuleSourcePathTest t = new ModuleSourcePathTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    66
    public void testSourcePathConflict(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        Path sp = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        Path msp = base.resolve("srcmodules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    70
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    72
                        "--source-path", sp.toString().replace('/', File.separatorChar),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    73
                        "--module-source-path", msp.toString().replace('/', File.separatorChar),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
                        "dummyClass")
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    75
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    77
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    79
        if (!log.contains("cannot specify both --source-path and --module-source-path"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            throw new Exception("expected diagnostic not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    84
    public void testUnnormalizedPath1(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
    86
        Path src_m1 = src.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
    87
        tb.writeJavaFiles(src_m1, "module m1x { }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    91
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    93
                        "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                .files(prefixAll(findJavaFiles(src), Paths.get("./")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   101
    public void testUnnormalizedPath2(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   103
        Path src_m1 = src.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   104
        tb.writeJavaFiles(src_m1, "module m1x { }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   108
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   110
                        "--module-source-path", "./" + src)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
    private Path[] prefixAll(Path[] paths, Path prefix) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        return Stream.of(paths)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                .map(prefix::resolve)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                .collect(Collectors.toList())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                .toArray(new Path[paths.length]);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   125
    public void regularBraces(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        generateModules(base, "src1", "src2/inner_dir");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   131
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   133
                        "--module-source-path", base + "/{src1,src2/inner_dir}")
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   134
                .files(base.resolve("src1/m0x/pkg0/A.java"), base.resolve("src2/inner_dir/m1x/pkg1/A.java"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   139
        checkFiles(modules.resolve("m0x/pkg0/A.class"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   140
                modules.resolve("m1x/pkg1/A.class"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   141
                modules.resolve("m0x/module-info.class"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   142
                modules.resolve("m1x/module-info.class"));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   146
    public void mismatchedBraces(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        final List<String> sourcePaths = Arrays.asList(
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
                "./}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                ".././{./",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                "src{}}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                "{{}{}}{}}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                "src/{a,b}/{",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                "src/{a,{,{}}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                "{.,..{}/src",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                "*}{",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                "{}*}"
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        );
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        for (String sourcepath : sourcePaths) {
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   162
            String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
                    .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   164
                            "--module-source-path", sourcepath.replace('/', File.separatorChar))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   165
                    .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                    .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   167
                    .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   169
            if (!log.contains("- compiler.err.illegal.argument.for.option: --module-source-path, mismatched braces"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                throw new Exception("expected output for path [" + sourcepath + "] not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   175
    public void deepBraces(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        String[] modulePaths = {"src/src1",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                "src/src2",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                "src/src3",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                "src/srcB/src1",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                "src/srcB/src2/srcXX",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                "src/srcB/src2/srcXY",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                "src/srcC/src1",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                "src/srcC/src2/srcXX",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                "src/srcC/src2/srcXY"};
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        generateModules(base, modulePaths);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   190
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   192
                        "--module-source-path",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                        base + "/{src/{{src1,src2,src3},{srcB,srcC}/{src1,src2/srcX{X,Y}/}},.}"
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                                .replace('/', File.separatorChar))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                .files(findJavaFiles(base.resolve(modulePaths[modulePaths.length - 1])))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        for (int i = 0; i < modulePaths.length; i++) {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   201
            checkFiles(modules.resolve("m" + i + "x/module-info.class"));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        }
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   203
        checkFiles(modules.resolve("m8x/pkg8/A.class"));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   207
    public void fileInPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        tb.writeJavaFiles(src.resolve("kettle$"), "module kettle$ { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        tb.writeFile(base.resolve("dummy.txt"), "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   215
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   217
                        "--module-source-path", base + "/{dummy.txt,src}")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                .files(src.resolve("kettle$/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        checkFiles(modules.resolve("kettle$/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        checkFiles(modules.resolve("kettle$/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   228
    public void noAlternative(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        tb.writeJavaFiles(src.resolve("kettle$"), "module kettle$ { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   235
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   237
                        "--module-source-path", base + "/{src}")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
                .files(src.resolve("kettle$/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        checkFiles(modules.resolve("kettle$/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        checkFiles(modules.resolve("kettle$/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   248
    public void noChoice(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        tb.writeJavaFiles(base.resolve("kettle$"), "module kettle$ { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   254
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   256
                        "--module-source-path", base + "/{}")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                .files(base.resolve("kettle$/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        checkFiles(modules.resolve("kettle$/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        checkFiles(modules.resolve("kettle$/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   267
    public void nestedModules(Path src) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
        Path carModule = src.resolve("car");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        tb.writeJavaFiles(carModule, "module car { }", "package light; class Headlight { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        tb.writeJavaFiles(carModule.resolve("engine"), "module engine { }", "package flat; class Piston { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
        final Path modules = src.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   275
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   277
                        "--module-source-path", "{" + src + "," + src + "/car}")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        checkFiles(modules.resolve("car/light/Headlight.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
        checkFiles(modules.resolve("engine/flat/Piston.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   287
    public void relativePaths(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        tb.writeJavaFiles(src.resolve("kettle"), "module kettle { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   294
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   296
                        "--module-source-path", base + "/src/./../src")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
                .files(src.resolve("kettle/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
        checkFiles(modules.resolve("kettle/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
        checkFiles(modules.resolve("kettle/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   306
    public void duplicatePaths(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   308
        tb.writeJavaFiles(src.resolve("m1x"), "module m1x { }", "package a; class A { }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   313
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   315
                        "--module-source-path", base + "/{src,src,src}")
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   316
                .files(src.resolve("m1x/a/A.java"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   321
        checkFiles(modules.resolve("m1x/module-info.class"));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   325
    public void notExistentPaths(Path base) throws Exception {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   326
        tb.writeJavaFiles(base.resolve("m1x"), "module m1x { requires m0x; }", "package a; class A { }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   331
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   333
                        "--module-source-path", base + "/not_exist" + PATH_SEP + base + "/{not_exist,}")
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   334
                .files(base.resolve("m1x/a/A.java"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
                .outdir(modules)
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   336
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   338
                .getOutput(Task.OutputKind.DIRECT);
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   339
        if (!log.contains("compiler.err.module.not.found: m0x"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
            throw new Exception("expected output for not existent module source path not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   344
    public void notExistentPathShouldBeSkipped(Path base) throws Exception {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   345
        tb.writeJavaFiles(base.resolve("m1x"), "module m1x { }", "package a; class A { }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   350
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   352
                        "--module-source-path", base + "{/not_exist,/}")
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   353
                .files(base.resolve("m1x/a/A.java"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   355
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   356
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   358
        checkFiles(modules.resolve("m1x/module-info.class"));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   362
    public void commas(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   364
        tb.writeJavaFiles(src.resolve("m1x"), "module m1x { }", "package a; class A { }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   369
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   371
                        "--module-source-path", base + "/{,{,,,,src,,,}}")
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   372
                .files(src.resolve("m1x/a/A.java"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   377
        checkFiles(modules.resolve("m1x/module-info.class"));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   378
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   379
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   380
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   381
    public void asterisk(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
        tb.writeJavaFiles(base.resolve("kettle").resolve("classes"), "module kettle { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
                "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   388
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   389
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   390
                        "--module-source-path", base + "/*/classes/")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   391
                .files(base.resolve("kettle/classes/electric/Heater.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   392
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   393
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
        checkFiles(modules.resolve("kettle/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
        checkFiles(modules.resolve("kettle/module-info.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   399
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   401
    public void asteriskInDifferentSets(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   403
        final Path module = src.resolve("kettle");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
        tb.writeJavaFiles(module.resolve("classes"), "module kettle { }", "package electric; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   405
        tb.writeJavaFiles(module.resolve("gensrc"), "package model; class Java { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
        tb.writeJavaFiles(module.resolve("special/classes"), "package gas; class Heater { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   407
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
        final Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   409
        tb.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   410
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   411
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   413
                        "--module-source-path", src + "{/*/gensrc/,/*/classes/}" + PATH_SEP
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
                                + src + "/*/special/classes")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   415
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   418
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   420
        checkFiles(modules.resolve("kettle/electric/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   421
        checkFiles(modules.resolve("kettle/gas/Heater.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   422
        checkFiles(modules.resolve("kettle/model/Java.class"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
        checkFiles(modules.resolve("kettle/module-info.class"));
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
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   427
    public void asteriskIllegalUse(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   428
        final List<String> sourcePaths = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   429
                "*",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   430
                "**",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   431
                "***",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   432
                "*.*",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   433
                ".*",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   434
                "*.",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   435
                "src/*/*/",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   436
                "{*,*}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   437
                "src/module*/"
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   438
        );
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   439
        for (String sourcepath : sourcePaths) {
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   440
            String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   441
                    .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   442
                            "--module-source-path", sourcepath.replace('/', File.separatorChar))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   443
                    .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   444
                    .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   445
                    .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   446
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   447
            if (!log.contains("- compiler.err.illegal.argument.for.option: --module-source-path, illegal use of *"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   448
                throw new Exception("expected output for path [" + sourcepath + "] not found");
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
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   452
    @Test
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   453
    public void setLocation(Path base) throws Exception {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   454
        Path src = base.resolve("src");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   455
        tb.writeJavaFiles(src.resolve("m1x"), "module m1x { }", "package a; class A { }");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   456
        Path modules = base.resolve("modules");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   457
        tb.createDirectories(modules);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   458
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   459
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   460
        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   461
            fm.setLocationFromPaths(StandardLocation.MODULE_SOURCE_PATH, List.of(src));
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   462
            new JavacTask(tb)
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   463
                    .options("-XDrawDiagnostics")
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   464
                    .fileManager(fm)
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   465
                    .outdir(modules)
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   466
                    .files(findJavaFiles(src))
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   467
                    .run()
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   468
                    .writeAll();
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   469
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   470
            checkFiles(modules.resolve("m1x/module-info.class"), modules.resolve("m1x/a/A.class"));
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   471
        }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   472
    }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   473
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   474
    @Test
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   475
    public void getLocation_valid(Path base) throws Exception {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   476
        Path src1 = base.resolve("src1");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   477
        tb.writeJavaFiles(src1.resolve("m1x"), "module m1x { }", "package a; class A { }");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   478
        Path src2 = base.resolve("src2");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   479
        tb.writeJavaFiles(src1.resolve("m2x"), "module m2x { }", "package b; class B { }");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   480
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   481
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   482
        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   483
            fm.setLocationFromPaths(StandardLocation.MODULE_SOURCE_PATH, List.of(src1, src2));
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   484
            checkLocation(fm.getLocationAsPaths(StandardLocation.MODULE_SOURCE_PATH), List.of(src1, src2));
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   485
        }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   486
    }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   487
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   488
    @Test
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   489
    public void getLocation_ISA(Path base) throws Exception {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   490
        Path src1 = base.resolve("src1");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   491
        tb.writeJavaFiles(src1.resolve("m1x"), "module m1x { }", "package a; class A { }");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   492
        Path src2 = base.resolve("src2");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   493
        tb.writeJavaFiles(src2.resolve("m2x").resolve("extra"), "module m2x { }", "package b; class B { }");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   494
        Path modules = base.resolve("modules");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   495
        tb.createDirectories(modules);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   496
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   497
        String FS = File.separator;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   498
        String PS = File.pathSeparator;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   499
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   500
        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   501
            fm.handleOption("--module-source-path",
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   502
                    List.of(src1 + PS + src2 + FS + "*" + FS + "extra").iterator());
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   503
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   504
            try {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   505
                Iterable<? extends Path> paths = fm.getLocationAsPaths(StandardLocation.MODULE_SOURCE_PATH);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   506
                out.println("result: " + asList(paths));
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   507
                throw new Exception("expected IllegalStateException not thrown");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   508
            } catch (IllegalStateException e) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   509
                out.println("Exception thrown, as expected: " + e);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   510
            }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   511
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   512
            // even if we can't do getLocation for the MODULE_SOURCE_PATH, we should be able
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   513
            // to do getLocation for the modules, which will additionally confirm the option
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   514
            // was effective as intended.
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   515
            Location locn1 = fm.getLocationForModule(StandardLocation.MODULE_SOURCE_PATH, "m1x");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   516
            checkLocation(fm.getLocationAsPaths(locn1), List.of(src1.resolve("m1x")));
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   517
            Location locn2 = fm.getLocationForModule(StandardLocation.MODULE_SOURCE_PATH, "m2x");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   518
            checkLocation(fm.getLocationAsPaths(locn2), List.of(src2.resolve("m2x").resolve("extra")));
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   519
        }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   520
    }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   521
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   522
    private void generateModules(Path base, String... paths) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   523
        for (int i = 0; i < paths.length; i++) {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   524
            String moduleName = "m" + i + "x";
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   525
            String dependency = i > 0 ? "requires m" + (i - 1) + "x;" : "";
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   526
            tb.writeJavaFiles(base.resolve(paths[i]).resolve(moduleName),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   527
                    "module " + moduleName + " { " + dependency + " }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   528
                    "package pkg" + i + "; class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   529
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   530
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   531
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   532
    private void checkFiles(Path... files) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   533
        for (Path file : files) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   534
            if (!Files.exists(file)) {
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   535
                throw new Exception("File not found: " + file);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   536
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   537
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   538
    }
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   539
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   540
    private void checkLocation(Iterable<? extends Path> locn, List<Path> ref) throws Exception {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   541
        List<Path> list = asList(locn);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   542
        if (!list.equals(ref)) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   543
            out.println("expect: " + ref);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   544
            out.println(" found: " + list);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   545
            throw new Exception("location not as expected");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   546
        }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   547
    }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   548
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   549
    private <T> List<T> asList(Iterable<? extends T> iter) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   550
        List<T> list = new ArrayList<>();
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   551
        for (T item : iter) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   552
            list.add(item);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   553
        }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   554
        return list;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   555
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   556
}