src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java
author serb
Sat, 09 Jun 2018 13:33:35 -0700
changeset 50647 a98ff7c2103d
parent 48543 7067fe4e054e
child 52650 c16b6cc93272
permissions -rw-r--r--
6608234: SwingWorker.get throws CancellationException Reviewed-by: psadhukhan, kaddepalli, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
     1
/*
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 48253
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
     4
 *
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    10
 *
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    15
 * accompanied this code).
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    16
 *
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    20
 *
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    23
 * questions.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    24
 */
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 30846
diff changeset
    25
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    26
package com.sun.tools.jdeps;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    27
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
    28
import com.sun.tools.jdeps.Analyzer.Type;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    29
import static com.sun.tools.jdeps.Analyzer.Type.*;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    30
import static com.sun.tools.jdeps.JdepsWriter.*;
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
    31
import static java.util.stream.Collectors.*;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    32
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    33
import java.io.IOException;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    34
import java.io.PrintWriter;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    35
import java.lang.module.ResolutionException;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    36
import java.nio.file.Files;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    37
import java.nio.file.Path;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    38
import java.nio.file.Paths;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    39
import java.text.MessageFormat;
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
    40
import java.util.*;
41164
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 40762
diff changeset
    41
import java.util.jar.JarFile;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    42
import java.util.regex.Pattern;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    43
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    44
/**
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    45
 * Implementation for the jdeps tool for static class dependency analysis.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    46
 */
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    47
class JdepsTask {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    48
    static interface BadArguments {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    49
        String getKey();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    50
        Object[] getArgs();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    51
        boolean showUsage();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    52
    }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    53
    static class BadArgs extends Exception implements BadArguments {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    54
        static final long serialVersionUID = 8765093759964640721L;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    55
        BadArgs(String key, Object... args) {
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
    56
            super(JdepsTask.getMessage(key, args));
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    57
            this.key = key;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    58
            this.args = args;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    59
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    60
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    61
        BadArgs showUsage(boolean b) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    62
            showUsage = b;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    63
            return this;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    64
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    65
        final String key;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    66
        final Object[] args;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    67
        boolean showUsage;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    68
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    69
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    70
        public String getKey() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    71
            return key;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    72
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    73
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    74
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    75
        public Object[] getArgs() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    76
            return args;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    77
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    78
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    79
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    80
        public boolean showUsage() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    81
            return showUsage;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    82
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    83
    }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    84
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    85
    static class UncheckedBadArgs extends RuntimeException implements BadArguments {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    86
        static final long serialVersionUID = -1L;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    87
        final BadArgs cause;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    88
        UncheckedBadArgs(BadArgs cause) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    89
            super(cause);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    90
            this.cause = cause;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    91
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    92
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    93
        public String getKey() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    94
            return cause.key;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    95
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    96
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    97
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    98
        public Object[] getArgs() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    99
            return cause.args;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   100
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   101
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   102
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   103
        public boolean showUsage() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   104
            return cause.showUsage;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   105
        }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   106
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   107
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   108
    static abstract class Option {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   109
        Option(boolean hasArg, String... aliases) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   110
            this.hasArg = hasArg;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   111
            this.aliases = aliases;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   112
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   113
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   114
        Option(boolean hasArg, CommandOption cmd) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   115
            this(hasArg, cmd.names());
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   116
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   117
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   118
        boolean isHidden() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   119
            return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   120
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   121
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   122
        boolean matches(String opt) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   123
            for (String a : aliases) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   124
                if (a.equals(opt))
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   125
                    return true;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   126
                if (hasArg && opt.startsWith(a + "="))
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   127
                    return true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   128
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   129
            return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   130
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   131
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   132
        boolean ignoreRest() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   133
            return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   134
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   135
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   136
        abstract void process(JdepsTask task, String opt, String arg) throws BadArgs;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   137
        final boolean hasArg;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   138
        final String[] aliases;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   139
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   140
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   141
    static abstract class HiddenOption extends Option {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   142
        HiddenOption(boolean hasArg, String... aliases) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   143
            super(hasArg, aliases);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   144
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   145
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   146
        boolean isHidden() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   147
            return true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   148
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   149
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   150
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   151
    enum CommandOption {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   152
        ANALYZE_DEPS(""),
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   153
        GENERATE_DOT_FILE("-dotoutput", "--dot-output"),
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   154
        GENERATE_MODULE_INFO("--generate-module-info"),
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41998
diff changeset
   155
        GENERATE_OPEN_MODULE("--generate-open-module"),
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   156
        LIST_DEPS("--list-deps"),
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   157
        LIST_REDUCED_DEPS("--list-reduced-deps"),
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   158
        PRINT_MODULE_DEPS("--print-module-deps"),
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   159
        CHECK_MODULES("--check");
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   160
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   161
        private final String[] names;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   162
        CommandOption(String... names) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   163
            this.names = names;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   164
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   165
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   166
        String[] names() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   167
            return names;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   168
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   169
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   170
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   171
        public String toString() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   172
            return names[0];
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   173
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   174
    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   175
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   176
    static Option[] recognizedOptions = {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   177
        new Option(false, "-h", "-?", "-help", "--help") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   178
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   179
                task.options.help = true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   180
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   181
        },
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   182
        new Option(true, CommandOption.GENERATE_DOT_FILE) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   183
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   184
                if (task.command != null) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   185
                    throw new BadArgs("err.command.set", task.command, opt);
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   186
                }
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   187
                task.command = task.genDotFile(Paths.get(arg));
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   188
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   189
        },
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   190
        new Option(false, "-s", "-summary") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   191
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   192
                task.options.showSummary = true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   193
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   194
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   195
        new Option(false, "-v", "-verbose",
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   196
                                "-verbose:module",
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   197
                                "-verbose:package",
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   198
                                "-verbose:class") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   199
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   200
                switch (opt) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   201
                    case "-v":
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   202
                    case "-verbose":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   203
                        task.options.verbose = VERBOSE;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   204
                        task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   205
                        task.options.filterSamePackage = false;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   206
                        break;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   207
                    case "-verbose:module":
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   208
                        task.options.verbose = MODULE;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   209
                        break;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   210
                    case "-verbose:package":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   211
                        task.options.verbose = PACKAGE;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   212
                        break;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   213
                    case "-verbose:class":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   214
                        task.options.verbose = CLASS;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   215
                        break;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   216
                    default:
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   217
                        throw new BadArgs("err.invalid.arg.for.option", opt);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   218
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   219
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   220
        },
41251
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   221
        new Option(false, "-apionly", "--api-only") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   222
            void process(JdepsTask task, String opt, String arg) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   223
                task.options.apiOnly = true;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   224
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   225
        },
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   226
41251
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   227
        new Option(false, "-jdkinternals", "--jdk-internals") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   228
            void process(JdepsTask task, String opt, String arg) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   229
                task.options.findJDKInternals = true;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   230
                if (task.options.includePattern == null) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   231
                    task.options.includePattern = Pattern.compile(".*");
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   232
                }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   233
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   234
        },
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   235
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   236
        // ---- paths option ----
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   237
        new Option(true, "-cp", "-classpath", "--class-path") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   238
            void process(JdepsTask task, String opt, String arg) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   239
                task.options.classpath = arg;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   240
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   241
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   242
        new Option(true, "--module-path") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   243
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   244
                task.options.modulePath = arg;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   245
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   246
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   247
        new Option(true, "--upgrade-module-path") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   248
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   249
                task.options.upgradeModulePath = arg;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   250
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   251
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   252
        new Option(true, "--system") {
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   253
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   254
                if (arg.equals("none")) {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   255
                    task.options.systemModulePath = null;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   256
                } else {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   257
                    Path path = Paths.get(arg);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   258
                    if (Files.isRegularFile(path.resolve("lib").resolve("modules")))
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   259
                        task.options.systemModulePath = arg;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   260
                    else
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   261
                        throw new BadArgs("err.invalid.path", arg);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   262
                }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   263
            }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   264
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   265
        new Option(true, "--add-modules") {
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   266
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   267
                Set<String> mods = Set.of(arg.split(","));
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   268
                task.options.addmods.addAll(mods);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   269
            }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   270
        },
