langtools/test/tools/javac/modules/PackageConflictTest.java
author jjg
Thu, 31 Mar 2016 15:20:50 -0700
changeset 36778 e04318f39f92
parent 36526 3b41f1c69604
child 37758 3ecf9b414e05
permissions -rw-r--r--
8152897: refactor ToolBox to allow reduced documented dependencies Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary 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
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    31
 * @build toolbox.ToolBox toolbox.JavacTask 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;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    41
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    42
import toolbox.ToolBox;
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    void testSimple(Path base) throws Exception {
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    void testDisjoint(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        Path m1 = base.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        Path m2 = base.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
                          "module m1 { }",
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,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                          "module m2 { }",
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)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
          .options("-Werror", "-modulesourcepath", base.toString())
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    void testConflictInDependencies(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        Path m1 = base.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        Path m2 = base.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        Path m3 = base.resolve("m3");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                          "module m1 { exports test; }",
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,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                          "module m2 { exports test; }",
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,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
                          "module m3 { requires m1; requires m2; }",
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)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                       .options("-XDrawDiagnostics", "-modulesourcepath", base.toString())
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 =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                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
   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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    void testSimple2(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        new ModuleBuilder("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                .exports("pack")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                .build(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        new ModuleBuilder("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                .classes("package pack; public class B { pack.A f; }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   137
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .options("-XDrawDiagnostics", "-mp", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                .files(findJavaFiles(modules.resolve("M")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   141
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   143
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        if (!log.contains("B.java:1:1: compiler.err.package.in.other.module: N"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
    void testPrivateConflict(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        new ModuleBuilder("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                .exports("publ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                .classes("package publ; public class B { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        new ModuleBuilder("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .classes("package pack; public class C { publ.B b; }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   162
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
                .options("-XDrawDiagnostics", "-modulesourcepath", modules + "/*/src")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                .files(findJavaFiles(modules))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   166
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   168
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        if (!log.contains(""))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            throw new Exception("unexpected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
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
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
    void testPrivateConflictOnModulePath(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        new ModuleBuilder("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                .exports("publ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                .classes("package publ; public class B { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                .build(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        new ModuleBuilder("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                .classes("package pack; public class C { publ.B b; }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   188
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                .options("-XDrawDiagnostics", "-mp", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                .files(findJavaFiles(modules.resolve("M")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   192
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   194
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        if (!log.contains(""))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
    void testRequiresConflictExports(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        new ModuleBuilder("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
                .exports("pack")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
                .classes("package pack; public class A { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
                .build(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        new ModuleBuilder("N")
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 B { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                .build(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        new ModuleBuilder("K")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                .requires("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                .classes("package pkg; public class C { pack.A a; pack.B b; }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   218
        List<String> log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                .options("-XDrawDiagnostics", "-mp", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                .files(findJavaFiles(modules.resolve("K")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   222
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   224
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        List<String> expected =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
                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
   228
                        "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        if (!log.containsAll(expected))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
    void testQulifiedExportsToDifferentModules(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        new ModuleBuilder("U").write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        new ModuleBuilder("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
                .exports("pkg to U")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                .classes("package pkg; public class A { public static boolean flagM; }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        new ModuleBuilder("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
                .exports("pkg to K")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                .classes("package pkg; public class A { public static boolean flagN; }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        ModuleBuilder moduleK = new ModuleBuilder("K");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
        moduleK.requires("M")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                .requires("N")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                .classes("package p; public class DependsOnN { boolean f = pkg.A.flagN; } ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                .write(modules);
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   250
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                .options("-modulesourcepath", modules + "/*/src")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                .files(findJavaFiles(modules.resolve("K")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   254
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
        //negative case
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        moduleK.classes("package pkg; public class DuplicatePackage { } ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                .classes("package p; public class DependsOnM { boolean f = pkg.A.flagM; } ")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   262
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
                .options("-XDrawDiagnostics",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                        "-modulesourcepath", modules + "/*/src")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                .files(findJavaFiles(modules.resolve("K")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   267
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   269
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                "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
   273
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
}