jdk/test/tools/jlink/IntegrationTest.java
author alanb
Tue, 03 May 2016 09:09:57 +0100
changeset 37779 7c84df693837
parent 36511 9d0388c6b336
child 38320 e24c7029e8ba
permissions -rw-r--r--
8154956: Module system implementation refresh (4/2016) Reviewed-by: alanb, mchung, chegar, redestad Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, erik.joelsson@oracle.com, chris.hegarty@oracle.com, peter.levart@gmail.com, sundararajan.athijegannathan@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.io.File;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.io.UncheckedIOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.util.ArrayList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.HashSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.util.Set;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import jdk.tools.jlink.Jlink;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import jdk.tools.jlink.Jlink.JlinkConfiguration;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import jdk.tools.jlink.Jlink.PluginsConfiguration;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import jdk.tools.jlink.builder.DefaultImageBuilder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import jdk.tools.jlink.plugin.ExecutableImage;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import jdk.tools.jlink.plugin.Pool;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import jdk.tools.jlink.plugin.PostProcessorPlugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import jdk.tools.jlink.plugin.TransformerPlugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import jdk.tools.jlink.internal.plugins.DefaultCompressPlugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import jdk.tools.jlink.internal.plugins.StripDebugPlugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import jdk.tools.jlink.plugin.Plugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import tests.Helper;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import tests.JImageGenerator;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
 * @summary Test integration API
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
 * @author Jean-Francois Denise
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
 * @library ../lib
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
 * @modules java.base/jdk.internal.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
 *          jdk.jdeps/com.sun.tools.classfile
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
 *          jdk.jlink/jdk.tools.jlink.internal
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
 *          jdk.jlink/jdk.tools.jlink.internal.plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
 *          jdk.jlink/jdk.tools.jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
 *          jdk.jlink/jdk.tools.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
 *          jdk.compiler
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
 * @build tests.*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
 * @run main IntegrationTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
