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