test/jdk/tools/jlink/DefaultProviderTest.java
author ihse
Tue, 22 Oct 2019 09:51:52 +0200
branchihse-cflags-rewrite-branch
changeset 58736 e878a0b7cff0
parent 48663 b742e0f9ce80
permissions -rw-r--r--
Add doubunder on solaris in two places.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
48663
b742e0f9ce80 8161348: Several tools/jlink tests failed in "-Xcomp" mode due to time out
anazarov
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
36511
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.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.util.ArrayList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.util.EnumSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.Set;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import jdk.tools.jlink.internal.PluginRepository;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import jdk.tools.jlink.plugin.Plugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import jdk.tools.jlink.plugin.PluginException;
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.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
    36
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import tests.Helper;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 * @summary Test plugins enabled by default
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
 * @author Jean-Francois Denise
48663
b742e0f9ce80 8161348: Several tools/jlink tests failed in "-Xcomp" mode due to time out
anazarov
parents: 47216
diff changeset
    43
 * @requires vm.compMode != "Xcomp"
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 * @library ../lib
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
 * @modules java.base/jdk.internal.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 *          jdk.jdeps/com.sun.tools.classfile
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
 *          jdk.jlink/jdk.tools.jlink.internal
43185
d75d9ff8d4e7 8171380: Remove all exports from jdk.jlink
chegar
parents: 39834
diff changeset
    48
 *          jdk.jlink/jdk.tools.jlink.plugin
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
 *          jdk.jlink/jdk.tools.jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
 *          jdk.jlink/jdk.tools.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
 *          jdk.compiler
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
 * @build tests.*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
 * @run main/othervm DefaultProviderTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
public class DefaultProviderTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private static final String NAME = "disable-toto";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    private final static Map<String, Object> expectedOptions = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    static {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        expectedOptions.put("disable-toto", "false");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        expectedOptions.put("option1", "value1");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        expectedOptions.put("option2", "value2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39129
diff changeset
    65
    private static class Custom implements Plugin {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        private boolean enabled = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        @Override
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    69
        public Set<State> getState() {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    70
             return enabled ? EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL)
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    71
                : EnumSet.of(State.DISABLED);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        @Override
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
    75
        public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
            if (!enabled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                throw new PluginException(NAME + " was set");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            DefaultProviderTest.isNewPluginsCalled = true;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    81
            in.transformAndCopy(content -> {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                return content;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
            }, out);
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
    84
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
    85
            return out.build();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
            return NAME;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        public String getDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
            return NAME;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        public boolean hasArguments() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
            return true;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        public void configure(Map<String, String> config) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
            if (config.containsKey(NAME)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
                enabled = !Boolean.parseBoolean(config.get(NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
            if (enabled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                DefaultProviderTest.receivedOptions = config;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                DefaultProviderTest.receivedOptions = null;
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
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
    private static boolean isNewPluginsCalled;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
    private static Map<String, String> receivedOptions;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
    private static void reset() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        isNewPluginsCalled = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        receivedOptions = null;
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
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        Helper helper = Helper.newHelper();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        if (helper == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
            System.err.println("Test not run");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
            return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        helper.generateDefaultModules();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        test(helper, new Custom());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
    private static void test(Helper helper, Plugin plugin) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        PluginRepository.registerPlugin(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
            String[] userOptions = {};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
            Path imageDir = helper.generateDefaultImage(userOptions, "composite2").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
            helper.checkImage(imageDir, "composite2", null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            if (!isNewPluginsCalled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                throw new Exception("Should have been called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            reset();
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
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
            String[] userOptions = {"--disable-toto=false:option1=value1:option2=value2"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
            Path imageDir = helper.generateDefaultImage(userOptions, "composite2").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
            helper.checkImage(imageDir, "composite2", null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
            if (!isNewPluginsCalled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                throw new Exception("Should have been called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
            if (!receivedOptions.equals(expectedOptions)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                throw new Exception("Optional options " + receivedOptions + " are not expected one "
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                        + expectedOptions);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
            System.err.println("OPTIONS " + receivedOptions);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
            reset();
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
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
            String[] userOptions = {"--disable-toto=true:option1=value1"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
            Path imageDir = helper.generateDefaultImage(userOptions, "composite2").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
            helper.checkImage(imageDir, "composite2", null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
            if (isNewPluginsCalled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                throw new Exception("Should not have been called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            if (receivedOptions != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                throw new Exception("Optional options are not expected");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
            reset();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
}