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