jdk/test/tools/jlink/JLinkTest.java
author mchung
Tue, 04 Oct 2016 18:56:28 -0700
changeset 41352 f9844bad9052
parent 41212 54a8bb41b174
child 41484 834b7539ada3
permissions -rw-r--r--
8166860: Add magic number to jmod file Reviewed-by: alanb, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.io.PrintWriter;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.io.StringWriter;
39153
26b3cb81aac9 8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents: 37893
diff changeset
    27
import java.lang.module.ModuleDescriptor;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.lang.reflect.Layer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.ArrayList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.util.stream.Stream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import jdk.tools.jlink.plugin.Plugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import jdk.tools.jlink.internal.PluginRepository;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import tests.Helper;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import tests.JImageGenerator;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import tests.JImageGenerator.InMemoryFile;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
 * @summary Test image creation
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 * @author Jean-Francois Denise
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
 * @library ../lib
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
 * @modules java.base/jdk.internal.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
 *          jdk.jdeps/com.sun.tools.classfile
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
 *          jdk.jlink/jdk.tools.jlink.internal
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
 *          jdk.jlink/jdk.tools.jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
 *          jdk.jlink/jdk.tools.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
 *          jdk.compiler
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
 * @build tests.*
39304
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    55
 * @run main/othervm -Xmx1g JLinkTest
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
public class JLinkTest {
39153
26b3cb81aac9 8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents: 37893
diff changeset
    58
    // number of built-in plugins from jdk.jlink module
26b3cb81aac9 8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents: 37893
diff changeset
    59
    private static int getNumJlinkPlugins() {
26b3cb81aac9 8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents: 37893
diff changeset
    60
        ModuleDescriptor desc = Plugin.class.getModule().getDescriptor();
26b3cb81aac9 8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents: 37893
diff changeset
    61
        return desc.provides().
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39304
diff changeset
    62
                    get(Plugin.class.getName()).
39153
26b3cb81aac9 8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents: 37893
diff changeset
    63
                    providers().size();
26b3cb81aac9 8153238: Improve test/tools/jlink/JLinkTest.java not to hard code the number of plugins
sundar
parents: 37893
diff changeset
    64
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
39304
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    66
    private static boolean isOfJLinkModule(Plugin p) {
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    67
        return p.getClass().getModule() == Plugin.class.getModule();
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    68
    }
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    69
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        Helper helper = Helper.newHelper();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        if (helper == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
            System.err.println("Test not run");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        helper.generateDefaultModules();
39304
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    78
        // expected num. of plugins from jdk.jlink module
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    79
        int expectedJLinkPlugins = getNumJlinkPlugins();
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    80
        int totalPlugins = 0;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
            // number of built-in plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
            List<Plugin> builtInPlugins = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            builtInPlugins.addAll(PluginRepository.getPlugins(Layer.boot()));
39304
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    85
            totalPlugins = builtInPlugins.size();
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    86
            // actual num. of plugins loaded from jdk.jlink module
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    87
            int actualJLinkPlugins = 0;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
            for (Plugin p : builtInPlugins) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
                p.getState();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                p.getType();
39304
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    91
                if (isOfJLinkModule(p)) {
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    92
                    actualJLinkPlugins++;
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    93
                }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            }
39304
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    95
            if (expectedJLinkPlugins != actualJLinkPlugins) {
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    96
                throw new AssertionError("Actual plugins loaded from jdk.jlink: " +
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    97
                        actualJLinkPlugins + " which doesn't match expected number : " +
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
    98
                        expectedJLinkPlugins);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            String moduleName = "bug8134651";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
            JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
                    .modulePath(helper.defaultModulePath())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
                    .output(helper.createNewImageDir(moduleName))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                    .addMods("leaf1")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                    .option("")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                    .call().assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
            JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                    .modulePath(helper.defaultModulePath())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                    .addMods("leaf1")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                    .option("--output")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                    .option("")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                    .call().assertFailure("Error: no value given for --output");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
            JImageGenerator.getJLinkTask()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                    .modulePath("")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                    .output(helper.createNewImageDir(moduleName))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                    .addMods("leaf1")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                    .option("")
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 40209
diff changeset
   121
                    .call().assertFailure("Error: no value given for --module-path");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        {
40209
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   125
            String moduleName = "m"; // 8163382
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   126
            Path jmod = helper.generateDefaultJModule(moduleName).assertSuccess();
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   127
            JImageGenerator.getJLinkTask()
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   128
                    .modulePath(helper.defaultModulePath())
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   129
                    .output(helper.createNewImageDir(moduleName))
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   130
                    .addMods("m")
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   131
                    .option("")
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   132
                    .call().assertSuccess();
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   133
            moduleName = "mod";
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   134
            jmod = helper.generateDefaultJModule(moduleName).assertSuccess();
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   135
            JImageGenerator.getJLinkTask()
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   136
                    .modulePath(helper.defaultModulePath())
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   137
                    .output(helper.createNewImageDir(moduleName))
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   138
                    .addMods("m")
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   139
                    .option("")
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   140
                    .call().assertSuccess();
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   141
        }
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   142
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 39321
diff changeset
   143
        {
41212
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   144
            String moduleName = "m_8165735"; // JDK-8165735
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   145
            helper.generateDefaultJModule(moduleName+"dependency").assertSuccess();
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   146
            Path jmod = helper.generateDefaultJModule(moduleName, moduleName+"dependency").assertSuccess();
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   147
            JImageGenerator.getJLinkTask()
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   148
                    .modulePath(helper.defaultModulePath())
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   149
                    .repeatedModulePath(".") // second --module-path overrides the first one
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   150
                    .output(helper.createNewImageDir(moduleName))
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   151
                    .addMods(moduleName)
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   152
                    // second --module-path does not have that module
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   153
                    .call().assertFailure("Error: Module m_8165735 not found");
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   154
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   155
            JImageGenerator.getJLinkTask()
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   156
                    .modulePath(".") // first --module-path overridden later
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   157
                    .repeatedModulePath(helper.defaultModulePath())
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   158
                    .output(helper.createNewImageDir(moduleName))
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   159
                    .addMods(moduleName)
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   160
                    // second --module-path has that module
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   161
                    .call().assertSuccess();
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   162
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   163
            JImageGenerator.getJLinkTask()
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   164
                    .modulePath(helper.defaultModulePath())
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   165
                    .output(helper.createNewImageDir(moduleName))
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   166
                    .limitMods(moduleName)
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   167
                    .repeatedLimitMods("java.base") // second --limit-modules overrides first
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   168
                    .addMods(moduleName)
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   169
                    .call().assertFailure("Error: Module m_8165735dependency not found, required by m_8165735");
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   170
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   171
            JImageGenerator.getJLinkTask()
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   172
                    .modulePath(helper.defaultModulePath())
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   173
                    .output(helper.createNewImageDir(moduleName))
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   174
                    .limitMods("java.base")
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   175
                    .repeatedLimitMods(moduleName) // second --limit-modules overrides first
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   176
                    .addMods(moduleName)
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   177
                    .call().assertSuccess();
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   178
        }
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   179
54a8bb41b174 8165735: jlink incorrectly accepts multiple --module-path and --limit-modules options
sundar
parents: 40261
diff changeset
   180
        {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
            // Help
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            StringWriter writer = new StringWriter();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
            jdk.tools.jlink.internal.Main.run(new String[]{"--help"}, new PrintWriter(writer));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            String output = writer.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
            if (output.split("\n").length < 10) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
                System.err.println(output);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                throw new AssertionError("Help");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
            // License files
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
            String copied = "LICENSE";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
            String[] arr = copied.split(",");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
            String[] copyFiles = new String[2];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
            copyFiles[0] = "--copy-files";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
            copyFiles[1] = copied;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
            Path imageDir = helper.generateDefaultImage(copyFiles, "composite2").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
            helper.checkImage(imageDir, "composite2", null, null, arr);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
            // List plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
            StringWriter writer = new StringWriter();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
            jdk.tools.jlink.internal.Main.run(new String[]{"--list-plugins"}, new PrintWriter(writer));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
            String output = writer.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
            long number = Stream.of(output.split("\\R"))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                    .filter((s) -> s.matches("Plugin Name:.*"))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                    .count();
39304
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
   210
            if (number != totalPlugins) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                System.err.println(output);
39304
8d9ceb81a46e 8160346: JLinkTest.java should compute exact number of plugins from jdk.jlink module
sundar
parents: 39153
diff changeset
   212
                throw new AssertionError("Found: " + number + " expected " + totalPlugins);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        // filter out files and resources + Skip debug + compress
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
            String[] userOptions = {"--compress", "2", "--strip-debug",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                "--exclude-resources", "*.jcov, */META-INF/*", "--exclude-files",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                "*" + Helper.getDebugSymbolsExtension()};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
            String moduleName = "excludezipskipdebugcomposite2";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
            helper.generateDefaultJModule(moduleName, "composite2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
            String[] res = {".jcov", "/META-INF/"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
            String[] files = {Helper.getDebugSymbolsExtension()};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
            Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
            helper.checkImage(imageDir, moduleName, res, files);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        // filter out + Skip debug + compress with filter + sort resources
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
            String[] userOptions2 = {"--compress=2:compress-filter=^/java.base/*",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                "--strip-debug", "--exclude-resources",
37893
f1cc7d17e66b 8156781: change to jlink has result in test failure
jlaskey
parents: 37779
diff changeset
   233
                "*.jcov, */META-INF/*", "--order-resources",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                "*/module-info.class,/sortcomposite2/*,*/javax/management/*"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
            String moduleName = "excludezipfilterskipdebugcomposite2";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            helper.generateDefaultJModule(moduleName, "composite2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            String[] res = {".jcov", "/META-INF/"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            Path imageDir = helper.generateDefaultImage(userOptions2, moduleName).assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
            helper.checkImage(imageDir, moduleName, res, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        // default compress
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
            testCompress(helper, "compresscmdcomposite2", "--compress", "2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
            testCompress(helper, "compressfiltercmdcomposite2",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                    "--compress=2:filter=^/java.base/java/lang/*");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        // compress 0
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
            testCompress(helper, "compress0filtercmdcomposite2",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                    "--compress=0:filter=^/java.base/java/lang/*");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        // compress 1
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
            testCompress(helper, "compress1filtercmdcomposite2",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                    "--compress=1:filter=^/java.base/java/lang/*");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        // compress 2
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
            testCompress(helper, "compress2filtercmdcomposite2",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                    "--compress=2:filter=^/java.base/java/lang/*");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        // invalid compress level
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
            String[] userOptions = {"--compress", "invalid"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
            String moduleName = "invalidCompressLevel";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
            helper.generateDefaultJModule(moduleName, "composite2");
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36757
diff changeset
   275
            helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: Invalid compression level invalid");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        // @file
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
            Path path = Paths.get("embedded.properties");
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 40209
diff changeset
   281
            Files.write(path, Collections.singletonList("--strip-debug --add-modules " +
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
                    "toto.unknown --compress UNKNOWN\n"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
            String[] userOptions = {"@", path.toAbsolutePath().toString()};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
            String moduleName = "configembeddednocompresscomposite2";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
            helper.generateDefaultJModule(moduleName, "composite2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
            Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
            helper.checkImage(imageDir, moduleName, null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
    private static void testCompress(Helper helper, String moduleName, String... userOptions) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        helper.generateDefaultJModule(moduleName, "composite2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
        Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        helper.checkImage(imageDir, moduleName, null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
}