langtools/test/tools/javac/modules/UsesTest.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 39103 91a64ec5b970
child 41931 d7c9720c4223
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary simple tests of module uses
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 UsesTest
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.Collection;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    41
import toolbox.JavacTask;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    42
import toolbox.ModuleBuilder;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    43
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    44
import toolbox.ToolBox;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    45
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
public class UsesTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        UsesTest t = new UsesTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    53
    public void testSimple(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
                "module m { uses p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    61
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    64
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    69
    public void testSimpleInner(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                "module m { uses p.C.Inner; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                "package p; public class C { public class Inner { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    77
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    80
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    @Test
37854
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    85
    public void testEnumAsAService(Path base) throws Exception {
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    86
        Path src = base.resolve("src");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    87
        tb.writeJavaFiles(src,
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    88
                "module m { uses pkg.EnumST; }",
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    89
                "package pkg; public enum EnumST {A, B}");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    90
        Path classes = base.resolve("classes");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    91
        Files.createDirectories(classes);
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    92
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    93
        List<String> output = new JavacTask(tb)
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    94
                .options("-XDrawDiagnostics")
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    95
                .outdir(classes)
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    96
                .files(tb.findJavaFiles(src))
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    97
                .run(Task.Expect.FAIL)
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    98
                .writeAll()
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    99
                .getOutputLines(Task.OutputKind.DIRECT);
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   100
        List<String> expected = Arrays.asList("module-info.java:1:20: compiler.err.service.definition.is.enum: pkg.EnumST",
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   101
                "1 error");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   102
        if (!output.containsAll(expected)) {
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   103
            throw new Exception("Expected output not found");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   104
        }
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   105
    }
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   106
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   107
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   108
    public void testSimpleAnnotation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                "module m { uses p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                "package p; public @interface C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   116
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   119
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   124
    public void testPrivateService(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                "module m { uses p.C.A; uses p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                "package p; public class C { protected class A { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   130
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   134
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   136
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        List<String> expected = Arrays.asList("module-info.java:1:20: compiler.err.report.access: p.C.A, protected, p.C",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   146
    public void testMulti(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        tb.writeJavaFiles(src.resolve("m1"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                "module m1 { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        tb.writeJavaFiles(src.resolve("m2"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                "module m2 { requires m1; uses p.C; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   156
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   157
                .options("--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   160
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   165
    public void testMultiOnModulePath(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37854
diff changeset
   166
        Path modSrc = base.resolve("modSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   168
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                .exports("p")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                .classes("package p; public class C { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   172
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                .requires("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                .uses("p.C")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37854
diff changeset
   175
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   177
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   178
                .options("-p", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                .outdir(modules)
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37854
diff changeset
   180
                .files(findJavaFiles(modSrc.resolve("m2")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   181
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   186
    public void testMultiOnModulePathInner(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37854
diff changeset
   187
        Path modSrc = base.resolve("modSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   189
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                .exports("p")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                .classes("package p; public class C { public class Inner { } }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   193
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                .requires("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                .uses("p.C.Inner")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37854
diff changeset
   196
                .write(modSrc);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   198
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   199
                .options("-p", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                .outdir(modules)
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37854
diff changeset
   201
                .files(findJavaFiles(modSrc.resolve("m2")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   202
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   207
    public void testDuplicateUses(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        tb.writeJavaFiles(src.resolve("m"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                "module m { uses p.C; uses p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   213
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   217
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   219
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        if (!output.containsAll(Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
                "module-info.java:1:22: compiler.err.duplicate.uses: p.C"))) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   228
    public void testServiceNotExist(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                "module m { uses p.NotExist; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   234
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   238
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   240
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        Collection<?> expected = Arrays.asList("module-info.java:1:18: compiler.err.cant.resolve.location: kindname.class, NotExist, , , (compiler.misc.location: kindname.package, p, null)",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   249
    public void testUsesUnexportedService(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
        tb.writeJavaFiles(src.resolve("m1"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        tb.writeJavaFiles(src.resolve("m2"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                "module m2 { requires m1; uses p.C; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   257
        List<String> output = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   258
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                .outdir(Files.createDirectories(base.resolve("modules")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   261
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   263
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        List<String> expected = Arrays.asList("module-info.java:1:32: compiler.err.not.def.access.package.cant.access: p.C, p",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   273
    public void testUsesUnexportedButProvidedService(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        tb.writeJavaFiles(src.resolve("m1"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                "module m1 { provides p.C with p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        tb.writeJavaFiles(src.resolve("m2"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
                "module m2 { requires m1; uses p.C; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   281
        List<String> output = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39103
diff changeset
   282
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
                .outdir(Files.createDirectories(base.resolve("modules")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   285
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   287
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        List<String> expected = Arrays.asList("module-info.java:1:32: compiler.err.not.def.access.package.cant.access: p.C, p",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
}