test/jdk/tools/jlink/multireleasejar/JLinkMRJavaBaseVersionTest.java
author sundar
Wed, 06 Dec 2017 08:04:35 +0530
changeset 48071 a5cadeee8763
parent 47737 acfedb75dd51
permissions -rw-r--r--
8185130: jlink should throw error if target image and current JDK versions don't match Reviewed-by: redestad, alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47737
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
     1
/*
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
     4
 *
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
     8
 *
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    13
 * accompanied this code).
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    14
 *
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    18
 *
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    21
 * questions.
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    22
 */
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    23
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    24
/*
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    25
 * @test
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    26
 * @bug 8177471
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    27
 * @summary  jlink should use the version from java.base.jmod to find modules
48071
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
    28
 * @bug 8185130
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
    29
 * @summary jlink should throw error if target image and current JDK versions don't match
47737
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.module
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    31
 * @library /test/lib
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    32
 * @build jdk.test.lib.process.* CheckRuntimeVersion
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    33
 * @run testng/othervm JLinkMRJavaBaseVersionTest
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    34
 */
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    35
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    36
import java.io.ByteArrayInputStream;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    37
import java.io.File;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    38
import java.io.IOException;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    39
import java.lang.module.ModuleFinder;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    40
import java.lang.module.ModuleReference;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    41
import java.nio.file.Files;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    42
import java.nio.file.Path;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    43
import java.nio.file.Paths;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    44
import java.util.List;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    45
import java.util.jar.JarFile;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    46
import java.util.spi.ToolProvider;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    47
import java.util.stream.Collectors;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    48
import java.util.stream.Stream;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    49
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    50
import jdk.internal.module.ModulePath;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    51
import jdk.test.lib.process.ProcessTools;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    52
import org.testng.Assert;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    53
import org.testng.annotations.BeforeClass;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    54
import org.testng.annotations.Test;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    55
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    56
public class JLinkMRJavaBaseVersionTest {
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    57
    private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    58
            .orElseThrow(() -> new RuntimeException("jar tool not found"));
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    59
    private static final ToolProvider JAVAC_TOOL = ToolProvider.findFirst("javac")
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    60
            .orElseThrow(() -> new RuntimeException("javac tool not found"));
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    61
    private static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    62
            .orElseThrow(() -> new RuntimeException("jlink tool not found"));
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    63
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    64
    private static final Path javaHome = Paths.get(System.getProperty("java.home"));
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    65
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    66
    // resource text for version 9
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    67
    private byte[] resource9 = ("9 resource file").getBytes();
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    68
    // resource text for current version
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    69
    private byte[] resource = (Runtime.version().major() + " resource file").getBytes();
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    70
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    71
    static Path getJmods() {
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    72
        Path jmods = Paths.get(System.getProperty("java9.home", javaHome.toString())).resolve("jmods");
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    73
        if (Files.notExists(jmods)) {
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    74
            throw new RuntimeException(jmods + " not found");
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    75
        }
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    76
        return jmods;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    77
    }
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    78
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    79
    @BeforeClass
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    80
    public void initialize() throws IOException {
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    81
        Path srcdir = Paths.get(System.getProperty("test.src"));
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    82
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    83
        // create class files from source
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    84
        Path base = srcdir.resolve("base");
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    85
        Path mr9 = Paths.get("mr9");
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    86
        javac(base, mr9, base.toString());
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    87
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    88
        // current version
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    89
        Path rt = srcdir.resolve("rt");
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    90
        Path rtmods = Paths.get("rtmods");
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    91
        javac(rt, rtmods, rt.toString());
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    92
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    93
        // build multi-release jar file with different module-info.class
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    94
        String[] args = {
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    95
                "-cf", "m1.jar",
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    96
                "-C", rtmods.resolve("m1").toString(), ".",
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    97
                "--release ", "9",
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    98
                "-C", mr9.resolve("m1").toString(), "."
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
    99
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   100
        };
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   101
        JAR_TOOL.run(System.out, System.err, args);
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   102
    }
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   103
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   104
    private void javac(Path source, Path destination, String srcpath) throws IOException {
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   105
        String[] args = Stream.concat(
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   106
                Stream.of("-d", destination.toString(), "--release", "9",
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   107
                          "--module-source-path", srcpath),
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   108
                Files.walk(source)
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   109
                     .map(Path::toString)
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   110
                     .filter(s -> s.endsWith(".java"))
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   111
        ).toArray(String[]::new);
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   112
        int rc = JAVAC_TOOL.run(System.out, System.err, args);
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   113
        Assert.assertEquals(rc, 0);
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   114
    }
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   115
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   116
    @Test
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   117
    public void basicTest() throws Throwable {
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   118
        if (Files.notExists(javaHome.resolve("lib").resolve("modules"))) {
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   119
            // exploded image
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   120
            return;
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   121
        }
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   122
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   123
        Runtime.Version version = targetRuntimeVersion();
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   124
        System.out.println("Testing jlink with " + getJmods() + " of target version " + version);
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   125
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   126
        // use jlink to build image from multi-release jar
48071
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   127
        if (jlink("m1.jar", "myimage")) {
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   128
            return;
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   129
        }
47737
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   130
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   131
        // validate runtime image
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   132
        Path java = Paths.get("myimage", "bin", "java");
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   133
        ProcessTools.executeProcess(java.toString(), "-m", "m1/p.Main");
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   134
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   135
        // validate the image linked with the proper MR version
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   136
48071
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   137
        if (!version.equalsIgnoreOptional(Runtime.version())) {
47737
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   138
            ProcessTools.executeProcess(java.toString(), "-cp", System.getProperty("test.classes"),
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   139
                                        "CheckRuntimeVersion", String.valueOf(version.major()),
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   140
                                        "java.base", "m1")
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   141
                .shouldHaveExitValue(0);
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   142
        }
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   143
    }
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   144
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   145
    private Runtime.Version targetRuntimeVersion() {
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   146
        ModuleReference mref = ModulePath.of(Runtime.version(), true, getJmods())
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   147
            .find("java.base")
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   148
            .orElseThrow(() -> new RuntimeException("java.base not found from " + getJmods()));
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   149
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   150
        return Runtime.Version.parse(mref.descriptor().version().get().toString());
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   151
    }
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   152
48071
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   153
    private boolean jlink(String jar, String image) {
47737
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   154
        List<String> args = List.of("--output", image,
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   155
                                    "--add-modules", "m1",
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   156
                                    "--module-path",
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   157
                                    getJmods().toString() + File.pathSeparator + jar);
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   158
        System.out.println("jlink " + args.stream().collect(Collectors.joining(" ")));
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   159
        int exitCode = JLINK_TOOL.run(System.out, System.err, args.toArray(new String[0]));
48071
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   160
        boolean isJDK9 = System.getProperty("java9.home") != null;
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   161
        if (isJDK9) {
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   162
            Assert.assertNotEquals(exitCode, 0);
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   163
        } else {
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   164
            Assert.assertEquals(exitCode, 0);
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   165
        }
a5cadeee8763 8185130: jlink should throw error if target image and current JDK versions don't match
sundar
parents: 47737
diff changeset
   166
        return isJDK9;
47737
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   167
    }
acfedb75dd51 8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff changeset
   168
}