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