jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java
author jlaskey
Tue, 28 Jun 2016 16:07:23 -0300
changeset 39308 f6517755057f
parent 39151 34455cc82f5e
child 39321 c60f34e8c057
permissions -rw-r--r--
8160459: jlink minor code clean up 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.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
package jdk.tools.jlink.internal.plugins;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.io.BufferedReader;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.io.InputStreamReader;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.io.UncheckedIOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.nio.charset.StandardCharsets;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.Comparator;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.util.TreeSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.util.function.Predicate;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.stream.Collectors;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import jdk.tools.jlink.plugin.TransformerPlugin;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    39
import jdk.tools.jlink.plugin.ModulePool;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    40
import jdk.tools.jlink.plugin.ModuleEntry;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import jdk.tools.jlink.plugin.PluginException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
 * Exclude VM plugin
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
public final class ExcludeVMPlugin implements TransformerPlugin {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
    private static final class JvmComparator implements Comparator<Jvm> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
        public int compare(Jvm o1, Jvm o2) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
            return o1.getEfficience() - o2.getEfficience();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    private enum Jvm {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        // The efficience order server - client - minimal.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        SERVER("server", 3), CLIENT("client", 2), MINIMAL("minimal", 1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        private final String name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        private final int efficience;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        Jvm(String name, int efficience) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
            this.name = name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
            this.efficience = efficience;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        private String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            return name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        private int getEfficience() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
            return efficience;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
    private static final String JVM_CFG = "jvm.cfg";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    public static final String NAME = "vm";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
    private static final String ALL = "all";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    private static final String CLIENT = "client";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    private static final String SERVER = "server";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    private static final String MINIMAL = "minimal";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
    private Predicate<String> predicate;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    private Jvm target;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
    private boolean keepAll;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        return NAME;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
     * VM paths:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
     * /java.base/native/{architecture}/{server|client|minimal}/{shared lib}
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
     * e.g.: /java.base/native/amd64/server/libjvm.so
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
     * /java.base/native/server/libjvm.dylib
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
     */
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   100
    private List<ModuleEntry> getVMs(ModulePool in) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        String jvmlib = jvmlib();
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   102
        List<ModuleEntry> ret = in.findModule("java.base").get().entries().filter((t) -> {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            return t.getPath().endsWith("/" + jvmlib);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        }).collect(Collectors.toList());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        return ret;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
    @Override
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   109
    public void visit(ModulePool in, ModulePool out) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        String jvmlib = jvmlib();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        TreeSet<Jvm> existing = new TreeSet<>(new JvmComparator());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        TreeSet<Jvm> removed = new TreeSet<>(new JvmComparator());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        if (!keepAll) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
            // First retrieve all available VM names and removed VM
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   115
            List<ModuleEntry> jvms = getVMs(in);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
            for (Jvm jvm : Jvm.values()) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   117
                for (ModuleEntry md : jvms) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                    if (md.getPath().endsWith("/" + jvm.getName() + "/" + jvmlib)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                        existing.add(jvm);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                        if (isRemoved(md)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                            removed.add(jvm);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        // Check that target exists
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        if (!keepAll) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
            if (!existing.contains(target)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                throw new PluginException("Selected VM " + target.getName() + " doesn't exist.");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        // Rewrite the jvm.cfg file.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   135
        in.transformAndCopy((file) -> {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            if (!keepAll) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   137
                if (file.getType().equals(ModuleEntry.Type.NATIVE_LIB)) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                    if (file.getPath().endsWith(JVM_CFG)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                            file = handleJvmCfgFile(file, existing, removed);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                        } catch (IOException ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
                            throw new UncheckedIOException(ex);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                file = isRemoved(file) ? null : file;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            return file;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        }, out);
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
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   153
    private boolean isRemoved(ModuleEntry file) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        return !predicate.test(file.getPath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
    @Override
39129
4b2086305b68 8159593: Plugin Set<Category> getType() should return a Category
sundar
parents: 39042
diff changeset
   158
    public Category getType() {
4b2086305b68 8159593: Plugin Set<Category> getType() should return a Category
sundar
parents: 39042
diff changeset
   159
        return Category.FILTER;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    public String getDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        return PluginsResourceBundle.getDescription(NAME);
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
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    public boolean hasArguments() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        return true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
    public String getArgumentsDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
       return PluginsResourceBundle.getArgument(NAME);
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
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
    public void configure(Map<String, String> config) {
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   179
        String value = config.get(NAME);
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   180
        String exclude = "";
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   181
        switch (value) {
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   182
            case ALL: {
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   183
                // no filter.
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   184
                keepAll = true;
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   185
                break;
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   186
            }
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   187
            case CLIENT: {
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   188
                target = Jvm.CLIENT;
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   189
                exclude = "/java.base/native**server/**,/java.base/native**minimal/**";
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   190
                break;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
            }
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   192
            case SERVER: {
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   193
                target = Jvm.SERVER;
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   194
                exclude = "/java.base/native**client/**,/java.base/native**minimal/**";
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   195
                break;
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   196
            }
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   197
            case MINIMAL: {
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   198
                target = Jvm.MINIMAL;
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   199
                exclude = "/java.base/native**server/**,/java.base/native**client/**";
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   200
                break;
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   201
            }
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   202
            default: {
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   203
                throw new IllegalArgumentException("Unknown exclude VM option: " + value);
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   204
            }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        }
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
   206
        predicate = ResourceFilter.excludeFilter(exclude);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   209
    private ModuleEntry handleJvmCfgFile(ModuleEntry orig,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
            TreeSet<Jvm> existing,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
            TreeSet<Jvm> removed) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        if (keepAll) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
            return orig;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        StringBuilder builder = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        // Keep comments
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        try (BufferedReader reader
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                = new BufferedReader(new InputStreamReader(orig.stream(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                        StandardCharsets.UTF_8))) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
            reader.lines().forEach((s) -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                if (s.startsWith("#")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
                    builder.append(s).append("\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        TreeSet<Jvm> remaining = new TreeSet<>(new JvmComparator());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        // Add entry in jvm.cfg file from the more efficient to less efficient.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        for (Jvm platform : existing) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            if (!removed.contains(platform)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                remaining.add(platform);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                builder.append("-").append(platform.getName()).append(" KNOWN\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        // removed JVM are aliased to the most efficient remaining JVM (last one).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        // The order in the file is from most to less efficient platform
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        for (Jvm platform : removed.descendingSet()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            builder.append("-").append(platform.getName()).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                    append(" ALIASED_TO -").
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                    append(remaining.last().getName()).append("\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   242
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        byte[] content = builder.toString().getBytes(StandardCharsets.UTF_8);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
39151
34455cc82f5e 8147794: Jlink's ModuleEntry.stream can't be consumed more than once and ModuleEntry content should be read only if needed
sundar
parents: 39129
diff changeset
   245
        return orig.create(content);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
    private static String jvmlib() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        String lib = "libjvm.so";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        if (isWindows()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
            lib = "jvm.dll";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        } else if (isMac()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
            lib = "libjvm.dylib";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
        return lib;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
    private static boolean isWindows() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        return System.getProperty("os.name").startsWith("Windows");
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
    private static boolean isMac() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        return System.getProperty("os.name").startsWith("Mac OS");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
}