langtools/test/tools/javac/modules/PackageConflictTest.java
author jjg
Fri, 17 Jun 2016 17:40:01 -0700
changeset 39103 91a64ec5b970
parent 37758 3ecf9b414e05
child 40308 274367a99f98
permissions -rw-r--r--
8159749: Update toolbox ModuleBuilder for doc comments Reviewed-by: 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 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
import toolbox.ToolBox;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    44
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
public class PackageConflictTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        PackageConflictTest t = new PackageConflictTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    52
    public void testSimple(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
                "package java.util; public class MyList { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    59
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    63
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    65
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        if (!log.contains("MyList.java:1:1: compiler.err.package.in.other.module: java.base"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    72
    public void testDisjoint(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        Path m1 = base.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        Path m2 = base.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                          "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                          "package test; public class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        tb.writeJavaFiles(m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                          "module m2 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                          "package test; public class B { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    84
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
          .options("-Werror", "-modulesourcepath", base.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
          .files(findJavaFiles(base))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
          .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    93
    public void testConflictInDependencies(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        Path m1 = base.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        Path m2 = base.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        Path m3 = base.resolve("m3");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                          "module m1 { exports test; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                          "package test; public class A { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        tb.writeJavaFiles(m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                          "module m2 { exports test; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                          "package test; public class B { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        tb.writeJavaFiles(m3,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
                          "module m3 { requires m1; requires m2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
                          "package impl; public class Impl { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   109
        List<String> log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                       .options("-XDrawDiagnostics", "-modulesourcepath", base.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                       .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                       .files(findJavaFiles(base))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   113
                       .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                       .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   115
                       .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        List<String> expected =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                Arrays.asList("module-info.java:1:1: compiler.err.package.clash.from.requires: m3, test, m1, m2",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        if (!expected.equals(log)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            throw new AssertionError("Unexpected output: " + log);
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   127
    public void testSimple2(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   128
        Path modSrc = base.resolve("modSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   130
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                .exports("pack")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   134
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                .classes("package pack; public class B { pack.A f; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   137
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   139
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                .options("-XDrawDiagnostics", "-mp", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   142
                .files(findJavaFiles(modSrc.resolve("M")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   143
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   145
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        if (!log.contains("B.java:1:1: compiler.err.package.in.other.module: N"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   152
    public void testPrivateConflict(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   153
        Path modSrc = base.resolve("modSrc");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   154
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                .exports("publ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .classes("package publ; public class B { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   158
                .write(modSrc);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   159
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                .classes("package pack; public class C { publ.B b; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   162
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   164
        String log = new JavacTask(tb)
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   165
                .options("-XDrawDiagnostics", "-modulesourcepath", modSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   167
                .files(findJavaFiles(modSrc))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   168
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   170
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        if (!log.contains(""))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
            throw new Exception("unexpected output not found");
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   178
    public void testPrivateConflictOnModulePath(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   179
        Path modSrc = base.resolve("modSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   181
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                .exports("publ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                .classes("package publ; public class B { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   186
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                .classes("package pack; public class C { publ.B b; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   189
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   191
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .options("-XDrawDiagnostics", "-mp", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   194
                .files(findJavaFiles(modSrc.resolve("M")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   195
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   197
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        if (!log.contains(""))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
            throw new Exception("expected output not found");
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   205
    public void testRequiresConflictExports(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   206
        Path modSrc = base.resolve("modSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   208
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                .exports("pack")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   212
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                .exports("pack")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                .classes("package pack; public class B { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   216
        new ModuleBuilder(tb, "K")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
                .requires("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                .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
   220
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   222
        List<String> log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                .options("-XDrawDiagnostics", "-mp", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   225
                .files(findJavaFiles(modSrc.resolve("K")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   226
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   228
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        List<String> expected =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                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
   232
                        "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        if (!log.containsAll(expected))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
    @Test
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   238
    public void testQualifiedExportsToDifferentModules(Path base) throws Exception {
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   239
        Path modSrc = base.resolve("modSrc");
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   240
        new ModuleBuilder(tb, "U").write(modSrc);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   241
        new ModuleBuilder(tb, "M")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
                .exports("pkg to U")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                .classes("package pkg; public class A { public static boolean flagM; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   244
                .write(modSrc);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   245
        new ModuleBuilder(tb, "N")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                .exports("pkg to K")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                .classes("package pkg; public class A { public static boolean flagN; }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   248
                .write(modSrc);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   249
        ModuleBuilder moduleK = new ModuleBuilder(tb, "K");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        moduleK.requires("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .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
   253
                .write(modSrc);
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   254
        new JavacTask(tb)
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   255
                .options("-modulesourcepath", modSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   257
                .files(findJavaFiles(modSrc.resolve("K")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   258
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        //negative case
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        moduleK.classes("package pkg; public class DuplicatePackage { } ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
                .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
   264
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   266
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                .options("-XDrawDiagnostics",
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   268
                        "-modulesourcepath", modSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                .outdir(Files.createDirectories(base.resolve("classes")))
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   270
                .files(findJavaFiles(modSrc.resolve("K")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   271
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   273
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                "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
   277
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
}