jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java
author mchung
Mon, 27 Mar 2017 15:12:01 -0700
changeset 44367 a81c9c6619fb
parent 43987 068a2419b5a7
child 44545 83b611b88ac8
permissions -rw-r--r--
8174826: jlink support for linking in service provider modules Reviewed-by: alanb, anazarov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  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;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.io.File;
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.PrintWriter;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.lang.module.Configuration;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.lang.module.ModuleFinder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.lang.reflect.Layer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.text.MessageFormat;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.ArrayList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.Arrays;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.util.HashSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.Locale;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.Map.Entry;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.util.MissingResourceException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.ResourceBundle;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import java.util.Set;
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
    49
import java.util.stream.Collectors;
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
    50
import java.util.stream.Stream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
41561
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
    52
import jdk.tools.jlink.internal.plugins.ExcludeJmodSectionPlugin;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import jdk.tools.jlink.plugin.Plugin;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    54
import jdk.tools.jlink.plugin.Plugin.Category;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
import jdk.tools.jlink.builder.DefaultImageBuilder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
import jdk.tools.jlink.builder.ImageBuilder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
import jdk.tools.jlink.plugin.PluginException;
41559
5b33f33df1fb 8168091: jlink should check security permission early when programmatic access is used
sundar
parents: 40261
diff changeset
    58
import jdk.tools.jlink.internal.Jlink.PluginsConfiguration;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
import jdk.tools.jlink.internal.plugins.PluginsResourceBundle;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
import jdk.tools.jlink.internal.plugins.DefaultCompressPlugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
import jdk.tools.jlink.internal.plugins.StripDebugPlugin;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42330
diff changeset
    62
import jdk.internal.module.ModulePath;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
 * JLink and JImage tools shared helper.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
