langtools/test/tools/javac/modules/UpgradeModulePathTest.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
changeset 36526 3b41f1c69604
child 36778 e04318f39f92
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
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
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
 * @build ToolBox ModuleTestBase
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 * @run main UpgradeModulePathTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.io.File;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
public class UpgradeModulePathTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
        UpgradeModulePathTest t = new UpgradeModulePathTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
    void simpleUsage(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        final Path module = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        final Path upgradeModule = base.resolve("upgradeModule");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
                .classes("package pkg2; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
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, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                .options("-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                        "-upgrademodulepath", upgradeModule.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    void onlyUpgradeModulePath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        final Path module = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        final Path upgradeModule = base.resolve("upgradeModule");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                .classes("package pkg2; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        tb.writeJavaFiles(src, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
                .options("-upgrademodulepath", upgradeModule + File.pathSeparator + module)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    void withModuleSourcePath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        final Path module = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        final Path upgradeModule = base.resolve("upgradeModule");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                .classes("package pkg2; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        final Path s = base.resolve("source");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        tb.writeJavaFiles(s.resolve("m3"), "module m3 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        final Path upgradeModule3 = base.resolve("upgradeModule");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        new ModuleBuilder("m3")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                .exports("pkg3")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .classes("package pkg3; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        tb.writeJavaFiles(src.resolve("m2"), "module m2 { requires m1; requires m3; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                .options("-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                        "-modulesourcepath", src + File.pathSeparator + s,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                        "-upgrademodulepath", upgradeModule + File.pathSeparator + upgradeModule3)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                .outdir(module)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
    void sameUpgradeAndModulePath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        final Path module = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        final Path upgradeModule = base.resolve("upgradeModule");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                .classes("package pkg2; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        tb.writeJavaFiles(src, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                .options("-modulepath", upgradeModule + File.pathSeparator + module,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                        "-upgrademodulepath", upgradeModule.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    void dummyFileInUpgradeModulePath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
        final Path module = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        Path dummy = base.resolve("dummy.txt");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        tb.writeFile(dummy, "");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        tb.writeJavaFiles(src, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                "package p; class A { void main() { pkg2.E.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
        String output = tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                        "-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                        "-upgrademodulepath", dummy.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        if (!output.contains("compiler.err.illegal.argument.for.option: -upgrademodulepath, " + dummy)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            throw new Exception("Expected output was not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
    void severalUpgradeModules(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        final Path module = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                .classes("package pkg1; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        new ModuleBuilder("m2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                .classes("package pkg2; public class B { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
        Path upgradeModule = base.resolve("upgradeModule");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        new ModuleBuilder("m2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                .classes("package pkg2; public class BC { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        new ModuleBuilder("m3")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
                .exports("pkg3")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                .classes("package pkg3; public class DC { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                .build(upgradeModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        tb.writeJavaFiles(src, "module m4 { requires m1; requires m2; requires m3; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                "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
   214
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                .options("-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
                        "-upgrademodulepath", upgradeModule.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        Path src2 = base.resolve("src2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        tb.writeJavaFiles(src2, "module m4 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                "package p; class A { void main() { pkg2.B.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
                        "-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
                        "-upgrademodulepath", upgradeModule.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                .files(findJavaFiles(src2))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
        if (!log.contains("compiler.err.doesnt.exist: pkg2")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
            throw new Exception("Expected output was not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
    void severalUpgradeModulePathsLastWin(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        final Path module = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                .exports("pkg1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                .classes("package pkg1; public class E { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                .build(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        final Path upgradeModule1 = base.resolve("upgradeModule1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                .classes("package pkg2; public class EC1 { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                .build(upgradeModule1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
        final Path upgradeModule2 = base.resolve("upgradeModule2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        new ModuleBuilder("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .exports("pkg2")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
                .classes("package pkg2; public class EC2 { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                .build(upgradeModule2);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        tb.writeJavaFiles(src, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                "package p; class A { void main() { pkg2.EC2.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                .options("-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                        "-upgrademodulepath", upgradeModule1.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                        "-upgrademodulepath", upgradeModule2.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
        Path src2 = base.resolve("src2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
        tb.writeJavaFiles(src2, "module m2 { requires m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                "package p; class A { void main() { pkg2.EC1.class.getName(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        final String log = tb.new JavacTask(ToolBox.Mode.CMDLINE)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
                        "-modulepath", module.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
                        "-upgrademodulepath", upgradeModule1.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
                        "-upgrademodulepath", upgradeModule2.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                .files(findJavaFiles(src2))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
                .run(ToolBox.Expect.FAIL)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
                .writeAll()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
                .getOutput(ToolBox.OutputKind.DIRECT);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        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
   286
            throw new Exception("Expected output was not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
}