langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 39101 fd8a6392b7ea
child 40762 f8883aa0053c
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
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
/*
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
     2
 * Copyright (c) 2012, 2014, 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
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    28
import static com.sun.tools.jdeps.Analyzer.Type.*;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    29
import static com.sun.tools.jdeps.JdepsWriter.*;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    30
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    31
import java.io.IOException;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    32
import java.io.PrintWriter;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    33
import java.lang.module.ResolutionException;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    34
import java.nio.file.Files;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    35
import java.nio.file.Path;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    36
import java.nio.file.Paths;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    37
import java.text.MessageFormat;
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
    38
import java.util.*;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    39
import java.util.regex.Pattern;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    40
import java.util.stream.Collectors;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    41
import java.util.stream.Stream;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    42
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
 * Implementation for the jdeps tool for static class dependency analysis.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    45
 */
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    46
class JdepsTask {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    47
    static interface BadArguments {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    48
        String getKey();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    49
        Object[] getArgs();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    50
        boolean showUsage();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    51
    }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    52
    static class BadArgs extends Exception implements BadArguments {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    53
        static final long serialVersionUID = 8765093759964640721L;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    54
        BadArgs(String key, Object... args) {
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
    55
            super(JdepsTask.getMessage(key, args));
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    56
            this.key = key;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    57
            this.args = args;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    58
        }
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
        BadArgs showUsage(boolean b) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    61
            showUsage = b;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    62
            return this;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    63
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    64
        final String key;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    65
        final Object[] args;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    66
        boolean showUsage;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    67
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    68
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    69
        public String getKey() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    70
            return key;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    71
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    72
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    73
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    74
        public Object[] getArgs() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    75
            return args;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    76
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    77
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    78
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    79
        public boolean showUsage() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    80
            return showUsage;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    81
        }
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
    static class UncheckedBadArgs extends RuntimeException implements BadArguments {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    85
        static final long serialVersionUID = -1L;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    86
        final BadArgs cause;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    87
        UncheckedBadArgs(BadArgs cause) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    88
            super(cause);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    89
            this.cause = cause;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    90
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    91
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    92
        public String getKey() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    93
            return cause.key;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    94
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    95
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    96
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    97
        public Object[] getArgs() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    98
            return cause.args;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    99
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   100
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   101
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   102
        public boolean showUsage() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   103
            return cause.showUsage;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   104
        }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   105
    }
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
    static abstract class Option {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   108
        Option(boolean hasArg, String... aliases) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   109
            this.hasArg = hasArg;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   110
            this.aliases = aliases;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   111
        }
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
        boolean isHidden() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   114
            return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   115
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   116
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   117
        boolean matches(String opt) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   118
            for (String a : aliases) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   119
                if (a.equals(opt))
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   120
                    return true;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   121
                if (hasArg && opt.startsWith(a + "="))
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   122
                    return true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   123
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   124
            return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   125
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   126
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   127
        boolean ignoreRest() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   128
            return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   129
        }
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
        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
   132
        final boolean hasArg;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   133
        final String[] aliases;
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
    static abstract class HiddenOption extends Option {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   137
        HiddenOption(boolean hasArg, String... aliases) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   138
            super(hasArg, 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
        boolean isHidden() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   142
            return true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   143
        }
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
    static Option[] recognizedOptions = {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   147
        new Option(false, "-h", "-?", "-help", "--help") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   148
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   149
                task.options.help = true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   150
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   151
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   152
        new Option(true, "-dotoutput") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   153
            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
   154
                Path p = Paths.get(arg);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   155
                if (Files.exists(p) && (!Files.isDirectory(p) || !Files.isWritable(p))) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   156
                    throw new BadArgs("err.invalid.path", arg);
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   157
                }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   158
                task.options.dotOutputDir = Paths.get(arg);;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   159
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   160
        },
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   161
        new Option(false, "-s", "-summary") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   162
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   163
                task.options.showSummary = true;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   164
                task.options.verbose = SUMMARY;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   165
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   166
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   167
        new Option(false, "-v", "-verbose",
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   168
                                "-verbose:module",
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   169
                                "-verbose:package",
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   170
                                "-verbose:class") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   171
            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
   172
                switch (opt) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   173
                    case "-v":
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   174
                    case "-verbose":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   175
                        task.options.verbose = VERBOSE;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   176
                        task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   177
                        task.options.filterSamePackage = false;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   178
                        break;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   179
                    case "-verbose:module":
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   180
                        task.options.verbose = MODULE;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   181
                        break;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   182
                    case "-verbose:package":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   183
                        task.options.verbose = PACKAGE;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   184
                        break;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   185
                    case "-verbose:class":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   186
                        task.options.verbose = CLASS;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   187
                        break;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   188
                    default:
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   189
                        throw new BadArgs("err.invalid.arg.for.option", opt);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   190
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   191
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   192
        },
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   193
        new Option(false, "-apionly") {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   194
            void process(JdepsTask task, String opt, String arg) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   195
                task.options.apiOnly = true;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   196
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   197
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   198
        new Option(true, "--check") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   199
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   200
                Set<String> mods =  Set.of(arg.split(","));
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   201
                task.options.checkModuleDeps = mods;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   202
                task.options.addmods.addAll(mods);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   203
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   204
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   205
        new Option(true, "--gen-module-info") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   206
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   207
                Path p = Paths.get(arg);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   208
                if (Files.exists(p) && (!Files.isDirectory(p) || !Files.isWritable(p))) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   209
                    throw new BadArgs("err.invalid.path", arg);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   210
                }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   211
                task.options.genModuleInfo = Paths.get(arg);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   212
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   213
        },
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   214
        new Option(false, "-jdkinternals") {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   215
            void process(JdepsTask task, String opt, String arg) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   216
                task.options.findJDKInternals = true;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   217
                task.options.verbose = CLASS;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   218
                if (task.options.includePattern == null) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   219
                    task.options.includePattern = Pattern.compile(".*");
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   220
                }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   221
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   222
        },
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   223
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   224
        // ---- paths option ----
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   225
        new Option(true, "-cp", "-classpath", "--class-path") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   226
            void process(JdepsTask task, String opt, String arg) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   227
                task.options.classpath = arg;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   228
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   229
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   230
        new Option(true, "--module-path") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   231
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   232
                task.options.modulePath = arg;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   233
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   234
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   235
        new Option(true, "--upgrade-module-path") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   236
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   237
                task.options.upgradeModulePath = arg;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   238
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   239
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   240
        new Option(true, "--system") {
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   241
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   242
                if (arg.equals("none")) {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   243
                    task.options.systemModulePath = null;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   244
                } else {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   245
                    Path path = Paths.get(arg);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   246
                    if (Files.isRegularFile(path.resolve("lib").resolve("modules")))
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   247
                        task.options.systemModulePath = arg;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   248
                    else
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   249
                        throw new BadArgs("err.invalid.path", arg);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   250
                }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   251
            }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   252
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   253
        new Option(true, "--add-modules") {
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   254
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   255
                Set<String> mods = Set.of(arg.split(","));
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   256
                task.options.addmods.addAll(mods);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   257
            }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   258
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   259
        new Option(true, "-m", "--module") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   260
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   261
                task.options.rootModule = arg;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   262
                task.options.addmods.add(arg);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   263
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   264
        },
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   265
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   266
        // ---- Target filtering options ----
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   267
        new Option(true, "-p", "-package") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   268
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   269
                task.options.packageNames.add(arg);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   270
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   271
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   272
        new Option(true, "-e", "-regex") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   273
            void process(JdepsTask task, String opt, String arg) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   274
                task.options.regex = Pattern.compile(arg);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   275
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   276
        },
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   277
        new Option(true, "-requires") {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   278
            void process(JdepsTask task, String opt, String arg) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   279
                task.options.requires.add(arg);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   280
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   281
        },
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   282
        new Option(true, "-f", "-filter") {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   283
            void process(JdepsTask task, String opt, String arg) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   284
                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
   285
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   286
        },
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   287
        new Option(false, "-filter:package",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   288
                          "-filter:archive", "-filter:module",
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   289
                          "-filter:none") {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   290
            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
   291
                switch (opt) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   292
                    case "-filter:package":
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   293
                        task.options.filterSamePackage = true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   294
                        task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   295
                        break;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   296
                    case "-filter:archive":
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   297
                    case "-filter:module":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   298
                        task.options.filterSameArchive = true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   299
                        task.options.filterSamePackage = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   300
                        break;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   301
                    case "-filter:none":
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   302
                        task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   303
                        task.options.filterSamePackage = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   304
                        break;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   305
                }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   306
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   307
        },
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   308
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   309
        // ---- Source filtering options ----
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   310
        new Option(true, "-include") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   311
            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
   312
                task.options.includePattern = Pattern.compile(arg);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   313
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   314
        },
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   315
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   316
        // Another alternative to list modules in -addmods option
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   317
        new HiddenOption(true, "--include-system-modules") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   318
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   319
                task.options.includeSystemModulePattern = Pattern.compile(arg);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   320
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   321
        },
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   322
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   323
        new Option(false, "-P", "-profile") {
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents: 16290
diff changeset
   324
            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
   325
                task.options.showProfile = true;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   326
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   327
        },
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   328
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   329
        new Option(false, "-R", "-recursive") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   330
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   331
                task.options.depth = 0;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   332
                // turn off filtering
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   333
                task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   334
                task.options.filterSamePackage = false;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   335
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   336
        },
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   337
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   338
        new Option(false, "-I", "-inverse") {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   339
            void process(JdepsTask task, String opt, String arg) {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   340
                task.options.inverse = true;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   341
                // equivalent to the inverse of compile-time view analysis
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   342
                task.options.compileTimeView = true;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   343
                task.options.filterSamePackage = true;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   344
                task.options.filterSameArchive = true;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   345
            }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   346
        },
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   347
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   348
        new Option(false, "--compile-time") {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   349
            void process(JdepsTask task, String opt, String arg) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   350
                task.options.compileTimeView = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   351
                task.options.filterSamePackage = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   352
                task.options.filterSameArchive = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   353
                task.options.depth = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   354
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   355
        },
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   356
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   357
        new Option(false, "-q", "-quiet") {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   358
            void process(JdepsTask task, String opt, String arg) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   359
                task.options.nowarning = true;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   360
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   361
        },
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   362
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   363
        new Option(false, "-version") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   364
            void process(JdepsTask task, String opt, String arg) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   365
                task.options.version = true;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   366
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   367
        },
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   368
        new HiddenOption(false, "-fullversion") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   369
            void process(JdepsTask task, String opt, String arg) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   370
                task.options.fullVersion = true;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   371
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   372
        },
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   373
        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
   374
            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
   375
                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
   376
            }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   377
        },
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   378
        new HiddenOption(false, "--hide-show-module") {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   379
            void process(JdepsTask task, String opt, String arg) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   380
                task.options.showModule = false;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   381
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   382
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   383
        new HiddenOption(true, "-depth") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   384
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   385
                try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   386
                    task.options.depth = Integer.parseInt(arg);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   387
                } catch (NumberFormatException e) {
16560
c6c7f0c26568 8010361: fix some langtools findbugs issues
jjg
parents: 16550
diff changeset
   388
                    throw new BadArgs("err.invalid.arg.for.option", opt);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   389
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   390
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   391
        },
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   392
    };
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   393
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   394
    private static final String PROGNAME = "jdeps";
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   395
    private final Options options = new Options();
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   396
    private final List<String> inputArgs = new ArrayList<>();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   397
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   398
    private PrintWriter log;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   399
    void setLog(PrintWriter out) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   400
        log = out;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   401
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   402
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   403
    /**
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   404
     * Result codes.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   405
     */
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   406
    static final int EXIT_OK = 0,       // Completed with no errors.
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   407
                     EXIT_ERROR = 1,    // Completed but reported errors.
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   408
                     EXIT_CMDERR = 2,   // Bad command-line arguments
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   409
                     EXIT_SYSERR = 3,   // System error or resource exhaustion.
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   410
                     EXIT_ABNORMAL = 4; // terminated abnormally
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   411
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   412
    int run(String... args) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   413
        if (log == null) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   414
            log = new PrintWriter(System.out);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   415
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   416
        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   417
            handleOptions(args);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   418
            if (options.help) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   419
                showHelp();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   420
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   421
            if (options.version || options.fullVersion) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   422
                showVersion(options.fullVersion);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   423
            }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   424
            if (!inputArgs.isEmpty() && options.rootModule != null) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   425
                reportError("err.invalid.arg.for.option", "-m");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   426
            }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   427
            if (inputArgs.isEmpty() && options.addmods.isEmpty() && options.includePattern == null
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   428
                    && options.includeSystemModulePattern == null && options.checkModuleDeps == null) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   429
                if (options.help || options.version || options.fullVersion) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   430
                    return EXIT_OK;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   431
                } else {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   432
                    showHelp();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   433
                    return EXIT_CMDERR;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   434
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   435
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   436
            if (options.genModuleInfo != null) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   437
                if (options.dotOutputDir != null || options.classpath != null || options.hasFilter()) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   438
                    showHelp();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   439
                    return EXIT_CMDERR;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   440
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   441
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   442
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   443
            if (options.numFilters() > 1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   444
                reportError("err.invalid.filters");
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   445
                return EXIT_CMDERR;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   446
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   447
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   448
            if (options.inverse && options.depth != 1) {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   449
                reportError("err.invalid.inverse.option", "-R");
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   450
                return EXIT_CMDERR;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   451
            }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   452
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   453
            if (options.inverse && options.numFilters() == 0) {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   454
                reportError("err.invalid.filters");
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   455
                return EXIT_CMDERR;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   456
            }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   457
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   458
            if ((options.findJDKInternals) && (options.hasFilter() || options.showSummary)) {
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   459
                showHelp();
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   460
                return EXIT_CMDERR;
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   461
            }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   462
            if (options.showSummary && options.verbose != SUMMARY) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   463
                showHelp();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   464
                return EXIT_CMDERR;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   465
            }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   466
            if (options.checkModuleDeps != null && !inputArgs.isEmpty()) {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   467
                reportError("err.invalid.module.option", inputArgs, "--check");
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   468
            }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   469
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   470
            boolean ok = run();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   471
            return ok ? EXIT_OK : EXIT_ERROR;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   472
        } catch (BadArgs|UncheckedBadArgs e) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   473
            reportError(e.getKey(), e.getArgs());
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   474
            if (e.showUsage()) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   475
                log.println(getMessage("main.usage.summary", PROGNAME));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   476
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   477
            return EXIT_CMDERR;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   478
        } catch (ResolutionException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   479
            reportError("err.exception.message", e.getMessage());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   480
            return EXIT_CMDERR;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   481
        } catch (IOException e) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   482
            e.printStackTrace();
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   483
            return EXIT_CMDERR;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   484
        } finally {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   485
            log.flush();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   486
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   487
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   488
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   489
    boolean run() throws IOException {
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   490
        try (JdepsConfiguration config = buildConfig()) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   491
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   492
            // detect split packages
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   493
            config.splitPackages().entrySet().stream()
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   494
                .sorted(Map.Entry.comparingByKey())
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   495
                .forEach(e -> System.out.format("split package: %s %s%n", e.getKey(),
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   496
                    e.getValue().toString()));
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   497
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   498
            // check if any module specified in -requires is missing
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   499
            Stream.concat(options.addmods.stream(), options.requires.stream())
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   500
                .filter(mn -> !config.isValidToken(mn))
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   501
                .forEach(mn -> config.findModule(mn).orElseThrow(() ->
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   502
                    new UncheckedBadArgs(new BadArgs("err.module.not.found", mn))));
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   503
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   504
            // --gen-module-info
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   505
            if (options.genModuleInfo != null) {
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   506
                return genModuleInfo(config);
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   507
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   508
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39101
diff changeset
   509
            // --check
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   510
            if (options.checkModuleDeps != null) {
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   511
                return new ModuleAnalyzer(config, log, options.checkModuleDeps).run();
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   512
            }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   513
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   514
            if (options.dotOutputDir != null &&
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   515
                (options.verbose == SUMMARY || options.verbose == MODULE) &&
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   516
                !options.addmods.isEmpty() && inputArgs.isEmpty()) {
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   517
                return new ModuleAnalyzer(config, log).genDotFiles(options.dotOutputDir);
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   518
            }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   519
38530
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   520
            if (options.inverse) {
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   521
                return analyzeInverseDeps(config);
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   522
            } else {
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   523
                return analyzeDeps(config);
8e89d567748c 8157391: jdeps left JarFile open
mchung
parents: 38525
diff changeset
   524
            }
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   525
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   526
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   527
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   528
    private JdepsConfiguration buildConfig() throws IOException {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   529
        JdepsConfiguration.Builder builder =
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   530
            new JdepsConfiguration.Builder(options.systemModulePath);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   531
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   532
        builder.upgradeModulePath(options.upgradeModulePath)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   533
               .appModulePath(options.modulePath)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   534
               .addmods(options.addmods);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   535
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   536
        if (options.checkModuleDeps != null) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   537
            // check all system modules in the image
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   538
            builder.allModules();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   539
        }
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   540
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   541
        if (options.classpath != null)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   542
            builder.addClassPath(options.classpath);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   543
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   544
        // build the root set of archives to be analyzed
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   545
        for (String s : inputArgs) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   546
            Path p = Paths.get(s);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   547
            if (Files.exists(p)) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   548
                builder.addRoot(p);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   549
            }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   550
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   551
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   552
        return builder.build();
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   553
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   554
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   555
    private boolean analyzeDeps(JdepsConfiguration config) throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   556
        // output result
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   557
        final JdepsWriter writer;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   558
        if (options.dotOutputDir != null) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   559
            writer = new DotFileWriter(options.dotOutputDir,
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   560
                                       options.verbose,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   561
                                       options.showProfile,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   562
                                       options.showModule,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   563
                                       options.showLabel);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   564
        } else {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   565
            writer = new SimpleWriter(log,
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   566
                                      options.verbose,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   567
                                      options.showProfile,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   568
                                      options.showModule);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   569
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   570
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   571
        // analyze the dependencies
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   572
        DepsAnalyzer analyzer = new DepsAnalyzer(config,
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   573
                                        dependencyFilter(config),
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   574
                                        writer,
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   575
                                        options.verbose,
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   576
                                        options.apiOnly);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   577
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   578
        boolean ok = analyzer.run(options.compileTimeView, options.depth);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   579
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   580
        // print skipped entries, if any
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   581
        analyzer.archives()
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   582
            .forEach(archive -> archive.reader()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   583
                .skippedEntries().stream()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   584
                .forEach(name -> warning("warn.skipped.entry",
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   585
                                         name, archive.getPathName())));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   586
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   587
        if (options.findJDKInternals && !options.nowarning) {
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   588
            Map<String, String> jdkInternals = new TreeMap<>();
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   589
            Set<String> deps = analyzer.dependences();
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   590
            // find the ones with replacement
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   591
            deps.forEach(cn -> replacementFor(cn).ifPresent(
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   592
                repl -> jdkInternals.put(cn, repl))
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   593
            );
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   594
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   595
            if (!deps.isEmpty()) {
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   596
                log.println();
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   597
                warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url"));
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   598
            }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   599
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   600
            if (!jdkInternals.isEmpty()) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   601
                log.println();
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   602
                log.format("%-40s %s%n", "JDK Internal API", "Suggested Replacement");
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   603
                log.format("%-40s %s%n", "----------------", "---------------------");
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   604
                jdkInternals.entrySet().stream()
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   605
                    .forEach(e -> {
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   606
                        String key = e.getKey();
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   607
                        String[] lines = e.getValue().split("\\n");
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   608
                        for (String s : lines) {
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   609
                            log.format("%-40s %s%n", key, s);
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   610
                            key = "";
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   611
                        }
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   612
                    });
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   613
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   614
        }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   615
        return ok;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   616
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   617
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   618
    private boolean analyzeInverseDeps(JdepsConfiguration config) throws IOException {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   619
        JdepsWriter writer = new SimpleWriter(log,
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   620
                                              options.verbose,
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   621
                                              options.showProfile,
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   622
                                              options.showModule);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   623
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   624
        InverseDepsAnalyzer analyzer = new InverseDepsAnalyzer(config,
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   625
                                                               dependencyFilter(config),
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   626
                                                               writer,
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   627
                                                               options.verbose,
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   628
                                                               options.apiOnly);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   629
        boolean ok = analyzer.run();
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   630
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   631
        log.println();
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   632
        if (!options.requires.isEmpty())
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   633
            log.format("Inverse transitive dependences on %s%n", options.requires);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   634
        else
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   635
            log.format("Inverse transitive dependences matching %s%n",
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   636
                options.regex != null
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   637
                    ? options.regex.toString()
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   638
                    : "packages " + options.packageNames);
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   639
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   640
        analyzer.inverseDependences().stream()
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   641
                .sorted(Comparator.comparing(this::sortPath))
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   642
                .forEach(path -> log.println(path.stream()
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   643
                                                .map(Archive::getName)
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   644
                                                .collect(Collectors.joining(" <- "))));
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   645
        return ok;
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   646
    }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   647
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   648
    private String sortPath(Deque<Archive> path) {
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   649
        return path.peekFirst().getName();
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   650
    }
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   651
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   652
    private boolean genModuleInfo(JdepsConfiguration config) throws IOException {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   653
        ModuleInfoBuilder builder
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   654
            = new ModuleInfoBuilder(config, inputArgs, options.genModuleInfo);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   655
        boolean ok = builder.run();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   656
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   657
        builder.modules().forEach(module -> {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   658
            if (module.packages().contains("")) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   659
                reportError("ERROR: %s contains unnamed package.  " +
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   660
                    "module-info.java not generated%n", module.getPathName());
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   661
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   662
        });
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   663
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   664
        if (!ok && !options.nowarning) {
38532
24f77d64bb1f 8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents: 38530
diff changeset
   665
            log.println("ERROR: missing dependencies");
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   666
            builder.visitMissingDeps(
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   667
                new Analyzer.Visitor() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   668
                    @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   669
                    public void visitDependence(String origin, Archive originArchive,
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   670
                                                String target, Archive targetArchive) {
38532
24f77d64bb1f 8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents: 38530
diff changeset
   671
                        if (builder.notFound(targetArchive))
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   672
                            log.format("   %-50s -> %-50s %s%n",
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   673
                                origin, target, targetArchive.getName());
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   674
                    }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   675
                });
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   676
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   677
        return ok;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   678
    }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   679
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   680
    /**
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   681
     * Returns a filter used during dependency analysis
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   682
     */
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   683
    private JdepsFilter dependencyFilter(JdepsConfiguration config) {
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   684
        // Filter specified by -filter, -package, -regex, and -requires options
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   685
        JdepsFilter.Builder builder = new JdepsFilter.Builder();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   686
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   687
        // source filters
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   688
        builder.includePattern(options.includePattern);
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   689
        builder.includeSystemModules(options.includeSystemModulePattern);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   690
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   691
        builder.filter(options.filterSamePackage, options.filterSameArchive);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   692
        builder.findJDKInternals(options.findJDKInternals);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   693
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   694
        // -requires
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   695
        if (!options.requires.isEmpty()) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   696
            options.requires.stream()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   697
                .forEach(mn -> {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   698
                    Module m = config.findModule(mn).get();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   699
                    builder.requires(mn, m.packages());
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   700
                });
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   701
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   702
        // -regex
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   703
        if (options.regex != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   704
            builder.regex(options.regex);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   705
        // -package
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   706
        if (!options.packageNames.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   707
            builder.packages(options.packageNames);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   708
        // -filter
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   709
        if (options.filterRegex != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   710
            builder.filter(options.filterRegex);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   711
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   712
        // check if system module is set
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   713
        config.rootModules().stream()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   714
            .map(Module::name)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   715
            .forEach(builder::includeIfSystemModule);
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   716
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   717
        return builder.build();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   718
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   719
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   720
    public void handleOptions(String[] args) throws BadArgs {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   721
        // process options
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   722
        for (int i=0; i < args.length; i++) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   723
            if (args[i].charAt(0) == '-') {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   724
                String name = args[i];
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   725
                Option option = getOption(name);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   726
                String param = null;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   727
                if (option.hasArg) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   728
                    if (name.startsWith("-") && name.indexOf('=') > 0) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   729
                        param = name.substring(name.indexOf('=') + 1, name.length());
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   730
                    } else if (i + 1 < args.length) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   731
                        param = args[++i];
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   732
                    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   733
                    if (param == null || param.isEmpty() || param.charAt(0) == '-') {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   734
                        throw new BadArgs("err.missing.arg", name).showUsage(true);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   735
                    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   736
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   737
                option.process(this, name, param);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   738
                if (option.ignoreRest()) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   739
                    i = args.length;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   740
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   741
            } else {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   742
                // process rest of the input arguments
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   743
                for (; i < args.length; i++) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   744
                    String name = args[i];
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   745
                    if (name.charAt(0) == '-') {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   746
                        throw new BadArgs("err.option.after.class", name).showUsage(true);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   747
                    }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   748
                    inputArgs.add(name);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   749
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   750
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   751
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   752
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   753
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   754
    private Option getOption(String name) throws BadArgs {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   755
        for (Option o : recognizedOptions) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   756
            if (o.matches(name)) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   757
                return o;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   758
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   759
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   760
        throw new BadArgs("err.unknown.option", name).showUsage(true);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   761
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   762
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   763
    private void reportError(String key, Object... args) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   764
        log.println(getMessage("error.prefix") + " " + getMessage(key, args));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   765
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   766
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   767
    void warning(String key, Object... args) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   768
        log.println(getMessage("warn.prefix") + " " + getMessage(key, args));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   769
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   770
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   771
    private void showHelp() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   772
        log.println(getMessage("main.usage", PROGNAME));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   773
        for (Option o : recognizedOptions) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   774
            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
   775
            name = name.charAt(0) == '-' ? name.substring(1) : name;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   776
            if (o.isHidden() || name.equals("h") || name.startsWith("filter:")) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   777
                continue;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   778
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   779
            log.println(getMessage("main.opt." + name));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   780
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   781
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   782
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   783
    private void showVersion(boolean full) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   784
        log.println(version(full ? "full" : "release"));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   785
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   786
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   787
    private String version(String key) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   788
        // key=version:  mm.nn.oo[-milestone]
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   789
        // key=full:     mm.mm.oo[-milestone]-build
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   790
        if (ResourceBundleHelper.versionRB == null) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   791
            return System.getProperty("java.version");
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   792
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   793
        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   794
            return ResourceBundleHelper.versionRB.getString(key);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   795
        } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   796
            return getMessage("version.unknown", System.getProperty("java.version"));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   797
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   798
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   799
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   800
    static String getMessage(String key, Object... args) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   801
        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   802
            return MessageFormat.format(ResourceBundleHelper.bundle.getString(key), args);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   803
        } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   804
            throw new InternalError("Missing message: " + key);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   805
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   806
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   807
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   808
    private static class Options {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   809
        boolean help;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   810
        boolean version;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   811
        boolean fullVersion;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   812
        boolean showProfile;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   813
        boolean showModule = true;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   814
        boolean showSummary;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   815
        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
   816
        boolean showLabel;
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   817
        boolean findJDKInternals;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   818
        boolean nowarning = false;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   819
        // default is to show package-level dependencies
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   820
        // and filter references from same package
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   821
        Analyzer.Type verbose = PACKAGE;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   822
        boolean filterSamePackage = true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   823
        boolean filterSameArchive = false;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   824
        Pattern filterRegex;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   825
        Path dotOutputDir;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   826
        Path genModuleInfo;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   827
        String classpath;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   828
        int depth = 1;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   829
        Set<String> requires = new HashSet<>();
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   830
        Set<String> packageNames = new HashSet<>();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   831
        Pattern regex;             // apply to the dependences
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   832
        Pattern includePattern;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   833
        Pattern includeSystemModulePattern;
38525
a2169f8fa712 8156575: Add jdeps -addmods, -system, -inverse options
mchung
parents: 38524
diff changeset
   834
        boolean inverse = false;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   835
        boolean compileTimeView = false;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   836
        Set<String> checkModuleDeps;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   837
        String systemModulePath = System.getProperty("java.home");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   838
        String upgradeModulePath;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   839
        String modulePath;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   840
        String rootModule;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   841
        Set<String> addmods = new HashSet<>();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   842
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   843
        boolean hasFilter() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   844
            return numFilters() > 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   845
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   846
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   847
        int numFilters() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   848
            int count = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   849
            if (requires.size() > 0) count++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   850
            if (regex != null) count++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   851
            if (packageNames.size() > 0) count++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   852
            return count;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   853
        }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   854
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   855
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   856
    private static class ResourceBundleHelper {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   857
        static final ResourceBundle versionRB;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   858
        static final ResourceBundle bundle;
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   859
        static final ResourceBundle jdkinternals;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   860
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   861
        static {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   862
            Locale locale = Locale.getDefault();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   863
            try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   864
                bundle = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdeps", locale);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   865
            } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   866
                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
   867
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   868
            try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   869
                versionRB = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.version");
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   870
            } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   871
                throw new InternalError("version.resource.missing");
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   872
            }
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   873
            try {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   874
                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
   875
            } catch (MissingResourceException e) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   876
                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
   877
            }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   878
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   879
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   880
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   881
    /**
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   882
     * 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
   883
     * 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
   884
     */
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   885
    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
   886
        String name = cn;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   887
        String value = null;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   888
        while (value == null && name != null) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   889
            try {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   890
                value = ResourceBundleHelper.jdkinternals.getString(name);
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   891
            } catch (MissingResourceException e) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   892
                // go up one subpackage level
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   893
                int i = name.lastIndexOf('.');
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   894
                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
   895
            }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   896
        }
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents: 38532
diff changeset
   897
        return Optional.ofNullable(value);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   898
    }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   899
}