41251
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   271
        new Option(true, "--multi-release") {
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   272
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   273
                if (arg.equalsIgnoreCase("base")) {
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   274
                    task.options.multiRelease = JarFile.baseVersion();
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   275
                } else {
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   276
                    try {
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   277
                        int v = Integer.parseInt(arg);
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   278
                        if (v < 9) {
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   279
                            throw new BadArgs("err.invalid.arg.for.option", arg);
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   280
                        }
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   281
                    } catch (NumberFormatException x) {
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   282
                        throw new BadArgs("err.invalid.arg.for.option", arg);
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   283
                    }
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   284
                    task.options.multiRelease = Runtime.Version.parse(arg);
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   285
                }
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   286
            }
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   287
        },
47308
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   288
        new Option(false, "-q", "-quiet") {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   289
            void process(JdepsTask task, String opt, String arg) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   290
                task.options.nowarning = true;
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   291
            }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   292
        },
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   293
        new Option(false, "-version", "--version") {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   294
            void process(JdepsTask task, String opt, String arg) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   295
                task.options.version = true;
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   296
            }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   297
        },
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   298
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   299
        // ---- module-specific options ----
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   300
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   301
        new Option(true, "-m", "--module") {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   302
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   303
                if (!task.options.rootModules.isEmpty()) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   304
                    throw new BadArgs("err.option.already.specified", opt);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   305
                }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   306
                task.options.rootModules.add(arg);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   307
                task.options.addmods.add(arg);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   308
            }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   309
        },
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   310
        new Option(true, CommandOption.GENERATE_MODULE_INFO) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   311
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   312
                if (task.command != null) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   313
                    throw new BadArgs("err.command.set", task.command, opt);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   314
                }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   315
                task.command = task.genModuleInfo(Paths.get(arg), false);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   316
            }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   317
        },
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   318
        new Option(true, CommandOption.GENERATE_OPEN_MODULE) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   319
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   320
                if (task.command != null) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   321
                    throw new BadArgs("err.command.set", task.command, opt);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   322
                }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   323
                task.command = task.genModuleInfo(Paths.get(arg), true);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   324
            }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   325
        },
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   326
        new Option(true, CommandOption.CHECK_MODULES) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   327
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   328
                if (task.command != null) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   329
                    throw new BadArgs("err.command.set", task.command, opt);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   330
                }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   331
                Set<String> mods =  Set.of(arg.split(","));
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   332
                task.options.addmods.addAll(mods);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   333
                task.command = task.checkModuleDeps(mods);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   334
            }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   335
        },
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   336
        new Option(false, CommandOption.LIST_DEPS) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   337
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   338
                if (task.command != null) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   339
                    throw new BadArgs("err.command.set", task.command, opt);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   340
                }
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   341
                task.command = task.listModuleDeps(CommandOption.LIST_DEPS);
47308
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   342
            }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   343
        },
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   344
        new Option(false, CommandOption.LIST_REDUCED_DEPS) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   345
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   346
                if (task.command != null) {
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   347
                    throw new BadArgs("err.command.set", task.command, opt);
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   348
                }
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   349
                task.command = task.listModuleDeps(CommandOption.LIST_REDUCED_DEPS);
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   350
            }
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   351
        },
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   352
        new Option(false, CommandOption.PRINT_MODULE_DEPS) {
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   353
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   354
                if (task.command != null) {
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   355
                    throw new BadArgs("err.command.set", task.command, opt);
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   356
                }
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   357
                task.command = task.listModuleDeps(CommandOption.PRINT_MODULE_DEPS);
47308
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   358
            }
5f351a1131e0 8188321: (jdeps) help message should say "requires transitive" rather than "requires public"
mchung
parents: 47216
diff changeset
   359
        },
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   360
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   361
        // ---- Target filtering options ----
41251
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   362
        new Option(true, "-p", "-package", "--package") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   363
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   364
                task.options.packageNames.add(arg);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   365
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   366
        },
