test/jdk/jdk/modules/etc/DefaultModules.java
author alanb
Tue, 19 Nov 2019 11:35:29 +0000
changeset 59133 580fb715b29d
parent 51675 b487c1e914d0
permissions -rw-r--r--
8233922: Service binding augments module graph with observable incubator modules Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50738
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
     1
/*
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
     4
 *
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
     8
 *
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    13
 * accompanied this code).
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    14
 *
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    18
 *
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    21
 * questions.
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    22
 */
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    23
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    24
/**
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    25
 * @test
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    26
 * @bug 8197532
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    27
 * @modules jdk.compiler
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    28
 *          jdk.jlink
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    29
 *          jdk.zipfs
51675
b487c1e914d0 8210112: remove jdk.testlibrary.ProcessTools
iignatyev
parents: 50738
diff changeset
    30
 * @library src /test/lib
50738
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    31
 * @build java.json/*
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    32
 * @run main DefaultModules
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    33
 * @summary Test that all modules that export an API are in the set of modules
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    34
 *          resolved when compiling or running code on the class path
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    35
 */
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    36
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    37
import java.io.PrintStream;
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    38
import java.nio.file.Files;
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    39
import java.nio.file.Path;
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    40
import java.util.spi.ToolProvider;
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    41
51675
b487c1e914d0 8210112: remove jdk.testlibrary.ProcessTools
iignatyev
parents: 50738
diff changeset
    42
import jdk.test.lib.process.ProcessTools;
50738
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    43
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    44
/**
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    45
 * This test compiles and runs the following tests on the class path:
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    46
 *
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    47
 *   TestRootModules.java.java - tests that every module that exports an API
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    48
 *       is resolved. Also tests that java.se is not resolved.
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    49
 *
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    50
 *   TestJson.java - exercises APIs exported by the java.json module. The
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    51
 *       java.json module is not a Java SE module.
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    52
 */
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    53
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    54
public class DefaultModules {
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    55
    private static final PrintStream out = System.out;
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    56
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    57
    public static void main(String[] args) throws Exception {
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    58
        String javaHome = System.getProperty("java.home");
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    59
        String testSrc = System.getProperty("test.src");
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    60
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    61
        // $JDK_HOME/bin/java TestModules.java
59133
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents: 51675
diff changeset
    62
        String source = Path.of(testSrc, "TestRootModules.java").toString();
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents: 51675
diff changeset
    63
        ProcessTools.executeTestJava("--add-exports", "java.base/jdk.internal.module=ALL-UNNAMED", source)
50738
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    64
                .outputTo(System.out)
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    65
                .errorTo(System.err)
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    66
                .shouldHaveExitValue(0);
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    67
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    68
        /**
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    69
         * Create a run-time image containing java.se, java.json and the javac
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    70
         * compiler. Use the run-time image to compile and run both
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    71
         * TestModules.java and JsonTest.java
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    72
         */
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    73
        if (Files.exists(Path.of(javaHome, "jmods", "java.se.jmod"))) {
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    74
            // jlink --add-modules java.se,java.json,jdk.compiler,jdk.zipfs
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    75
            Path here = Path.of(".");
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    76
            Path image = Files.createTempDirectory(here, "images").resolve("myimage");
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    77
            ToolProvider jlink = ToolProvider.findFirst("jlink")
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    78
                    .orElseThrow(() -> new RuntimeException("jlink not found"));
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    79
            int exitCode = jlink.run(System.out, System.err,
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    80
                    "--module-path", System.getProperty("test.module.path"),
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    81
                    "--add-modules", "java.se,java.json,jdk.compiler,jdk.zipfs",
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    82
                    "--output", image.toString());
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    83
            if (exitCode != 0)
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    84
                throw new RuntimeException("jlink failed");
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    85
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    86
            // path to java launcher in run-time image
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    87
            String javaLauncher = image.resolve("bin").resolve("java").toString();
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    88
            if (System.getProperty("os.name").startsWith("Windows"))
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    89
                javaLauncher += ".exe";
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    90
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    91
            // $CUSTOM_JDK/bin/java TestRootModules.java
59133
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents: 51675
diff changeset
    92
            source = Path.of(testSrc, "TestRootModules.java").toString();
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents: 51675
diff changeset
    93
            ProcessBuilder pb = new ProcessBuilder(javaLauncher,
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents: 51675
diff changeset
    94
                    "--add-exports", "java.base/jdk.internal.module=ALL-UNNAMED",
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents: 51675
diff changeset
    95
                    source);
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents: 51675
diff changeset
    96
            out.format("Command line: [%s]%n", pb.command());
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents: 51675
diff changeset
    97
            ProcessTools.executeProcess(pb)
50738
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    98
                    .outputTo(System.out)
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
    99
                    .errorTo(System.err)
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   100
                    .shouldHaveExitValue(0);
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   101
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   102
            // $CUSTOM_JDK/bin/java TestJson.java
59133
580fb715b29d 8233922: Service binding augments module graph with observable incubator modules
alanb
parents: 51675
diff changeset
   103
            source = Path.of(testSrc, "TestJson.java").toString();
50738
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   104
            out.format("Command line: [%s %s]%n", javaLauncher, source);
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   105
            ProcessTools.executeProcess(new ProcessBuilder(javaLauncher, source))
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   106
                    .outputTo(System.out)
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   107
                    .errorTo(System.err)
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   108
                    .shouldHaveExitValue(0);
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   109
        }
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   110
    }
6cc2dc161c64 8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
diff changeset
   111
}