langtools/test/tools/javac/modules/ModulePathTest.java
author jjg
Thu, 26 May 2016 10:45:13 -0700
changeset 38611 b5a479aff686
parent 37758 3ecf9b414e05
child 39103 91a64ec5b970
permissions -rw-r--r--
8156962: javac should support options specified in _JAVAC_OPTIONS 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
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;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    43
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    44
import toolbox.JavacTask;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    45
import toolbox.ModuleBuilder;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    46
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    47
import toolbox.ToolBox;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    48
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
public class ModulePathTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    public static final String PATH_SEP = File.pathSeparator;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        ModulePathTest t = new ModulePathTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    59
    public void testNotExistsOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    63
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                        "-modulepath", "doesNotExist")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    67
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    69
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        if (!log.contains("- compiler.err.illegal.argument.for.option: -modulepath, doesNotExist"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    76
    public void testNotADirOnPath_1(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        tb.writeFile("dummy.txt", "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    81
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                        "-modulepath", "dummy.txt")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    85
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    87
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        if (!log.contains("- compiler.err.illegal.argument.for.option: -modulepath, dummy.txt"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    94
    public void testNotADirOnPath_2(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        tb.writeFile("dummy.jimage", "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    99
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                        "-modulepath", "dummy.jimage")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   103
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   105
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        if (!log.contains("- compiler.err.illegal.argument.for.option: -modulepath, dummy.jimage"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   112
    public void testExplodedModuleOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        Path modSrc = base.resolve("modSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        tb.writeJavaFiles(modSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                "module m1 { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                "package p; public class CC { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        Path modClasses = base.resolve("modClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        Files.createDirectories(modClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   120
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                .outdir(modClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                .files(findJavaFiles(modSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                "module m { requires m1 ; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   133
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .options("-modulepath", modClasses.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   142
    public void testBadExplodedModuleOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
        Path modClasses = base.resolve("modClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        tb.writeFile(modClasses.resolve("module-info.class"), "module m1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
                "module m { requires m1 ; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   153
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                        "-modulepath", modClasses.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   158
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   160
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
        if (!log.contains("- compiler.err.locn.bad.module-info: " + modClasses.toString()))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   167
    public void testAutoJarOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        Path jarSrc = base.resolve("jarSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        tb.writeJavaFiles(jarSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                "package p; public class CC { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        Path jarClasses = base.resolve("jarClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        Files.createDirectories(jarClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   174
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                .outdir(jarClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                .files(findJavaFiles(jarSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        Path moduleJar = base.resolve("m1.jar");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   181
        new JarTask(tb, moduleJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
          .baseDir(jarClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
          .files("p/CC.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        tb.writeJavaFiles(src, "class C { p.CC cc; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   191
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                .options("-modulepath", moduleJar.toString(), "-addmods", "m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   200
    public void testModJarOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
        Path jarSrc = base.resolve("jarSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        tb.writeJavaFiles(jarSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
                "module m1 { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                "package p; public class CC { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        Path jarClasses = base.resolve("jarClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        Files.createDirectories(jarClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   208
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                .outdir(jarClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                .files(findJavaFiles(jarSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        Path moduleJar = base.resolve("myModule.jar"); // deliberately not m1
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   215
        new JarTask(tb, moduleJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
          .baseDir(jarClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
          .files("module-info.class", "p/CC.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
                "module m { requires m1 ; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   227
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
                .options("-modulepath", moduleJar.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   236
    public void testBadJarOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        tb.writeFile("dummy.jar", "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   241
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                        "-modulepath", "dummy.jar")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   245
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   247
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        if (!log.contains("- compiler.err.locn.cant.read.file: dummy.jar"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   254
    public void testJModOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
        Path jmodSrc = base.resolve("jmodSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        tb.writeJavaFiles(jmodSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                "module m1 { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                "package p; public class CC { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        Path jmodClasses = base.resolve("jmodClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        Files.createDirectories(jmodClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   262
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
                .outdir(jmodClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                .files(findJavaFiles(jmodSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
        Path jmod = base.resolve("myModule.jmod"); // deliberately not m1
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        jmod(jmodClasses, jmod);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                "module m { requires m1 ; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   278
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                .options("-modulepath", jmod.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   287
    public void testBadJModOnPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        tb.writeJavaFiles(src, "class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
        tb.writeFile("dummy.jmod", "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   292
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                        "-modulepath", "dummy.jmod")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   296
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   298
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
        if (!log.contains("- compiler.err.locn.cant.read.file: dummy.jmod"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   305
    public void relativePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
        final Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   307
        new ModuleBuilder(tb, "m1").build(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
        tb.writeJavaFiles(src, "module m2 { requires m1; }", "class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   312
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
                        "-modulepath", modules + "/./../modules")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   321
    public void duplicatePaths_1(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
        final Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   323
        new ModuleBuilder(tb, "m1").build(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
        tb.writeJavaFiles(src, "module m2 { requires m1; }", "class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   328
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
                        "-modulepath", modules + "/./../modules" + PATH_SEP + modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   337
    public void duplicatePaths_2(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
        final Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   339
        new ModuleBuilder(tb, "m1").build(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
        tb.writeJavaFiles(src, "module m2 { requires m1; }", "class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   344
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   345
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                        "-modulepath", modules.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
                        "-modulepath", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   354
    public void oneModuleHidesAnother(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   355
        final Path module = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   356
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
        final Path deepModuleDir = module.resolve("deepModuleDir");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   362
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   364
                .classes("package pkg2; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
                .build(deepModuleDir);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
        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
   369
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   370
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   372
                        "-modulepath", deepModuleDir + PATH_SEP + module)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   378
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   379
    public void modulesInDifferentContainers(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   380
        final Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   381
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                .exports("one")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
                .classes("package one; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
                .build(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   386
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
                .requires("m1", modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   388
                .build(base.resolve("tmp"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   389
        jar(base.resolve("tmp/m2"), modules.resolve("m2.jar"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   390
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   391
        new ModuleBuilder(tb, "m3")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   392
                .requires("m2", modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   393
                .build(base.resolve("tmp"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
        jmod(base.resolve("tmp/m3"), modules.resolve("m3.jmod"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
        tb.writeJavaFiles(src, "module m { requires m3; requires m2; requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
                "package p; class A { void main() { one.A.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   399
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   400
        new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   401
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
                        "-modulepath", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   403
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   405
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   407
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
    private void jar(Path dir, Path jar) throws IOException {
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   409
        new JarTask(tb, jar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   410
                .baseDir(dir)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   411
                .files(".")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   413
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   415
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
    private void jmod(Path dir, Path jmod) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
        String[] args = {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   418
                "create",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
                "--class-path", dir.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   420
                jmod.toString()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   421
        };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   422
        jdk.tools.jmod.Main.run(args, System.out);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   424
}