41251
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   367
        new Option(true, "-e", "-regex", "--regex") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   368
            void process(JdepsTask task, String opt, String arg) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   369
                task.options.regex = Pattern.compile(arg);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   370
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   371
        },
41251
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   372
        new Option(true, "--require") {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   373
            void process(JdepsTask task, String opt, String arg) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   374
                task.options.requires.add(arg);
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   375
                task.options.addmods.add(arg);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   376
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   377
        },
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   378
        new Option(true, "-f", "-filter") {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   379
            void process(JdepsTask task, String opt, String arg) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   380
                task.options.filterRegex = Pattern.compile(arg);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   381
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   382
        },
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   383
        new Option(false, "-filter:package",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   384
                          "-filter:archive", "-filter:module",
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   385
                          "-filter:none") {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   386
            void process(JdepsTask task, String opt, String arg) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   387
                switch (opt) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   388
                    case "-filter:package":
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   389
                        task.options.filterSamePackage = true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   390
                        task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   391
                        break;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   392
                    case "-filter:archive":
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   393
                    case "-filter:module":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   394
                        task.options.filterSameArchive = true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   395
                        task.options.filterSamePackage = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   396
                        break;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   397
                    case "-filter:none":
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   398
                        task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   399
                        task.options.filterSamePackage = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   400
                        break;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   401
                }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   402
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   403
        },
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   404
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   405
        // ---- Source filtering options ----
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   406
        new Option(true, "-include") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   407
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   408
                task.options.includePattern = Pattern.compile(arg);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   409
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   410
        },
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   411
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   412
        new Option(false, "-P", "-profile") {
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents: 16290
diff changeset
   413
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   414
                task.options.showProfile = true;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   415
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   416
        },
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   417
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   418
        new Option(false, "-R", "-recursive") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   419
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   420
                task.options.depth = 0;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   421
                // turn off filtering
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   422
                task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   423
                task.options.filterSamePackage = false;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   424
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   425
        },
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   426
41251
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 41164
diff changeset
   427
        new Option(false, "-I", "--inverse") {
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   428
            void process(JdepsTask task, String opt, String arg) {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   429
                task.options.inverse = true;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   430
                // equivalent to the inverse of compile-time view analysis
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   431
                task.options.compileTimeView = true;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   432
                task.options.filterSamePackage = true;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   433
                task.options.filterSameArchive = true;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   434
            }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   435
        },
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   436
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   437
        new Option(false, "--compile-time") {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   438
            void process(JdepsTask task, String opt, String arg) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   439
                task.options.compileTimeView = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   440
                task.options.filterSamePackage = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   441
                task.options.filterSameArchive = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   442
                task.options.depth = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   443
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   444
        },
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   445
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   446
        new HiddenOption(false, "-fullversion") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   447
            void process(JdepsTask task, String opt, String arg) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   448
                task.options.fullVersion = true;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   449
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   450
        },
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   451
        new HiddenOption(false, "-showlabel") {
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   452
            void process(JdepsTask task, String opt, String arg) {
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   453
                task.options.showLabel = true;
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   454
            }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   455
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   456
        new HiddenOption(false, "--hide-show-module") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   457
            void process(JdepsTask task, String opt, String arg) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   458
                task.options.showModule = false;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   459
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   460
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   461
        new HiddenOption(true, "-depth") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   462
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   463
                try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   464
                    task.options.depth = Integer.parseInt(arg);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   465
                } catch (NumberFormatException e) {
16560
c6c7f0c26568 8010361: fix some langtools findbugs issues
jjg
parents: 16550
diff changeset
   466
                    throw new BadArgs("err.invalid.arg.for.option", opt);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   467
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   468
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   469
        },
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   470
    };
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   471
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   472
    private static final String PROGNAME = "jdeps";
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   473
    private final Options options = new Options();
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   474
    private final List<String> inputArgs = new ArrayList<>();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   475
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   476
    private Command command;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   477
    private PrintWriter log;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   478
    void setLog(PrintWriter out) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   479
        log = out;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   480
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   481
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   482
    /**
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   483
     * Result codes.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   484
     */
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   485
    static final int EXIT_OK = 0,       // Completed with no errors.
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   486
                     EXIT_ERROR = 1,    // Completed but reported errors.
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   487
                     EXIT_CMDERR = 2,   // Bad command-line arguments
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   488
                     EXIT_SYSERR = 3,   // System error or resource exhaustion.
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   489
                     EXIT_ABNORMAL = 4; // terminated abnormally
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   490
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   491
    int run(String... args) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   492
        if (log == null) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   493
            log = new PrintWriter(System.out);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   494
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   495
        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   496
            handleOptions(args);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   497
            if (options.help) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   498
                showHelp();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   499
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   500
            if (options.version || options.fullVersion) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   501
                showVersion(options.fullVersion);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   502
            }
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   503
            if (options.help || options.version || options.fullVersion) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   504
                return EXIT_OK;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   505
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   506
            if (options.numFilters() > 1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   507
                reportError("err.invalid.filters");
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   508
                return EXIT_CMDERR;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   509
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   510
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   511
            // default command to analyze dependences
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   512
            if (command == null) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   513
                command = analyzeDeps();
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   514
            }
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   515
            if (!command.checkOptions()) {
41442
14db641d4a9f 8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents: 41251
diff changeset
   516
                return EXIT_CMDERR;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   517
            }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   518
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   519
            boolean ok = run();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   520
            return ok ? EXIT_OK : EXIT_ERROR;
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   521
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   522
        } catch (BadArgs|UncheckedBadArgs e) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   523
            reportError(e.getKey(), e.getArgs());
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   524
            if (e.showUsage()) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   525
                log.println(getMessage("main.usage.summary", PROGNAME));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   526
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   527
            return EXIT_CMDERR;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   528
        } catch (ResolutionException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   529
            reportError("err.exception.message", e.getMessage());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   530
            return EXIT_CMDERR;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   531
        } catch (IOException e) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   532
            e.printStackTrace();
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   533
            return EXIT_CMDERR;
