jdk/test/tools/jlink/plugins/ExcludeVMPluginTest.java
author chegar
Wed, 18 Jan 2017 09:36:24 +0000
changeset 43185 d75d9ff8d4e7
parent 40124 01f8745abd3c
child 43729 21db38703675
permissions -rw-r--r--
8171380: Remove all exports from jdk.jlink Reviewed-by: alanb, mchung, sundar
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
 /*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary Test exclude VM plugin
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @author Jean-Francois Denise
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules jdk.jlink/jdk.tools.jlink.internal
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *          jdk.jlink/jdk.tools.jlink.internal.plugins
43185
d75d9ff8d4e7 8171380: Remove all exports from jdk.jlink
chegar
parents: 40124
diff changeset
    30
 *          jdk.jlink/jdk.tools.jlink.plugin
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 * @run main ExcludeVMPluginTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.io.ByteArrayInputStream;
40124
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
    34
import java.net.URI;
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
    35
import java.nio.file.Path;
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
    36
import java.nio.file.Paths;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.Map;
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    39
import jdk.tools.jlink.internal.ResourcePoolManager;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import jdk.tools.jlink.internal.plugins.ExcludeVMPlugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import jdk.tools.jlink.plugin.Plugin;
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    43
import jdk.tools.jlink.plugin.ResourcePool;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
    44
import jdk.tools.jlink.plugin.ResourcePoolEntry;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
public class ExcludeVMPluginTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    private static final String TAG = "# orig in test\n";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    private static final String[] ARCHITECTURES = {"/", "/amd64/", "/i386/", "/arm/",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
        "/aarch64/", "/toto/"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private static final String[] CLIENT = {"client/" + jvmlib(),};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    private static final String[] SERVER = {"server/" + jvmlib()};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private static final String[] MINIMAL = {"minimal/" + jvmlib()};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private static final String[] ALL = {CLIENT[0], SERVER[0], MINIMAL[0]};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    private static final String JVM_CFG_ALL = TAG + "-server KNOWN\n-client KNOWN\n-minimal KNOWN\n";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    private static final String JVM_CFG_CLIENT = TAG + "-client KNOWN\n";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    private static final String JVM_CFG_SERVER = TAG + "-server KNOWN\n";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    private static final String JVM_CFG_SERVER_ALIAS_OTHERS = TAG + "-server KNOWN\n-client ALIASED_TO -server\n-minimal ALIASED_TO -server\n";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    private static final String JVM_CFG_CLIENT_ALIAS_OTHERS = TAG + "-client KNOWN\n-server ALIASED_TO -client\n-minimal ALIASED_TO -client\n";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    private static final String JVM_CFG_MINIMAL_ALIAS_OTHERS = TAG + "-minimal KNOWN\n-server ALIASED_TO -minimal\n-client ALIASED_TO -minimal\n";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    private static final String JVM_CFG_MINIMAL = TAG + "-minimal KNOWN\n";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        new ExcludeVMPluginTest().test();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    public void test() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        boolean failed = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
            checkVM("toto", ALL, JVM_CFG_ALL, ALL, JVM_CFG_ALL);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            throw new Exception("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
            if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                throw ex;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        checkVM("all", ALL, JVM_CFG_ALL, ALL, JVM_CFG_ALL);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        checkVM("all", CLIENT, JVM_CFG_CLIENT, CLIENT, JVM_CFG_CLIENT);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        checkVM("all", SERVER, JVM_CFG_SERVER, SERVER, JVM_CFG_SERVER);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        checkVM("all", MINIMAL, JVM_CFG_MINIMAL, MINIMAL, JVM_CFG_MINIMAL);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        checkVM("server", ALL, JVM_CFG_ALL, SERVER, JVM_CFG_SERVER_ALIAS_OTHERS);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        checkVM("server", SERVER, JVM_CFG_SERVER, SERVER, JVM_CFG_SERVER);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
            checkVM("server", CLIENT, JVM_CFG_CLIENT, SERVER, JVM_CFG_SERVER);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
            throw new Exception("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                throw ex;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            checkVM("server", MINIMAL, JVM_CFG_MINIMAL, SERVER, JVM_CFG_SERVER);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
            throw new Exception("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
                throw ex;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        checkVM("client", ALL, JVM_CFG_ALL, CLIENT, JVM_CFG_CLIENT_ALIAS_OTHERS);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        checkVM("client", CLIENT, JVM_CFG_CLIENT, CLIENT, JVM_CFG_CLIENT);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
            checkVM("client", SERVER, JVM_CFG_SERVER, CLIENT, JVM_CFG_CLIENT);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
            throw new Exception("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
            if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                throw ex;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
            checkVM("client", MINIMAL, JVM_CFG_MINIMAL, CLIENT, JVM_CFG_CLIENT);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            throw new Exception("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                throw ex;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        checkVM("minimal", ALL, JVM_CFG_ALL, MINIMAL, JVM_CFG_MINIMAL_ALIAS_OTHERS);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        checkVM("minimal", MINIMAL, JVM_CFG_MINIMAL, MINIMAL, JVM_CFG_MINIMAL);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            checkVM("minimal", SERVER, JVM_CFG_SERVER, MINIMAL, JVM_CFG_MINIMAL);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            throw new Exception("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                throw ex;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
            checkVM("minimal", CLIENT, JVM_CFG_CLIENT, MINIMAL, JVM_CFG_MINIMAL);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            throw new Exception("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                throw ex;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
    public void checkVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        for (String arch : ARCHITECTURES) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
            String[] winput = new String[input.length];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
            String[] woutput = new String[expectedOutput.length];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            for (int i = 0; i < input.length; i++) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                winput[i] = "/java.base/native" + arch + input[i];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
            for (int i = 0; i < expectedOutput.length; i++) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                woutput[i] = "/java.base/native" + arch + expectedOutput[i];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
            doCheckVM(vm, winput, jvmcfg, woutput, expectdJvmCfg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
    private void doCheckVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        // Create a pool with jvm.cfg and the input paths.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        byte[] jvmcfgContent = jvmcfg.getBytes();
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   170
        ResourcePoolManager poolMgr = new ResourcePoolManager();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   171
        poolMgr.add(
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   172
            ResourcePoolEntry.create("/java.base/native/jvm.cfg",
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   173
                ResourcePoolEntry.Type.NATIVE_LIB, jvmcfgContent));
40124
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   174
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   175
        // java.base/module-info.class is used by exclude vm plugin
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   176
        // to get current osName(). We read it from jrt-fs and add a
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   177
        // ResourcePoolEntry
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   178
        poolMgr.add(
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   179
            ResourcePoolEntry.create("/java.base/module-info.class",
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   180
                ResourcePoolEntry.Type.CLASS_OR_RESOURCE, getJavaBaseModuleInfo()));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        for (String in : input) {
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   182
            poolMgr.add(ResourcePoolEntry.create(in,
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   183
                    ResourcePoolEntry.Type.NATIVE_LIB, new byte[0]));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        }
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   185
        ResourcePoolManager outMgr = new ResourcePoolManager();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39151
diff changeset
   187
        Plugin p = new ExcludeVMPlugin();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        Map<String, String> config = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        if (vm != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
            config.put(ExcludeVMPlugin.NAME, vm);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        p.configure(config);
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   193
        ResourcePool out = p.transform(poolMgr.resourcePool(), outMgr.resourcePoolBuilder());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   195
        String newContent = new String(out.findEntry("/java.base/native/jvm.cfg").get().contentBytes());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        if (!expectdJvmCfg.equals(newContent)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
            throw new Exception("Got content " + newContent + " expected " + expectdJvmCfg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
40124
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   201
        // Apart from native resources, we should find jvm.cfg and
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   202
        // java.base/module-info.class. So, we add 2 here to the
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   203
        // expected count!
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   204
        if (out.entryCount() != (expectedOutput.length + 2)) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   205
            out.entries().forEach(m -> {
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   206
                System.err.println(m.path());
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   207
            });
40124
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   208
            throw new Exception("Invalid output size " + out.entryCount() + " expected " + (expectedOutput.length + 2));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   211
        out.entries().forEach(md -> {
40124
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   212
            if (md.path().equals("/java.base/native/jvm.cfg") ||
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   213
                md.path().equals("/java.base/module-info.class")) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   214
                return;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
            boolean contained = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
            for (String o : expectedOutput) {
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   218
                if (md.path().equals(o)) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                    contained = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                    break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
            if (!contained) {
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39321
diff changeset
   224
                throw new RuntimeException(md.path() + " not expected");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
            }
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   226
        });
40124
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   227
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
40124
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   229
    // read java.base/module-info.class from jrt-fs
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   230
    private static Path getJavaBaseModuleInfo() {
01f8745abd3c 8163116: jlink exclude VM plugin does not fully support cross platform image creation
sundar
parents: 39834
diff changeset
   231
        return Paths.get(URI.create("jrt:/modules/java.base/module-info.class"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
    private static boolean isWindows() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        return System.getProperty("os.name").startsWith("Windows");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
    private static boolean isMac() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        return System.getProperty("os.name").startsWith("Mac OS");
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
    private static String jvmlib() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        String lib = "libjvm.so";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        if (isWindows()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
            lib = "jvm.dll";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
        } else if (isMac()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
            lib = "libjvm.dylib";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        return lib;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
}