langtools/test/tools/javac/modules/ModulePathTest.java
author mchung
Wed, 12 Oct 2016 15:37:27 -0700
changeset 41521 9f45ffccd1c8
parent 40308 274367a99f98
child 42407 f3702cff2933
permissions -rw-r--r--
8164689: Retrofit jar, jlink, jmod as a ToolProvider Reviewed-by: alanb, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
    26
 * @summary tests for --module-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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.jdeps/com.sun.tools.javap
41521
9f45ffccd1c8 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40308
diff changeset
    32
 *      jdk.jlink
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.ModuleBuilder
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    34
 *      ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 * @run main ModulePathTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.io.File;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.io.IOException;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.nio.file.Path;
41521
9f45ffccd1c8 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40308
diff changeset
    42
import java.util.spi.ToolProvider;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    44
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    45
import toolbox.JavacTask;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    46
import toolbox.ModuleBuilder;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    47
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    48
import toolbox.ToolBox;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    49
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
public class ModulePathTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    public static final String PATH_SEP = File.pathSeparator;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        ModulePathTest t = new ModulePathTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    60
    public void testNotExistsOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    64
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
    66
                        "--module-path", "doesNotExist")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    68
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    70
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
    72
        if (!log.contains("- compiler.err.illegal.argument.for.option: --module-path, doesNotExist"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    77
    public void testNotADirOnPath_1(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        tb.writeFile("dummy.txt", "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    82
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
    84
                        "--module-path", "dummy.txt")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    86
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    88
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
    90
        if (!log.contains("- compiler.err.illegal.argument.for.option: --module-path, dummy.txt"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    95
    public void testNotADirOnPath_2(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        tb.writeFile("dummy.jimage", "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   100
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   102
                        "--module-path", "dummy.jimage")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   104
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   106
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   108
        if (!log.contains("- compiler.err.illegal.argument.for.option: --module-path, dummy.jimage"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   113
    public void testExplodedModuleOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        Path modSrc = base.resolve("modSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        tb.writeJavaFiles(modSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                "module m1 { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                "package p; public class CC { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        Path modClasses = base.resolve("modClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        Files.createDirectories(modClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   121
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                .outdir(modClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                .files(findJavaFiles(modSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                "module m { requires m1 ; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   134
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .outdir(classes)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   136
                .options("--module-path", modClasses.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   143
    public void testBadExplodedModuleOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        Path modClasses = base.resolve("modClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        tb.writeFile(modClasses.resolve("module-info.class"), "module m1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                "module m { requires m1 ; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   154
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   157
                        "--module-path", modClasses.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   159
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   161
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        if (!log.contains("- compiler.err.locn.bad.module-info: " + modClasses.toString()))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   168
    public void testAutoJarOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        Path jarSrc = base.resolve("jarSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        tb.writeJavaFiles(jarSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                "package p; public class CC { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        Path jarClasses = base.resolve("jarClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        Files.createDirectories(jarClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   175
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                .outdir(jarClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                .files(findJavaFiles(jarSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        Path moduleJar = base.resolve("m1.jar");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   182
        new JarTask(tb, moduleJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
          .baseDir(jarClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
          .files("p/CC.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        tb.writeJavaFiles(src, "class C { p.CC cc; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   192
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                .outdir(classes)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   194
                .options("--module-path", moduleJar.toString(), "--add-modules", "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   201
    public void testModJarOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        Path jarSrc = base.resolve("jarSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        tb.writeJavaFiles(jarSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                "module m1 { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
                "package p; public class CC { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        Path jarClasses = base.resolve("jarClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        Files.createDirectories(jarClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   209
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                .outdir(jarClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                .files(findJavaFiles(jarSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        Path moduleJar = base.resolve("myModule.jar"); // deliberately not m1
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   216
        new JarTask(tb, moduleJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
          .baseDir(jarClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
          .files("module-info.class", "p/CC.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                "module m { requires m1 ; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   228
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
                .outdir(classes)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   230
                .options("--module-path", moduleJar.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   237
    public void testBadJarOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        tb.writeFile("dummy.jar", "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   242
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   244
                        "--module-path", "dummy.jar")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   246
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   248
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        if (!log.contains("- compiler.err.locn.cant.read.file: dummy.jar"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   255
    public void testJModOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        Path jmodSrc = base.resolve("jmodSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
        tb.writeJavaFiles(jmodSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                "module m1 { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                "package p; public class CC { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        Path jmodClasses = base.resolve("jmodClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        Files.createDirectories(jmodClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   263
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                .outdir(jmodClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                .files(findJavaFiles(jmodSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        Path jmod = base.resolve("myModule.jmod"); // deliberately not m1
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        jmod(jmodClasses, jmod);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                "module m { requires m1 ; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   279
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                .outdir(classes)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   281
                .options("--module-path", jmod.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   288
    public void testBadJModOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        tb.writeFile("dummy.jmod", "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   293
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   295
                        "--module-path", "dummy.jmod")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   297
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   299
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
        if (!log.contains("- compiler.err.locn.cant.read.file: dummy.jmod"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
            throw new Exception("expected output not found");
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 relativePath(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   307
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   308
        new ModuleBuilder(tb, "m1").build(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
        tb.writeJavaFiles(src, "module m2 { requires m1; }", "class A { }");
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: 39103
diff changeset
   315
                        "--module-path", modules + "/./../modules")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   322
    public void duplicatePaths_1(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   323
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   324
        new ModuleBuilder(tb, "m1").build(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
        tb.writeJavaFiles(src, "module m2 { requires m1; }", "class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   329
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   331
                        "--module-path", modules + "/./../modules" + PATH_SEP + modules)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   338
    public void duplicatePaths_2(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   339
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   340
        new ModuleBuilder(tb, "m1").build(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
        tb.writeJavaFiles(src, "module m2 { requires m1; }", "class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   345
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   347
                        "--module-path", modules.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   348
                        "--module-path", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   355
    public void oneModuleHidesAnother(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   356
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   357
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
                .classes("package pkg1; public class E { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   360
                .build(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   362
        Path deepModuleDirSrc = base.resolve("deepModuleDirSrc");
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   363
        Path deepModuleDir = modules.resolve("deepModuleDir");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   364
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
                .classes("package pkg2; public class E { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   367
                .build(deepModuleDirSrc, deepModuleDir);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   369
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
        tb.writeJavaFiles(src, "module m2 { requires m1; }", " package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   372
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   374
                        "--module-path", deepModuleDir + PATH_SEP + modules)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
                .writeAll();
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 modulesInDifferentContainers(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   382
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   383
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
                .exports("one")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
                .classes("package one; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
                .build(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   388
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   389
                .requires("m1", modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   390
                .build(base.resolve("tmp"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   391
        jar(base.resolve("tmp/m2"), modules.resolve("m2.jar"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   392
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   393
        new ModuleBuilder(tb, "m3")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
                .requires("m2", modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
                .build(base.resolve("tmp"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
        jmod(base.resolve("tmp/m3"), modules.resolve("m3.jmod"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   399
        tb.writeJavaFiles(src, "module m { requires m3; requires m2; requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
                "package p; class A { void main() { one.A.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   401
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   402
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   403
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   404
                        "--module-path", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   405
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   407
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   409
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   410
    private void jar(Path dir, Path jar) throws IOException {
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   411
        new JarTask(tb, jar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
                .baseDir(dir)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   413
                .files(".")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   415
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   418
    private void jmod(Path dir, Path jmod) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
        String[] args = {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   420
                "create",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   421
                "--class-path", dir.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   422
                jmod.toString()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
        };
41521
9f45ffccd1c8 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40308
diff changeset
   424
        ToolProvider jmodTool = ToolProvider.findFirst("jmod").orElseThrow(() ->
9f45ffccd1c8 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40308
diff changeset
   425
                new RuntimeException("jmod tool not found")
9f45ffccd1c8 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40308
diff changeset
   426
        );
9f45ffccd1c8 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40308
diff changeset
   427
        jmodTool.run(System.out, System.err, args);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   428
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   429
}