langtools/test/tools/javac/modules/AddReadsTest.java
author jjg
Tue, 22 Nov 2016 15:57:32 -0800
changeset 42269 24a766b7c106
parent 41938 8e66bf10fcec
child 42822 a84956e7ee4d
permissions -rw-r--r--
8164590: javac --inherit-runtime-environment fails with "cannot find modules: ALL-DEFAULT" Reviewed-by: mchung
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
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    26
 * @summary Test the --add-reads option
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *          jdk.jdeps/com.sun.tools.javap
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
    31
 *          java.desktop
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    32
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 * @run main AddReadsTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import javax.annotation.processing.AbstractProcessor;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import javax.annotation.processing.RoundEnvironment;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import javax.annotation.processing.SupportedAnnotationTypes;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import javax.lang.model.SourceVersion;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import javax.lang.model.element.ModuleElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import javax.lang.model.element.ModuleElement.RequiresDirective;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import javax.lang.model.element.TypeElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import javax.lang.model.util.ElementFilter;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    49
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    50
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    51
import toolbox.JavapTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    52
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    53
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
public class AddReadsTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        new AddReadsTest().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    61
    public void testAddReads(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                          "module m1 { exports api; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                          "package api; public class Api { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        Path src_m2 = src.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        tb.writeJavaFiles(src_m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
                          "module m2 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
                          "package test; public class Test extends api.Api { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    74
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    76
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    79
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    81
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
    83
        checkOutputContains(log,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
    84
            "Test.java:1:44: compiler.err.not.def.access.package.cant.access: api.Api, api");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        //test add dependencies:
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    87
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    88
                .options("--add-reads", "m2=m1",
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    89
                         "--module-source-path", src.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                         "-processor", VerifyRequires.class.getName())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    96
        String decompiled = new JavapTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                .options("-verbose", classes.resolve("m2").resolve("module-info.class").toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                .run()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    99
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        if (decompiled.contains("m1")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
            throw new Exception("Incorrectly refers to m1 module.");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        //cyclic dependencies OK when created through addReads:
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   106
        new JavacTask(tb)
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   107
                .options("--add-reads", "m2=m1",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   108
                         "--add-reads", "m1=m2",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   109
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        tb.writeJavaFiles(src_m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                          "module m2 { requires m1; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   118
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   119
                .options("--add-reads", "m1=m2",
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   120
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    public static final class VerifyRequires extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            ModuleElement m2Module = processingEnv.getElementUtils().getModuleElement("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            if (m2Module == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                throw new AssertionError("Cannot find the m2 module!");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            boolean foundM1 = false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
            for (RequiresDirective rd : ElementFilter.requiresIn(m2Module.getDirectives())) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                foundM1 |= rd.getDependency().getSimpleName().contentEquals("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
            if (!foundM1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                throw new AssertionError("Cannot find the dependency on m1 module!");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        public SourceVersion getSupportedSourceVersion() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            return SourceVersion.latest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   154
    public void testAddReadsUnnamedModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        Path jar = prepareTestJar(base);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                          "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                          "package impl; public class Impl { api.Api api; }");
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: 37758
diff changeset
   169
          .options("--class-path", jar.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   170
                   "--add-reads", "m1=ALL-UNNAMED",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                   "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
          .files(findJavaFiles(moduleSrc))
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
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   179
    public void testAddReadsUnnamedModulePackageConflict(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        Path jar = prepareTestJar(base);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                          "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                          "package api; public class Api { public static void test() { } }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                          "package impl; public class Impl { { api.Api.test(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   194
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   195
          .options("--class-path", jar.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   196
                   "--module-source-path", moduleSrc.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   197
                   "--add-reads", "m1=ALL-UNNAMED",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                   "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
          .files(m1.resolve("impl").resolve("Impl.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
          .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   206
    public void testAddReadsUnnamedToJavaBase(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        Path jar = prepareTestJar(base);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                          "package impl; public class Impl { api.Api a; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   216
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   217
          .options("--class-path", jar.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   218
                   "--add-reads", "java.base=ALL-UNNAMED",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                   "-Xmodule:java.base")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
          .files(src.resolve("impl").resolve("Impl.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
          .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   227
    public void testAddReadsToJavaBase(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                          "package impl; public class Impl { javax.swing.JButton b; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   236
        new JavacTask(tb)
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   237
          .options("--add-modules", "java.desktop",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   238
                   "--add-reads", "java.base=java.desktop",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                   "-Xmodule:java.base")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
          .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
          .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
          .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
    private Path prepareTestJar(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        Path legacySrc = base.resolve("legacy-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        tb.writeJavaFiles(legacySrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                          "package api; public abstract class Api {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        Path legacyClasses = base.resolve("legacy-classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
        Files.createDirectories(legacyClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   253
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
                .options()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .outdir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
                .files(findJavaFiles(legacySrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   259
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        if (!log.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
            throw new Exception("unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        Path lib = base.resolve("lib");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
        Files.createDirectories(lib);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        Path jar = lib.resolve("test-api-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   271
        new JarTask(tb, jar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
          .baseDir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
          .files("api/Api.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        return jar;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   280
    public void testX(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
                          "module m1 { provides java.lang.Runnable with impl.Impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
                          "package impl; public class Impl implements Runnable { public void run() { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   289
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   290
                .options("--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
        Path unnamedSrc = base.resolve("unnamed-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
        Path unnamedClasses = base.resolve("unnamed-classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
        Files.createDirectories(unnamedClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
        tb.writeJavaFiles(unnamedSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
                          "package impl; public class Impl { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   304
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   305
          .options("--add-reads", "m1=ALL-UNNAMED",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
                   "-Xmodule:m1",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   307
                   "--module-path", classes.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
          .outdir(unnamedClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
          .files(findJavaFiles(unnamedSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
          .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
          .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
    }
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   313
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   314
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   315
    public void testAddSelf(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   316
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   317
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   318
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   319
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   320
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   321
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   322
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   323
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   324
        new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   325
                .options("--module-source-path", src.toString(),
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   326
                         "--add-reads", "m1=m1")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   327
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   328
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   329
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   330
                .writeAll();
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   331
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   332
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   333
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   334
    public void testEmpty(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   335
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   336
        tb.writeJavaFiles(src, "class Dummy { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   337
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   338
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   339
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   340
        testEmpty(src, classes, "--add-reads", "");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   341
        testEmpty(src, classes, "--add-reads=");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   342
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   343
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   344
    private void testEmpty(Path src, Path classes, String... options) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   345
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   346
                .options(options)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   347
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   348
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   349
                .run(Task.Expect.FAIL)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   350
                .writeAll()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   351
                .getOutput(Task.OutputKind.DIRECT);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   352
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   353
        checkOutputContains(log,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   354
            "javac: no value for --add-reads option");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   355
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   356
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   357
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   358
    public void testEmptyItem(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   359
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   360
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   361
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   362
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   363
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   364
        Path src_m2 = src.resolve("m2");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   365
        tb.writeJavaFiles(src_m2,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   366
                          "module m2 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   367
                          "package p2; class C2 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   368
        Path src_m3 = src.resolve("m3");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   369
        tb.writeJavaFiles(src_m3,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   370
                          "module m3 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   371
                          "package p3; class C3 { p1.C1 c1; }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   372
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   373
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   374
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   375
        testEmptyItem(src, classes, "m3=,m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   376
        testEmptyItem(src, classes, "m3=m1,,m2");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   377
        testEmptyItem(src, classes, "m3=m1,");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   378
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   379
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   380
    private void testEmptyItem(Path src, Path classes, String option) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   381
        new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   382
                .options("--module-source-path", src.toString(),
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   383
                         "--add-reads", option)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   384
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   385
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   386
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   387
                .writeAll();
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   388
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   389
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   390
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   391
    public void testEmptyList(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   392
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   393
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   394
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   395
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   396
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   397
        Path src_m2 = src.resolve("m2");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   398
        tb.writeJavaFiles(src_m2,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   399
                          "module m2 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   400
                          "package p2; class C2 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   401
        Path src_m3 = src.resolve("m3");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   402
        tb.writeJavaFiles(src_m3,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   403
                          "module m3 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   404
                          "package p3; class C3 { p1.C1 c1; }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   405
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   406
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   407
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   408
        testEmptyList(src, classes, "m3=");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   409
        testEmptyList(src, classes, "m3=,");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   410
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   411
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   412
    private void testEmptyList(Path src, Path classes, String option) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   413
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   414
                .options("--module-source-path", src.toString(),
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   415
                         "--add-reads", option)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   416
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   417
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   418
                .run(Task.Expect.FAIL)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   419
                .writeAll()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   420
                .getOutput(Task.OutputKind.DIRECT);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   421
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   422
        checkOutputContains(log,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   423
            "javac: bad value for --add-reads option: '" + option + "'");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   424
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   425
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   426
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   427
    public void testMultipleAddReads_DifferentModules(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   428
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   429
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   430
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   431
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   432
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   433
        Path src_m2 = src.resolve("m2");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   434
        tb.writeJavaFiles(src_m2,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   435
                          "module m2 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   436
                          "package p2; class C2 { p1.C1 c1; }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   437
        Path src_m3 = src.resolve("m3");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   438
        tb.writeJavaFiles(src_m3,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   439
                          "module m3 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   440
                          "package p3; class C3 { p1.C1 c1; }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   441
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   442
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   443
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   444
        new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   445
                .options("--module-source-path", src.toString(),
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   446
                         "--add-reads", "m2=m1",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   447
                         "--add-reads", "m3=m1")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   448
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   449
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   450
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   451
                .writeAll();
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   452
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   453
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   454
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   455
    public void testMultipleAddReads_SameModule(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   456
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   457
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   458
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   459
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   460
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   461
        Path src_m2 = src.resolve("m2");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   462
        tb.writeJavaFiles(src_m2,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   463
                          "module m2 { exports p2; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   464
                          "package p2; public class C2 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   465
        Path src_m3 = src.resolve("m3");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   466
        tb.writeJavaFiles(src_m3,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   467
                          "module m3 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   468
                          "package p3; class C3 { p1.C1 c1; p2.C2 c2; }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   469
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   470
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   471
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   472
        new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   473
                .options("--module-source-path", src.toString(),
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   474
                         "--add-reads", "m3=m1",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   475
                         "--add-reads", "m3=m2")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   476
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   477
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   478
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   479
                .writeAll();
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   480
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   481
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   482
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   483
    public void testDuplicateAddReads_SameOption(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   484
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   485
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   486
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   487
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   488
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   489
        Path src_m2 = src.resolve("m2");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   490
        tb.writeJavaFiles(src_m2,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   491
                          "module m2 { exports p2; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   492
                          "package p2; class C2 { p1.C1 c1; }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   493
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   494
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   495
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   496
        new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   497
                .options("--module-source-path", src.toString(),
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   498
                         "--add-reads", "m2=m1,m1")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   499
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   500
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   501
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   502
                .writeAll();
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   503
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   504
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   505
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   506
    public void testDuplicateAddReads_MultipleOptions(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   507
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   508
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   509
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   510
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   511
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   512
        Path src_m2 = src.resolve("m2");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   513
        tb.writeJavaFiles(src_m2,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   514
                          "module m2 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   515
                          "package p2; class C2 { p1.C1 c1; }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   516
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   517
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   518
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   519
        new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   520
                .options("--module-source-path", src.toString(),
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   521
                         "--add-reads", "m2=m1",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   522
                         "--add-reads", "m2=m1")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   523
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   524
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   525
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   526
                .writeAll();
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   527
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   528
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   529
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   530
    public void testRepeatedAddReads(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   531
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   532
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   533
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   534
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   535
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   536
        Path src_m2 = src.resolve("m2");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   537
        tb.writeJavaFiles(src_m2,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   538
                          "module m2 { exports p2; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   539
                          "package p2; public class C2 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   540
        Path src_m3 = src.resolve("m3");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   541
        tb.writeJavaFiles(src_m3,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   542
                          "module m3 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   543
                          "package p3; class C3 { p1.C1 c1; p2.C2 c2; }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   544
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   545
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   546
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   547
        new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   548
                .options("--module-source-path", src.toString(),
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   549
                         "--add-reads", "m3=m1",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   550
                         "--add-reads", "m3=m2")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   551
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   552
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   553
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   554
                .writeAll();
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   555
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   556
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   557
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   558
    public void testNoEquals(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   559
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   560
        tb.writeJavaFiles(src, "class Dummy { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   561
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   562
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   563
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   564
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   565
                .options("-XDrawDiagnostics",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   566
                         "--add-reads", "m1:m2")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   567
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   568
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   569
                .run(Task.Expect.FAIL)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   570
                .writeAll()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   571
                .getOutput(Task.OutputKind.DIRECT);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   572
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   573
        checkOutputContains(log,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   574
            "javac: bad value for --add-reads option: 'm1:m2'");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   575
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   576
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   577
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   578
    public void testBadSourceName(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   579
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   580
        tb.writeJavaFiles(src, "class Dummy { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   581
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   582
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   583
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   584
        String log = new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   585
                .options("-XDrawDiagnostics",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   586
                         "--add-reads", "bad*Source=m2")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   587
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   588
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   589
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   590
                .writeAll()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   591
                .getOutput(Task.OutputKind.DIRECT);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   592
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   593
        checkOutputContains(log,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   594
            "- compiler.warn.bad.name.for.option: --add-reads, bad*Source");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   595
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   596
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   597
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   598
    public void testBadTargetName(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   599
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   600
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   601
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   602
                          "module m1 { }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   603
                          "package p1; class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   604
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   605
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   606
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   607
        String log = new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   608
                .options("-XDrawDiagnostics",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   609
                         "--add-reads", "m1=badTarget!")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   610
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   611
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   612
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   613
                .writeAll()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   614
                .getOutput(Task.OutputKind.DIRECT);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   615
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   616
        checkOutputContains(log,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   617
            "- compiler.warn.bad.name.for.option: --add-reads, badTarget!");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   618
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   619
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   620
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   621
    public void testSourceNameNotFound(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   622
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   623
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   624
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   625
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   626
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   627
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   628
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   629
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   630
        String log = new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   631
                .options("-XDrawDiagnostics",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   632
                         "--add-reads", "missingSource=m1")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   633
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   634
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   635
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   636
                .writeAll()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   637
                .getOutput(Task.OutputKind.DIRECT);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   638
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   639
        checkOutputContains(log,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   640
            "- compiler.warn.module.for.option.not.found: --add-reads, missingSource");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   641
    }
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   642
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   643
    @Test
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   644
    public void testTargetNameNotFound(Path base) throws Exception {
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   645
        Path src = base.resolve("src");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   646
        Path src_m1 = src.resolve("m1");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   647
        tb.writeJavaFiles(src_m1,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   648
                          "module m1 { exports p1; }",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   649
                          "package p1; public class C1 { }");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   650
        Path classes = base.resolve("classes");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   651
        tb.createDirectories(classes);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   652
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   653
        String log = new JavacTask(tb)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   654
                .options("-XDrawDiagnostics",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   655
                         "--add-reads", "m1=missingTarget")
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   656
                .outdir(classes)
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   657
                .files(findJavaFiles(src))
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   658
                .run()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   659
                .writeAll()
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   660
                .getOutput(Task.OutputKind.DIRECT);
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   661
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   662
        checkOutputContains(log,
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   663
            "- compiler.warn.module.for.option.not.found: --add-reads, missingTarget");
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   664
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   665
}