jdk/test/tools/jlink/IntegrationTest.java
author sundar
Mon, 16 May 2016 14:47:27 +0530
changeset 38320 e24c7029e8ba
parent 37779 7c84df693837
child 39129 4b2086305b68
permissions -rw-r--r--
8156914: jlink API minor cleanups Reviewed-by: mchung
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;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    42
import jdk.tools.jlink.plugin.ModulePool;
36511
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
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    59
 *          jdk.jlink/jdk.tools.jlink
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    60
 *          jdk.jlink/jdk.tools.jlink.builder
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
 *          jdk.jlink/jdk.tools.jlink.internal
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
 *          jdk.jlink/jdk.tools.jlink.internal.plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
 *          jdk.jlink/jdk.tools.jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
 *          jdk.jlink/jdk.tools.jimage
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
 *          jdk.compiler
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
 * @build tests.*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
 * @run main IntegrationTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
public class IntegrationTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    private static final List<Integer> ordered = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    public static class MyPostProcessor implements PostProcessorPlugin {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        public static final String NAME = "mypostprocessor";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        public List<String> process(ExecutableImage image) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                Files.createFile(image.getHome().resolve("toto.txt"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
            } catch (IOException ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                throw new UncheckedIOException(ex);
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            return NAME;
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
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    93
        public Set<Category> getType() {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    94
            Set<Category> set = new HashSet<>();
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    95
            set.add(Category.PROCESSOR);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            return Collections.unmodifiableSet(set);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        public void configure(Map<String, String> config) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
            throw new UnsupportedOperationException("Shouldn't be called");
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    public static class MyPlugin1 implements TransformerPlugin {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        Integer index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        Set<String> after;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        Set<String> before;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        private MyPlugin1(Integer index, Set<String> after, Set<String> before) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
            this.index = index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
            this.after = after;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
            this.before = before;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        public Set<String> isAfter() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
            return after;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        public Set<String> isBefore() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            return before;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
            return NAME + index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        @Override
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   133
        public void visit(ModulePool in, ModulePool out) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            System.err.println(NAME + index);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
            ordered.add(index);
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   136
            in.transformAndCopy((file) -> {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                return file;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
            }, out);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        @Override
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   142
        public Set<Category> getType() {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   143
            Set<Category> set = new HashSet<>();
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   144
            set.add(Category.TRANSFORMER);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            return Collections.unmodifiableSet(set);
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        public String getDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
            return null;
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
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        public String getOption() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
            return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        static final String NAME = "myprovider";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        static final String INDEX = "INDEX";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        public void configure(Map<String, String> config) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
            throw new UnsupportedOperationException("Shouldn't be called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        Helper helper = Helper.newHelper();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        if (helper == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            System.err.println("Test not run");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        apitest();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        test();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
        testOrder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        testCycleOrder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
    private static void apitest() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        boolean failed = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        Jlink jl = new Jlink();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            jl.build(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
            // XXX OK
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
            throw new Exception("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        System.out.println(jl);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        JlinkConfiguration config
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                = new JlinkConfiguration(null, null, null, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        System.out.println(config);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        Plugin p = Jlink.newPlugin("toto", Collections.emptyMap(), null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        if (p != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
            throw new Exception("Plugin should be null");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        Plugin p2 = Jlink.newPlugin("compress", Collections.emptyMap(), null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        if (p2 == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
            throw new Exception("Plugin should not be null");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
    private static void test() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        Jlink jlink = new Jlink();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        Path output = Paths.get("integrationout");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        List<Path> modulePaths = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        File jmods
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk")));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        modulePaths.add(jmods.toPath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        Set<String> mods = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        mods.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        Set<String> limits = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        limits.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        JlinkConfiguration config = new Jlink.JlinkConfiguration(output,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
                modulePaths, mods, limits, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        List<Plugin> lst = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        //Strip debug
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
            Map<String, String> config1 = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            config1.put(StripDebugPlugin.NAME, "");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
            Plugin strip = Jlink.newPlugin("strip-debug", config1, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
            lst.add(strip);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        // compress
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
            Map<String, String> config1 = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            config1.put(DefaultCompressPlugin.NAME, "2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            Plugin compress
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
                    = Jlink.newPlugin("compress", config1, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
            lst.add(compress);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        // Post processor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
            lst.add(new MyPostProcessor());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        // Image builder
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   246
        DefaultImageBuilder builder = new DefaultImageBuilder(output);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        PluginsConfiguration plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                = new Jlink.PluginsConfiguration(lst, builder, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        jlink.build(config, plugins);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        if (!Files.exists(output)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
            throw new AssertionError("Directory not created");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
        File jimage = new File(output.toString(), "lib" + File.separator + "modules");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        if (!jimage.exists()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
            throw new AssertionError("jimage not generated");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        File release = new File(output.toString(), "release");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        if (!release.exists()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
            throw new AssertionError("release not generated");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        if (!Files.exists(output.resolve("toto.txt"))) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
            throw new AssertionError("Post processing not called");
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
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
    private static void testOrder() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
        Jlink jlink = new Jlink();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
        Path output = Paths.get("integrationout2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
        List<Path> modulePaths = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        File jmods
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk")));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        modulePaths.add(jmods.toPath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        Set<String> mods = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        mods.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        Set<String> limits = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
        limits.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
        JlinkConfiguration config = new Jlink.JlinkConfiguration(output,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
                modulePaths, mods, limits, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        List<Plugin> lst = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        // Order is Plug1>Plug2>Plug3
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        // Plug1
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
        // TRANSFORMER 3, must be after 2.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
            Set<String> after = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
            after.add(MyPlugin1.NAME+"2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
            lst.add(new MyPlugin1(3, after, Collections.emptySet()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
        // TRANSFORMER 2, must be after 1.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
            Set<String> after = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   300
            after.add(MyPlugin1.NAME+"1");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   301
            lst.add(new MyPlugin1(2, after, Collections.emptySet()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   302
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   303
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
        // TRANSFORMER 1
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   306
            Set<String> before = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   307
            before.add(MyPlugin1.NAME+"2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   308
            lst.add(new MyPlugin1(1, Collections.emptySet(), before));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   309
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   310
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   311
        // Image builder
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   312
        DefaultImageBuilder builder = new DefaultImageBuilder(output);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
        PluginsConfiguration plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   314
                = new Jlink.PluginsConfiguration(lst, builder, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
        jlink.build(config, plugins);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
        if (ordered.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
            throw new AssertionError("Plugins not called");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        List<Integer> clone = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   322
        clone.addAll(ordered);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   323
        Collections.sort(clone);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   324
        if (!clone.equals(ordered)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   325
            throw new AssertionError("Ordered is not properly sorted" + ordered);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   326
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   327
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   328
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   329
    private static void testCycleOrder() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        Jlink jlink = new Jlink();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
        Path output = Paths.get("integrationout3");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
        List<Path> modulePaths = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   333
        File jmods
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   334
                = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk")));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   335
        modulePaths.add(jmods.toPath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
        Set<String> mods = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   337
        mods.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
        Set<String> limits = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
        limits.add("java.management");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
        JlinkConfiguration config = new Jlink.JlinkConfiguration(output,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
                modulePaths, mods, limits, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   343
        List<Plugin> lst = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   345
        // packager 1
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
            Set<String> before = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
            before.add(MyPlugin1.NAME+"2");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
            lst.add(new MyPlugin1(1, Collections.emptySet(), before));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   350
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   352
        // packager 2
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
            Set<String> before = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
            before.add(MyPlugin1.NAME+"1");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
            lst.add(new MyPlugin1(2, Collections.emptySet(), before));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   357
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   358
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   359
        // Image builder
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   360
        DefaultImageBuilder builder = new DefaultImageBuilder(output);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   361
        PluginsConfiguration plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
                = new Jlink.PluginsConfiguration(lst, builder, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
        boolean failed = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   364
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   365
            jlink.build(config, plugins);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
            failed = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
            // XXX OK
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
        if (failed) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
            throw new AssertionError("Should have failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   372
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   373
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   374
}