langtools/test/tools/javac/modules/AddLimitMods.java
author alanb
Fri, 07 Apr 2017 08:08:26 +0000
changeset 44573 245bb4e6f983
parent 43772 4e5350b7be75
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: jjg Contributed-by: alan.bateman@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43581
af18ebffc685 8173604: Rename module 8173604 java.annotations.common to java.xml.ws.annoations
lancea
parents: 43138
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
42841
1768507dae6b 8171412: tools/javac/modules/AddLimitMods.java failed with "error: module not found"
jjg
parents: 42822
diff changeset
    26
 * @bug 8142968 8154956 8170987 8171412
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
    27
 * @summary Test --add-modules and --limit-modules; also test the "enabled" modules.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.compiler/com.sun.tools.javac.code
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 *      jdk.compiler/com.sun.tools.javac.main
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 *      jdk.compiler/com.sun.tools.javac.model
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 *      jdk.compiler/com.sun.tools.javac.processing
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 *      jdk.compiler/com.sun.tools.javac.util
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 *      jdk.jdeps/com.sun.tools.javap
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    37
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavaTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 * @run main AddLimitMods
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.io.File;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.nio.file.Path;
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
    44
import java.util.AbstractMap.SimpleEntry;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.ArrayList;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.Collections;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import java.util.HashSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import java.util.LinkedHashMap;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import java.util.Map;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import java.util.Map.Entry;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import java.util.Objects;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
import javax.annotation.processing.AbstractProcessor;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
import javax.annotation.processing.RoundEnvironment;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
import javax.annotation.processing.SupportedAnnotationTypes;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
import javax.annotation.processing.SupportedOptions;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
import javax.lang.model.SourceVersion;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
import javax.lang.model.element.ModuleElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
import javax.lang.model.element.TypeElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
import com.sun.tools.javac.code.Symbol.ClassSymbol;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
import com.sun.tools.javac.code.Symtab;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
import com.sun.tools.javac.model.JavacElements;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
import com.sun.tools.javac.util.Context;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    70
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    71
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    72
import toolbox.JavaTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    73
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    74
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
public class AddLimitMods extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        AddLimitMods t = new AddLimitMods();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36994
diff changeset
    83
    public void testManual(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    85
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    88
                          "module m1x { requires m2x; requires m3x; }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    90
        Path m2 = moduleSrc.resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        tb.writeJavaFiles(m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    93
                          "module m2x { requires m3x; exports m2x; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    94
                          "package m2x; public class M2 {}");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    96
        Path m3 = moduleSrc.resolve("m3x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        tb.writeJavaFiles(m3,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    99
                          "module m3x { exports m3x; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   100
                          "package m3x; public class M3 {}");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   106
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   107
                .options("--module-source-path", moduleSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                .files(findJavaFiles(m3))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   113
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   114
                .options("--module-source-path", moduleSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                .files(findJavaFiles(m2))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        //real test
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   121
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   122
                .options("--module-path", modulePath.toString(),
40835
6ab9ed1abc46 8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents: 40308
diff changeset
   123
                         "--should-stop:ifNoError=FLOW",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   124
                         "--limit-modules", "java.base")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                .files(findJavaFiles(m1))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   127
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                .writeAll();
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
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   131
                .options("--module-path", modulePath.toString(),
40835
6ab9ed1abc46 8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents: 40308
diff changeset
   132
                         "--should-stop:ifNoError=FLOW",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   133
                         "--limit-modules", "java.base",
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   134
                         "--add-modules", "m2x")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                .files(findJavaFiles(m1))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   137
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   140
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   141
                .options("--module-path", modulePath.toString(),
40835
6ab9ed1abc46 8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents: 40308
diff changeset
   142
                         "--should-stop:ifNoError=FLOW",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   143
                         "--limit-modules", "java.base",
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   144
                         "--add-modules", "m2x,m3x")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                .files(findJavaFiles(m1))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   150
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   151
                .options("--module-path", modulePath.toString(),
40835
6ab9ed1abc46 8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents: 40308
diff changeset
   152
                         "--should-stop:ifNoError=FLOW",
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   153
                         "--limit-modules", "m2x")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                .files(findJavaFiles(m1))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   159
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   160
                .options("--module-path", modulePath.toString(),
40835
6ab9ed1abc46 8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents: 40308
diff changeset
   161
                         "--should-stop:ifNoError=FLOW",
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   162
                         "--limit-modules", "m3x")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                .files(findJavaFiles(m1))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   165
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   168
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   169
                .options("--module-path", modulePath.toString(),
40835
6ab9ed1abc46 8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents: 40308
diff changeset
   170
                         "--should-stop:ifNoError=FLOW",
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   171
                         "--limit-modules", "m3x",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   172
                         "--add-modules", "m2x")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                .files(findJavaFiles(m1))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
    @Test
37849
alanb
parents: 37758 37848
diff changeset
   180
    public void testObservableForUnnamed(Path base) throws Exception {
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   181
        Path src = base.resolve("src");
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   182
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   183
        tb.writeJavaFiles(src,
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   184
                          "package test;\n" +
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   185
                          "@javax.annotation.Generated(\"test\")\n" +
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   186
                          "public class Test {\n" +
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   187
                          "    com.sun.tools.javac.Main m;\n" +
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   188
                          "    javax.xml.bind.JAXBException e;\n" +
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   189
                          "}\n");
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   190
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   191
        Path out = base.resolve("out");
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   192
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   193
        Files.createDirectories(out);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   194
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   195
        for (Entry<String[], String> variant : variants) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   196
            System.err.println("running variant: options=" + Arrays.asList(variant.getKey()) + ", expected log: " + variant.getValue());
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   197
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   198
            List<String> options = new ArrayList<>();
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   199
            options.add("-XDrawDiagnostics");
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   200
            options.addAll(Arrays.asList(variant.getKey()));
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   201
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   202
            String log = new JavacTask(tb)
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   203
                    .options(options.toArray(new String[0]))
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   204
                    .outdir(out)
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   205
                    .files(findJavaFiles(src))
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   206
                    .run(variant.getValue() == null ? Task.Expect.SUCCESS : Task.Expect.FAIL)
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   207
                    .writeAll()
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   208
                    .getOutput(Task.OutputKind.DIRECT);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   209
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   210
            log = log.replace(System.getProperty("line.separator"), "\n");
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   211
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   212
            if (variant.getValue() != null && !log.equals(variant.getValue())) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   213
                throw new AssertionError();
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   214
            }
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   215
        }
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   216
    }
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   217
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   218
    private static final List<Entry<String[], String>> variants = Arrays.asList(
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   219
            new SimpleEntry<String[], String>(new String[] {},
43581
af18ebffc685 8173604: Rename module 8173604 java.annotations.common to java.xml.ws.annoations
lancea
parents: 43138
diff changeset
   220
                                              "Test.java:2:7: compiler.err.package.not.visible: javax.annotation, (compiler.misc.not.def.access.does.not.read.from.unnamed: javax.annotation, java.xml.ws.annotation)\n"
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42841
diff changeset
   221
                                            + "Test.java:5:14: compiler.err.package.not.visible: javax.xml.bind, (compiler.misc.not.def.access.does.not.read.from.unnamed: javax.xml.bind, java.xml.bind)\n"
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   222
                                            + "2 errors\n"),
43581
af18ebffc685 8173604: Rename module 8173604 java.annotations.common to java.xml.ws.annoations
lancea
parents: 43138
diff changeset
   223
            new SimpleEntry<String[], String>(new String[] {"--add-modules", "java.xml.ws.annotation,java.xml.bind"},
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   224
                                              null),
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   225
            new SimpleEntry<String[], String>(new String[] {"--limit-modules", "java.xml.ws,jdk.compiler"},
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   226
                                              null),
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   227
            new SimpleEntry<String[], String>(new String[] {"--add-modules", "ALL-SYSTEM"},
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   228
                                              null)
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   229
    );
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   230
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36994
diff changeset
   231
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36994
diff changeset
   232
    public void testAllModulePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        if (Files.isDirectory(base))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            tb.cleanDirectory(base);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   237
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   240
                          "module m1x { exports api; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                          "package api; public class Api { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   247
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   248
                .options("--module-source-path", moduleSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        Path cpSrc = base.resolve("cp-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
        tb.writeJavaFiles(cpSrc, "package test; public class Test { api.Api api; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
        Path cpOut = base.resolve("cp-out");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        Files.createDirectories(cpOut);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   261
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   262
                .options("--module-path", modulePath.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
                .outdir(cpOut)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                .files(findJavaFiles(cpSrc))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   265
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   268
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   269
                .options("--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   270
                         "--add-modules", "ALL-MODULE-PATH")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .outdir(cpOut)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                .files(findJavaFiles(cpSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        List<String> actual;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
                "- compiler.err.addmods.all.module.path.invalid",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
                "1 error");
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
        actual = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   282
                   .options("--module-source-path", moduleSrc.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
                            "-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   284
                            "--add-modules", "ALL-MODULE-PATH")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
                   .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
                   .files(findJavaFiles(moduleSrc))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   287
                   .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
                   .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   289
                   .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        if (!Objects.equals(actual, expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
            throw new IllegalStateException("incorrect errors; actual=" + actual + "; expected=" + expected);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   295
        actual = new JavacTask(tb)
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43581
diff changeset
   296
                   .options("--patch-module", "java.base=" + cpSrc.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
                            "-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   298
                            "--add-modules", "ALL-MODULE-PATH")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
                   .outdir(cpOut)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
                   .files(findJavaFiles(cpSrc))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   301
                   .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
                   .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   303
                   .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
        if (!Objects.equals(actual, expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
            throw new IllegalStateException("incorrect errors; actual=" + actual + "; expected=" + expected);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   309
        actual = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
                   .options("-source", "8", "-target", "8",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
                            "-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   312
                            "--add-modules", "ALL-MODULE-PATH")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
                   .outdir(cpOut)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
                   .files(findJavaFiles(cpSrc))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   315
                   .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
                   .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   317
                   .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   319
        if (!actual.contains("javac: option --add-modules not allowed with target 1.8")) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
            throw new IllegalStateException("incorrect errors; actual=" + actual);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   323
        tb.writeJavaFiles(cpSrc, "module m1x {}");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   325
        actual = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
                   .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   327
                            "--add-modules", "ALL-MODULE-PATH")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
                   .outdir(cpOut)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
                   .files(findJavaFiles(cpSrc))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   330
                   .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
                   .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   332
                   .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
        if (!Objects.equals(actual, expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
            throw new IllegalStateException("incorrect errors; actual=" + actual + "; expected=" + expected);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36994
diff changeset
   340
    public void testRuntime2Compile(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
        Path classpathSrc = base.resolve("classpath-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
        Path classpathOut = base.resolve("classpath-out");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
        tb.writeJavaFiles(classpathSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   345
                          generateCheckAccessibleClass("cp.CP"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        Files.createDirectories(classpathOut);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 40835
diff changeset
   349
        System.err.println("Compiling classpath-src files:");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   350
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
                .outdir(classpathOut)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
                .files(findJavaFiles(classpathSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   355
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   356
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
        Path automaticSrc = base.resolve("automatic-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
        Path automaticOut = base.resolve("automatic-out");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
        tb.writeJavaFiles(automaticSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
                          generateCheckAccessibleClass("automatic.Automatic"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
        Files.createDirectories(automaticOut);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   364
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 40835
diff changeset
   365
        System.err.println("Compiling automatic-src files:");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   366
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
                .outdir(automaticOut)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
                .files(findJavaFiles(automaticSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   369
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   371
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   372
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
        Path automaticJar = modulePath.resolve("automatic.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   378
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 40835
diff changeset
   379
        System.err.println("Creating automatic.jar:");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   380
        new JarTask(tb, automaticJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   381
          .baseDir(automaticOut)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
          .files("automatic/Automatic.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   386
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   388
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   389
                          "module m1x { exports api; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   390
                          "package api; public class Api { public void test() { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   391
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 40835
diff changeset
   392
        System.err.println("Compiling module-src files:");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   393
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   394
                .options("--module-source-path", moduleSrc.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   399
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   401
        int index = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   403
        for (String moduleInfo : MODULE_INFO_VARIANTS) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
            for (String[] options : OPTIONS_VARIANTS) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   405
                index++;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 40835
diff changeset
   407
                System.err.println("Running check: " + moduleInfo + "; " + Arrays.asList(options));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   409
                Path m2Runtime = base.resolve(index + "-runtime").resolve("m2x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   410
                Path out = base.resolve(index + "-runtime").resolve("out").resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   411
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
                Files.createDirectories(out);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   413
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
                StringBuilder testClassNamed = new StringBuilder();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   415
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
                testClassNamed.append("package test;\n" +
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
                                      "public class Test {\n" +
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   418
                                      "    public static void main(String... args) throws Exception {\n");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   420
                for (Entry<String, String> e : MODULES_TO_CHECK_TO_SAMPLE_CLASS.entrySet()) {
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43772
diff changeset
   421
                    testClassNamed.append("        System.err.println(\"visible:" + e.getKey() + ":\" + ModuleLayer.boot().findModule(\"" + e.getKey() + "\").isPresent());\n");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   422
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   424
                testClassNamed.append("        Class<?> cp = Class.forName(Test.class.getClassLoader().getUnnamedModule(), \"cp.CP\");\n");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   425
                testClassNamed.append("        cp.getDeclaredMethod(\"runMe\").invoke(null);\n");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   426
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43772
diff changeset
   427
                testClassNamed.append("        Class<?> automatic = Class.forName(ModuleLayer.boot().findModule(\"automatic\").get(), \"automatic.Automatic\");\n");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   428
                testClassNamed.append("        automatic.getDeclaredMethod(\"runMe\").invoke(null);\n");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   429
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   430
                testClassNamed.append("    }\n" +
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   431
                                      "}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   432
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   433
                tb.writeJavaFiles(m2Runtime, moduleInfo, testClassNamed.toString());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   434
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 40835
diff changeset
   435
                System.err.println("Compiling " + m2Runtime + " files:");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   436
                new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   437
                   .options("--module-path", modulePath.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   438
                   .outdir(out)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   439
                   .files(findJavaFiles(m2Runtime))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   440
                   .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   441
                   .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   442
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   443
                boolean success;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   444
                String output;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   445
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   446
                try {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   447
                    System.err.println("Running m2x/test.Test:");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   448
                    output = new JavaTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   449
                       .vmOptions(augmentOptions(options,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   450
                                                 Collections.emptyList(),
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   451
                                                 "--module-path", modulePath.toString() + File.pathSeparator + out.getParent().toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   452
                                                 "--class-path", classpathOut.toString(),
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   453
                                                 "--add-reads", "m2x=ALL-UNNAMED,automatic",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   454
                                                 "-m", "m2x/test.Test"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   455
                       .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   456
                       .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   457
                       .getOutput(Task.OutputKind.STDERR);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   458
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   459
                    success = true;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   460
                } catch (Task.TaskError err) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   461
                    success = false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   462
                    output = "";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   463
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   464
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   465
                Path m2 = base.resolve(String.valueOf(index)).resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   466
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   467
                tb.writeJavaFiles(m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   468
                                  moduleInfo,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   469
                                  "package test;\n" +
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   470
                                  "public class Test {}\n");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   471
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   472
                List<String> auxOptions = success ? Arrays.asList(
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   473
                    "--processor-path", System.getProperty("test.class.path"),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   474
                    "-processor", CheckVisibleModule.class.getName(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   475
                    "-Aoutput=" + output,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   476
                    "-XDaccessInternalAPI=true"
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   477
                ) : Collections.emptyList();
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 40835
diff changeset
   478
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   479
                System.err.println("Compiling/processing m2x files:");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   480
                new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   481
                   .options(augmentOptions(options,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   482
                                           auxOptions,
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   483
                                           "--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   484
                                           "--class-path", classpathOut.toString(),
40835
6ab9ed1abc46 8162546: change hidden options -Xdebug to --debug, -XshouldStop to --should-stop, and -diags to --diags
vromero
parents: 40308
diff changeset
   485
                                           "--should-stop:ifNoError=FLOW"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   486
                   .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   487
                   .files(findJavaFiles(m2))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   488
                   .run(success ? Task.Expect.SUCCESS : Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   489
                   .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   490
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   491
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   492
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   493
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   494
    private String generateCheckAccessibleClass(String fqn) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   495
        String packageName = fqn.substring(0, fqn.lastIndexOf('.'));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   496
        String simpleName = fqn.substring(fqn.lastIndexOf('.') + 1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   497
        StringBuilder checkClassesAccessible = new StringBuilder();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   498
        checkClassesAccessible.append("package " + packageName + ";" +
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   499
                                      "public class " + simpleName + " {" +
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   500
                                      "    public static void runMe() throws Exception {");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   501
        for (Entry<String, String> e : MODULES_TO_CHECK_TO_SAMPLE_CLASS.entrySet()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   502
            checkClassesAccessible.append("try {");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   503
            checkClassesAccessible.append("Class.forName(\"" + e.getValue() + "\").newInstance();");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   504
            checkClassesAccessible.append("System.err.println(\"" + fqn + ":" + e.getKey() + ":true\");");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   505
            checkClassesAccessible.append("} catch (Exception ex) {");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   506
            checkClassesAccessible.append("System.err.println(\"" + fqn + ":" + e.getKey() + ":false\");");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   507
            checkClassesAccessible.append("}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   508
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   509
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   510
        checkClassesAccessible.append("    }\n" +
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   511
                                      "}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   512
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   513
        return checkClassesAccessible.toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   514
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   515
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   516
    private static final Map<String, String> MODULES_TO_CHECK_TO_SAMPLE_CLASS = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   517
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   518
    static {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   519
        MODULES_TO_CHECK_TO_SAMPLE_CLASS.put("m1x", "api.Api");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   520
        MODULES_TO_CHECK_TO_SAMPLE_CLASS.put("m2x", "test.Test");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   521
        MODULES_TO_CHECK_TO_SAMPLE_CLASS.put("java.base", "java.lang.Object");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   522
    };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   523
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   524
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   525
    @SupportedOptions("output")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   526
    public static final class CheckVisibleModule extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   527
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   528
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   529
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   530
            String expected = processingEnv.getOptions().get("output");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   531
            Set<String> expectedElements = new HashSet<>(Arrays.asList(expected.split(System.getProperty("line.separator"))));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   532
            Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   533
            Symtab syms = Symtab.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   534
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   535
            for (Entry<String, String> e : MODULES_TO_CHECK_TO_SAMPLE_CLASS.entrySet()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   536
                String module = e.getKey();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   537
                ModuleElement mod = processingEnv.getElementUtils().getModuleElement(module);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   538
                String visible = "visible:" + module + ":" + (mod != null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   539
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   540
                if (!expectedElements.contains(visible)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   541
                    throw new AssertionError("actual: " + visible + "; expected: " + expected);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   542
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   543
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   544
                JavacElements javacElements = JavacElements.instance(context);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   545
                ClassSymbol unnamedClass = javacElements.getTypeElement(syms.unnamedModule, e.getValue());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   546
                String unnamed = "cp.CP:" + module + ":" + (unnamedClass != null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   547
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   548
                if (!expectedElements.contains(unnamed)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   549
                    throw new AssertionError("actual: " + unnamed + "; expected: " + expected);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   550
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   551
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   552
                ModuleElement automaticMod = processingEnv.getElementUtils().getModuleElement("automatic");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   553
                ClassSymbol automaticClass = javacElements.getTypeElement(automaticMod, e.getValue());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   554
                String automatic = "automatic.Automatic:" + module + ":" + (automaticClass != null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   555
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   556
                if (!expectedElements.contains(automatic)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   557
                    throw new AssertionError("actual: " + automatic + "; expected: " + expected);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   558
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   559
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   560
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   561
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   562
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   563
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   564
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   565
        public SourceVersion getSupportedSourceVersion() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   566
            return SourceVersion.latest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   567
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   568
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   569
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   570
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   571
    public String[] augmentOptions(String[] options, List<String> auxOptions, String... baseOptions) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   572
        List<String> all = new ArrayList<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   573
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   574
        all.addAll(Arrays.asList(options));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   575
        all.addAll(Arrays.asList(baseOptions));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   576
        all.addAll(auxOptions);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   577
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   578
        return all.toArray(new String[0]);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   579
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   580
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   581
    private static final String[] MODULE_INFO_VARIANTS = {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   582
        "module m2x { exports test; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   583
        "module m2x { requires m1x; exports test; }"
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   584
    };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   585
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   586
    private static final String[][] OPTIONS_VARIANTS = {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   587
        {"--add-modules", "automatic"},
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   588
        {"--add-modules", "m1x,automatic"},
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   589
        {"--add-modules", "jdk.compiler,automatic"},
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   590
        {"--add-modules", "m1x,jdk.compiler,automatic"},
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   591
        {"--add-modules", "ALL-SYSTEM,automatic"},
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   592
        {"--limit-modules", "java.base", "--add-modules", "automatic"},
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   593
        {"--limit-modules", "java.base", "--add-modules", "ALL-SYSTEM,automatic"},
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   594
        {"--limit-modules", "m2x", "--add-modules", "automatic"},
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39601
diff changeset
   595
        {"--limit-modules", "jdk.compiler", "--add-modules", "automatic"},
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   596
    };
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   597
}