test/langtools/tools/javac/modules/ModuleSourcePathTest.java
author jjg
Fri, 31 Aug 2018 14:54:42 -0700
changeset 51615 afbb33428df7
parent 49822 53aae0c219e6
permissions -rw-r--r--
8208608: Update --module-source-path to allow explicit source paths for specific modules Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, 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
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents: 47216
diff changeset
    79
        if (!log.contains("compiler.err.sourcepath.modulesourcepath.conflict"))
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
51615
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   522
    @Test
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   523
    public void moduleSpecificFormsOnly(Path base) throws Exception {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   524
        // The dirs for the modules do not use a subdirectory named for the module,
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   525
        // meaning they can only be used by the module-specific form of the option.
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   526
        String[] srcDirs = {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   527
                "src0",         // m0x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   528
                "src1",         // m1x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   529
                "src2",         // m2x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   530
                "src3"          // m3x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   531
        };
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   532
        generateModules(base, false, srcDirs);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   533
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   534
        final Path modules = base.resolve("modules");
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   535
        tb.createDirectories(modules);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   536
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   537
        new JavacTask(tb, Task.Mode.CMDLINE)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   538
                .options("-XDrawDiagnostics",
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   539
                        "--module-source-path", "m0x=" + base.resolve("src0"),
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   540
                        "--module-source-path", "m1x=" + base.resolve("src1"),
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   541
                        "--module-source-path", "m2x=" + base.resolve("src2"),
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   542
                        "--module-source-path", "m3x=" + base.resolve("src3"))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   543
                .files(findJavaFiles(base.resolve(srcDirs[srcDirs.length - 1])))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   544
                .outdir(modules)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   545
                .run()
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   546
                .writeAll();
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   547
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   548
        for (int i = 0; i < srcDirs.length; i++) {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   549
            checkFiles(modules.resolve("m" + i + "x/module-info.class"));
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   550
        }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   551
        checkFiles(modules.resolve("m3x/pkg3/A.class"));
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   552
    }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   553
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   554
    @Test
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   555
    public void modulePatternWithEquals(Path base) throws Exception {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   556
        // The dirs for the modules contain an '=' character, but
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   557
        // the option should still be recognized as the module pattern form.
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   558
        String[] srcDirs = {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   559
                "src=",         // m0x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   560
                "src=",         // m1x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   561
                "src=",         // m2x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   562
                "src="  // m3x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   563
        };
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   564
        generateModules(base, true, srcDirs);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   565
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   566
        final Path modules = base.resolve("modules");
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   567
        tb.createDirectories(modules);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   568
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   569
        new JavacTask(tb, Task.Mode.CMDLINE)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   570
                .options("-XDrawDiagnostics",
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   571
                        "--module-source-path", base.resolve("src=").toString())
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   572
                .files(findJavaFiles(base.resolve(srcDirs[srcDirs.length - 1])))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   573
                .outdir(modules)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   574
                .run()
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   575
                .writeAll();
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   576
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   577
        for (int i = 0; i < srcDirs.length; i++) {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   578
            checkFiles(modules.resolve("m" + i + "x/module-info.class"));
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   579
        }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   580
        checkFiles(modules.resolve("m3x/pkg3/A.class"));
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   581
    }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   582
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   583
    @Test
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   584
    public void duplicateModuleSpecificForms(Path base) throws Exception {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   585
        // The dirs for the modules do not use a subdirectory named for the module,
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   586
        // meaning they can only be used by the module-specific form of the option.
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   587
        String[] srcDirs = {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   588
                "src0",         // m0x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   589
                "src1",         // m1x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   590
                "src2",         // m2x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   591
                "src3"          // m3x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   592
        };
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   593
        generateModules(base, false, srcDirs);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   594
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   595
        final Path modules = base.resolve("modules");
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   596
        tb.createDirectories(modules);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   597
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   598
        // in the following, it should not matter that src1 does not contain
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   599
        // a definition of m0x; it is bad/wrong to specify the option for m0x twice.
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   600
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   601
                .options("-XDrawDiagnostics",
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   602
                        "--module-source-path", "m0x=" + base.resolve("src0"),
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   603
                        "--module-source-path", "m0x=" + base.resolve("src1"))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   604
                .files(findJavaFiles(base.resolve(srcDirs[srcDirs.length - 1])))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   605
                .outdir(modules)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   606
                .run(Task.Expect.FAIL)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   607
                .writeAll()
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   608
                .getOutput(Task.OutputKind.DIRECT);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   609
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   610
        if (!log.contains("error: --module-source-path specified more than once for module m0x"))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   611
            throw new Exception("Expected error message not found");
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   612
    }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   613
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   614
    @Test
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   615
    public void duplicateModulePatternForms(Path base) throws Exception {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   616
        // module-specific subdirs are used to allow for use of module-pattern form
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   617
        String[] srcDirs = {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   618
                "src",  // m0x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   619
                "src",  // m1x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   620
                "src",  // m2x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   621
                "src"   // m3x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   622
        };
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   623
        generateModules(base, true, srcDirs);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   624
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   625
        final Path modules = base.resolve("modules");
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   626
        tb.createDirectories(modules);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   627
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   628
        // in the following, it should not matter that the same pattern
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   629
        // is used for both occurrences; it is bad/wrong to give any two patterns
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   630
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   631
                .options("-XDrawDiagnostics",
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   632
                        "--module-source-path", base.resolve("src").toString(),
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   633
                        "--module-source-path", base.resolve("src").toString())
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   634
                .files(findJavaFiles(base.resolve(srcDirs[srcDirs.length - 1])))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   635
                .outdir(modules)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   636
                .run(Task.Expect.FAIL)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   637
                .writeAll()
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   638
                .getOutput(Task.OutputKind.DIRECT);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   639
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   640
        if (!log.contains("error: --module-source-path specified more than once with a pattern argument"))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   641
            throw new Exception("Expected error message not found");
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   642
    }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   643
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   644
    @Test
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   645
    public void mixedOptionForms(Path base) throws Exception {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   646
        // The dirs for m0x, m2x use a subdirectory named for the module,
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   647
        // meaning they can be used in the module pattern form of the option;
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   648
        // the dirs for m1x, m3x do not use a subdirectory named for the module,
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   649
        // meaning they can only be used by the module-specific form of the option
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   650
        String[] srcDirs = {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   651
                "src/m0x",      // m0x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   652
                "src1",         // m1x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   653
                "src/m2x",      // m2x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   654
                "src3"          // m3x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   655
        };
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   656
        generateModules(base, false, srcDirs);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   657
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   658
        final Path modules = base.resolve("modules");
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   659
        tb.createDirectories(modules);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   660
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   661
        new JavacTask(tb, Task.Mode.CMDLINE)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   662
                .options("-XDrawDiagnostics",
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   663
                        "--module-source-path", base.resolve("src").toString(), // for m0x, m2x
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   664
                        "--module-source-path", "m1x=" + base.resolve("src1"),
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   665
                        "--module-source-path", "m3x=" + base.resolve("src3"))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   666
                .files(findJavaFiles(base.resolve(srcDirs[srcDirs.length - 1])))
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   667
                .outdir(modules)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   668
                .run()
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   669
                .writeAll();
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   670
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   671
        for (int i = 0; i < srcDirs.length; i++) {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   672
            checkFiles(modules.resolve("m" + i + "x/module-info.class"));
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   673
        }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   674
        checkFiles(modules.resolve("m3x/pkg3/A.class"));
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   675
    }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   676
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   677
    private void generateModules(Path base, String... paths) throws IOException {
51615
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   678
        generateModules(base, true, paths);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   679
    }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   680
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   681
    private void generateModules(Path base, boolean useModuleSubdirs, String... paths)
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   682
                throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   683
        for (int i = 0; i < paths.length; i++) {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   684
            String moduleName = "m" + i + "x";
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40599
diff changeset
   685
            String dependency = i > 0 ? "requires m" + (i - 1) + "x;" : "";
51615
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   686
            Path dir = base.resolve(paths[i]);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   687
            if (useModuleSubdirs) {
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   688
                dir = dir.resolve(moduleName);
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   689
            }
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 49822
diff changeset
   690
            tb.writeJavaFiles(dir,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   691
                    "module " + moduleName + " { " + dependency + " }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   692
                    "package pkg" + i + "; class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   693
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   694
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   695
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   696
    private void checkFiles(Path... files) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   697
        for (Path file : files) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   698
            if (!Files.exists(file)) {
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   699
                throw new Exception("File not found: " + file);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   700
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   701
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   702
    }
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   703
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   704
    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
   705
        List<Path> list = asList(locn);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   706
        if (!list.equals(ref)) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   707
            out.println("expect: " + ref);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   708
            out.println(" found: " + list);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   709
            throw new Exception("location not as expected");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   710
        }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   711
    }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   712
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   713
    private <T> List<T> asList(Iterable<? extends T> iter) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   714
        List<T> list = new ArrayList<>();
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   715
        for (T item : iter) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   716
            list.add(item);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   717
        }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   718
        return list;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 42822
diff changeset
   719
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   720
}