public class IntegrationTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    private static final List<Integer> ordered = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    public static class MyPostProcessor implements PostProcessorPlugin {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        public static final String NAME = "mypostprocessor";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        public List<String> process(ExecutableImage image) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                Files.createFile(image.getHome().resolve("toto.txt"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            } catch (IOException ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                throw new UncheckedIOException(ex);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            return NAME;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        public Set<PluginType> getType() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
            Set<PluginType> set = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
            set.add(CATEGORY.PROCESSOR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            return Collections.unmodifiableSet(set);
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 void configure(Map<String, String> config) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            throw new UnsupportedOperationException("Shouldn't be called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    public static class MyPlugin1 implements TransformerPlugin {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        Integer index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        Set<String> after;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        Set<String> before;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        private MyPlugin1(Integer index, Set<String> after, Set<String> before) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
            this.index = index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
            this.after = after;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
            this.before = before;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        public Set<String> isAfter() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
            return after;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        public Set<String> isBefore() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            return before;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
            return NAME + index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        public void visit(Pool in, Pool out) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            System.err.println(NAME + index);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            ordered.add(index);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            in.visit((file) -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                return file;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            }, out);
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        public Set<PluginType> getType() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
            Set<PluginType> set = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            set.add(CATEGORY.TRANSFORMER);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            return Collections.unmodifiableSet(set);
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        public String getDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            return null;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        public String getOption() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
            return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        static final String NAME = "myprovider";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        static final String INDEX = "INDEX";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        public void configure(Map<String, String> config) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
            throw new UnsupportedOperationException("Shouldn't be called");
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
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        Helper helper = Helper.newHelper();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        if (helper == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
            System.err.println("Test not run");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        apitest();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        test();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        testOrder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        testCycleOrder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
    private static void apitest() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        boolean failed = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        Jlink jl = new Jlink();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            jl.build(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
            // XXX OK
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            throw new Exception("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        System.out.println(jl);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        JlinkConfiguration config
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                = new JlinkConfiguration(null, null, null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        System.out.println(config);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        Plugin p = Jlink.newPlugin("toto", Collections.emptyMap(), null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        if (p != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
            throw new Exception("Plugin should be null");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        Plugin p2 = Jlink.newPlugin("compress", Collections.emptyMap(), null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        if (p2 == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
            throw new Exception("Plugin should not be null");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        }
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
    private static void test() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        Jlink jlink = new Jlink();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        Path output = Paths.get("integrationout");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        List<Path> modulePaths = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        File jmods
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk")));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        modulePaths.add(jmods.toPath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        Set<String> mods = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        mods.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        Set<String> limits = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        limits.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        JlinkConfiguration config = new Jlink.JlinkConfiguration(output,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                modulePaths, mods, limits, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        List<Plugin> lst = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        //Strip debug
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
            Map<String, String> config1 = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
            config1.put(StripDebugPlugin.NAME, "");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
            Plugin strip = Jlink.newPlugin("strip-debug", config1, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            lst.add(strip);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        // compress
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
            Map<String, String> config1 = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            config1.put(DefaultCompressPlugin.NAME, "2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
            Plugin compress
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                    = Jlink.newPlugin("compress", config1, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            lst.add(compress);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        // Post processor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
            lst.add(new MyPostProcessor());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        // Image builder
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   244
        DefaultImageBuilder builder = new DefaultImageBuilder(output);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        PluginsConfiguration plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                = new Jlink.PluginsConfiguration(lst, builder, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        jlink.build(config, plugins);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        if (!Files.exists(output)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
            throw new AssertionError("Directory not created");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
        File jimage = new File(output.toString(), "lib" + File.separator + "modules");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        if (!jimage.exists()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
            throw new AssertionError("jimage not generated");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
        File release = new File(output.toString(), "release");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        if (!release.exists()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
            throw new AssertionError("release not generated");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        if (!Files.exists(output.resolve("toto.txt"))) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
            throw new AssertionError("Post processing not called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
    private static void testOrder() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        Jlink jlink = new Jlink();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        Path output = Paths.get("integrationout2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
        List<Path> modulePaths = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
        File jmods
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk")));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        modulePaths.add(jmods.toPath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
        Set<String> mods = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        mods.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        Set<String> limits = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        limits.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        JlinkConfiguration config = new Jlink.JlinkConfiguration(output,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                modulePaths, mods, limits, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        List<Plugin> lst = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        // Order is Plug1>Plug2>Plug3
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        // Plug1
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        // TRANSFORMER 3, must be after 2.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
            Set<String> after = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
            after.add(MyPlugin1.NAME+"2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
            lst.add(new MyPlugin1(3, after, Collections.emptySet()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        // TRANSFORMER 2, must be after 1.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
            Set<String> after = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
            after.add(MyPlugin1.NAME+"1");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
            lst.add(new MyPlugin1(2, after, Collections.emptySet()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   300
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   301
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   302
        // TRANSFORMER 1
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   303
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
            Set<String> before = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
            before.add(MyPlugin1.NAME+"2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   306
            lst.add(new MyPlugin1(1, Collections.emptySet(), before));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   307
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   308
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   309
        // Image builder
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   310
        DefaultImageBuilder builder = new DefaultImageBuilder(output);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   311
        PluginsConfiguration plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   312
                = new Jlink.PluginsConfiguration(lst, builder, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   314
        jlink.build(config, plugins);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
        if (ordered.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
            throw new AssertionError("Plugins not called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
        List<Integer> clone = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        clone.addAll(ordered);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        Collections.sort(clone);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   322
        if (!clone.equals(ordered)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   323
            throw new AssertionError("Ordered is not properly sorted" + ordered);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   324
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   325
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   326
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   327
    private static void testCycleOrder() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   328
        Jlink jlink = new Jlink();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        Path output = Paths.get("integrationout3");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        List<Path> modulePaths = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
        File jmods
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk")));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   333
        modulePaths.add(jmods.toPath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   334
        Set<String> mods = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   335
        mods.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
        Set<String> limits = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   337
        limits.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
        JlinkConfiguration config = new Jlink.JlinkConfiguration(output,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
                modulePaths, mods, limits, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
        List<Plugin> lst = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   343
        // packager 1
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   345
            Set<String> before = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
            before.add(MyPlugin1.NAME+"2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
            lst.add(new MyPlugin1(1, Collections.emptySet(), before));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   350
        // packager 2
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   352
            Set<String> before = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
            before.add(MyPlugin1.NAME+"1");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
            lst.add(new MyPlugin1(2, Collections.emptySet(), before));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   357
        // Image builder
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   358
        DefaultImageBuilder builder = new DefaultImageBuilder(output);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   359
        PluginsConfiguration plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   360
                = new Jlink.PluginsConfiguration(lst, builder, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   361
        boolean failed = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
            jlink.build(config, plugins);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   364
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   365
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
            // XXX OK
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
        if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
            throw new AssertionError("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   372
}