langtools/test/tools/javac/modules/IncubatingTest.java
author alanb
Fri, 07 Apr 2017 08:08:26 +0000
changeset 44573 245bb4e6f983
parent 43270 de9a02e20567
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: jjg Contributed-by: alan.bateman@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43270
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
     1
/*
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
     4
 *
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
     8
 *
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    14
 *
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    18
 *
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    21
 * questions.
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    22
 */
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    23
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    24
/*
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    25
 * @test
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    26
 * @bug 8171177
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    27
 * @summary Verify that ModuleResolution attribute flags are honored.
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    28
 * @library /tools/lib
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    31
 *          jdk.jdeps/com.sun.tools.classfile
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    32
 *          jdk.jdeps/com.sun.tools.javap
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask ModuleTestBase
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    34
 * @run main IncubatingTest
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    35
 */
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    36
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    37
import java.io.IOException;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    38
import java.io.OutputStream;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    39
import java.net.URI;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    40
import java.nio.file.FileSystem;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    41
import java.nio.file.FileSystems;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    42
import java.nio.file.Files;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    43
import java.nio.file.Path;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    44
import java.util.ArrayList;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    45
import java.util.Arrays;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    46
import java.util.HashMap;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    47
import java.util.List;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    48
import java.util.Map;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    49
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    50
import com.sun.tools.classfile.Attribute;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    51
import com.sun.tools.classfile.Attributes;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    52
import com.sun.tools.classfile.ClassFile;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    53
import com.sun.tools.classfile.ClassWriter;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    54
import com.sun.tools.classfile.ConstantPool;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    55
import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    56
import com.sun.tools.classfile.ConstantPool.CPInfo;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    57
import com.sun.tools.classfile.ModuleResolution_attribute;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    58
import toolbox.JavacTask;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    59
import toolbox.Task;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    60
import toolbox.Task.Expect;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    61
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    62
public class IncubatingTest extends ModuleTestBase {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    63
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    64
    public static void main(String... args) throws Exception {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    65
        new IncubatingTest().runTests();
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    66
    }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    67
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    68
    @Test
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    69
    public void testDoNotResolve(Path base) throws Exception {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    70
        Path src = base.resolve("src");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    71
        tb.writeJavaFiles(src,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    72
                          "module jdk.i { exports api; }",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    73
                          "package api; public class Api { }");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    74
        Path classes = base.resolve("classes");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    75
        Files.deleteIfExists(classes);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    76
        Path iClasses = classes.resolve("jdk.i");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    77
        tb.createDirectories(iClasses);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    78
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    79
        new JavacTask(tb)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    80
                .outdir(iClasses)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    81
                .files(findJavaFiles(src))
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    82
                .run()
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    83
                .writeAll();
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    84
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    85
        copyJavaBase(classes);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    86
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    87
        Path jdkIModuleInfo = iClasses.resolve("module-info.class");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    88
        addModuleResolutionAttribute(jdkIModuleInfo, ModuleResolution_attribute.DO_NOT_RESOLVE_BY_DEFAULT);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    89
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    90
        Path testSrc = base.resolve("test-src");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    91
        tb.writeJavaFiles(testSrc,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    92
                          "class T { api.Api api; }");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    93
        Path testClasses = base.resolve("test-classes");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    94
        tb.createDirectories(testClasses);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    95
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    96
        List<String> log;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    97
        List<String> expected;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    98
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
    99
        log = new JavacTask(tb)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   100
                .options("--system", "none",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   101
                         "--upgrade-module-path", classes.toString(),
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   102
                         "-XDrawDiagnostics")
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   103
                .outdir(testClasses)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   104
                .files(findJavaFiles(testSrc))
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   105
                .run(Expect.FAIL)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   106
                .writeAll()
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   107
                .getOutputLines(Task.OutputKind.DIRECT);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   108
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   109
        expected = Arrays.asList(
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   110
                "T.java:1:11: compiler.err.package.not.visible: api, (compiler.misc.not.def.access.does.not.read.from.unnamed: api, jdk.i)",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   111
                "1 error"
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   112
        );
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   113
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   114
        if (!expected.equals(log)) {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   115
            throw new AssertionError("Unexpected output: " + log);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   116
        }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   117
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   118
        log = new JavacTask(tb)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   119
                .options("--system", "none",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   120
                         "--upgrade-module-path", classes.toString(),
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   121
                         "--add-modules", "ALL-SYSTEM",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   122
                         "-XDrawDiagnostics")
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   123
                .outdir(testClasses)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   124
                .files(findJavaFiles(testSrc))
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43270
diff changeset
   125
                .run(Expect.SUCCESS)
43270
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   126
                .writeAll()
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   127
                .getOutputLines(Task.OutputKind.DIRECT);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   128
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43270
diff changeset
   129
        expected = Arrays.asList("");
43270
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   130
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   131
        if (!expected.equals(log)) {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   132
            throw new AssertionError("Unexpected output: " + log);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   133
        }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   134
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   135
        new JavacTask(tb)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   136
                .options("--system", "none",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   137
                         "--upgrade-module-path", classes.toString(),
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   138
                         "--add-modules", "jdk.i")
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   139
                .outdir(testClasses)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   140
                .files(findJavaFiles(testSrc))
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   141
                .run()
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   142
                .writeAll();
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   143
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   144
        Path testModuleSrc = base.resolve("test-module-src");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   145
        tb.writeJavaFiles(testModuleSrc,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   146
                          "module test { requires jdk.i; }", //explicit requires of an incubating module
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   147
                          "class T { api.Api api; }");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   148
        Path testModuleClasses = base.resolve("test-module-classes");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   149
        tb.createDirectories(testModuleClasses);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   150
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   151
        new JavacTask(tb)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   152
                .options("--system", "none",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   153
                         "--upgrade-module-path", classes.toString())
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   154
                .outdir(testModuleClasses)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   155
                .files(findJavaFiles(testModuleSrc))
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   156
                .run()
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   157
                .writeAll();
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   158
    }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   159
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   160
    @Test
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   161
    public void testIncubating(Path base) throws Exception {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   162
        Path src = base.resolve("src");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   163
        tb.writeJavaFiles(src,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   164
                          "module jdk.i { exports api; }",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   165
                          "package api; public class Api { }");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   166
        Path classes = base.resolve("classes");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   167
        Files.deleteIfExists(classes);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   168
        Path iClasses = classes.resolve("jdk.i");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   169
        tb.createDirectories(iClasses);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   170
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   171
        new JavacTask(tb)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   172
                .outdir(iClasses)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   173
                .files(findJavaFiles(src))
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   174
                .run()
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   175
                .writeAll();
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   176
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   177
        Path jdkIModuleInfo = iClasses.resolve("module-info.class");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   178
        addModuleResolutionAttribute(jdkIModuleInfo, ModuleResolution_attribute.WARN_INCUBATING);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   179
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   180
        Path testSrc = base.resolve("test-src");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   181
        tb.writeJavaFiles(testSrc,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   182
                          "class T { api.Api api; }");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   183
        Path testClasses = base.resolve("test-classes");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   184
        tb.createDirectories(testClasses);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   185
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   186
        List<String> log;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   187
        List<String> expected;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   188
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   189
        log = new JavacTask(tb)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   190
                .options("--module-path", classes.toString(),
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   191
                         "--add-modules", "jdk.i",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   192
                         "-XDrawDiagnostics",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   193
                         "-Werror")
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   194
                .outdir(testClasses)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   195
                .files(findJavaFiles(testSrc))
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   196
                .run(Expect.FAIL)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   197
                .writeAll()
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   198
                .getOutputLines(Task.OutputKind.DIRECT);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   199
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   200
        expected = Arrays.asList(
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   201
                "- compiler.warn.incubating.modules: jdk.i",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   202
                "- compiler.err.warnings.and.werror",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   203
                "1 error",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   204
                "1 warning"
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   205
        );
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   206
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   207
        if (!expected.equals(log)) {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   208
            throw new AssertionError("Unexpected output: " + log);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   209
        }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   210
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   211
        Path testModuleSrc = base.resolve("test-module-src");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   212
        tb.writeJavaFiles(testModuleSrc,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   213
                          "module test { requires jdk.i; }", //explicit requires of an incubating module
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   214
                          "class T { api.Api api; }");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   215
        Path testModuleClasses = base.resolve("test-module-classes");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   216
        tb.createDirectories(testModuleClasses);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   217
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   218
        log = new JavacTask(tb)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   219
                .options("--module-path", classes.toString(),
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   220
                         "-XDrawDiagnostics",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   221
                         "-Werror")
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   222
                .outdir(testModuleClasses)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   223
                .files(findJavaFiles(testModuleSrc))
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   224
                .run(Expect.FAIL)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   225
                .writeAll()
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   226
                .getOutputLines(Task.OutputKind.DIRECT);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   227
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   228
        expected = Arrays.asList(
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   229
                "- compiler.warn.incubating.modules: jdk.i",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   230
                "- compiler.err.warnings.and.werror",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   231
                "1 error",
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   232
                "1 warning"
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   233
        );
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   234
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   235
        if (!expected.equals(log)) {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   236
            throw new AssertionError("Unexpected output: " + log);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   237
        }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   238
    }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   239
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   240
    private void copyJavaBase(Path targetDir) throws IOException {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   241
        FileSystem jrt = FileSystems.getFileSystem(URI.create("jrt:/"));
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   242
        Path javaBase = jrt.getPath("modules", "java.base");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   243
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   244
        if (!Files.exists(javaBase)) {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   245
            throw new AssertionError("No java.base?");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   246
        }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   247
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   248
        Path javaBaseClasses = targetDir.resolve("java.base");
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   249
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   250
        for (Path clazz : tb.findFiles("class", javaBase)) {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   251
            Path target = javaBaseClasses.resolve(javaBase.relativize(clazz).toString());
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   252
            Files.createDirectories(target.getParent());
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   253
            Files.copy(clazz, target);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   254
        }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   255
    }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   256
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   257
    private void addModuleResolutionAttribute(Path classfile, int resolution_flags) throws Exception {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   258
        ClassFile cf = ClassFile.read(classfile);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   259
        Attributes attrs = cf.attributes;
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   260
        List<CPInfo> cpData = new ArrayList<>();
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   261
        cpData.add(null);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   262
        for (CPInfo info : cf.constant_pool.entries()) {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   263
            cpData.add(info);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   264
            if (info.size() == 2)
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   265
                cpData.add(null);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   266
        }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   267
        cpData.add(new CONSTANT_Utf8_info(Attribute.ModuleResolution));
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   268
        ConstantPool newCP = new ConstantPool(cpData.toArray(new CPInfo[0]));
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   269
        ModuleResolution_attribute res = new ModuleResolution_attribute(newCP, resolution_flags);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   270
        Map<String, Attribute> newAttributeMap = new HashMap<>(attrs.map);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   271
        newAttributeMap.put(Attribute.ModuleResolution, res);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   272
        Attributes newAttrs = new Attributes(newAttributeMap);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   273
        ClassFile newCF = new ClassFile(cf.magic,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   274
                                        cf.minor_version,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   275
                                        cf.major_version,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   276
                                        newCP,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   277
                                        cf.access_flags,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   278
                                        cf.this_class,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   279
                                        cf.super_class,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   280
                                        cf.interfaces,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   281
                                        cf.fields,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   282
                                        cf.methods,
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   283
                                        newAttrs);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   284
        try (OutputStream out = Files.newOutputStream(classfile)) {
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   285
            new ClassWriter().write(newCF, out);
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   286
        }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   287
    }
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
diff changeset
   288
}