langtools/test/tools/javac/modules/PackageConflictTest.java
author alanb
Fri, 16 Jun 2017 09:21:38 -0700
changeset 45682 fc3b228b9e2a
parent 42822 a84956e7ee4d
permissions -rw-r--r--
8181087: Module system implementation refresh (6/2017) Reviewed-by: jjg Contributed-by: alan.bateman@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36526
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 test module/package conflicts
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 PackageConflictTest
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.nio.file.Files;
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
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    40
import toolbox.JavacTask;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    41
import toolbox.ModuleBuilder;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    42
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    43
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
public class PackageConflictTest extends ModuleTestBase {
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
        PackageConflictTest t = new PackageConflictTest();
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 testSimple(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
                "package java.util; public class MyList { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    58
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    62
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    64
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        if (!log.contains("MyList.java:1:1: compiler.err.package.in.other.module: java.base"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    71
    public void testDisjoint(Path base) throws Exception {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
    72
        Path m1 = base.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
    73
        Path m2 = base.resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
    75
                          "module m1x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                          "package test; public class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        tb.writeJavaFiles(m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
    78
                          "module m2x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                          "package test; public class B { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    83
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
    84
          .options("-Werror", "--module-source-path", base.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
          .files(findJavaFiles(base))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
          .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    92
    public void testConflictInDependencies(Path base) throws Exception {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
    93
        Path m1 = base.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
    94
        Path m2 = base.resolve("m2x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
    95
        Path m3 = base.resolve("m3x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
    97
                          "module m1x { exports test; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                          "package test; public class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        tb.writeJavaFiles(m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
   100
                          "module m2x { exports test; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                          "package test; public class B { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        tb.writeJavaFiles(m3,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
   103
                          "module m3x { requires m1x; requires m2x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
                          "package impl; public class Impl { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   108
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   109
                       .options("-XDrawDiagnostics", "--module-source-path", base.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                       .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                       .files(findJavaFiles(base))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   112
                       .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                       .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   114
                       .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        List<String> expected =
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 40308
diff changeset
   117
                Arrays.asList("module-info.java:1:1: compiler.err.package.clash.from.requires: m3x, test, m1x, m2x",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        if (!expected.equals(log)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
            throw new AssertionError("Unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   126
    public void testSimple2(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   127
        Path modSrc = base.resolve("modSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   129
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                .exports("pack")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   133
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .classes("package pack; public class B { pack.A f; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   136
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   138
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   139
                .options("-XDrawDiagnostics", "-p", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   141
                .files(findJavaFiles(modSrc.resolve("M")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   142
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   144
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        if (!log.contains("B.java:1:1: compiler.err.package.in.other.module: N"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   151
    public void testPrivateConflict(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   152
        Path modSrc = base.resolve("modSrc");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   153
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                .exports("publ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .classes("package publ; public class B { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   157
                .write(modSrc);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   158
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                .classes("package pack; public class C { publ.B b; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   161
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   163
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   164
                .options("-XDrawDiagnostics", "--module-source-path", modSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   166
                .files(findJavaFiles(modSrc))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   167
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   169
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        if (!log.contains(""))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
            throw new Exception("unexpected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   177
    public void testPrivateConflictOnModulePath(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   178
        Path modSrc = base.resolve("modSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   180
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                .exports("publ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                .classes("package publ; public class B { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   185
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                .classes("package pack; public class C { publ.B b; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   188
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   190
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   191
                .options("-XDrawDiagnostics", "-p", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   193
                .files(findJavaFiles(modSrc.resolve("M")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   194
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   196
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        if (!log.contains(""))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   204
    public void testRequiresConflictExports(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   205
        Path modSrc = base.resolve("modSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   207
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                .exports("pack")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   211
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
                .exports("pack")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                .classes("package pack; public class B { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   215
        new ModuleBuilder(tb, "K")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                .requires("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                .classes("package pkg; public class C { pack.A a; pack.B b; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   219
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   221
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   222
                .options("-XDrawDiagnostics", "-p", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   224
                .files(findJavaFiles(modSrc.resolve("K")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   225
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   227
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        List<String> expected =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                Arrays.asList("module-info.java:1:1: compiler.err.package.clash.from.requires: K, pack, M, N",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                        "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        if (!log.containsAll(expected))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
    @Test
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   237
    public void testQualifiedExportsToDifferentModules(Path base) throws Exception {
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   238
        Path modSrc = base.resolve("modSrc");
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   239
        new ModuleBuilder(tb, "U").write(modSrc);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   240
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                .exports("pkg to U")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
                .classes("package pkg; public class A { public static boolean flagM; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   243
                .write(modSrc);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   244
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                .exports("pkg to K")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                .classes("package pkg; public class A { public static boolean flagN; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   247
                .write(modSrc);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   248
        ModuleBuilder moduleK = new ModuleBuilder(tb, "K");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        moduleK.requires("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                .classes("package p; public class DependsOnN { boolean f = pkg.A.flagN; } ")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   252
                .write(modSrc);
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   253
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   254
                .options("--module-source-path", modSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   256
                .files(findJavaFiles(modSrc.resolve("K")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   257
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        //negative case
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        moduleK.classes("package pkg; public class DuplicatePackage { } ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
                .classes("package p; public class DependsOnM { boolean f = pkg.A.flagM; } ")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   263
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   265
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   267
                        "--module-source-path", modSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   269
                .files(findJavaFiles(modSrc.resolve("K")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   270
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   272
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                "DependsOnM.java:1:55: compiler.err.cant.resolve.location: kindname.variable, flagM, , , (compiler.misc.location: kindname.class, pkg.A, null)");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
    }
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   280
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   281
    @Test
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   282
    public void testConflictInDependenciesInUnnamed(Path base) throws Exception {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   283
        Path msp = base.resolve("module-path-source");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   284
        Path m1 = msp.resolve("m1x");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   285
        Path m2 = msp.resolve("m2x");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   286
        tb.writeJavaFiles(m1,
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   287
                          "module m1x { exports test; }",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   288
                          "package test; public class A { }");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   289
        tb.writeJavaFiles(m2,
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   290
                          "module m2x { exports test; }",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   291
                          "package test; public class B { }");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   292
        Path mp = base.resolve("module-path");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   293
        Files.createDirectories(mp);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   294
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   295
        new JavacTask(tb)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   296
            .options("--module-source-path", msp.toString())
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   297
            .outdir(mp)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   298
            .files(findJavaFiles(msp))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   299
            .run()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   300
            .writeAll();
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   301
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   302
        Path src = base.resolve("src");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   303
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   304
        tb.writeJavaFiles(src,
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   305
                          "package impl; public class Impl { }");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   306
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   307
        Path out = base.resolve("out");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   308
        Files.createDirectories(out);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   309
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   310
        List<String> log = new JavacTask(tb)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   311
                       .options("-XDrawDiagnostic",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   312
                                "--module-path", mp.toString(),
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   313
                                "--add-modules", "ALL-MODULE-PATH")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   314
                       .outdir(out)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   315
                       .files(findJavaFiles(src))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   316
                       .run(Task.Expect.FAIL)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   317
                       .writeAll()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   318
                       .getOutputLines(Task.OutputKind.DIRECT);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   319
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   320
        List<String> expected1 =
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   321
                Arrays.asList("error: the unnamed module reads package test from both m1x and m2x",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   322
                              "1 error");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   323
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   324
        List<String> expected2 =
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   325
                Arrays.asList("error: the unnamed module reads package test from both m2x and m1x",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   326
                              "1 error");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   327
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   328
        if (!expected1.equals(log) && !expected2.equals(log)) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   329
            throw new AssertionError("Unexpected output: " + log);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   330
        }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   331
    }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 42822
diff changeset
   332
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
}