public final class TaskHelper {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    public static final String JLINK_BUNDLE = "jdk.tools.jlink.resources.jlink";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    public static final String JIMAGE_BUNDLE = "jdk.tools.jimage.resources.jimage";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    private static final String DEFAULTS_PROPERTY = "jdk.jlink.defaults";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    public final class BadArgs extends Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        static final long serialVersionUID = 8765093759964640721L;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        private BadArgs(String key, Object... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            super(bundleHelper.getMessage(key, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
            this.key = key;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
            this.args = args;
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
        public BadArgs showUsage(boolean b) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
            showUsage = b;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        public final String key;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        public final Object[] args;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        public boolean showUsage;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
    94
    public static class Option<T> implements Comparable<T> {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        public interface Processing<T> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
            void process(T task, String opt, String arg) throws BadArgs;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        final boolean hasArg;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        final Processing<T> processing;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        final boolean hidden;
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   103
        final String name;
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   104
        final String shortname;
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   105
        final boolean terminalOption;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   107
        public Option(boolean hasArg,
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   108
                      Processing<T> processing,
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   109
                      boolean hidden,
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   110
                      String name,
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   111
                      String shortname,
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   112
                      boolean isTerminal)
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   113
        {
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   114
            if (!name.startsWith("--")) {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   115
                throw new RuntimeException("option name missing --, " + name);
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   116
            }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   117
            if (!shortname.isEmpty() && !shortname.startsWith("-")) {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   118
                throw new RuntimeException("short name missing -, " + shortname);
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   119
            }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   120
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
            this.hasArg = hasArg;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            this.processing = processing;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
            this.hidden = hidden;
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   124
            this.name = name;
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   125
            this.shortname = shortname;
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   126
            this.terminalOption = isTerminal;
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   127
        }
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   128
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   129
        public Option(boolean hasArg, Processing<T> processing, String name, String shortname, boolean isTerminal) {
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   130
            this(hasArg, processing, false, name, shortname, isTerminal);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   133
        public Option(boolean hasArg, Processing<T> processing, String name, String shortname) {
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   134
            this(hasArg, processing, false, name, shortname, false);
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   135
        }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   136
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   137
        public Option(boolean hasArg, Processing<T> processing, boolean hidden, String name) {
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   138
            this(hasArg, processing, hidden, name, "", false);
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   139
        }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   140
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   141
        public Option(boolean hasArg, Processing<T> processing, String name) {
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   142
            this(hasArg, processing, false, name, "", false);
36511
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
        public boolean isHidden() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            return hidden;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   149
        public boolean isTerminal() {
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   150
            return terminalOption;
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   151
        }
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   152
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        public boolean matches(String opt) {
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   154
            return opt.equals(name) ||
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   155
                   opt.equals(shortname) ||
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   156
                   hasArg && opt.startsWith("--") && opt.startsWith(name + "=");
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   157
         }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        public boolean ignoreRest() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
            return false;
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
        void process(T task, String opt, String arg) throws BadArgs {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
            processing.process(task, opt, arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        }
38869
4bac8f3bce74 8156994: jimage --help is not helpful
jlaskey
parents: 38457
diff changeset
   166
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   167
        public String getName() {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   168
            return name;
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   169
        }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   170
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   171
        public String resourceName() {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   172
            return resourcePrefix() + name.substring(2);
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   173
        }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   175
        public String getShortname() {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   176
            return shortname;
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   177
        }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   178
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   179
        public String resourcePrefix() {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   180
            return "main.opt.";
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   181
        }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   182
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   183
        @Override
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   184
        public int compareTo(Object object) {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   185
            if (!(object instanceof Option<?>)) {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   186
                throw new RuntimeException("comparing non-Option");
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   187
            }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   188
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   189
            Option<?> option = (Option<?>)object;
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   190
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   191
            return name.compareTo(option.name);
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   192
        }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   193
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   194
    }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   195
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   196
    private static class PluginOption extends Option<PluginsHelper> {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   197
        public PluginOption(boolean hasArg,
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   198
                Processing<PluginsHelper> processing, boolean hidden, String name, String shortname) {
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   199
            super(hasArg, processing, hidden, name, shortname, false);
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   200
        }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   201
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   202
        public PluginOption(boolean hasArg,
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   203
                Processing<PluginsHelper> processing, boolean hidden, String name) {
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   204
            super(hasArg, processing, hidden, name, "", false);
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   205
        }
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   206
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   207
        public String resourcePrefix() {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   208
            return "plugin.opt.";
38869
4bac8f3bce74 8156994: jimage --help is not helpful
jlaskey
parents: 38457
diff changeset
   209
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   212
    private final class PluginsHelper {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        private Layer pluginsLayer = Layer.boot();
41831
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   215
        private final List<Plugin> plugins;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        private String lastSorter;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        private boolean listPlugins;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        private Path existingImage;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        // plugin to args maps. Each plugin may be used more than once in command line.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        // Each such occurrence results in a Map of arguments. So, there could be multiple
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        // args maps per plugin instance.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        private final Map<Plugin, List<Map<String, String>>> pluginToMaps = new HashMap<>();
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   224
        private final List<PluginOption> pluginsOptions = new ArrayList<>();
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   225
        private final List<PluginOption> mainOptions = new ArrayList<>();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   227
        private PluginsHelper(String pp) throws BadArgs {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            if (pp != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                String[] dirs = pp.split(File.pathSeparator);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                List<Path> paths = new ArrayList<>(dirs.length);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                for (String dir : dirs) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                    paths.add(Paths.get(dir));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                pluginsLayer = createPluginsLayer(paths);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
41831
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   239
            plugins = PluginRepository.getPlugins(pluginsLayer);
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   240
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
            Set<String> optionsSeen = new HashSet<>();
41831
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   242
            for (Plugin plugin : plugins) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                if (!Utils.isDisabled(plugin)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                    addOrderedPluginOptions(plugin, optionsSeen);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
            }
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   247
            mainOptions.add(new PluginOption(true, (task, opt, arg) -> {
41831
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   248
                    for (Plugin plugin : plugins) {
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   249
                        if (plugin.getName().equals(arg)) {
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   250
                            pluginToMaps.remove(plugin);
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   251
                            return;
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   252
                        }
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   253
                    }
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   254
                    throw newBadArgs("err.no.such.plugin", arg);
2dd91b18195b 8160063: Provide a means to disable a plugin via the command line
sundar
parents: 41817
diff changeset
   255
                },
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   256
                false, "--disable-plugin"));
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   257
            mainOptions.add(new PluginOption(true, (task, opt, arg) -> {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                Path path = Paths.get(arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                if (!Files.exists(path) || !Files.isDirectory(path)) {
41953
3e89e6103470 8155756: Better context for some jlink exceptions
jlaskey
parents: 41919
diff changeset
   260
                    throw newBadArgs("err.image.must.exist", path);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
                existingImage = path.toAbsolutePath();
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   263
            }, true, "--post-process-path"));
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   264
            mainOptions.add(new PluginOption(true,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                    (task, opt, arg) -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                        lastSorter = arg;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                    },
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                    true, "--resources-last-sorter"));
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   269
            mainOptions.add(new PluginOption(false,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                    (task, opt, arg) -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                        listPlugins = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                    },
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   273
                    false, "--list-plugins"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        private List<Map<String, String>> argListFor(Plugin plugin) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
            List<Map<String, String>> mapList = pluginToMaps.get(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
            if (mapList == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
                mapList = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                pluginToMaps.put(plugin, mapList);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
            return mapList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        private void addEmptyArgumentMap(Plugin plugin) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
            argListFor(plugin).add(Collections.emptyMap());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        private Map<String, String> addArgumentMap(Plugin plugin) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
            Map<String, String> map = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
            argListFor(plugin).add(map);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
            return map;
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
        private void addOrderedPluginOptions(Plugin plugin,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
            Set<String> optionsSeen) throws BadArgs {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
            String option = plugin.getOption();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
            if (option == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
                return;
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
            // make sure that more than one plugin does not use the same option!
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   303
            if (optionsSeen.contains(option)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
                throw new BadArgs("err.plugin.mutiple.options",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
                        option);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   306
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   307
            optionsSeen.add(option);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   308
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   309
            PluginOption plugOption
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   310
                    = new PluginOption(plugin.hasArguments(),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   311
                            (task, opt, arg) -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   312
                                if (!Utils.isFunctional(plugin)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
                                    throw newBadArgs("err.provider.not.functional",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   314
                                            option);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
                                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
                                if (! plugin.hasArguments()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
                                    addEmptyArgumentMap(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
                                    return;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
                                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   322
                                Map<String, String> m = addArgumentMap(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   323
                                // handle one or more arguments
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   324
                                if (arg.indexOf(':') == -1) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   325
                                    // single argument case
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   326
                                    m.put(option, arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   327
                                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   328
                                    // This option can accept more than one arguments
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   329
                                    // like --option_name=arg_value:arg2=value2:arg3=value3
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
                                    // ":" followed by word char condition takes care of args that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                                    // like Windows absolute paths "C:\foo", "C:/foo" [cygwin] etc.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   333
                                    // This enforces that key names start with a word character.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   334
                                    String[] args = arg.split(":(?=\\w)", -1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   335
                                    String firstArg = args[0];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
                                    if (firstArg.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   337
                                        throw newBadArgs("err.provider.additional.arg.error",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
                                            option, arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
                                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
                                    m.put(option, firstArg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
                                    // process the additional arguments
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
                                    for (int i = 1; i < args.length; i++) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   343
                                        String addArg = args[i];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
                                        int eqIdx = addArg.indexOf('=');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   345
                                        if (eqIdx == -1) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                                            throw newBadArgs("err.provider.additional.arg.error",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
                                                option, arg);
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
                                        String addArgName = addArg.substring(0, eqIdx);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
                                        String addArgValue = addArg.substring(eqIdx+1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   352
                                        if (addArgName.isEmpty() || addArgValue.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
                                            throw newBadArgs("err.provider.additional.arg.error",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
                                                option, arg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
                                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
                                        m.put(addArgName, addArgValue);
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
                            },
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   360
                            false, "--" + option);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   361
            pluginsOptions.add(plugOption);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
            if (Utils.isFunctional(plugin)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   364
                if (Utils.isAutoEnabled(plugin)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   365
                    addEmptyArgumentMap(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
                if (plugin instanceof DefaultCompressPlugin) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
                    plugOption
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   370
                        = new PluginOption(false,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
                            (task, opt, arg) -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   372
                                Map<String, String> m = addArgumentMap(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                                m.put(DefaultCompressPlugin.NAME, DefaultCompressPlugin.LEVEL_2);
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   374
                            }, false, "--compress", "-c");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   375
                    mainOptions.add(plugOption);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   376
                } else if (plugin instanceof StripDebugPlugin) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377
                    plugOption
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   378
                        = new PluginOption(false,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   379
                            (task, opt, arg) -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                                addArgumentMap(plugin);
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   381
                            }, false, "--strip-debug", "-G");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                    mainOptions.add(plugOption);
41561
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   383
                } else if (plugin instanceof ExcludeJmodSectionPlugin) {
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   384
                    plugOption = new PluginOption(false, (task, opt, arg) -> {
41561
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   385
                            Map<String, String> m = addArgumentMap(plugin);
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   386
                            m.put(ExcludeJmodSectionPlugin.NAME,
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   387
                                  ExcludeJmodSectionPlugin.MAN_PAGES);
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   388
                        }, false, "--no-man-pages");
41561
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   389
                    mainOptions.add(plugOption);
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   390
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   391
                    plugOption = new PluginOption(false, (task, opt, arg) -> {
41561
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   392
                        Map<String, String> m = addArgumentMap(plugin);
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   393
                        m.put(ExcludeJmodSectionPlugin.NAME,
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   394
                              ExcludeJmodSectionPlugin.INCLUDE_HEADER_FILES);
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   395
                    }, false, "--no-header-files");
41561
0c6942d13f2e 8167558: Add new JMOD section for header files and man pages
mchung
parents: 41559
diff changeset
   396
                    mainOptions.add(plugOption);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   397
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   398
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   399
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   400
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   401
        private PluginOption getOption(String name) throws BadArgs {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   402
            for (PluginOption o : pluginsOptions) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   403
                if (o.matches(name)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   404
                    return o;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   405
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   406
            }
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   407
            for (PluginOption o : mainOptions) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   408
                if (o.matches(name)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   409
                    return o;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   410
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   411
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   412
            return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   413
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   414
42762
11a1ad340d4f 8170289: Re-examine entry point support in jlink
sundar
parents: 42703
diff changeset
   415
        private PluginsConfiguration getPluginsConfig(Path output, Map<String, String> launchers
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   416
                    ) throws IOException, BadArgs {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   417
            if (output != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   418
                if (Files.exists(output)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   419
                    throw new PluginException(PluginsResourceBundle.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   420
                            getMessage("err.dir.already.exits", output));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   421
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   422
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   423
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   424
            List<Plugin> pluginsList = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   425
            for (Entry<Plugin, List<Map<String, String>>> entry : pluginToMaps.entrySet()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   426
                Plugin plugin = entry.getKey();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   427
                List<Map<String, String>> argsMaps = entry.getValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   428
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   429
                // same plugin option may be used multiple times in command line.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   430
                // we call configure once for each occurrence. It is upto the plugin
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   431
                // to 'merge' and/or 'override' arguments.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   432
                for (Map<String, String> map : argsMaps) {
42330
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 42174
diff changeset
   433
                    try {
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 42174
diff changeset
   434
                        plugin.configure(Collections.unmodifiableMap(map));
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 42174
diff changeset
   435
                    } catch (IllegalArgumentException e) {
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 42174
diff changeset
   436
                        if (JlinkTask.DEBUG) {
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 42174
diff changeset
   437
                            System.err.println("Plugin " + plugin.getName() + " threw exception with config: " + map);
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 42174
diff changeset
   438
                            e.printStackTrace();
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 42174
diff changeset
   439
                        }
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 42174
diff changeset
   440
                        throw e;
bd999576b78d 8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents: 42174
diff changeset
   441
                    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   442
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   443
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   444
                if (!Utils.isDisabled(plugin)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   445
                    pluginsList.add(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   446
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   447
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   448
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   449
            // recreate or postprocessing don't require an output directory.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   450
            ImageBuilder builder = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   451
            if (output != null) {
42762
11a1ad340d4f 8170289: Re-examine entry point support in jlink
sundar
parents: 42703
diff changeset
   452
                builder = new DefaultImageBuilder(output, launchers);
11a1ad340d4f 8170289: Re-examine entry point support in jlink
sundar
parents: 42703
diff changeset
   453
            }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   454
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   455
            return new Jlink.PluginsConfiguration(pluginsList,
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   456
                    builder, lastSorter);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   457
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   458
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   459
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   460
    private static final class ResourceBundleHelper {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   461
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   462
        private final ResourceBundle bundle;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   463
        private final ResourceBundle pluginBundle;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   464
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   465
        ResourceBundleHelper(String path) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   466
            Locale locale = Locale.getDefault();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   467
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   468
                bundle = ResourceBundle.getBundle(path, locale);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   469
                pluginBundle = ResourceBundle.getBundle("jdk.tools.jlink.resources.plugins", locale);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   470
            } catch (MissingResourceException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   471
                throw new InternalError("Cannot find jlink resource bundle for locale " + locale);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   472
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   473
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   474
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   475
        String getMessage(String key, Object... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   476
            String val;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   477
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   478
                val = bundle.getString(key);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   479
            } catch (MissingResourceException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   480
                // XXX OK, check in plugin bundle
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   481
                val = pluginBundle.getString(key);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   482
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   483
            return MessageFormat.format(val, args);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   484
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   485
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   486
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   487
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   488
    public final class OptionsHelper<T> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   489
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   490
        private final List<Option<T>> options;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   491
        private String[] command;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   492
        private String defaults;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   493
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   494
        OptionsHelper(List<Option<T>> options) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   495
            this.options = options;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   496
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   497
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   498
        private boolean hasArgument(String optionName) throws BadArgs {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   499
            Option<?> opt = getOption(optionName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   500
            if (opt == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   501
                opt = pluginOptions.getOption(optionName);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   502
                if (opt == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   503
                    throw new BadArgs("err.unknown.option", optionName).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   504
                            showUsage(true);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   505
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   506
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   507
            return opt.hasArg;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   508
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   509
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   510
        public boolean shouldListPlugins() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   511
            return pluginOptions.listPlugins;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   512
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   513
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   514
        private String getPluginsPath(String[] args) throws BadArgs {
43328
91f9c9170d97 8172864: Remove custom plugin module path
sundar
parents: 42762
diff changeset
   515
            return null;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   516
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   517
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   518
        /**
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   519
         * Handles all options.  This method stops processing the argument
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   520
         * at the first non-option argument i.e. not starts with `-`, or
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   521
         * at the first terminal option and returns the remaining arguments,
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   522
         * if any.
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   523
         */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   524
        public List<String> handleOptions(T task, String[] args) throws BadArgs {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   525
            // findbugs warning, copy instead of keeping a reference.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   526
            command = Arrays.copyOf(args, args.length);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   527
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   528
            // Must extract it prior to do any option analysis.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   529
            // Required to interpret custom plugin options.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   530
            // Unit tests can call Task multiple time in same JVM.
43328
91f9c9170d97 8172864: Remove custom plugin module path
sundar
parents: 42762
diff changeset
   531
            pluginOptions = new PluginsHelper(null);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   532
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   533
            // process options
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   534
            for (int i = 0; i < args.length; i++) {
43987
068a2419b5a7 8169713: jimage fails with StringIndexOutOfBoundsException when path to the inspected image is an empty string
redestad
parents: 43712
diff changeset
   535
                if (args[i].startsWith("-")) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   536
                    String name = args[i];
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   537
                    PluginOption pluginOption = null;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   538
                    Option<T> option = getOption(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   539
                    if (option == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   540
                        pluginOption = pluginOptions.getOption(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   541
                        if (pluginOption == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   542
                            throw new BadArgs("err.unknown.option", name).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   543
                                    showUsage(true);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   544
                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   545
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   546
                    Option<?> opt = pluginOption == null ? option : pluginOption;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   547
                    String param = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   548
                    if (opt.hasArg) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   549
                        if (name.startsWith("--") && name.indexOf('=') > 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   550
                            param = name.substring(name.indexOf('=') + 1,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   551
                                    name.length());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   552
                        } else if (i + 1 < args.length) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   553
                            param = args[++i];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   554
                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   555
                        if (param == null || param.isEmpty()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   556
                                || (param.length() >= 2 && param.charAt(0) == '-'
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   557
                                && param.charAt(1) == '-')) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   558
                            throw new BadArgs("err.missing.arg", name).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   559
                                    showUsage(true);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   560
                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   561
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   562
                    if (pluginOption != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   563
                        pluginOption.process(pluginOptions, name, param);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   564
                    } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   565
                        option.process(task, name, param);
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   566
                        if (option.isTerminal()) {
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   567
                            return ++i < args.length
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   568
                                        ? Stream.of(Arrays.copyOfRange(args, i, args.length))
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   569
                                                .collect(Collectors.toList())
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   570
                                        : Collections.emptyList();
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   571
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   572
                        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   573
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   574
                    if (opt.ignoreRest()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   575
                        i = args.length;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   576
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   577
                } else {
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   578
                    return Stream.of(Arrays.copyOfRange(args, i, args.length))
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   579
                                 .collect(Collectors.toList());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   580
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   581
            }
44367
a81c9c6619fb 8174826: jlink support for linking in service provider modules
mchung
parents: 43987
diff changeset
   582
            return Collections.emptyList();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   583
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   584
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   585
        private Option<T> getOption(String name) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   586
            for (Option<T> o : options) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   587
                if (o.matches(name)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   588
                    return o;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   589
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   590
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   591
            return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   592
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   593
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   594
        public void showHelp(String progName) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   595
            log.println(bundleHelper.getMessage("main.usage", progName));
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   596
            Stream.concat(options.stream(), pluginOptions.mainOptions.stream())
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   597
                .filter(option -> !option.isHidden())
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   598
                .sorted()
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   599
                .forEach(option -> {
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   600
                     log.println(bundleHelper.getMessage(option.resourceName()));
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   601
                });
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   602
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   603
            log.println(bundleHelper.getMessage("main.command.files"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   604
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   605
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   606
        public void listPlugins() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   607
            log.println("\n" + bundleHelper.getMessage("main.extended.help"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   608
            List<Plugin> pluginList = PluginRepository.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   609
                    getPlugins(pluginOptions.pluginsLayer);
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   610
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   611
            for (Plugin plugin : Utils.getSortedPlugins(pluginList)) {
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   612
                showPlugin(plugin, log);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   613
            }
39150
cb99396625b4 8159172: Update usage of jlink/jimage/jmod to show option patterns
jlaskey
parents: 38869
diff changeset
   614
cb99396625b4 8159172: Update usage of jlink/jimage/jmod to show option patterns
jlaskey
parents: 38869
diff changeset
   615
            log.println("\n" + bundleHelper.getMessage("main.extended.help.footer"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   616
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   617
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   618
        private void showPlugin(Plugin plugin, PrintWriter log) {
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   619
            if (showsPlugin(plugin)) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   620
                log.println("\n" + bundleHelper.getMessage("main.plugin.name")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   621
                        + ": " + plugin.getName());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   622
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   623
                // print verbose details for non-builtin plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   624
                if (!Utils.isBuiltin(plugin)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   625
                    log.println(bundleHelper.getMessage("main.plugin.class")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   626
                         + ": " + plugin.getClass().getName());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   627
                    log.println(bundleHelper.getMessage("main.plugin.module")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   628
                         + ": " + plugin.getClass().getModule().getName());
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   629
                    Category category = plugin.getType();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   630
                    log.println(bundleHelper.getMessage("main.plugin.category")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   631
                         + ": " + category.getName());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   632
                    log.println(bundleHelper.getMessage("main.plugin.state")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   633
                        + ": " + plugin.getStateDescription());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   634
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   635
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   636
                String option = plugin.getOption();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   637
                if (option != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   638
                    log.println(bundleHelper.getMessage("main.plugin.option")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   639
                        + ": --" + plugin.getOption()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   640
                        + (plugin.hasArguments()? ("=" + plugin.getArgumentsDescription()) : ""));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   641
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   642
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   643
                // description can be long spanning more than one line and so
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   644
                // print a newline after description label.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   645
                log.println(bundleHelper.getMessage("main.plugin.description")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   646
                        + ": " + plugin.getDescription());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   647
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   648
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   649
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   650
        String[] getInputCommand() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   651
            return command;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   652
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   653
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   654
        String getDefaults() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   655
            return defaults;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   656
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   657
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   658
        public Layer getPluginsLayer() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   659
            return pluginOptions.pluginsLayer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   660
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   661
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   662
42174
fa763b059501 8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents: 41953
diff changeset
   663
    private PluginsHelper pluginOptions;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   664
    private PrintWriter log;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   665
    private final ResourceBundleHelper bundleHelper;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   666
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   667
    public TaskHelper(String path) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   668
        if (!JLINK_BUNDLE.equals(path) && !JIMAGE_BUNDLE.equals(path)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   669
            throw new IllegalArgumentException("Invalid Bundle");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   670
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   671
        this.bundleHelper = new ResourceBundleHelper(path);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   672
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   673
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   674
    public <T> OptionsHelper<T> newOptionsHelper(Class<T> clazz,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   675
            Option<?>[] options) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   676
        List<Option<T>> optionsList = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   677
        for (Option<?> o : options) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   678
            @SuppressWarnings("unchecked")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   679
            Option<T> opt = (Option<T>) o;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   680
            optionsList.add(opt);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   681
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   682
        return new OptionsHelper<>(optionsList);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   683
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   684
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   685
    public BadArgs newBadArgs(String key, Object... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   686
        return new BadArgs(key, args);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   687
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   688
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   689
    public String getMessage(String key, Object... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   690
        return bundleHelper.getMessage(key, args);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   691
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   692
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   693
    public void setLog(PrintWriter log) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   694
        this.log = log;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   695
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   696
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   697
    public void reportError(String key, Object... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   698
        log.println(bundleHelper.getMessage("error.prefix") + " "
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   699
                + bundleHelper.getMessage(key, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   700
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   701
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   702
    public void reportUnknownError(String message) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   703
        log.println(bundleHelper.getMessage("error.prefix") + " " + message);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   704
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   705
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   706
    public void warning(String key, Object... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   707
        log.println(bundleHelper.getMessage("warn.prefix") + " "
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   708
                + bundleHelper.getMessage(key, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   709
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   710
42762
11a1ad340d4f 8170289: Re-examine entry point support in jlink
sundar
parents: 42703
diff changeset
   711
    public PluginsConfiguration getPluginsConfig(Path output, Map<String, String> launchers)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   712
            throws IOException, BadArgs {
42762
11a1ad340d4f 8170289: Re-examine entry point support in jlink
sundar
parents: 42703
diff changeset
   713
        return pluginOptions.getPluginsConfig(output, launchers);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   714
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   715
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   716
    public Path getExistingImage() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   717
        return pluginOptions.existingImage;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   718
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   719
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   720
    public void showVersion(boolean full) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   721
        log.println(version(full ? "full" : "release"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   722
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   723
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   724
    public String version(String key) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   725
        return System.getProperty("java.version");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   726
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   727
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   728
    static Layer createPluginsLayer(List<Path> paths) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   729
41817
b90ad1de93ea 8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents: 41766
diff changeset
   730
        Path[] dirs = paths.toArray(new Path[0]);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43495
diff changeset
   731
        ModuleFinder finder = ModulePath.of(Runtime.version(), true, dirs);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   732
        Configuration bootConfiguration = Layer.boot().configuration();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   733
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   734
            Configuration cf = bootConfiguration
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43495
diff changeset
   735
                .resolveAndBind(ModuleFinder.of(),
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43495
diff changeset
   736
                                finder,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43495
diff changeset
   737
                                Collections.emptySet());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   738
            ClassLoader scl = ClassLoader.getSystemClassLoader();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   739
            return Layer.boot().defineModulesWithOneLoader(cf, scl);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   740
        } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   741
            // Malformed plugin modules (e.g.: same package in multiple modules).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   742
            throw new PluginException("Invalid modules in the plugins path: " + ex);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   743
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   744
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   745
39321
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   746
    // Display all plugins
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   747
    private static boolean showsPlugin(Plugin plugin) {
c60f34e8c057 8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents: 39150
diff changeset
   748
        return (!Utils.isDisabled(plugin) && plugin.getOption() != null);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   749
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   750
}