langtools/test/tools/javac/modules/AutomaticModules.java
author alanb
Fri, 16 Jun 2017 09:21:38 -0700
changeset 45682 fc3b228b9e2a
parent 44576 9e18c9ce29e7
permissions -rw-r--r--
8181087: Module system implementation refresh (6/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
44576
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
    26
 * @bug 8155026 8178011
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
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
    37
import java.io.File;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.nio.file.Path;
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
    40
import java.util.Arrays;
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
    41
import java.util.List;
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
    42
import java.util.zip.ZipEntry;
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
    43
import java.util.zip.ZipOutputStream;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    45
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    46
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    47
import toolbox.Task;
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
    48
import toolbox.Task.Mode;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    49
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
public class AutomaticModules extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        AutomaticModules t = new AutomaticModules();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    58
    public void testSimple(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        Path legacySrc = base.resolve("legacy-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        tb.writeJavaFiles(legacySrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                          "package api; import java.awt.event.ActionListener; public abstract class Api implements ActionListener {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        Path legacyClasses = base.resolve("legacy-classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        Files.createDirectories(legacyClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    65
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                .options()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                .outdir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                .files(findJavaFiles(legacySrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    71
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        if (!log.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
            throw new Exception("unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        Path jar = modulePath.resolve("test-api-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    83
        new JarTask(tb, jar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
          .baseDir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
          .files("api/Api.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    89
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    96
                          "module m1x { requires test.api; requires java.desktop; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                          "package impl; public class Impl { public void e(api.Api api) { api.actionPerformed(null); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    99
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   100
                .options("--module-source-path", moduleSrc.toString(), "--module-path", modulePath.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   108
    public void testUnnamedModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        Path legacySrc = base.resolve("legacy-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        tb.writeJavaFiles(legacySrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                          "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
   112
                          "package base; public interface Base { public void run(); }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        Path legacyClasses = base.resolve("legacy-classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        Files.createDirectories(legacyClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   116
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .options()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                .outdir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                .files(findJavaFiles(legacySrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   122
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        if (!log.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
            throw new Exception("unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        Path apiJar = modulePath.resolve("test-api-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   134
        new JarTask(tb, apiJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
          .baseDir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
          .files("api/Api.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        Path baseJar = base.resolve("base.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   141
        new JarTask(tb, baseJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
          .baseDir(legacyClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
          .files("base/Base.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   147
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   154
                          "module m1x { requires test.api; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                          "package impl; public class Impl { public void e(api.Api api) { api.run(\"\"); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   157
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   158
                .options("--module-source-path", moduleSrc.toString(), "--module-path", modulePath.toString(), "--class-path", baseJar.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   166
    public void testModuleInfoFromClassFileDependsOnAutomatic(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        Path automaticSrc = base.resolve("automaticSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        tb.writeJavaFiles(automaticSrc, "package api; public class Api {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        Path automaticClasses = base.resolve("automaticClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        tb.createDirectories(automaticClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   172
        String automaticLog = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                                .outdir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                                .files(findJavaFiles(automaticSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   177
                                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        if (!automaticLog.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
            throw new Exception("expected output not found: " + automaticLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        Path automaticJar = modulePath.resolve("automatic-1.0.jar");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   188
        new JarTask(tb, automaticJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
          .baseDir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
          .files("api/Api.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        Path depSrc = base.resolve("depSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        Path depClasses = base.resolve("depClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        Files.createDirectories(depSrc);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        Files.createDirectories(depClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        tb.writeJavaFiles(depSrc,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   200
                          "module m1x { requires transitive automatic; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                          "package dep; public class Dep { api.Api api; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   203
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   204
                .options("--module-path", modulePath.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
                .outdir(depClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
                .files(findJavaFiles(depSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   210
        Path moduleJar = modulePath.resolve("m1x.jar");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   212
        new JarTask(tb, moduleJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
          .baseDir(depClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
          .files("module-info.class", "dep/Dep.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        Path testSrc = base.resolve("testSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        Path testClasses = base.resolve("testClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        Files.createDirectories(testSrc);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        Files.createDirectories(testClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        tb.writeJavaFiles(testSrc,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   224
                          "module m2x { requires automatic; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
                          "package test; public class Test { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   227
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   228
                .options("--module-path", modulePath.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
                .outdir(testClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                .files(findJavaFiles(testSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    }
39366
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
    @Test
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   236
    public void testAutomaticAndNamedModules(Path base) throws Exception {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   237
        Path modulePath = base.resolve("module-path");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   238
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   239
        Files.createDirectories(modulePath);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   240
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   241
        for (char c : new char[] {'A', 'B'}) {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   242
            Path automaticSrc = base.resolve("automaticSrc" + c);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   243
            tb.writeJavaFiles(automaticSrc, "package api" + c + "; public class Api {}");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   244
            Path automaticClasses = base.resolve("automaticClasses" + c);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   245
            tb.createDirectories(automaticClasses);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   246
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   247
            String automaticLog = new JavacTask(tb)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   248
                                    .outdir(automaticClasses)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   249
                                    .files(findJavaFiles(automaticSrc))
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   250
                                    .run()
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   251
                                    .writeAll()
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   252
                                    .getOutput(Task.OutputKind.DIRECT);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   253
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   254
            if (!automaticLog.isEmpty())
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   255
                throw new Exception("expected output not found: " + automaticLog);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   256
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   257
            Path automaticJar = modulePath.resolve("automatic" + c + "-1.0.jar");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   258
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   259
            new JarTask(tb, automaticJar)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   260
              .baseDir(automaticClasses)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   261
              .files("api" + c + "/Api.class")
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   262
              .run();
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   263
        }
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   264
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   265
        Path moduleSrc = base.resolve("module-src");
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("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   268
                          "module m1x { requires static automaticA; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   269
                          "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
   270
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   271
        tb.writeJavaFiles(moduleSrc.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   272
                          "module m2x { exports m2x; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   273
                          "package m2x; public class M2 { }");
39366
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
        Path classes = base.resolve("classes");
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   276
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   277
        Files.createDirectories(classes);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   278
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   279
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   280
                .options("--module-source-path", moduleSrc.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   281
                         "--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   282
                         "--add-modules", "automaticB",
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   283
                         "-XDrawDiagnostics")
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   284
                .outdir(classes)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   285
                .files(findJavaFiles(moduleSrc))
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   286
                .run(Task.Expect.FAIL)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   287
                .writeAll()
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   288
                .getOutputLines(Task.OutputKind.DIRECT);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   289
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42822
diff changeset
   290
        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
   291
                                              "1 error");
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
        if (!expected.equals(log)) {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   294
            throw new Exception("expected output not found: " + log);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   295
        }
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   296
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   297
        log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   298
                .options("--module-source-path", moduleSrc.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39366
diff changeset
   299
                         "--module-path", modulePath.toString(),
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   300
                         "-XDrawDiagnostics")
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   301
                .outdir(classes)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   302
                .files(findJavaFiles(moduleSrc))
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   303
                .run(Task.Expect.FAIL)
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   304
                .writeAll()
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   305
                .getOutputLines(Task.OutputKind.DIRECT);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   306
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   307
        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
   308
                                 "1 error");
39366
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   309
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   310
        if (!expected.equals(log)) {
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   311
            throw new Exception("expected output not found: " + log);
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   312
        }
8bf5fe72ca88 8155026: javac grants implied readability to explicit modules
jlahoda
parents: 37758
diff changeset
   313
    }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   314
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   315
    @Test
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   316
    public void testWithTrailingVersion(Path base) throws Exception {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   317
        Path legacySrc = base.resolve("legacy-src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   318
        tb.writeJavaFiles(legacySrc,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   319
                          "package api; public class Api {}");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   320
        Path legacyClasses = base.resolve("legacy-classes");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   321
        Files.createDirectories(legacyClasses);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   322
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   323
        String log = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   324
                .options()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   325
                .outdir(legacyClasses)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   326
                .files(findJavaFiles(legacySrc))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   327
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   328
                .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   329
                .getOutput(Task.OutputKind.DIRECT);
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
        if (!log.isEmpty()) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   332
            throw new Exception("unexpected output: " + log);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   333
        }
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 modulePath = base.resolve("module-path");
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
        Files.createDirectories(modulePath);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   338
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   339
        Path jar = modulePath.resolve("test1.jar");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   340
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   341
        new JarTask(tb, jar)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   342
          .baseDir(legacyClasses)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   343
          .files("api/Api.class")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   344
          .run();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   345
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   346
        Path moduleSrc = base.resolve("module-src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   347
        Path m = moduleSrc.resolve("m");
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
        Path classes = base.resolve("classes");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   350
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   351
        Files.createDirectories(classes);
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
        tb.writeJavaFiles(m,
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   354
                          "module m { requires test1; }",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   355
                          "package impl; public class Impl { public void e(api.Api api) { } }");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   356
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   357
        new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   358
                .options("--module-source-path", moduleSrc.toString(), "--module-path", modulePath.toString())
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   359
                .outdir(classes)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   360
                .files(findJavaFiles(moduleSrc))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   361
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   362
                .writeAll();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   363
    }
44573
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
    @Test
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   366
    public void testMultipleAutomatic(Path base) throws Exception {
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   367
        Path modulePath = base.resolve("module-path");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   368
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   369
        Files.createDirectories(modulePath);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   370
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   371
        for (char c : new char[] {'A', 'B'}) {
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   372
            Path automaticSrc = base.resolve("automaticSrc" + c);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   373
            tb.writeJavaFiles(automaticSrc, "package api" + c + "; public class Api {}");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   374
            Path automaticClasses = base.resolve("automaticClasses" + c);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   375
            tb.createDirectories(automaticClasses);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   376
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   377
            String automaticLog = new JavacTask(tb)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   378
                                    .outdir(automaticClasses)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   379
                                    .files(findJavaFiles(automaticSrc))
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   380
                                    .run()
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   381
                                    .writeAll()
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   382
                                    .getOutput(Task.OutputKind.DIRECT);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   383
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   384
            if (!automaticLog.isEmpty())
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   385
                throw new Exception("expected output not found: " + automaticLog);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   386
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   387
            Path automaticJar = modulePath.resolve("automatic" + c + "-1.0.jar");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   388
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   389
            new JarTask(tb, automaticJar)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   390
              .baseDir(automaticClasses)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   391
              .files("api" + c + "/Api.class")
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   392
              .run();
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   393
        }
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   394
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   395
        Path src = base.resolve("src");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   396
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   397
        tb.writeJavaFiles(src.resolve("m1x"),
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   398
                          "package impl; public class Impl { apiA.Api a; apiB.Api b; }");
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
        Path classes = base.resolve("classes");
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   401
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   402
        Files.createDirectories(classes);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   403
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   404
        List<String> log = new JavacTask(tb)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   405
                .options("--module-path", modulePath.toString(),
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   406
                         "-XDrawDiagnostics")
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   407
                .outdir(classes)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   408
                .files(findJavaFiles(src))
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   409
                .run(Task.Expect.FAIL)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   410
                .writeAll()
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   411
                .getOutputLines(Task.OutputKind.DIRECT);
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
        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
   414
                                              "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
   415
                                              "2 errors");
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
        if (!expected.equals(log)) {
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   418
            throw new Exception("expected output not found: " + log);
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   419
        }
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   420
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   421
        new JavacTask(tb)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   422
                .options("--module-path", modulePath.toString(),
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   423
                         "--add-modules", "automaticA",
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   424
                         "-XDrawDiagnostics")
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   425
                .outdir(classes)
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   426
                .files(findJavaFiles(src))
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   427
                .run()
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   428
                .writeAll();
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43138
diff changeset
   429
    }
44576
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   430
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   431
    @Test
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   432
    public void testLintRequireAutomatic(Path base) throws Exception {
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   433
        Path modulePath = base.resolve("module-path");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   434
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   435
        Files.createDirectories(modulePath);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   436
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   437
        for (char c : new char[] {'A', 'B'}) {
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   438
            Path automaticSrc = base.resolve("automaticSrc" + c);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   439
            tb.writeJavaFiles(automaticSrc, "package api" + c + "; public class Api {}");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   440
            Path automaticClasses = base.resolve("automaticClasses" + c);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   441
            tb.createDirectories(automaticClasses);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   442
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   443
            String automaticLog = new JavacTask(tb)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   444
                                    .outdir(automaticClasses)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   445
                                    .files(findJavaFiles(automaticSrc))
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   446
                                    .run()
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   447
                                    .writeAll()
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   448
                                    .getOutput(Task.OutputKind.DIRECT);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   449
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   450
            if (!automaticLog.isEmpty())
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   451
                throw new Exception("expected output not found: " + automaticLog);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   452
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   453
            Path automaticJar = modulePath.resolve("automatic" + c + "-1.0.jar");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   454
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   455
            new JarTask(tb, automaticJar)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   456
              .baseDir(automaticClasses)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   457
              .files("api" + c + "/Api.class")
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   458
              .run();
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   459
        }
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   460
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   461
        Path src = base.resolve("src");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   462
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   463
        tb.writeJavaFiles(src,
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   464
                          "module m1x {\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   465
                          "    requires transitive automaticA;\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   466
                          "    requires automaticB;\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   467
                          "}");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   468
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   469
        Path classes = base.resolve("classes");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   470
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   471
        Files.createDirectories(classes);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   472
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   473
        List<String> expected;
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   474
        List<String> log;
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   475
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   476
        log = new JavacTask(tb)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   477
            .options("--source-path", src.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   478
                     "--module-path", modulePath.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   479
                     "-XDrawDiagnostics",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   480
                     "-Werror")
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   481
            .outdir(classes)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   482
            .files(findJavaFiles(src))
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   483
            .run(Task.Expect.FAIL)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   484
            .writeAll()
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   485
            .getOutputLines(Task.OutputKind.DIRECT);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   486
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   487
        expected = Arrays.asList("module-info.java:2:25: compiler.warn.requires.transitive.automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   488
                                 "- compiler.err.warnings.and.werror",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   489
                                 "1 error",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   490
                                 "1 warning");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   491
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   492
        if (!expected.equals(log)) {
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   493
            throw new Exception("expected output not found: " + log);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   494
        }
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   495
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   496
        log = new JavacTask(tb)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   497
            .options("--source-path", src.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   498
                     "--module-path", modulePath.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   499
                     "-Xlint:requires-automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   500
                     "-XDrawDiagnostics",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   501
                     "-Werror")
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   502
            .outdir(classes)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   503
            .files(findJavaFiles(src))
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   504
            .run(Task.Expect.FAIL)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   505
            .writeAll()
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   506
            .getOutputLines(Task.OutputKind.DIRECT);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   507
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   508
        expected = Arrays.asList("module-info.java:2:25: compiler.warn.requires.transitive.automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   509
                                 "module-info.java:3:14: compiler.warn.requires.automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   510
                                 "- compiler.err.warnings.and.werror",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   511
                                 "1 error",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   512
                                 "2 warnings");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   513
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   514
        if (!expected.equals(log)) {
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   515
            throw new Exception("expected output not found: " + log);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   516
        }
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   517
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   518
        log = new JavacTask(tb)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   519
            .options("--source-path", src.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   520
                     "--module-path", modulePath.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   521
                     "-Xlint:-requires-transitive-automatic,requires-automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   522
                     "-XDrawDiagnostics",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   523
                     "-Werror")
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   524
            .outdir(classes)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   525
            .files(findJavaFiles(src))
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   526
            .run(Task.Expect.FAIL)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   527
            .writeAll()
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   528
            .getOutputLines(Task.OutputKind.DIRECT);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   529
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   530
        expected = Arrays.asList("module-info.java:2:25: compiler.warn.requires.automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   531
                                 "module-info.java:3:14: compiler.warn.requires.automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   532
                                 "- compiler.err.warnings.and.werror",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   533
                                 "1 error",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   534
                                 "2 warnings");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   535
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   536
        if (!expected.equals(log)) {
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   537
            throw new Exception("expected output not found: " + log);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   538
        }
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   539
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   540
        new JavacTask(tb)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   541
            .options("--source-path", src.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   542
                     "--module-path", modulePath.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   543
                     "-Xlint:-requires-transitive-automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   544
                     "-XDrawDiagnostics",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   545
                     "-Werror")
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   546
            .outdir(classes)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   547
            .files(findJavaFiles(src))
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   548
            .run(Task.Expect.SUCCESS)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   549
            .writeAll()
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   550
            .getOutputLines(Task.OutputKind.DIRECT);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   551
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   552
        tb.writeJavaFiles(src,
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   553
                          "@SuppressWarnings(\"requires-transitive-automatic\")\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   554
                          "module m1x {\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   555
                          "    requires transitive automaticA;\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   556
                          "    requires automaticB;\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   557
                          "}");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   558
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   559
        new JavacTask(tb)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   560
            .options("--source-path", src.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   561
                     "--module-path", modulePath.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   562
                     "-XDrawDiagnostics",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   563
                     "-Werror")
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   564
            .outdir(classes)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   565
            .files(findJavaFiles(src))
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   566
            .run(Task.Expect.SUCCESS)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   567
            .writeAll()
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   568
            .getOutputLines(Task.OutputKind.DIRECT);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   569
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   570
        log = new JavacTask(tb)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   571
            .options("--source-path", src.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   572
                     "--module-path", modulePath.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   573
                     "-Xlint:requires-automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   574
                     "-XDrawDiagnostics",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   575
                     "-Werror")
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   576
            .outdir(classes)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   577
            .files(findJavaFiles(src))
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   578
            .run(Task.Expect.FAIL)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   579
            .writeAll()
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   580
            .getOutputLines(Task.OutputKind.DIRECT);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   581
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   582
        expected = Arrays.asList("module-info.java:3:25: compiler.warn.requires.automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   583
                                 "module-info.java:4:14: compiler.warn.requires.automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   584
                                 "- compiler.err.warnings.and.werror",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   585
                                 "1 error",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   586
                                 "2 warnings");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   587
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   588
        if (!expected.equals(log)) {
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   589
            throw new Exception("expected output not found: " + log);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   590
        }
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   591
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   592
        tb.writeJavaFiles(src,
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   593
                          "@SuppressWarnings(\"requires-automatic\")\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   594
                          "module m1x {\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   595
                          "    requires transitive automaticA;\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   596
                          "    requires automaticB;\n" +
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   597
                          "}");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   598
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   599
        log = new JavacTask(tb)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   600
            .options("--source-path", src.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   601
                     "--module-path", modulePath.toString(),
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   602
                     "-Xlint:requires-automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   603
                     "-XDrawDiagnostics",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   604
                     "-Werror")
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   605
            .outdir(classes)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   606
            .files(findJavaFiles(src))
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   607
            .run(Task.Expect.FAIL)
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   608
            .writeAll()
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   609
            .getOutputLines(Task.OutputKind.DIRECT);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   610
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   611
        expected = Arrays.asList("module-info.java:3:25: compiler.warn.requires.transitive.automatic",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   612
                                 "- compiler.err.warnings.and.werror",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   613
                                 "1 error",
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   614
                                 "1 warning");
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   615
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   616
        if (!expected.equals(log)) {
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   617
            throw new Exception("expected output not found: " + log);
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   618
        }
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   619
    }
9e18c9ce29e7 8178011: Automatic module warnings
jlahoda
parents: 44573
diff changeset
   620
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   621
    @Test
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   622
    public void testAutomaticModuleNameCorrect(Path base) throws Exception {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   623
        Path modulePath = base.resolve("module-path");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   624
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   625
        Files.createDirectories(modulePath);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   626
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   627
        Path automaticSrc = base.resolve("automaticSrc");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   628
        tb.writeJavaFiles(automaticSrc, "package api; public class Api {}");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   629
        Path automaticClasses = base.resolve("automaticClasses");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   630
        tb.createDirectories(automaticClasses);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   631
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   632
        String automaticLog = new JavacTask(tb)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   633
                                .outdir(automaticClasses)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   634
                                .files(findJavaFiles(automaticSrc))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   635
                                .run()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   636
                                .writeAll()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   637
                                .getOutput(Task.OutputKind.DIRECT);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   638
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   639
        if (!automaticLog.isEmpty())
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   640
            throw new Exception("expected output not found: " + automaticLog);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   641
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   642
        Path automaticJar = modulePath.resolve("automatic-1.0.jar");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   643
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   644
        new JarTask(tb, automaticJar)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   645
          .baseDir(automaticClasses)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   646
          .files("api/Api.class")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   647
          .manifest("Automatic-Module-Name: custom.module.name\n\n")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   648
          .run();
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   649
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   650
        Path src = base.resolve("src");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   651
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   652
        tb.writeJavaFiles(src,
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   653
                          "module m { requires custom.module.name; }",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   654
                          "package impl; public class Impl { api.Api a; }");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   655
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   656
        Path classes = base.resolve("classes");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   657
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   658
        Files.createDirectories(classes);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   659
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   660
        new JavacTask(tb)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   661
                .options("--module-path", modulePath.toString(),
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   662
                         "-XDrawDiagnostics")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   663
                .outdir(classes)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   664
                .files(findJavaFiles(src))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   665
                .run(Task.Expect.SUCCESS)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   666
                .writeAll()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   667
                .getOutputLines(Task.OutputKind.DIRECT);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   668
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   669
        tb.writeJavaFiles(src,
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   670
                          "module m { requires automatic; }");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   671
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   672
        List<String> log = new JavacTask(tb)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   673
                .options("--module-path", modulePath.toString(),
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   674
                         "-XDrawDiagnostics")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   675
                .outdir(classes)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   676
                .files(findJavaFiles(src))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   677
                .run(Task.Expect.FAIL)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   678
                .writeAll()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   679
                .getOutputLines(Task.OutputKind.DIRECT);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   680
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   681
        List<String> expected =
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   682
                Arrays.asList("module-info.java:1:21: compiler.err.module.not.found: automatic",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   683
                              "1 error");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   684
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   685
        if (!expected.equals(log)) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   686
            throw new Exception("expected output not found: " + log);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   687
        }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   688
    }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   689
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   690
    @Test
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   691
    public void testAutomaticModuleNameIncorrect(Path base) throws Exception {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   692
        for (String name : new String[] {"", "999", "foo.class", "foo._"}) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   693
            if (Files.isDirectory(base)) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   694
                tb.cleanDirectory(base);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   695
            }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   696
            Path modulePath = base.resolve("module-path");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   697
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   698
            Files.createDirectories(modulePath);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   699
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   700
            Path automaticSrc = base.resolve("automaticSrc");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   701
            tb.writeJavaFiles(automaticSrc, "package api; public class Api {}");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   702
            Path automaticClasses = base.resolve("automaticClasses");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   703
            tb.createDirectories(automaticClasses);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   704
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   705
            String automaticLog = new JavacTask(tb)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   706
                                    .outdir(automaticClasses)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   707
                                    .files(findJavaFiles(automaticSrc))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   708
                                    .run()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   709
                                    .writeAll()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   710
                                    .getOutput(Task.OutputKind.DIRECT);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   711
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   712
            if (!automaticLog.isEmpty())
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   713
                throw new Exception("expected output not found: " + automaticLog);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   714
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   715
            Path automaticJar = modulePath.resolve("automatic-1.0.jar");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   716
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   717
            new JarTask(tb, automaticJar)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   718
              .baseDir(automaticClasses)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   719
              .files("api/Api.class")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   720
              .manifest("Automatic-Module-Name: " + name + "\n\n")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   721
              .run();
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   722
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   723
            Path src = base.resolve("src");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   724
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   725
            tb.writeJavaFiles(src,
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   726
                              "package impl; public class Impl { api.Api a; }");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   727
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   728
            Path classes = base.resolve("classes");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   729
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   730
            Files.createDirectories(classes);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   731
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   732
            List<String> log = new JavacTask(tb, Mode.CMDLINE)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   733
                    .options("--module-path", modulePath.toString(),
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   734
                             "--add-modules", "ALL-MODULE-PATH",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   735
                             "-XDrawDiagnostics")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   736
                    .outdir(classes)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   737
                    .files(findJavaFiles(src))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   738
                    .run(Task.Expect.FAIL)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   739
                    .writeAll()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   740
                    .getOutputLines(Task.OutputKind.DIRECT);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   741
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   742
            List<String> expected =
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   743
                    Arrays.asList("- compiler.err.locn.cant.get.module.name.for.jar: " +
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   744
                                      "testAutomaticModuleNameIncorrect/module-path/automatic-1.0.jar".replace("/", File.separator),
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   745
                                  "1 error");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   746
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   747
            if (!expected.equals(log)) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   748
                throw new Exception("expected output not found: " + log);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   749
            }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   750
        }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   751
    }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   752
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   753
    @Test
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   754
    public void testAutomaticModuleNameBroken(Path base) throws Exception {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   755
        Path modulePath = base.resolve("module-path");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   756
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   757
        Files.createDirectories(modulePath);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   758
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   759
        Path automaticSrc = base.resolve("automaticSrc");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   760
        tb.writeJavaFiles(automaticSrc, "package api; public class Api {}");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   761
        Path automaticClasses = base.resolve("automaticClasses");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   762
        tb.createDirectories(automaticClasses);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   763
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   764
        String automaticLog = new JavacTask(tb)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   765
                                .outdir(automaticClasses)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   766
                                .files(findJavaFiles(automaticSrc))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   767
                                .run()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   768
                                .writeAll()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   769
                                .getOutput(Task.OutputKind.DIRECT);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   770
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   771
        if (!automaticLog.isEmpty())
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   772
            throw new Exception("expected output not found: " + automaticLog);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   773
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   774
        Path automaticJar = modulePath.resolve("automatic-1.0.jar");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   775
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   776
        try (ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(automaticJar))) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   777
            out.putNextEntry(new ZipEntry("api/Api.class"));
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   778
            Files.copy(automaticClasses.resolve("api").resolve("Api.class"), out);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   779
        }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   780
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   781
        Path src = base.resolve("src");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   782
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   783
        tb.writeJavaFiles(src,
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   784
                          "module m { requires automatic; }",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   785
                          "package impl; public class Impl { api.Api a; }");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   786
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   787
        Path classes = base.resolve("classes");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   788
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   789
        Files.createDirectories(classes);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   790
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   791
        new JavacTask(tb)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   792
                .options("--module-path", modulePath.toString(),
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   793
                         "-XDrawDiagnostics")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   794
                .outdir(classes)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   795
                .files(findJavaFiles(src))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   796
                .run(Task.Expect.SUCCESS)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   797
                .writeAll()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   798
                .getOutputLines(Task.OutputKind.DIRECT);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   799
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   800
        tb.writeJavaFiles(src,
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   801
                          "module m { requires custom.module.name; }");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   802
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   803
        List<String> log = new JavacTask(tb)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   804
                .options("--module-path", modulePath.toString(),
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   805
                         "-XDrawDiagnostics")
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   806
                .outdir(classes)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   807
                .files(findJavaFiles(src))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   808
                .run(Task.Expect.FAIL)
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   809
                .writeAll()
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   810
                .getOutputLines(Task.OutputKind.DIRECT);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   811
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   812
        List<String> expected =
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   813
                Arrays.asList("module-info.java:1:34: compiler.err.module.not.found: custom.module.name",
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   814
                              "1 error");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   815
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   816
        if (!expected.equals(log)) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   817
            throw new Exception("expected output not found: " + log);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   818
        }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   819
    }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44576
diff changeset
   820
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   821
}