langtools/test/tools/javac/modules/AutomaticModules.java
author alanb
Fri, 07 Apr 2017 08:08:26 +0000
changeset 44573 245bb4e6f983
parent 43138 680d378b9d64
child 44576 9e18c9ce29e7
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: jjg Contributed-by: alan.bateman@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
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
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
    26
 * @bug 8155026
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @summary Test automatic modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @modules
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
    30
 *      java.desktop
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 *      jdk.compiler/com.sun.tools.javac.main
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JavacTask toolbox.JarTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 * @run main AutomaticModules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.nio.file.Path;
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
    39
import java.util.Arrays;
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
    40
import java.util.List;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    42
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    43
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    44
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    45
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
public class AutomaticModules extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        AutomaticModules t = new AutomaticModules();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    54
    public void testSimple(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        Path legacySrc = base.resolve("legacy-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        tb.writeJavaFiles(legacySrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
                          "package api; import java.awt.event.ActionListener; public abstract class Api implements ActionListener {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        Path legacyClasses = base.resolve("legacy-classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        Files.createDirectories(legacyClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    61
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                .options()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                .outdir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
                .files(findJavaFiles(legacySrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    67
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        if (!log.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
            throw new Exception("unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        Path jar = modulePath.resolve("test-api-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    79
        new JarTask(tb, jar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
          .baseDir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
          .files("api/Api.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    85
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    92
                          "module m1x { requires test.api; requires java.desktop; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                          "package impl; public class Impl { public void e(api.Api api) { api.actionPerformed(null); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    95
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
    96
                .options("--module-source-path", moduleSrc.toString(), "--module-path", modulePath.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   104
    public void testUnnamedModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        Path legacySrc = base.resolve("legacy-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        tb.writeJavaFiles(legacySrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                          "package api; public abstract class Api { public void run(CharSequence str) { } private void run(base.Base base) { } }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                          "package base; public interface Base { public void run(); }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        Path legacyClasses = base.resolve("legacy-classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        Files.createDirectories(legacyClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   112
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                .options()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                .outdir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                .files(findJavaFiles(legacySrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   118
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        if (!log.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
            throw new Exception("unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        Path apiJar = modulePath.resolve("test-api-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   130
        new JarTask(tb, apiJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
          .baseDir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
          .files("api/Api.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        Path baseJar = base.resolve("base.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   137
        new JarTask(tb, baseJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
          .baseDir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
          .files("base/Base.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   143
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   150
                          "module m1x { requires test.api; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                          "package impl; public class Impl { public void e(api.Api api) { api.run(\"\"); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   153
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   154
                .options("--module-source-path", moduleSrc.toString(), "--module-path", modulePath.toString(), "--class-path", baseJar.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   162
    public void testModuleInfoFromClassFileDependsOnAutomatic(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        Path automaticSrc = base.resolve("automaticSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        tb.writeJavaFiles(automaticSrc, "package api; public class Api {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        Path automaticClasses = base.resolve("automaticClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        tb.createDirectories(automaticClasses);
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
        String automaticLog = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                                .outdir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                                .files(findJavaFiles(automaticSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   173
                                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
        if (!automaticLog.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
            throw new Exception("expected output not found: " + automaticLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        Path automaticJar = modulePath.resolve("automatic-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   184
        new JarTask(tb, automaticJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
          .baseDir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
          .files("api/Api.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        Path depSrc = base.resolve("depSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        Path depClasses = base.resolve("depClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        Files.createDirectories(depSrc);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        Files.createDirectories(depClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        tb.writeJavaFiles(depSrc,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   196
                          "module m1x { requires transitive automatic; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                          "package dep; public class Dep { api.Api api; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   199
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   200
                .options("--module-path", modulePath.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                .outdir(depClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
                .files(findJavaFiles(depSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   206
        Path moduleJar = modulePath.resolve("m1x.jar");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   208
        new JarTask(tb, moduleJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
          .baseDir(depClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
          .files("module-info.class", "dep/Dep.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        Path testSrc = base.resolve("testSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        Path testClasses = base.resolve("testClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        Files.createDirectories(testSrc);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        Files.createDirectories(testClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        tb.writeJavaFiles(testSrc,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   220
                          "module m2x { requires automatic; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                          "package test; public class Test { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   223
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   224
                .options("--module-path", modulePath.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
                .outdir(testClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
                .files(findJavaFiles(testSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
    }
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   230
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   231
    @Test
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   232
    public void testAutomaticAndNamedModules(Path base) throws Exception {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   233
        Path modulePath = base.resolve("module-path");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   234
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   235
        Files.createDirectories(modulePath);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   236
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   237
        for (char c : new char[] {'A', 'B'}) {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   238
            Path automaticSrc = base.resolve("automaticSrc" + c);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   239
            tb.writeJavaFiles(automaticSrc, "package api" + c + "; public class Api {}");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   240
            Path automaticClasses = base.resolve("automaticClasses" + c);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   241
            tb.createDirectories(automaticClasses);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   242
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   243
            String automaticLog = new JavacTask(tb)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   244
                                    .outdir(automaticClasses)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   245
                                    .files(findJavaFiles(automaticSrc))
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   246
                                    .run()
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   247
                                    .writeAll()
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   248
                                    .getOutput(Task.OutputKind.DIRECT);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   249
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   250
            if (!automaticLog.isEmpty())
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   251
                throw new Exception("expected output not found: " + automaticLog);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   252
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   253
            Path automaticJar = modulePath.resolve("automatic" + c + "-1.0.jar");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   254
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   255
            new JarTask(tb, automaticJar)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   256
              .baseDir(automaticClasses)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   257
              .files("api" + c + "/Api.class")
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   258
              .run();
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   259
        }
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   260
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   261
        Path moduleSrc = base.resolve("module-src");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   262
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   263
        tb.writeJavaFiles(moduleSrc.resolve("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   264
                          "module m1x { requires static automaticA; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   265
                          "package impl; public class Impl { apiA.Api a; apiB.Api b; m2x.M2 m;}");
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   266
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   267
        tb.writeJavaFiles(moduleSrc.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   268
                          "module m2x { exports m2x; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   269
                          "package m2x; public class M2 { }");
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   270
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   271
        Path classes = base.resolve("classes");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   272
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   273
        Files.createDirectories(classes);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   274
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   275
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   276
                .options("--module-source-path", moduleSrc.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   277
                         "--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   278
                         "--add-modules", "automaticB",
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   279
                         "-XDrawDiagnostics")
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   280
                .outdir(classes)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   281
                .files(findJavaFiles(moduleSrc))
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   282
                .run(Task.Expect.FAIL)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   283
                .writeAll()
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   284
                .getOutputLines(Task.OutputKind.DIRECT);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   285
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42822
diff changeset
   286
        List<String> expected = Arrays.asList("Impl.java:1:59: compiler.err.package.not.visible: m2x, (compiler.misc.not.def.access.does.not.read: m1x, m2x, m2x)",
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   287
                                              "1 error");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   288
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   289
        if (!expected.equals(log)) {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   290
            throw new Exception("expected output not found: " + log);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   291
        }
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   292
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   293
        log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   294
                .options("--module-source-path", moduleSrc.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   295
                         "--module-path", modulePath.toString(),
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   296
                         "-XDrawDiagnostics")
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   297
                .outdir(classes)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   298
                .files(findJavaFiles(moduleSrc))
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   299
                .run(Task.Expect.FAIL)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   300
                .writeAll()
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   301
                .getOutputLines(Task.OutputKind.DIRECT);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   302
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   303
        expected = Arrays.asList("Impl.java:1:59: compiler.err.package.not.visible: m2x, (compiler.misc.not.def.access.does.not.read: m1x, m2x, m2x)",
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   304
                                 "1 error");
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   305
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   306
        if (!expected.equals(log)) {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   307
            throw new Exception("expected output not found: " + log);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   308
        }
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   309
    }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   310
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   311
    @Test
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   312
    public void testWithTrailingVersion(Path base) throws Exception {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   313
        Path legacySrc = base.resolve("legacy-src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   314
        tb.writeJavaFiles(legacySrc,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   315
                          "package api; public class Api {}");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   316
        Path legacyClasses = base.resolve("legacy-classes");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   317
        Files.createDirectories(legacyClasses);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   318
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   319
        String log = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   320
                .options()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   321
                .outdir(legacyClasses)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   322
                .files(findJavaFiles(legacySrc))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   323
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   324
                .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   325
                .getOutput(Task.OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   326
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   327
        if (!log.isEmpty()) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   328
            throw new Exception("unexpected output: " + log);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   329
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   330
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   331
        Path modulePath = base.resolve("module-path");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   332
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   333
        Files.createDirectories(modulePath);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   334
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   335
        Path jar = modulePath.resolve("test1.jar");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   336
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   337
        new JarTask(tb, jar)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   338
          .baseDir(legacyClasses)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   339
          .files("api/Api.class")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   340
          .run();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   341
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   342
        Path moduleSrc = base.resolve("module-src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   343
        Path m = moduleSrc.resolve("m");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   344
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   345
        Path classes = base.resolve("classes");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   346
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   347
        Files.createDirectories(classes);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   348
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   349
        tb.writeJavaFiles(m,
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   350
                          "module m { requires test1; }",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   351
                          "package impl; public class Impl { public void e(api.Api api) { } }");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   352
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   353
        new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   354
                .options("--module-source-path", moduleSrc.toString(), "--module-path", modulePath.toString())
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   355
                .outdir(classes)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   356
                .files(findJavaFiles(moduleSrc))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   357
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   358
                .writeAll();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   359
    }
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   360
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   361
    @Test
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   362
    public void testMultipleAutomatic(Path base) throws Exception {
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   363
        Path modulePath = base.resolve("module-path");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   364
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   365
        Files.createDirectories(modulePath);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   366
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   367
        for (char c : new char[] {'A', 'B'}) {
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   368
            Path automaticSrc = base.resolve("automaticSrc" + c);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   369
            tb.writeJavaFiles(automaticSrc, "package api" + c + "; public class Api {}");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   370
            Path automaticClasses = base.resolve("automaticClasses" + c);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   371
            tb.createDirectories(automaticClasses);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   372
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   373
            String automaticLog = new JavacTask(tb)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   374
                                    .outdir(automaticClasses)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   375
                                    .files(findJavaFiles(automaticSrc))
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   376
                                    .run()
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   377
                                    .writeAll()
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   378
                                    .getOutput(Task.OutputKind.DIRECT);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   379
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   380
            if (!automaticLog.isEmpty())
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   381
                throw new Exception("expected output not found: " + automaticLog);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   382
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   383
            Path automaticJar = modulePath.resolve("automatic" + c + "-1.0.jar");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   384
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   385
            new JarTask(tb, automaticJar)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   386
              .baseDir(automaticClasses)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   387
              .files("api" + c + "/Api.class")
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   388
              .run();
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   389
        }
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   390
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   391
        Path src = base.resolve("src");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   392
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   393
        tb.writeJavaFiles(src.resolve("m1x"),
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   394
                          "package impl; public class Impl { apiA.Api a; apiB.Api b; }");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   395
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   396
        Path classes = base.resolve("classes");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   397
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   398
        Files.createDirectories(classes);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   399
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   400
        List<String> log = new JavacTask(tb)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   401
                .options("--module-path", modulePath.toString(),
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   402
                         "-XDrawDiagnostics")
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   403
                .outdir(classes)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   404
                .files(findJavaFiles(src))
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   405
                .run(Task.Expect.FAIL)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   406
                .writeAll()
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   407
                .getOutputLines(Task.OutputKind.DIRECT);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   408
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   409
        List<String> expected = Arrays.asList("Impl.java:1:35: compiler.err.package.not.visible: apiA, (compiler.misc.not.def.access.does.not.read.from.unnamed: apiA, automaticA)",
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   410
                                              "Impl.java:1:47: compiler.err.package.not.visible: apiB, (compiler.misc.not.def.access.does.not.read.from.unnamed: apiB, automaticB)",
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   411
                                              "2 errors");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   412
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   413
        if (!expected.equals(log)) {
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   414
            throw new Exception("expected output not found: " + log);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   415
        }
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   416
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   417
        new JavacTask(tb)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   418
                .options("--module-path", modulePath.toString(),
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   419
                         "--add-modules", "automaticA",
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   420
                         "-XDrawDiagnostics")
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   421
                .outdir(classes)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   422
                .files(findJavaFiles(src))
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   423
                .run()
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   424
                .writeAll();
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   425
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   426
}