langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 28706 langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/JdepsTask.java@a724585645ce
child 34752 9c262a013456
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
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
 */
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    25
package com.sun.tools.jdeps;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    26
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    27
import com.sun.tools.classfile.AccessFlags;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    28
import com.sun.tools.classfile.ClassFile;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    29
import com.sun.tools.classfile.ConstantPoolException;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    30
import com.sun.tools.classfile.Dependencies;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    31
import com.sun.tools.classfile.Dependencies.ClassFileError;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    32
import com.sun.tools.classfile.Dependency;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    33
import com.sun.tools.classfile.Dependency.Location;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    34
import static com.sun.tools.jdeps.Analyzer.Type.*;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    35
import java.io.*;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    36
import java.nio.file.DirectoryStream;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    37
import java.nio.file.Files;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    38
import java.nio.file.Path;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    39
import java.nio.file.Paths;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    40
import java.text.MessageFormat;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    41
import java.util.*;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    42
import java.util.regex.Pattern;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    43
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    44
/**
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    45
 * Implementation for the jdeps tool for static class dependency analysis.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    46
 */
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    47
class JdepsTask {
16560
c6c7f0c26568 8010361: fix some langtools findbugs issues
jjg
parents: 16550
diff changeset
    48
    static class BadArgs extends Exception {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    49
        static final long serialVersionUID = 8765093759964640721L;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    50
        BadArgs(String key, Object... args) {
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
    51
            super(JdepsTask.getMessage(key, args));
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    52
            this.key = key;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    53
            this.args = args;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    54
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    55
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    56
        BadArgs showUsage(boolean b) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    57
            showUsage = b;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    58
            return this;
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
        final String key;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    61
        final Object[] args;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    62
        boolean showUsage;
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
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    65
    static abstract class Option {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    66
        Option(boolean hasArg, String... aliases) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    67
            this.hasArg = hasArg;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    68
            this.aliases = aliases;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    69
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    70
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    71
        boolean isHidden() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    72
            return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    73
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    74
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    75
        boolean matches(String opt) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    76
            for (String a : aliases) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    77
                if (a.equals(opt))
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    78
                    return true;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
    79
                if (hasArg && opt.startsWith(a + "="))
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    80
                    return true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    81
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    82
            return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    83
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    84
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    85
        boolean ignoreRest() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    86
            return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    87
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    88
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    89
        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
    90
        final boolean hasArg;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    91
        final String[] aliases;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    92
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    93
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    94
    static abstract class HiddenOption extends Option {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    95
        HiddenOption(boolean hasArg, String... aliases) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    96
            super(hasArg, aliases);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    97
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    98
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
    99
        boolean isHidden() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   100
            return true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   101
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   102
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   103
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   104
    static Option[] recognizedOptions = {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   105
        new Option(false, "-h", "-?", "-help") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   106
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   107
                task.options.help = true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   108
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   109
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   110
        new Option(true, "-dotoutput") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   111
            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
   112
                Path p = Paths.get(arg);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   113
                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
   114
                    throw new BadArgs("err.invalid.path", arg);
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   115
                }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   116
                task.options.dotOutputDir = arg;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   117
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   118
        },
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   119
        new Option(false, "-s", "-summary") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   120
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   121
                task.options.showSummary = true;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   122
                task.options.verbose = SUMMARY;
15030
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
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   125
        new Option(false, "-v", "-verbose",
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   126
                          "-verbose:package",
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   127
                          "-verbose:class") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   128
            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
   129
                switch (opt) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   130
                    case "-v":
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   131
                    case "-verbose":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   132
                        task.options.verbose = VERBOSE;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   133
                        task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   134
                        task.options.filterSamePackage = false;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   135
                        break;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   136
                    case "-verbose:package":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   137
                        task.options.verbose = PACKAGE;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   138
                        break;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   139
                    case "-verbose:class":
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   140
                        task.options.verbose = CLASS;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   141
                        break;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   142
                    default:
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   143
                        throw new BadArgs("err.invalid.arg.for.option", opt);
15030
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
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   147
        new Option(true, "-cp", "-classpath") {
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.classpath = arg;
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, "-p", "-package") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   153
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   154
                task.options.packageNames.add(arg);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   155
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   156
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   157
        new Option(true, "-e", "-regex") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   158
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   159
                task.options.regex = arg;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   160
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   161
        },
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   162
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   163
        new Option(true, "-f", "-filter") {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   164
            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
   165
                task.options.filterRegex = arg;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   166
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   167
        },
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   168
        new Option(false, "-filter:package",
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   169
                          "-filter:archive",
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   170
                          "-filter:none") {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   171
            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
   172
                switch (opt) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   173
                    case "-filter:package":
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   174
                        task.options.filterSamePackage = true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   175
                        task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   176
                        break;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   177
                    case "-filter:archive":
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   178
                        task.options.filterSameArchive = true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   179
                        task.options.filterSamePackage = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   180
                        break;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   181
                    case "-filter:none":
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   182
                        task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   183
                        task.options.filterSamePackage = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   184
                        break;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   185
                }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   186
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   187
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   188
        new Option(true, "-include") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   189
            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
   190
                task.options.includePattern = Pattern.compile(arg);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   191
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   192
        },
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   193
        new Option(false, "-P", "-profile") {
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents: 16290
diff changeset
   194
            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
   195
                task.options.showProfile = true;
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   196
                task.options.showModule = false;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   197
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   198
        },
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   199
        new Option(false, "-M", "-module") {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   200
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   201
                task.options.showModule = true;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   202
                task.options.showProfile = false;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   203
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   204
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   205
        new Option(false, "-apionly") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   206
            void process(JdepsTask task, String opt, String arg) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   207
                task.options.apiOnly = true;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   208
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   209
        },
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   210
        new Option(false, "-R", "-recursive") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   211
            void process(JdepsTask task, String opt, String arg) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   212
                task.options.depth = 0;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   213
                // turn off filtering
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   214
                task.options.filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   215
                task.options.filterSamePackage = false;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   216
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   217
        },
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   218
        new Option(false, "-jdkinternals") {
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   219
            void process(JdepsTask task, String opt, String arg) {
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   220
                task.options.findJDKInternals = true;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   221
                task.options.verbose = CLASS;
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   222
                if (task.options.includePattern == null) {
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   223
                    task.options.includePattern = Pattern.compile(".*");
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   224
                }
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   225
            }
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   226
        },
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   227
            new HiddenOption(false, "-verify:access") {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   228
                void process(JdepsTask task, String opt, String arg) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   229
                    task.options.verifyAccess = true;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   230
                    task.options.verbose = VERBOSE;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   231
                    task.options.filterSameArchive = false;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   232
                    task.options.filterSamePackage = false;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   233
                }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   234
            },
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   235
            new HiddenOption(true, "-mp") {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   236
                void process(JdepsTask task, String opt, String arg) throws BadArgs {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   237
                    task.options.mpath = Paths.get(arg);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   238
                    if (!Files.isDirectory(task.options.mpath)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   239
                        throw new BadArgs("err.invalid.path", arg);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   240
                    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   241
                    if (task.options.includePattern == null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   242
                        task.options.includePattern = Pattern.compile(".*");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   243
                    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   244
                }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   245
            },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   246
        new Option(false, "-version") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   247
            void process(JdepsTask task, String opt, String arg) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   248
                task.options.version = true;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   249
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   250
        },
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   251
        new HiddenOption(false, "-fullversion") {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   252
            void process(JdepsTask task, String opt, String arg) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   253
                task.options.fullVersion = true;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   254
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   255
        },
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   256
        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
   257
            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
   258
                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
   259
            }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   260
        },
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   261
        new HiddenOption(false, "-q", "-quiet") {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   262
            void process(JdepsTask task, String opt, String arg) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   263
                task.options.nowarning = true;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   264
            }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   265
        },
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   266
        new HiddenOption(true, "-depth") {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   267
            void process(JdepsTask task, String opt, String arg) throws BadArgs {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   268
                try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   269
                    task.options.depth = Integer.parseInt(arg);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   270
                } catch (NumberFormatException e) {
16560
c6c7f0c26568 8010361: fix some langtools findbugs issues
jjg
parents: 16550
diff changeset
   271
                    throw new BadArgs("err.invalid.arg.for.option", opt);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   272
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   273
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   274
        },
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
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   277
    private static final String PROGNAME = "jdeps";
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   278
    private final Options options = new Options();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22007
diff changeset
   279
    private final List<String> classes = new ArrayList<>();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   280
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   281
    private PrintWriter log;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   282
    void setLog(PrintWriter out) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   283
        log = out;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   284
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   285
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   286
    /**
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   287
     * Result codes.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   288
     */
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   289
    static final int EXIT_OK = 0, // Completed with no errors.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   290
                     EXIT_ERROR = 1, // Completed but reported errors.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   291
                     EXIT_CMDERR = 2, // Bad command-line arguments
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   292
                     EXIT_SYSERR = 3, // System error or resource exhaustion.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   293
                     EXIT_ABNORMAL = 4;// terminated abnormally
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   294
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   295
    int run(String[] args) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   296
        if (log == null) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   297
            log = new PrintWriter(System.out);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   298
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   299
        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   300
            handleOptions(args);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   301
            if (options.help) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   302
                showHelp();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   303
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   304
            if (options.version || options.fullVersion) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   305
                showVersion(options.fullVersion);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   306
            }
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   307
            if (classes.isEmpty() && options.includePattern == null) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   308
                if (options.help || options.version || options.fullVersion) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   309
                    return EXIT_OK;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   310
                } else {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   311
                    showHelp();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   312
                    return EXIT_CMDERR;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   313
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   314
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   315
            if (options.regex != null && options.packageNames.size() > 0) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   316
                showHelp();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   317
                return EXIT_CMDERR;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   318
            }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   319
            if ((options.findJDKInternals || options.verifyAccess) &&
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   320
                   (options.regex != null || options.packageNames.size() > 0 || options.showSummary)) {
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   321
                showHelp();
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   322
                return EXIT_CMDERR;
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   323
            }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   324
            if (options.showSummary && options.verbose != SUMMARY) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   325
                showHelp();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   326
                return EXIT_CMDERR;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   327
            }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   328
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   329
            boolean ok = run();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   330
            return ok ? EXIT_OK : EXIT_ERROR;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   331
        } catch (BadArgs e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   332
            reportError(e.key, e.args);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   333
            if (e.showUsage) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   334
                log.println(getMessage("main.usage.summary", PROGNAME));
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
            return EXIT_CMDERR;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   337
        } catch (IOException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   338
            return EXIT_ABNORMAL;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   339
        } finally {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   340
            log.flush();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   341
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   342
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   343
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   344
    private final List<Archive> sourceLocations = new ArrayList<>();
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   345
    private final List<Archive> classpaths = new ArrayList<>();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   346
    private final List<Archive> initialArchives = new ArrayList<>();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   347
    private boolean run() throws IOException {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   348
        buildArchives();
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   349
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   350
        if (options.verifyAccess) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   351
            return verifyModuleAccess();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   352
        } else {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   353
            return analyzeDeps();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   354
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   355
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   356
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   357
    private boolean analyzeDeps() throws IOException {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   358
        Analyzer analyzer = new Analyzer(options.verbose, new Analyzer.Filter() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   359
            @Override
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   360
            public boolean accepts(Location origin, Archive originArchive,
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   361
                                   Location target, Archive targetArchive)
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   362
            {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   363
                if (options.findJDKInternals) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   364
                    // accepts target that is JDK class but not exported
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   365
                    return isJDKModule(targetArchive) &&
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   366
                              !((Module) targetArchive).isExported(target.getClassName());
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   367
                } else if (options.filterSameArchive) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   368
                    // accepts origin and target that from different archive
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   369
                    return originArchive != targetArchive;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   370
                }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   371
                return true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   372
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   373
        });
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   374
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   375
        // parse classfiles and find all dependencies
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   376
        findDependencies(options.apiOnly);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   377
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   378
        // analyze the dependencies
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   379
        analyzer.run(sourceLocations);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   380
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   381
        // output result
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   382
        if (options.dotOutputDir != null) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   383
            Path dir = Paths.get(options.dotOutputDir);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   384
            Files.createDirectories(dir);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   385
            generateDotFiles(dir, analyzer);
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   386
        } else {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   387
            printRawOutput(log, analyzer);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   388
        }
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   389
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   390
        if (options.findJDKInternals && !options.nowarning) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   391
            showReplacements(analyzer);
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   392
        }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   393
        return true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   394
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   395
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   396
    private boolean verifyModuleAccess() throws IOException {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   397
        // two passes
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   398
        // 1. check API dependences where the types of dependences must be re-exported
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   399
        // 2. check all dependences where types must be accessible
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   400
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   401
        // pass 1
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   402
        findDependencies(true /* api only */);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   403
        Analyzer analyzer = Analyzer.getExportedAPIsAnalyzer();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   404
        boolean pass1 = analyzer.run(sourceLocations);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   405
        if (!pass1) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   406
            System.out.println("ERROR: Failed API access verification");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   407
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   408
        // pass 2
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   409
        findDependencies(false);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   410
        analyzer =  Analyzer.getModuleAccessAnalyzer();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   411
        boolean pass2 = analyzer.run(sourceLocations);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   412
        if (!pass2) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   413
            System.out.println("ERROR: Failed module access verification");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   414
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   415
        if (pass1 & pass2) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   416
            System.out.println("Access verification succeeded.");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   417
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   418
        return pass1 & pass2;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   419
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   420
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   421
    private void generateSummaryDotFile(Path dir, Analyzer analyzer) throws IOException {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   422
        // If verbose mode (-v or -verbose option),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   423
        // the summary.dot file shows package-level dependencies.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   424
        Analyzer.Type summaryType =
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   425
            (options.verbose == PACKAGE || options.verbose == SUMMARY) ? SUMMARY : PACKAGE;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   426
        Path summary = dir.resolve("summary.dot");
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   427
        try (PrintWriter sw = new PrintWriter(Files.newOutputStream(summary));
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   428
             SummaryDotFile dotfile = new SummaryDotFile(sw, summaryType)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   429
            for (Archive archive : sourceLocations) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   430
                if (!archive.isEmpty()) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   431
                    if (options.verbose == PACKAGE || options.verbose == SUMMARY) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   432
                        if (options.showLabel) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   433
                            // build labels listing package-level dependencies
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   434
                            analyzer.visitDependences(archive, dotfile.labelBuilder(), PACKAGE);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   435
                        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   436
                    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   437
                    analyzer.visitDependences(archive, dotfile, summaryType);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   438
                }
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   439
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   440
        }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   441
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   443
    private void generateDotFiles(Path dir, Analyzer analyzer) throws IOException {
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   444
        // output individual .dot file for each archive
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   445
        if (options.verbose != SUMMARY) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   446
            for (Archive archive : sourceLocations) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   447
                if (analyzer.hasDependences(archive)) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   448
                    Path dotfile = dir.resolve(archive.getName() + ".dot");
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   449
                    try (PrintWriter pw = new PrintWriter(Files.newOutputStream(dotfile));
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   450
                         DotFileFormatter formatter = new DotFileFormatter(pw, archive)) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   451
                        analyzer.visitDependences(archive, formatter);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   452
                    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   453
                }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   454
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   455
        }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   456
        // generate summary dot file
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   457
        generateSummaryDotFile(dir, analyzer);
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   458
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   459
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   460
    private void printRawOutput(PrintWriter writer, Analyzer analyzer) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   461
        RawOutputFormatter depFormatter = new RawOutputFormatter(writer);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   462
        RawSummaryFormatter summaryFormatter = new RawSummaryFormatter(writer);
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   463
        for (Archive archive : sourceLocations) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   464
            if (!archive.isEmpty()) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   465
                analyzer.visitDependences(archive, summaryFormatter, SUMMARY);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   466
                if (analyzer.hasDependences(archive) && options.verbose != SUMMARY) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   467
                    analyzer.visitDependences(archive, depFormatter);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   468
                }
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   469
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   470
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   471
    }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   472
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   473
    private boolean isValidClassName(String name) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   474
        if (!Character.isJavaIdentifierStart(name.charAt(0))) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   475
            return false;
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
        for (int i=1; i < name.length(); i++) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   478
            char c = name.charAt(i);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   479
            if (c != '.'  && !Character.isJavaIdentifierPart(c)) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   480
                return false;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   481
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   482
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   483
        return true;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   484
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   485
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   486
    /*
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   487
     * Dep Filter configured based on the input jdeps option
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   488
     * 1. -p and -regex to match target dependencies
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   489
     * 2. -filter:package to filter out same-package dependencies
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   490
     *
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   491
     * This filter is applied when jdeps parses the class files
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   492
     * and filtered dependencies are not stored in the Analyzer.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   493
     *
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   494
     * -filter:archive is applied later in the Analyzer as the
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   495
     * containing archive of a target class may not be known until
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   496
     * the entire archive
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   497
     */
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   498
    class DependencyFilter implements Dependency.Filter {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   499
        final Dependency.Filter filter;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   500
        final Pattern filterPattern;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   501
        DependencyFilter() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   502
            if (options.regex != null) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   503
                this.filter = Dependencies.getRegexFilter(Pattern.compile(options.regex));
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   504
            } else if (options.packageNames.size() > 0) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   505
                this.filter = Dependencies.getPackageFilter(options.packageNames, false);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   506
            } else {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   507
                this.filter = null;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   508
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   509
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   510
            this.filterPattern =
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   511
                options.filterRegex != null ? Pattern.compile(options.filterRegex) : null;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   512
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   513
        @Override
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   514
        public boolean accepts(Dependency d) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   515
            if (d.getOrigin().equals(d.getTarget())) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   516
                return false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   517
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   518
            String pn = d.getTarget().getPackageName();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   519
            if (options.filterSamePackage && d.getOrigin().getPackageName().equals(pn)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   520
                return false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   521
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   522
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   523
            if (filterPattern != null && filterPattern.matcher(pn).matches()) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   524
                return false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   525
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   526
            return filter != null ? filter.accepts(d) : true;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   527
        }
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   528
    }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   529
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   530
    /**
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   531
     * Tests if the given class matches the pattern given in the -include option
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   532
     */
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   533
    private boolean matches(String classname) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   534
        if (options.includePattern != null) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   535
            return options.includePattern.matcher(classname.replace('/', '.')).matches();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   536
        } else {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   537
            return true;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   538
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   539
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   540
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   541
    private void buildArchives() throws IOException {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   542
        for (String s : classes) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   543
            Path p = Paths.get(s);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   544
            if (Files.exists(p)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   545
                initialArchives.add(Archive.getInstance(p));
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   546
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   547
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   548
        sourceLocations.addAll(initialArchives);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   549
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   550
        classpaths.addAll(getClassPathArchives(options.classpath));
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   551
        if (options.includePattern != null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   552
            initialArchives.addAll(classpaths);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   553
        }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   554
        classpaths.addAll(PlatformClassPath.getModules(options.mpath));
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   555
        if (options.mpath != null) {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   556
            initialArchives.addAll(PlatformClassPath.getModules(options.mpath));
28143
3cc6372e77a3 8067360: verify-modules target was dropped in jdk9 b41
mchung
parents: 27579
diff changeset
   557
        } else {
3cc6372e77a3 8067360: verify-modules target was dropped in jdk9 b41
mchung
parents: 27579
diff changeset
   558
            classpaths.addAll(PlatformClassPath.getJarFiles());
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   559
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   560
        // add all classpath archives to the source locations for reporting
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   561
        sourceLocations.addAll(classpaths);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   562
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   563
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   564
    private void findDependencies(boolean apiOnly) throws IOException {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   565
        Dependency.Finder finder =
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   566
            apiOnly ? Dependencies.getAPIFinder(AccessFlags.ACC_PROTECTED)
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   567
                    : Dependencies.getClassDependencyFinder();
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   568
        Dependency.Filter filter = new DependencyFilter();
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   569
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   570
        Deque<String> roots = new LinkedList<>();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   571
        for (String s : classes) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   572
            Path p = Paths.get(s);
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   573
            if (!Files.exists(p)) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   574
                if (isValidClassName(s)) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   575
                    roots.add(s);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   576
                } else {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   577
                    warning("warn.invalid.arg", s);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   578
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   579
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   580
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   581
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   582
        // Work queue of names of classfiles to be searched.
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   583
        // Entries will be unique, and for classes that do not yet have
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   584
        // dependencies in the results map.
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   585
        Deque<String> deque = new LinkedList<>();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   586
        Set<String> doneClasses = new HashSet<>();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   587
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   588
        // get the immediate dependencies of the input files
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   589
        for (Archive a : initialArchives) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   590
            for (ClassFile cf : a.reader().getClassFiles()) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   591
                String classFileName;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   592
                try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   593
                    classFileName = cf.getName();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   594
                } catch (ConstantPoolException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   595
                    throw new ClassFileError(e);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   596
                }
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   597
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   598
                // tests if this class matches the -include or -apiOnly option if specified
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   599
                if (!matches(classFileName) || (apiOnly && !cf.access_flags.is(AccessFlags.ACC_PUBLIC))) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   600
                    continue;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   601
                }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   602
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   603
                if (!doneClasses.contains(classFileName)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   604
                    doneClasses.add(classFileName);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   605
                }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   606
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   607
                for (Dependency d : finder.findDependencies(cf)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   608
                    if (filter.accepts(d)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   609
                        String cn = d.getTarget().getName();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   610
                        if (!doneClasses.contains(cn) && !deque.contains(cn)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   611
                            deque.add(cn);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   612
                        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   613
                        a.addClass(d.getOrigin(), d.getTarget());
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   614
                    } else {
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   615
                        // ensure that the parsed class is added the archive
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   616
                        a.addClass(d.getOrigin());
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   617
                    }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   618
                }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   619
                for (String name : a.reader().skippedEntries()) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   620
                    warning("warn.skipped.entry", name, a.getPathName());
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   621
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   622
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   623
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   624
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   625
        // add Archive for looking up classes from the classpath
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   626
        // for transitive dependency analysis
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   627
        Deque<String> unresolved = roots;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   628
        int depth = options.depth > 0 ? options.depth : Integer.MAX_VALUE;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   629
        do {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   630
            String name;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   631
            while ((name = unresolved.poll()) != null) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   632
                if (doneClasses.contains(name)) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   633
                    continue;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   634
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   635
                ClassFile cf = null;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   636
                for (Archive a : classpaths) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   637
                    cf = a.reader().getClassFile(name);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   638
                    if (cf != null) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   639
                        String classFileName;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   640
                        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   641
                            classFileName = cf.getName();
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   642
                        } catch (ConstantPoolException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   643
                            throw new ClassFileError(e);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   644
                        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   645
                        if (!doneClasses.contains(classFileName)) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   646
                            // if name is a fully-qualified class name specified
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   647
                            // from command-line, this class might already be parsed
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   648
                            doneClasses.add(classFileName);
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   649
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   650
                            for (Dependency d : finder.findDependencies(cf)) {
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   651
                                if (depth == 0) {
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   652
                                    // ignore the dependency
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   653
                                    a.addClass(d.getOrigin());
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   654
                                    break;
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   655
                                } else if (filter.accepts(d)) {
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   656
                                    a.addClass(d.getOrigin(), d.getTarget());
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   657
                                    String cn = d.getTarget().getName();
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   658
                                    if (!doneClasses.contains(cn) && !deque.contains(cn)) {
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   659
                                        deque.add(cn);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   660
                                    }
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   661
                                } else {
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   662
                                    // ensure that the parsed class is added the archive
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   663
                                    a.addClass(d.getOrigin());
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   664
                                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   665
                            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   666
                        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   667
                        break;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   668
                    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   669
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   670
                if (cf == null) {
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   671
                    doneClasses.add(name);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   672
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   673
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   674
            unresolved = deque;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   675
            deque = new LinkedList<>();
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   676
        } while (!unresolved.isEmpty() && depth-- > 0);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   677
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   678
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   679
    public void handleOptions(String[] args) throws BadArgs {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   680
        // process options
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   681
        for (int i=0; i < args.length; i++) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   682
            if (args[i].charAt(0) == '-') {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   683
                String name = args[i];
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   684
                Option option = getOption(name);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   685
                String param = null;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   686
                if (option.hasArg) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   687
                    if (name.startsWith("-") && name.indexOf('=') > 0) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   688
                        param = name.substring(name.indexOf('=') + 1, name.length());
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   689
                    } else if (i + 1 < args.length) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   690
                        param = args[++i];
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   691
                    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   692
                    if (param == null || param.isEmpty() || param.charAt(0) == '-') {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   693
                        throw new BadArgs("err.missing.arg", name).showUsage(true);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   694
                    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   695
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   696
                option.process(this, name, param);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   697
                if (option.ignoreRest()) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   698
                    i = args.length;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   699
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   700
            } else {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   701
                // process rest of the input arguments
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   702
                for (; i < args.length; i++) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   703
                    String name = args[i];
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   704
                    if (name.charAt(0) == '-') {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   705
                        throw new BadArgs("err.option.after.class", name).showUsage(true);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   706
                    }
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   707
                    classes.add(name);
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   708
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   709
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   710
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   711
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   712
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   713
    private Option getOption(String name) throws BadArgs {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   714
        for (Option o : recognizedOptions) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   715
            if (o.matches(name)) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   716
                return o;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   717
            }
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
        throw new BadArgs("err.unknown.option", name).showUsage(true);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   720
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   721
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   722
    private void reportError(String key, Object... args) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   723
        log.println(getMessage("error.prefix") + " " + getMessage(key, args));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   724
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   725
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   726
    private void warning(String key, Object... args) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   727
        log.println(getMessage("warn.prefix") + " " + getMessage(key, args));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   728
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   729
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   730
    private void showHelp() {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   731
        log.println(getMessage("main.usage", PROGNAME));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   732
        for (Option o : recognizedOptions) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   733
            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
   734
            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
   735
            if (o.isHidden() || name.equals("h") || name.startsWith("filter:")) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   736
                continue;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   737
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   738
            log.println(getMessage("main.opt." + name));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   739
        }
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
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   742
    private void showVersion(boolean full) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   743
        log.println(version(full ? "full" : "release"));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   744
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   745
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   746
    private String version(String key) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   747
        // key=version:  mm.nn.oo[-milestone]
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   748
        // key=full:     mm.mm.oo[-milestone]-build
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   749
        if (ResourceBundleHelper.versionRB == null) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   750
            return System.getProperty("java.version");
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
        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   753
            return ResourceBundleHelper.versionRB.getString(key);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   754
        } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   755
            return getMessage("version.unknown", System.getProperty("java.version"));
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   756
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   757
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   758
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents: 15030
diff changeset
   759
    static String getMessage(String key, Object... args) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   760
        try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   761
            return MessageFormat.format(ResourceBundleHelper.bundle.getString(key), args);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   762
        } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   763
            throw new InternalError("Missing message: " + key);
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   764
        }
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
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   767
    private static class Options {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   768
        boolean help;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   769
        boolean version;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   770
        boolean fullVersion;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   771
        boolean showProfile;
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   772
        boolean showModule;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   773
        boolean showSummary;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   774
        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
   775
        boolean showLabel;
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   776
        boolean findJDKInternals;
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   777
        boolean nowarning;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   778
        // 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
   779
        // and filter references from same package
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   780
        Analyzer.Type verbose = PACKAGE;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   781
        boolean filterSamePackage = true;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   782
        boolean filterSameArchive = false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   783
        String filterRegex;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   784
        String dotOutputDir;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   785
        String classpath = "";
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   786
        int depth = 1;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   787
        Set<String> packageNames = new HashSet<>();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   788
        String regex;             // apply to the dependences
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   789
        Pattern includePattern;   // apply to classes
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   790
        // module boundary access check
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   791
        boolean verifyAccess;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   792
        Path mpath;
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   793
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   794
    private static class ResourceBundleHelper {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   795
        static final ResourceBundle versionRB;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   796
        static final ResourceBundle bundle;
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   797
        static final ResourceBundle jdkinternals;
15030
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
        static {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   800
            Locale locale = Locale.getDefault();
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
                bundle = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdeps", locale);
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("Cannot find jdeps resource bundle for locale " + locale);
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
            try {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   807
                versionRB = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.version");
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   808
            } catch (MissingResourceException e) {
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   809
                throw new InternalError("version.resource.missing");
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   810
            }
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   811
            try {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   812
                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
   813
            } catch (MissingResourceException e) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   814
                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
   815
            }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   816
        }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   817
    }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   818
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   819
    /*
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   820
     * Returns the list of Archive specified in cpaths and not included
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   821
     * initialArchives
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   822
     */
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   823
    private List<Archive> getClassPathArchives(String cpaths)
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   824
            throws IOException
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   825
    {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   826
        List<Archive> result = new ArrayList<>();
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   827
        if (cpaths.isEmpty()) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   828
            return result;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   829
        }
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   830
        List<Path> paths = new ArrayList<>();
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   831
        for (String p : cpaths.split(File.pathSeparator)) {
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   832
            if (p.length() > 0) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   833
                // wildcard to parse all JAR files e.g. -classpath dir/*
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   834
                int i = p.lastIndexOf(".*");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   835
                if (i > 0) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   836
                    Path dir = Paths.get(p.substring(0, i));
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   837
                    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.jar")) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   838
                        for (Path entry : stream) {
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   839
                            paths.add(entry);
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   840
                        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   841
                    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   842
                } else {
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   843
                    paths.add(Paths.get(p));
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   844
                }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   845
            }
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   846
        }
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   847
        for (Path path : paths) {
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   848
            boolean found = initialArchives.stream()
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   849
                                           .map(Archive::path)
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   850
                                           .anyMatch(p -> isSameFile(path, p));
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   851
            if (!found && Files.exists(path)) {
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   852
                result.add(Archive.getInstance(path));
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   853
            }
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   854
        }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   855
        return result;
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
   856
    }
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   857
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   858
    private boolean isSameFile(Path p1, Path p2) {
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   859
        try {
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   860
            return Files.isSameFile(p1, p2);
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   861
        } catch (IOException e) {
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   862
            throw new UncheckedIOException(e);
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   863
        }
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   864
    }
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 28143
diff changeset
   865
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   866
    class RawOutputFormatter implements Analyzer.Visitor {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   867
        private final PrintWriter writer;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   868
        private String pkg = "";
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   869
        RawOutputFormatter(PrintWriter writer) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   870
            this.writer = writer;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   871
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   872
        @Override
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   873
        public void visitDependence(String origin, Archive originArchive,
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   874
                                    String target, Archive targetArchive) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   875
            String tag = toTag(target, targetArchive);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   876
            if (options.verbose == VERBOSE) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   877
                writer.format("   %-50s -> %-50s %s%n", origin, target, tag);
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   878
            } else {
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   879
                if (!origin.equals(pkg)) {
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   880
                    pkg = origin;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   881
                    writer.format("   %s (%s)%n", origin, originArchive.getName());
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21503
diff changeset
   882
                }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   883
                writer.format("      -> %-50s %s%n", target, tag);
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   884
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   885
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   886
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   887
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   888
    class RawSummaryFormatter implements Analyzer.Visitor {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   889
        private final PrintWriter writer;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   890
        RawSummaryFormatter(PrintWriter writer) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   891
            this.writer = writer;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   892
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   893
        @Override
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   894
        public void visitDependence(String origin, Archive originArchive,
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   895
                                    String target, Archive targetArchive) {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   896
            String targetName =  targetArchive.getPathName();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   897
            if (options.showModule && isJDKModule(targetArchive)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   898
                targetName = ((Module)targetArchive).name();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   899
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   900
            writer.format("%s -> %s", originArchive.getName(), targetName);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   901
            if (options.showProfile && isJDKModule(targetArchive)) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   902
                writer.format(" (%s)", target);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   903
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   904
            writer.format("%n");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   905
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   906
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   907
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   908
    class DotFileFormatter implements Analyzer.Visitor, AutoCloseable {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   909
        private final PrintWriter writer;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   910
        private final String name;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   911
        DotFileFormatter(PrintWriter writer, Archive archive) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   912
            this.writer = writer;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   913
            this.name = archive.getName();
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   914
            writer.format("digraph \"%s\" {%n", name);
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   915
            writer.format("    // Path: %s%n", archive.getPathName());
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   916
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   917
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   918
        @Override
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   919
        public void close() {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   920
            writer.println("}");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   921
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   922
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   923
        @Override
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   924
        public void visitDependence(String origin, Archive originArchive,
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   925
                                    String target, Archive targetArchive) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   926
            String tag = toTag(target, targetArchive);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   927
            writer.format("   %-50s -> \"%s\";%n",
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   928
                          String.format("\"%s\"", origin),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   929
                          tag.isEmpty() ? target
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   930
                                        : String.format("%s (%s)", target, tag));
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   931
        }
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   932
    }
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   933
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   934
    class SummaryDotFile implements Analyzer.Visitor, AutoCloseable {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   935
        private final PrintWriter writer;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   936
        private final Analyzer.Type type;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   937
        private final Map<Archive, Map<Archive,StringBuilder>> edges = new HashMap<>();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   938
        SummaryDotFile(PrintWriter writer, Analyzer.Type type) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   939
            this.writer = writer;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   940
            this.type = type;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   941
            writer.format("digraph \"summary\" {%n");
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   942
        }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   943
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   944
        @Override
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   945
        public void close() {
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   946
            writer.println("}");
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   947
        }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   948
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   949
        @Override
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   950
        public void visitDependence(String origin, Archive originArchive,
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   951
                                    String target, Archive targetArchive) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   952
            String targetName = type == PACKAGE ? target : targetArchive.getName();
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   953
            if (isJDKModule(targetArchive)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   954
                Module m = (Module)targetArchive;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   955
                String n = showProfileOrModule(m);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   956
                if (!n.isEmpty()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   957
                    targetName += " (" + n + ")";
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   958
                }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   959
            } else if (type == PACKAGE) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   960
                targetName += " (" + targetArchive.getName() + ")";
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   961
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   962
            String label = getLabel(originArchive, targetArchive);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   963
            writer.format("  %-50s -> \"%s\"%s;%n",
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   964
                          String.format("\"%s\"", origin), targetName, label);
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   965
        }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   966
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   967
        String getLabel(Archive origin, Archive target) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   968
            if (edges.isEmpty())
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   969
                return "";
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   970
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   971
            StringBuilder label = edges.get(origin).get(target);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   972
            return label == null ? "" : String.format(" [label=\"%s\",fontsize=9]", label.toString());
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   973
        }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   974
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   975
        Analyzer.Visitor labelBuilder() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   976
            // show the package-level dependencies as labels in the dot graph
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   977
            return new Analyzer.Visitor() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   978
                @Override
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   979
                public void visitDependence(String origin, Archive originArchive, String target, Archive targetArchive) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   980
                    edges.putIfAbsent(originArchive, new HashMap<>());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   981
                    edges.get(originArchive).putIfAbsent(targetArchive, new StringBuilder());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   982
                    StringBuilder sb = edges.get(originArchive).get(targetArchive);
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   983
                    String tag = toTag(target, targetArchive);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   984
                    addLabel(sb, origin, target, tag);
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   985
                }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   986
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   987
                void addLabel(StringBuilder label, String origin, String target, String tag) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   988
                    label.append(origin).append(" -> ").append(target);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   989
                    if (!tag.isEmpty()) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   990
                        label.append(" (" + tag + ")");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   991
                    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   992
                    label.append("\\n");
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   993
                }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   994
            };
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   995
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16560
diff changeset
   996
    }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   997
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   998
    /**
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   999
     * Test if the given archive is part of the JDK
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1000
     */
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1001
    private boolean isJDKModule(Archive archive) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1002
        return Module.class.isInstance(archive);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1003
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1004
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1005
    /**
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1006
     * If the given archive is JDK archive, this method returns the profile name
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1007
     * only if -profile option is specified; it accesses a private JDK API and
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1008
     * the returned value will have "JDK internal API" prefix
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1009
     *
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1010
     * For non-JDK archives, this method returns the file name of the archive.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1011
     */
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1012
    private String toTag(String name, Archive source) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1013
        if (!isJDKModule(source)) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1014
            return source.getName();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1015
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1016
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1017
        Module module = (Module)source;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1018
        boolean isExported = false;
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1019
        if (options.verbose == CLASS || options.verbose == VERBOSE) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1020
            isExported = module.isExported(name);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1021
        } else {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1022
            isExported = module.isExportedPackage(name);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1023
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1024
        if (isExported) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1025
            // exported API
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1026
            return showProfileOrModule(module);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1027
        } else {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1028
            return "JDK internal API (" + source.getName() + ")";
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1029
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1030
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1031
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1032
    private String showProfileOrModule(Module m) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1033
        String tag = "";
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1034
        if (options.showProfile) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1035
            Profile p = Profile.getProfile(m);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1036
            if (p != null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1037
                tag = p.profileName();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1038
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1039
        } else if (options.showModule) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1040
            tag = m.name();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1041
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1042
        return tag;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1043
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1044
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1045
    private Profile getProfile(String name) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1046
        String pn = name;
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
  1047
        if (options.verbose == CLASS || options.verbose == VERBOSE) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1048
            int i = name.lastIndexOf('.');
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1049
            pn = i > 0 ? name.substring(0, i) : "";
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1050
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1051
        return Profile.getProfile(pn);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
  1052
    }
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1053
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1054
    /**
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1055
     * 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
  1056
     * 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
  1057
     */
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1058
    private String replacementFor(String cn) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1059
        String name = cn;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1060
        String value = null;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1061
        while (value == null && name != null) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1062
            try {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1063
                value = ResourceBundleHelper.jdkinternals.getString(name);
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1064
            } catch (MissingResourceException e) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1065
                // go up one subpackage level
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1066
                int i = name.lastIndexOf('.');
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1067
                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
  1068
            }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1069
        }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1070
        return value;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1071
    };
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1072
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1073
    private void showReplacements(Analyzer analyzer) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1074
        Map<String,String> jdkinternals = new TreeMap<>();
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1075
        boolean useInternals = false;
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1076
        for (Archive source : sourceLocations) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1077
            useInternals = useInternals || analyzer.hasDependences(source);
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1078
            for (String cn : analyzer.dependences(source)) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1079
                String repl = replacementFor(cn);
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1080
                if (repl != null) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1081
                    jdkinternals.putIfAbsent(cn, repl);
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1082
                }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1083
            }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1084
        }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1085
        if (useInternals) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1086
            log.println();
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1087
            warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url"));
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1088
        }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1089
        if (!jdkinternals.isEmpty()) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1090
            log.println();
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1091
            log.format("%-40s %s%n", "JDK Internal API", "Suggested Replacement");
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1092
            log.format("%-40s %s%n", "----------------", "---------------------");
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1093
            for (Map.Entry<String,String> e : jdkinternals.entrySet()) {
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1094
                log.format("%-40s %s%n", e.getKey(), e.getValue());
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1095
            }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1096
        }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1097
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
  1098
    }
15030
2d8dec41f029 8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
diff changeset
  1099
}