41164
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 40762
diff changeset
   534
        } catch (MultiReleaseException e) {
44182
ce2f0cbc81b9 8176333: jdeps error message should include a proper MR jar file name
mchung
parents: 43873
diff changeset
   535
            reportError(e.getKey(), e.getParams());
41164
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 40762
diff changeset
   536
            return EXIT_CMDERR;  // could be EXIT_ABNORMAL sometimes
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   537
        } finally {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   538
            log.flush();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   539
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   540
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   541
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   542
    boolean run() throws IOException {
48253
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   543
        try (JdepsConfiguration config = buildConfig()) {
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   544
            if (!options.nowarning) {
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   545
                // detect split packages
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   546
                config.splitPackages().entrySet()
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   547
                      .stream()
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   548
                      .sorted(Map.Entry.comparingByKey())
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   549
                      .forEach(e -> warning("warn.split.package",
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   550
                                            e.getKey(),
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   551
                                            e.getValue().stream().collect(joining(" "))));
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   552
            }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   553
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   554
            // check if any module specified in --add-modules, --require, and -m is missing
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   555
            options.addmods.stream()
48253
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   556
                .filter(mn -> !JdepsConfiguration.isToken(mn))
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   557
                .forEach(mn -> config.findModule(mn).orElseThrow(() ->
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   558
                    new UncheckedBadArgs(new BadArgs("err.module.not.found", mn))));
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   559
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   560
            return command.run(config);
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   561
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   562
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   563
48253
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   564
    private JdepsConfiguration buildConfig() throws IOException {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   565
        JdepsConfiguration.Builder builder =
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   566
            new JdepsConfiguration.Builder(options.systemModulePath);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   567
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   568
        builder.upgradeModulePath(options.upgradeModulePath)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   569
               .appModulePath(options.modulePath)
48253
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   570
               .addmods(options.addmods)
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   571
               .addmods(command.addModules());
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   572
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   573
        if (options.classpath != null)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   574
            builder.addClassPath(options.classpath);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   575
41164
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 40762
diff changeset
   576
        if (options.multiRelease != null)
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 40762
diff changeset
   577
            builder.multiRelease(options.multiRelease);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 40762
diff changeset
   578
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   579
        // build the root set of archives to be analyzed
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   580
        for (String s : inputArgs) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   581
            Path p = Paths.get(s);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   582
            if (Files.exists(p)) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   583
                builder.addRoot(p);
41164
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 40762
diff changeset
   584
            } else {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 40762
diff changeset
   585
                warning("warn.invalid.arg", s);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   586
            }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   587
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   588
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   589
        return builder.build();
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   590
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   591
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   592
    // ---- factory methods to create a Command
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   593
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   594
    private AnalyzeDeps analyzeDeps() throws BadArgs {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   595
        return options.inverse ? new InverseAnalyzeDeps()
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   596
                               : new AnalyzeDeps();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   597
    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   598
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   599
    private GenDotFile genDotFile(Path dir) throws BadArgs {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   600
        if (Files.exists(dir) && (!Files.isDirectory(dir) || !Files.isWritable(dir))) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   601
            throw new BadArgs("err.invalid.path", dir.toString());
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   602
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   603
        return new GenDotFile(dir);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   604
    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   605
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41998
diff changeset
   606
    private GenModuleInfo genModuleInfo(Path dir, boolean openModule) throws BadArgs {
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   607
        if (Files.exists(dir) && (!Files.isDirectory(dir) || !Files.isWritable(dir))) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   608
            throw new BadArgs("err.invalid.path", dir.toString());
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   609
        }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41998
diff changeset
   610
        return new GenModuleInfo(dir, openModule);
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   611
    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   612
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   613
    private ListModuleDeps listModuleDeps(CommandOption option) throws BadArgs {
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   614
        switch (option) {
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   615
            case LIST_DEPS:
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   616
                return new ListModuleDeps(option, true, false);
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   617
            case LIST_REDUCED_DEPS:
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   618
                return new ListModuleDeps(option, true, true);
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   619
            case PRINT_MODULE_DEPS:
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   620
                return new ListModuleDeps(option, false, true, ",");
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   621
            default:
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   622
                throw new IllegalArgumentException(option.toString());
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   623
        }
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   624
    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   625
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   626
    private CheckModuleDeps checkModuleDeps(Set<String> mods) throws BadArgs {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   627
        return new CheckModuleDeps(mods);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   628
    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   629
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   630
    abstract class Command {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   631
        final CommandOption option;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   632
        protected Command(CommandOption option) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   633
            this.option = option;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   634
        }
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   635
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   636
        /**
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   637
         * Returns true if the command-line options are all valid;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   638
         * otherwise, returns false.
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   639
         */
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   640
        abstract boolean checkOptions();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   641
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   642
        /**
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   643
         * Do analysis
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   644
         */
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   645
        abstract boolean run(JdepsConfiguration config) throws IOException;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   646
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   647
        /**
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   648
         * Includes all modules on system module path and application module path
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   649
         *
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   650
         * When a named module is analyzed, it will analyze the dependences
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   651
         * only.  The method should be overridden when this command should
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   652
         * analyze all modules instead.
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   653
         */
48253
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   654
        Set<String> addModules() {
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   655
            return Set.of();
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   656
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   657
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   658
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   659
        public String toString() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   660
            return option.toString();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   661
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   662
    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   663
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   664
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   665
    /**
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   666
     * Analyze dependences
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   667
     */
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   668
    class AnalyzeDeps extends Command {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   669
        JdepsWriter writer;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   670
        AnalyzeDeps() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   671
            this(CommandOption.ANALYZE_DEPS);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   672
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   673
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   674
        AnalyzeDeps(CommandOption option) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   675
            super(option);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   676
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   677
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   678
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   679
        boolean checkOptions() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   680
            if (options.findJDKInternals) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   681
                // cannot set any filter, -verbose and -summary option
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   682
                if (options.showSummary || options.verbose != null) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   683
                    reportError("err.invalid.options", "-summary or -verbose",
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   684
                                "-jdkinternals");
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   685
                    return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   686
                }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   687
                if (options.hasFilter()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   688
                    reportError("err.invalid.options", "--package, --regex, --require",
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   689
                                "-jdkinternals");
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   690
                    return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   691
                }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   692
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   693
            if (options.showSummary) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   694
                // -summary cannot use with -verbose option
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   695
                if (options.verbose != null) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   696
                    reportError("err.invalid.options", "-v, -verbose", "-s, -summary");
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   697
                    return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   698
                }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   699
            }
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   700
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   701
            if (!inputArgs.isEmpty() && !options.rootModules.isEmpty()) {
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   702
                reportError("err.invalid.arg.for.option", "-m");
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   703
            }
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   704
            if (inputArgs.isEmpty() && !options.hasSourcePath()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   705
                showHelp();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   706
                return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   707
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   708
            return true;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   709
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   710
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   711
        /*
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   712
         * Default is to show package-level dependencies
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   713
         */
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   714
        Type getAnalyzerType() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   715
            if (options.showSummary)
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   716
                return Type.SUMMARY;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   717
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   718
            if (options.findJDKInternals)
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   719
                return Type.CLASS;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   720
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   721
            // default to package-level verbose
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   722
           return options.verbose != null ? options.verbose : PACKAGE;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   723
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   724
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   725
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   726
        boolean run(JdepsConfiguration config) throws IOException {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   727
            Type type = getAnalyzerType();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   728
            // default to package-level verbose
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   729
            JdepsWriter writer = new SimpleWriter(log,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   730
                                                  type,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   731
                                                  options.showProfile,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   732
                                                  options.showModule);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   733
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   734
            return run(config, writer, type);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   735
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   736
43873
705d732d3715 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43026
diff changeset
   737
        boolean run(JdepsConfiguration config, JdepsWriter writer, Type type)
705d732d3715 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43026
diff changeset
   738
            throws IOException
705d732d3715 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43026
diff changeset
   739
        {
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   740
            // analyze the dependencies
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   741
            DepsAnalyzer analyzer = new DepsAnalyzer(config,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   742
                                                     dependencyFilter(config),
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   743
                                                     writer,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   744
                                                     type,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   745
                                                     options.apiOnly);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   746
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   747
            boolean ok = analyzer.run(options.compileTimeView, options.depth);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   748
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   749
            // print skipped entries, if any
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   750
            if (!options.nowarning) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   751
                analyzer.archives()
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   752
                    .forEach(archive -> archive.reader()
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   753
                        .skippedEntries().stream()
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   754
                        .forEach(name -> warning("warn.skipped.entry", name)));
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   755
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   756
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   757
            if (options.findJDKInternals && !options.nowarning) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   758
                Map<String, String> jdkInternals = new TreeMap<>();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   759
                Set<String> deps = analyzer.dependences();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   760
                // find the ones with replacement
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   761
                deps.forEach(cn -> replacementFor(cn).ifPresent(
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   762
                    repl -> jdkInternals.put(cn, repl))
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   763
                );
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   764
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   765
                if (!deps.isEmpty()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   766
                    log.println();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   767
                    warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url"));
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   768
                }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   769
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   770
                if (!jdkInternals.isEmpty()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   771
                    log.println();
42262
251bfd8289ee 8169659: (jdeps) missing messages for localization
reinhapa
parents: 41998
diff changeset
   772
                    String internalApiTitle = getMessage("internal.api.column.header");
251bfd8289ee 8169659: (jdeps) missing messages for localization
reinhapa
parents: 41998
diff changeset
   773
                    String replacementApiTitle = getMessage("public.api.replacement.column.header");
251bfd8289ee 8169659: (jdeps) missing messages for localization
reinhapa
parents: 41998
diff changeset
   774
                    log.format("%-40s %s%n", internalApiTitle, replacementApiTitle);
251bfd8289ee 8169659: (jdeps) missing messages for localization
reinhapa
parents: 41998
diff changeset
   775
                    log.format("%-40s %s%n",
251bfd8289ee 8169659: (jdeps) missing messages for localization
reinhapa
parents: 41998
diff changeset
   776
                               internalApiTitle.replaceAll(".", "-"),
251bfd8289ee 8169659: (jdeps) missing messages for localization
reinhapa
parents: 41998
diff changeset
   777
                               replacementApiTitle.replaceAll(".", "-"));
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   778
                    jdkInternals.entrySet().stream()
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   779
                        .forEach(e -> {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   780
                            String key = e.getKey();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   781
                            String[] lines = e.getValue().split("\\n");
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   782
                            for (String s : lines) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   783
                                log.format("%-40s %s%n", key, s);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   784
                                key = "";
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   785
                            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   786
                        });
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   787
                }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   788
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   789
            return ok;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   790
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   791
    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   792
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   793
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   794
    class InverseAnalyzeDeps extends AnalyzeDeps {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   795
        InverseAnalyzeDeps() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   796
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   797
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   798
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   799
        boolean checkOptions() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   800
            if (options.depth != 1) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   801
                reportError("err.invalid.options", "-R", "--inverse");
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   802
                return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   803
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   804
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   805
            if (options.numFilters() == 0) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   806
                reportError("err.filter.not.specified");
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   807
                return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   808
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   809
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   810
            if (!super.checkOptions()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   811
                return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   812
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   813
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   814
            return true;
41443
6398801363f2 8167014: jdeps: Missing message: warn.skipped.entry
mchung
parents: 41442
diff changeset
   815
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   816
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   817
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   818
        boolean run(JdepsConfiguration config) throws IOException {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   819
            Type type = getAnalyzerType();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   820
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   821
            InverseDepsAnalyzer analyzer =
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   822
                new InverseDepsAnalyzer(config,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   823
                                        dependencyFilter(config),
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   824
                                        writer,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   825
                                        type,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   826
                                        options.apiOnly);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   827
            boolean ok = analyzer.run();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   828
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   829
            log.println();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   830
            if (!options.requires.isEmpty())
42262
251bfd8289ee 8169659: (jdeps) missing messages for localization
reinhapa
parents: 41998
diff changeset
   831
                log.println(getMessage("inverse.transitive.dependencies.on",
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   832
                                       options.requires));
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   833
            else
42262
251bfd8289ee 8169659: (jdeps) missing messages for localization
reinhapa
parents: 41998
diff changeset
   834
                log.println(getMessage("inverse.transitive.dependencies.matching",
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   835
                                       options.regex != null
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   836
                                           ? options.regex.toString()
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   837
                                           : "packages " + options.packageNames));
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   838
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   839
            analyzer.inverseDependences()
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   840
                    .stream()
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   841
                    .sorted(comparator())
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   842
                    .map(this::toInversePath)
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   843
                    .forEach(log::println);
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   844
            return ok;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   845
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   846
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   847
        private String toInversePath(Deque<Archive> path) {
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   848
            return path.stream()
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   849
                       .map(Archive::getName)
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   850
                       .collect(joining(" <- "));
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   851
        }
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   852
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   853
        /*
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   854
         * Returns a comparator for sorting the inversed path, grouped by
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   855
         * the first module name, then the shortest path and then sort by
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   856
         * the module names of each path
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   857
         */
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   858
        private Comparator<Deque<Archive>> comparator() {
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   859
            return Comparator.<Deque<Archive>, String>
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   860
                comparing(deque -> deque.peekFirst().getName())
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   861
                    .thenComparingInt(Deque::size)
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   862
                    .thenComparing(this::toInversePath);
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   863
        }
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   864
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   865
        /*
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   866
         * Returns true if --require is specified so that all modules are
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   867
         * analyzed to find all modules that depend on the modules specified in the
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   868
         * --require option directly and indirectly
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   869
         */
48253
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   870
        Set<String> addModules() {
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   871
            return options.requires.size() > 0 ? Set.of("ALL-SYSTEM") : Set.of();
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   872
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   873
    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   874
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   875
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   876
    class GenModuleInfo extends Command {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   877
        final Path dir;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41998
diff changeset
   878
        final boolean openModule;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41998
diff changeset
   879
        GenModuleInfo(Path dir, boolean openModule) {
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   880
            super(CommandOption.GENERATE_MODULE_INFO);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   881
            this.dir = dir;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41998
diff changeset
   882
            this.openModule = openModule;
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   883
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   884
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   885
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   886
        boolean checkOptions() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   887
            if (options.classpath != null) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   888
                reportError("err.invalid.options", "-classpath",
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   889
                            option);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   890
                return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   891
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   892
            if (options.hasFilter()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   893
                reportError("err.invalid.options", "--package, --regex, --require",
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   894
                            option);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   895
                return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   896
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   897
            return true;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   898
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   899
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   900
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   901
        boolean run(JdepsConfiguration config) throws IOException {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   902
            // check if any JAR file contains unnamed package
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   903
            for (String arg : inputArgs) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   904
                try (ClassFileReader reader = ClassFileReader.newInstance(Paths.get(arg))) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   905
                    Optional<String> classInUnnamedPackage =
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   906
                        reader.entries().stream()
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   907
                             .filter(n -> n.endsWith(".class"))
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   908
                             .filter(cn -> toPackageName(cn).isEmpty())
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   909
                             .findFirst();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   910
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   911
                    if (classInUnnamedPackage.isPresent()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   912
                        if (classInUnnamedPackage.get().equals("module-info.class")) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   913
                            reportError("err.genmoduleinfo.not.jarfile", arg);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   914
                        } else {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   915
                            reportError("err.genmoduleinfo.unnamed.package", arg);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   916
                        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   917
                        return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   918
                    }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   919
                }
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   920
            }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   921
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   922
            ModuleInfoBuilder builder
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41998
diff changeset
   923
                 = new ModuleInfoBuilder(config, inputArgs, dir, openModule);
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   924
            boolean ok = builder.run();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   925
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   926
            if (!ok && !options.nowarning) {
42262
251bfd8289ee 8169659: (jdeps) missing messages for localization
reinhapa
parents: 41998
diff changeset
   927
                reportError("err.missing.dependences");
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   928
                builder.visitMissingDeps(
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42408
diff changeset
   929
                        (origin, originArchive, target, targetArchive) -> {
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   930
                            if (builder.notFound(targetArchive))
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   931
                                log.format("   %-50s -> %-50s %s%n",
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   932
                                    origin, target, targetArchive.getName());
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42408
diff changeset
   933
                        });
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   934
            }
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   935
            return ok;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   936
        }
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   937
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   938
        private String toPackageName(String name) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   939
            int i = name.lastIndexOf('/');
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   940
            return i > 0 ? name.replace('/', '.').substring(0, i) : "";
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   941
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   942
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   943
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   944
    class CheckModuleDeps extends Command {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   945
        final Set<String> modules;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   946
        CheckModuleDeps(Set<String> mods) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   947
            super(CommandOption.CHECK_MODULES);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   948
            this.modules = mods;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   949
        }
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   950
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   951
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   952
        boolean checkOptions() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   953
            if (!inputArgs.isEmpty()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   954
                reportError("err.invalid.options", inputArgs, "--check");
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   955
                return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   956
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   957
            return true;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   958
        }
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   959
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   960
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   961
        boolean run(JdepsConfiguration config) throws IOException {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   962
            if (!config.initialArchives().isEmpty()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   963
                String list = config.initialArchives().stream()
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   964
                                    .map(Archive::getPathName).collect(joining(" "));
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   965
                throw new UncheckedBadArgs(new BadArgs("err.invalid.options",
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   966
                                                       list, "--check"));
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   967
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   968
            return new ModuleAnalyzer(config, log, modules).run();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   969
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   970
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   971
        /*
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   972
         * Returns true to analyze all modules
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
   973
         */
48253
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   974
        Set<String> addModules() {
82767203606e 8193192: jdeps --generate-module-info does not look at module path
mchung
parents: 47357
diff changeset
   975
            return Set.of("ALL-SYSTEM", "ALL-MODULE-PATH");
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   976
        }
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   977
    }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   978
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   979
    class ListModuleDeps extends Command {
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   980
        final boolean jdkinternals;
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   981
        final boolean reduced;
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   982
        final String separator;
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   983
        ListModuleDeps(CommandOption option, boolean jdkinternals, boolean reduced) {
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   984
            this(option, jdkinternals, reduced, System.getProperty("line.separator"));
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   985
        }
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   986
        ListModuleDeps(CommandOption option, boolean jdkinternals, boolean reduced, String sep) {
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   987
            super(option);
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   988
            this.jdkinternals = jdkinternals;
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   989
            this.reduced = reduced;
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
   990
            this.separator = sep;
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   991
        }
41442
14db641d4a9f 8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents: 41251
diff changeset
   992
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   993
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   994
        boolean checkOptions() {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   995
            if (options.showSummary || options.verbose != null) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   996
                reportError("err.invalid.options", "-summary or -verbose",
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   997
                            option);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
   998
                return false;
41442
14db641d4a9f 8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents: 41251
diff changeset
   999
            }
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1000
            if (options.findJDKInternals) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1001
                reportError("err.invalid.options", "-jdkinternals",
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1002
                            option);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1003
                return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1004
            }
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
  1005
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
  1006
            if (!inputArgs.isEmpty() && !options.rootModules.isEmpty()) {
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
  1007
                reportError("err.invalid.arg.for.option", "-m");
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
  1008
            }
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1009
            if (inputArgs.isEmpty() && !options.hasSourcePath()) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1010
                showHelp();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1011
                return false;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1012
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1013
            return true;
41442
14db641d4a9f 8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents: 41251
diff changeset
  1014
        }
14db641d4a9f 8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents: 41251
diff changeset
  1015
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1016
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1017
        boolean run(JdepsConfiguration config) throws IOException {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1018
            return new ModuleExportsAnalyzer(config,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1019
                                             dependencyFilter(config),
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
  1020
                                             jdkinternals,
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1021
                                             reduced,
47357
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
  1022
                                             log,
74700c8e39e9 8189202: (jdeps) Need jdeps output format easy for jlink --add-modules to use
mchung
parents: 47308
diff changeset
  1023
                                             separator).run();
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1024
        }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1025
    }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1026
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1027
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1028
    class GenDotFile extends AnalyzeDeps {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1029
        final Path dotOutputDir;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1030
        GenDotFile(Path dotOutputDir) {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1031
            super(CommandOption.GENERATE_DOT_FILE);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1032
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1033
            this.dotOutputDir = dotOutputDir;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1034
        }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1035
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1036
        @Override
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1037
        boolean run(JdepsConfiguration config) throws IOException {
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1038
            if ((options.showSummary || options.verbose == MODULE) &&
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1039
                !options.addmods.isEmpty() && inputArgs.isEmpty()) {
43873
705d732d3715 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43026
diff changeset
  1040
                // generate dot graph from the resolved graph from module
705d732d3715 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43026
diff changeset
  1041
                // resolution.  No class dependency analysis is performed.
705d732d3715 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43026
diff changeset
  1042
                return new ModuleDotGraph(config, options.apiOnly)
705d732d3715 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43026
diff changeset
  1043
                        .genDotFiles(dotOutputDir);
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1044
            }
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1045
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1046
            Type type = getAnalyzerType();
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1047
            JdepsWriter writer = new DotFileWriter(dotOutputDir,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1048
                                                   type,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1049
                                                   options.showProfile,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1050
                                                   options.showModule,
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1051
                                                   options.showLabel);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1052
            return run(config, writer, type);
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1053
        }
41442
14db641d4a9f 8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents: 41251
diff changeset
  1054
    }
14db641d4a9f 8166846: jdeps fails to generate module info if there is any class in unnamed package
mchung
parents: 41251
diff changeset
  1055
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1056
    /**
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1057
     * Returns a filter used during dependency analysis
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1058
     */
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1059
    private JdepsFilter dependencyFilter(JdepsConfiguration config) {
41860
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 41522
diff changeset
  1060
        // Filter specified by -filter, -package, -regex, and --require options
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1061
        JdepsFilter.Builder builder = new JdepsFilter.Builder();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1062
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1063
        // source filters
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1064
        builder.includePattern(options.includePattern);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1065
42840
dfe1a03d4db4 8171418: Remove jdeps internal --include-system-modules option
mchung
parents: 42827
diff changeset
  1066
        // target filters
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1067
        builder.filter(options.filterSamePackage, options.filterSameArchive);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1068
        builder.findJDKInternals(options.findJDKInternals);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1069
41860
906670ff49c7 8167057: jdeps option to list modules and internal APIs for @modules for test dev
mchung
parents: 41522
diff changeset
  1070
        // --require
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1071
        if (!options.requires.isEmpty()) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1072
            options.requires.stream()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1073
                .forEach(mn -> {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1074
                    Module m = config.findModule(mn).get();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1075
                    builder.requires(mn, m.packages());
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1076
                });
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1077
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1078
        // -regex
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1079
        if (options.regex != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1080
            builder.regex(options.regex);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1081
        // -package
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1082
        if (!options.packageNames.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1083
            builder.packages(options.packageNames);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1084
        // -filter
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1085
        if (options.filterRegex != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1086
            builder.filter(options.filterRegex);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1087
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1088
        return builder.build();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1089
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1090
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1091
    public void handleOptions(String[] args) throws BadArgs {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1092
        // process options
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1093
        for (int i=0; i < args.length; i++) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1094
            if (args[i].charAt(0) == '-') {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1095
                String name = args[i];
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1096
                Option option = getOption(name);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1097
                String param = null;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1098
                if (option.hasArg) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
  1099
                    if (name.startsWith("-") && name.indexOf('=') > 0) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1100
                        param = name.substring(name.indexOf('=') + 1, name.length());
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1101
                    } else if (i + 1 < args.length) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1102
                        param = args[++i];
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1103
                    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1104
                    if (param == null || param.isEmpty() || param.charAt(0) == '-') {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1105
                        throw new BadArgs("err.missing.arg", name).showUsage(true);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1106
                    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1107
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1108
                option.process(this, name, param);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1109
                if (option.ignoreRest()) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1110
                    i = args.length;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1111
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1112
            } else {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1113
                // process rest of the input arguments
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1114
                for (; i < args.length; i++) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1115
                    String name = args[i];
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1116
                    if (name.charAt(0) == '-') {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1117
                        throw new BadArgs("err.option.after.class", name).showUsage(true);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1118
                    }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1119
                    inputArgs.add(name);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1120
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1121
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1122
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1123
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1124
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1125
    private Option getOption(String name) throws BadArgs {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1126
        for (Option o : recognizedOptions) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1127
            if (o.matches(name)) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1128
                return o;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1129
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1130
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1131
        throw new BadArgs("err.unknown.option", name).showUsage(true);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1132
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1133
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1134
    private void reportError(String key, Object... args) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1135
        log.println(getMessage("error.prefix") + " " + getMessage(key, args));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1136
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1137
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1138
    void warning(String key, Object... args) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1139
        log.println(getMessage("warn.prefix") + " " + getMessage(key, args));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1140
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1141
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1142
    private void showHelp() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1143
        log.println(getMessage("main.usage", PROGNAME));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1144
        for (Option o : recognizedOptions) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1145
            String name = o.aliases[0].substring(1); // there must always be at least one name
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1146
            name = name.charAt(0) == '-' ? name.substring(1) : name;
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 48253
diff changeset
  1147
            if (o.isHidden() || name.startsWith("filter:")) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1148
                continue;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1149
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1150
            log.println(getMessage("main.opt." + name));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1151
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1152
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1153
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1154
    private void showVersion(boolean full) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1155
        log.println(version(full ? "full" : "release"));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1156
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1157
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1158
    private String version(String key) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1159
        // key=version:  mm.nn.oo[-milestone]
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1160
        // key=full:     mm.mm.oo[-milestone]-build
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1161
        if (ResourceBundleHelper.versionRB == null) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1162
            return System.getProperty("java.version");
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1163
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1164
        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1165
            return ResourceBundleHelper.versionRB.getString(key);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1166
        } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1167
            return getMessage("version.unknown", System.getProperty("java.version"));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1168
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1169
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1170
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
  1171
    static String getMessage(String key, Object... args) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1172
        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1173
            return MessageFormat.format(ResourceBundleHelper.bundle.getString(key), args);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1174
        } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1175
            throw new InternalError("Missing message: " + key);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1176
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1177
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1178
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1179
    private static class Options {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1180
        boolean help;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1181
        boolean version;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1182
        boolean fullVersion;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1183
        boolean showProfile;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1184
        boolean showModule = true;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1185
        boolean showSummary;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
  1186
        boolean apiOnly;
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
  1187
        boolean showLabel;
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
  1188
        boolean findJDKInternals;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1189
        boolean nowarning = false;
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1190
        Analyzer.Type verbose;
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1191
        // default filter references from same package
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1192
        boolean filterSamePackage = true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1193
        boolean filterSameArchive = false;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1194
        Pattern filterRegex;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1195
        String classpath;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1196
        int depth = 1;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1197
        Set<String> requires = new HashSet<>();
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
  1198
        Set<String> packageNames = new HashSet<>();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1199
        Pattern regex;             // apply to the dependences
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1200
        Pattern includePattern;
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
  1201
        boolean inverse = false;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1202
        boolean compileTimeView = false;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1203
        String systemModulePath = System.getProperty("java.home");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1204
        String upgradeModulePath;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1205
        String modulePath;
43026
8e8b50c7491d 8172212: jdeps --require and --check should detect the specified module in the image
mchung
parents: 42840
diff changeset
  1206
        Set<String> rootModules = new HashSet<>();
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1207
        Set<String> addmods = new HashSet<>();
41164
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 40762
diff changeset
  1208
        Runtime.Version multiRelease;
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1209
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1210
        boolean hasSourcePath() {
42840
dfe1a03d4db4 8171418: Remove jdeps internal --include-system-modules option
mchung
parents: 42827
diff changeset
  1211
            return !addmods.isEmpty() || includePattern != null;
41997
79da2a8f4274 8168386: Fix jdeps verbose options
mchung
parents: 41860
diff changeset
  1212
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1213
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1214
        boolean hasFilter() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1215
            return numFilters() > 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1216
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1217
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1218
        int numFilters() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1219
            int count = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1220
            if (requires.size() > 0) count++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1221
            if (regex != null) count++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1222
            if (packageNames.size() > 0) count++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1223
            return count;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1224
        }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
  1225
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1226
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1227
    private static class ResourceBundleHelper {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1228
        static final ResourceBundle versionRB;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1229
        static final ResourceBundle bundle;
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1230
        static final ResourceBundle jdkinternals;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1231
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1232
        static {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1233
            Locale locale = Locale.getDefault();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1234
            try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1235
                bundle = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdeps", locale);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1236
            } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1237
                throw new InternalError("Cannot find jdeps resource bundle for locale " + locale);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1238
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1239
            try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1240
                versionRB = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.version");
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1241
            } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1242
                throw new InternalError("version.resource.missing");
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1243
            }
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1244
            try {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1245
                jdkinternals = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdkinternals");
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1246
            } catch (MissingResourceException e) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1247
                throw new InternalError("Cannot find jdkinternals resource bundle");
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1248
            }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1249
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1250
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1251
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1252
    /**
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1253
     * Returns the recommended replacement API for the given classname;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1254
     * or return null if replacement API is not known.
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1255
     */
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
  1256
    private Optional<String> replacementFor(String cn) {
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1257
        String name = cn;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1258
        String value = null;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1259
        while (value == null && name != null) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1260
            try {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1261
                value = ResourceBundleHelper.jdkinternals.getString(name);
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1262
            } catch (MissingResourceException e) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1263
                // go up one subpackage level
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1264
                int i = name.lastIndexOf('.');
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1265
                name = i > 0 ? name.substring(0, i) : null;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1266
            }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1267
        }
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
  1268
        return Optional.ofNullable(value);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1269
    }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1270
}