jdk/test/tools/jlink/DefaultProviderTest.java
author alanb
Thu, 17 Mar 2016 19:04:16 +0000
changeset 36511 9d0388c6b336
child 38320 e24c7029e8ba
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, chris.hegarty@oracle.com, alexandr.scherbatiy@oracle.com, amy.lu@oracle.com, calvin.cheung@oracle.com, daniel.fuchs@oracle.com, erik.joelsson@oracle.com, harold.seigel@oracle.com, jaroslav.bachorik@oracle.com, jean-francois.denise@oracle.com, jan.lahoda@oracle.com, james.laskey@oracle.com, lois.foltan@oracle.com, miroslav.kos@oracle.com, huaming.li@oracle.com, sean.mullan@oracle.com, naoto.sato@oracle.com, masayoshi.okutsu@oracle.com, peter.levart@gmail.com, philip.race@oracle.com, claes.redestad@oracle.com, sergey.bylokhov@oracle.com, alexandre.iline@oracle.com, volker.simonis@gmail.com, staffan.larsen@oracle.com, stuart.marks@oracle.com, semyon.sadetsky@oracle.com, serguei.spitsyn@oracle.com, sundararajan.athijegannathan@oracle.com, valerie.peng@oracle.com, vincent.x.ryan@oracle.com, weijun.wang@oracle.com, yuri.nesterenko@oracle.com, yekaterina.kantserova@oracle.com, alexander.kulyakhtin@oracle.com, felix.yang@oracle.com, andrei.eremeev@oracle.com, frank.yuan@oracle.com, sergei.pikalev@oracle.com, sibabrata.sahoo@oracle.com, tiantian.du@oracle.com, sha.jiang@oracle.com
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.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.HashSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.Set;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import jdk.tools.jlink.internal.PluginRepository;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import jdk.tools.jlink.plugin.Plugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import jdk.tools.jlink.plugin.PluginException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import jdk.tools.jlink.plugin.Pool;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import jdk.tools.jlink.plugin.TransformerPlugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import tests.Helper;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
 * @summary Test plugins enabled by default
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
 * @author Jean-Francois Denise
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
 *          jdk.jlink/jdk.tools.jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
 *          jdk.jlink/jdk.tools.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
 *          jdk.compiler
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
 * @build tests.*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
 * @run main/othervm DefaultProviderTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
public class DefaultProviderTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private static final String NAME = "disable-toto";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private final static Map<String, Object> expectedOptions = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    static {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        expectedOptions.put("disable-toto", "false");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        expectedOptions.put("option1", "value1");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        expectedOptions.put("option2", "value2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    private static class Custom implements TransformerPlugin {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        private boolean enabled = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        public Set<PluginType> getType() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            Set<PluginType> set = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
            set.add(CATEGORY.TRANSFORMER);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
            return Collections.unmodifiableSet(set);
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        public Set<STATE> getState() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
             return enabled ? EnumSet.of(STATE.AUTO_ENABLED, STATE.FUNCTIONAL)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                : EnumSet.of(STATE.DISABLED);
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        public void visit(Pool in, Pool out) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
            if (!enabled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                throw new PluginException(NAME + " was set");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
            DefaultProviderTest.isNewPluginsCalled = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            in.visit((Pool.ModuleData content) -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                return content;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            }, out);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            return NAME;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        public String getDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            return NAME;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        public boolean hasArguments() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
            return true;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        public void configure(Map<String, String> config) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
            if (config.containsKey(NAME)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                enabled = !Boolean.parseBoolean(config.get(NAME));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
            if (enabled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                DefaultProviderTest.receivedOptions = config;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                DefaultProviderTest.receivedOptions = null;
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
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
    private static boolean isNewPluginsCalled;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    private static Map<String, String> receivedOptions;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    private static void reset() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        isNewPluginsCalled = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        receivedOptions = null;
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
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        Helper helper = Helper.newHelper();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        if (helper == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            System.err.println("Test not run");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        helper.generateDefaultModules();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        test(helper, new Custom());
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
    private static void test(Helper helper, Plugin plugin) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        PluginRepository.registerPlugin(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            String[] userOptions = {};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
            Path imageDir = helper.generateDefaultImage(userOptions, "composite2").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            helper.checkImage(imageDir, "composite2", null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            if (!isNewPluginsCalled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
                throw new Exception("Should have been called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
            reset();
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
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
            String[] userOptions = {"--disable-toto=false:option1=value1:option2=value2"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
            Path imageDir = helper.generateDefaultImage(userOptions, "composite2").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
            helper.checkImage(imageDir, "composite2", null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
            if (!isNewPluginsCalled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                throw new Exception("Should have been called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
            if (!receivedOptions.equals(expectedOptions)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                throw new Exception("Optional options " + receivedOptions + " are not expected one "
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                        + expectedOptions);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
            System.err.println("OPTIONS " + receivedOptions);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
            reset();
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
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
            String[] userOptions = {"--disable-toto=true:option1=value1"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            Path imageDir = helper.generateDefaultImage(userOptions, "composite2").assertSuccess();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            helper.checkImage(imageDir, "composite2", null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            if (isNewPluginsCalled) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                throw new Exception("Should not have been called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
            if (receivedOptions != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                throw new Exception("Optional options are not expected");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
            reset();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
}