langtools/test/tools/javac/modules/UpgradeModulePathTest.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 39103 91a64ec5b970
child 40763 209113892b0d
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
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 -upgrademodulepath
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
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    31
 * @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @run main UpgradeModulePathTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.io.File;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    38
import toolbox.JavacTask;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    39
import toolbox.ModuleBuilder;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    40
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    41
import toolbox.ToolBox;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    42
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
public class UpgradeModulePathTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        UpgradeModulePathTest t = new UpgradeModulePathTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    51
    public void simpleUsage(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    52
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    53
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
                .classes("package pkg1; public class E { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    56
                .build(modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    58
        final Path upgradeModules = base.resolve("upgradeModules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    59
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                .classes("package pkg2; public class E { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    62
                .build(upgradeModules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        tb.writeJavaFiles(src, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    68
        new JavacTask(tb, Task.Mode.CMDLINE)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
    69
                .options("--module-path", modules.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
    70
                        "--upgrade-module-path", upgradeModules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    77
    public void onlyUpgradeModulePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        final Path module = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    79
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        final Path upgradeModule = base.resolve("upgradeModule");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    85
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                .classes("package pkg2; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        tb.writeJavaFiles(src, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    94
        new JavacTask(tb, Task.Mode.CMDLINE)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
    95
                .options("--upgrade-module-path", upgradeModule + File.pathSeparator + module)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   102
    public void withModuleSourcePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        final Path module = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   104
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        final Path upgradeModule = base.resolve("upgradeModule");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   110
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                .classes("package pkg2; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        final Path s = base.resolve("source");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        tb.writeJavaFiles(s.resolve("m3"), "module m3 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        final Path upgradeModule3 = base.resolve("upgradeModule");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   119
        new ModuleBuilder(tb, "m3")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                .exports("pkg3")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                .classes("package pkg3; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                .build(upgradeModule);
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.resolve("m2"), "module m2 { requires m1; requires m3; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   128
        new JavacTask(tb, Task.Mode.CMDLINE)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   129
                .options("--module-path", module.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   130
                        "--module-source-path", src + File.pathSeparator + s,
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   131
                        "--upgrade-module-path", upgradeModule + File.pathSeparator + upgradeModule3)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                .outdir(module)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   139
    public void sameUpgradeAndModulePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        final Path module = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   141
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        final Path upgradeModule = base.resolve("upgradeModule");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   147
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                .classes("package pkg2; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        tb.writeJavaFiles(src, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   156
        new JavacTask(tb, Task.Mode.CMDLINE)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   157
                .options("--module-path", upgradeModule + File.pathSeparator + module,
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   158
                        "--upgrade-module-path", upgradeModule.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                .writeAll();
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
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   165
    public void dummyFileInUpgradeModulePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        final Path module = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   167
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        Path dummy = base.resolve("dummy.txt");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        tb.writeFile(dummy, "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        tb.writeJavaFiles(src, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   179
        String output = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   181
                        "--module-path", module.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   182
                        "--upgrade-module-path", dummy.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   184
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   186
                .getOutput(Task.OutputKind.DIRECT);
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   187
        if (!output.contains("compiler.err.illegal.argument.for.option: --upgrade-module-path, " + dummy)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            throw new Exception("Expected output was not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   193
    public void severalUpgradeModules(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        final Path module = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   195
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                .classes("package pkg1; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   200
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
                .classes("package pkg2; public class B { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        Path upgradeModule = base.resolve("upgradeModule");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   206
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                .classes("package pkg2; public class BC { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                .build(upgradeModule);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   210
        new ModuleBuilder(tb, "m3")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                .exports("pkg3")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
                .classes("package pkg3; public class DC { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        tb.writeJavaFiles(src, "module m4 { requires m1; requires m2; requires m3; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
                "package p; class A { void main() { pkg1.A.class.getName(); pkg2.BC.class.getName(); pkg3.DC.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   219
        new JavacTask(tb, Task.Mode.CMDLINE)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   220
                .options("--module-path", module.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   221
                        "--upgrade-module-path", upgradeModule.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        Path src2 = base.resolve("src2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        tb.writeJavaFiles(src2, "module m4 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
                "package p; class A { void main() { pkg2.B.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   230
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   232
                        "--module-path", module.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   233
                        "--upgrade-module-path", upgradeModule.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                .files(findJavaFiles(src2))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   235
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   237
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        if (!log.contains("compiler.err.doesnt.exist: pkg2")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
            throw new Exception("Expected output was not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   244
    public void severalUpgradeModulePathsLastWin(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        final Path module = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   246
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
        final Path upgradeModule1 = base.resolve("upgradeModule1");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   252
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
                .classes("package pkg2; public class EC1 { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .build(upgradeModule1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
        final Path upgradeModule2 = base.resolve("upgradeModule2");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   258
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
                .classes("package pkg2; public class EC2 { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                .build(upgradeModule2);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        tb.writeJavaFiles(src, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                "package p; class A { void main() { pkg2.EC2.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   267
        new JavacTask(tb, Task.Mode.CMDLINE)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   268
                .options("--module-path", module.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   269
                        "--upgrade-module-path", upgradeModule1.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   270
                        "--upgrade-module-path", upgradeModule2.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        Path src2 = base.resolve("src2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        tb.writeJavaFiles(src2, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
                "package p; class A { void main() { pkg2.EC1.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   279
        final String log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   281
                        "--module-path", module.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   282
                        "--upgrade-module-path", upgradeModule1.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   283
                        "--upgrade-module-path", upgradeModule2.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
                .files(findJavaFiles(src2))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   285
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   287
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        if (!log.contains("compiler.err.cant.resolve.location: kindname.class, EC1, , , (compiler.misc.location: kindname.package, pkg2, null)")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
            throw new Exception("Expected output was not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
}