src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java
author serb
Sat, 09 Jun 2018 13:33:35 -0700
changeset 50647 a98ff7c2103d
parent 47216 71c04702a3d5
child 52650 c16b6cc93272
permissions -rw-r--r--
6608234: SwingWorker.get throws CancellationException Reviewed-by: psadhukhan, kaddepalli, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
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) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
     4
 *
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    10
 *
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    15
 * accompanied this code).
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    16
 *
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    20
 *
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    23
 * questions.
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    24
 */
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 30846
diff changeset
    25
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    26
package com.sun.tools.jdeps;
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    27
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
    28
import com.sun.tools.classfile.Dependency.Location;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    29
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
    30
import java.io.BufferedReader;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    31
import java.io.IOException;
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
    32
import java.io.InputStream;
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
    33
import java.io.InputStreamReader;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    34
import java.io.UncheckedIOException;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    35
import java.util.Collections;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    36
import java.util.Comparator;
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    37
import java.util.HashMap;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    38
import java.util.HashSet;
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    39
import java.util.Map;
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
    40
import java.util.Objects;
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    41
import java.util.Set;
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
    42
import java.util.stream.Collectors;
30843
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
    43
import java.util.stream.Stream;
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
    44
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    45
/**
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    46
 * Dependency Analyzer.
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    47
 */
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    48
public class Analyzer {
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    49
    /**
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    50
     * Type of the dependency analysis.  Appropriate level of data
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    51
     * will be stored.
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    52
     */
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    53
    public enum Type {
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    54
        SUMMARY,
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    55
        MODULE,  // equivalent to summary in addition, print module descriptor
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    56
        PACKAGE,
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    57
        CLASS,
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    58
        VERBOSE
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21503
diff changeset
    59
    }
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    60
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    61
    /**
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    62
     * Filter to be applied when analyzing the dependencies from the given archives.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    63
     * Only the accepted dependencies are recorded.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    64
     */
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    65
    interface Filter {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    66
        boolean accepts(Location origin, Archive originArchive,
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    67
                        Location target, Archive targetArchive);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    68
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    69
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    70
    protected final JdepsConfiguration configuration;
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
    71
    protected final Type type;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
    72
    protected final Filter filter;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    73
    protected final Map<Archive, Dependences> results = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    74
    protected final Map<Location, Archive> locationToArchive = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    75
    static final Archive NOT_FOUND
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    76
        = new Archive(JdepsTask.getMessage("artifact.not.found"));
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    77
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    78
    /**
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    79
     * Constructs an Analyzer instance.
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    80
     *
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    81
     * @param type Type of the dependency analysis
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    82
     * @param filter
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    83
     */
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    84
    Analyzer(JdepsConfiguration config, Type type, Filter filter) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    85
        this.configuration = config;
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    86
        this.type = type;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    87
        this.filter = filter;
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    88
    }
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    89
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    90
    /**
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    91
     * Performs the dependency analysis on the given archives.
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
    92
     */
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    93
    boolean run(Iterable<? extends Archive> archives,
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    94
                Map<Location, Archive> locationMap)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    95
    {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    96
        this.locationToArchive.putAll(locationMap);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    97
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    98
        // traverse and analyze all dependencies
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
    99
        for (Archive archive : archives) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   100
            Dependences deps = new Dependences(archive, type);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   101
            archive.visitDependences(deps);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   102
            results.put(archive, deps);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   103
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   104
        return true;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   105
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   106
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   107
    /**
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   108
     * Returns the analyzed archives
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   109
     */
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   110
    Set<Archive> archives() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   111
        return results.keySet();
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   112
    }
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   113
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   114
    /**
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   115
     * Returns true if the given archive has dependences.
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   116
     */
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   117
    boolean hasDependences(Archive archive) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
   118
        if (results.containsKey(archive)) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   119
            return results.get(archive).dependencies().size() > 0;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
   120
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
   121
        return false;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
   122
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
   123
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   124
    /**
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   125
     * Returns the dependences, either class name or package name
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   126
     * as specified in the given verbose level, from the given source.
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   127
     */
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   128
    Set<String> dependences(Archive source) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   129
        if (!results.containsKey(source)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   130
            return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   131
        }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   132
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   133
        return results.get(source).dependencies()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   134
                      .stream()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   135
                      .map(Dep::target)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   136
                      .collect(Collectors.toSet());
25692
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   137
    }
39537fdca12c 8050804: (jdeps) Recommend supported API to replace use of JDK internal API
mchung
parents: 25442
diff changeset
   138
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   139
    /**
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   140
     * Returns the direct dependences of the given source
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   141
     */
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   142
    Stream<Archive> requires(Archive source) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   143
        if (!results.containsKey(source)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   144
            return Stream.empty();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   145
        }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   146
        return results.get(source).requires()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   147
                      .stream();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   148
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   149
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   150
    interface Visitor {
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   151
        /**
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   152
         * Visits a recorded dependency from origin to target which can be
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   153
         * a fully-qualified classname, a package name, a module or
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   154
         * archive name depending on the Analyzer's type.
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   155
         */
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   156
        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
   157
                                    String target, Archive targetArchive);
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   158
    }
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   159
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   160
    /**
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   161
     * Visit the dependencies of the given source.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   162
     * If the requested level is SUMMARY, it will visit the required archives list.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   163
     */
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   164
    void visitDependences(Archive source, Visitor v, Type level) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   165
        if (level == Type.SUMMARY) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   166
            final Dependences result = results.get(source);
30843
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   167
            final Set<Archive> reqs = result.requires();
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   168
            Stream<Archive> stream = reqs.stream();
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   169
            if (reqs.isEmpty()) {
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   170
                if (hasDependences(source)) {
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   171
                    // If reqs.isEmpty() and we have dependences, then it means
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   172
                    // that the dependences are from 'source' onto itself.
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   173
                    stream = Stream.of(source);
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   174
                }
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   175
            }
6e378856c5a2 8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents: 28706
diff changeset
   176
            stream.sorted(Comparator.comparing(Archive::getName))
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   177
                  .forEach(archive -> {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   178
                      Profile profile = result.getTargetProfile(archive);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   179
                      v.visitDependence(source.getName(), source,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   180
                                        profile != null ? profile.profileName()
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   181
                                                        : archive.getName(), archive);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   182
                  });
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   183
        } else {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   184
            Dependences result = results.get(source);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   185
            if (level != type) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   186
                // requesting different level of analysis
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   187
                result = new Dependences(source, level);
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   188
                source.visitDependences(result);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   189
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   190
            result.dependencies().stream()
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   191
                  .sorted(Comparator.comparing(Dep::origin)
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   192
                                    .thenComparing(Dep::target))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   193
                  .forEach(d -> v.visitDependence(d.origin(), d.originArchive(),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   194
                                                  d.target(), d.targetArchive()));
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   195
        }
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   196
    }
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   197
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   198
    void visitDependences(Archive source, Visitor v) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   199
        visitDependences(source, v, type);
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   200
    }
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   201
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   202
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   203
     * Dependences contains the dependencies for an Archive that can have one or
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   204
     * more classes.
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   205
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   206
    class Dependences implements Archive.Visitor {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   207
        protected final Archive archive;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   208
        protected final Set<Archive> requires;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   209
        protected final Set<Dep> deps;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   210
        protected final Type level;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   211
        private Profile profile;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   212
        Dependences(Archive archive, Type level) {
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   213
            this.archive = archive;
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   214
            this.deps = new HashSet<>();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   215
            this.requires = new HashSet<>();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   216
            this.level = level;
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   217
        }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   218
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   219
        Set<Dep> dependencies() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   220
            return deps;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   221
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   222
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   223
        Set<Archive> requires() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   224
            return requires;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   225
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   226
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   227
        Profile getTargetProfile(Archive target) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   228
            if (target.getModule().isJDK()) {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   229
                return Profile.getProfile((Module) target);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   230
            } else {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   231
                return null;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   232
            }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   233
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   234
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   235
        /*
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   236
         * Returns the archive that contains the given location.
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   237
         */
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   238
        Archive findArchive(Location t) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   239
            // local in this archive
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   240
            if (archive.getClasses().contains(t))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   241
                return archive;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   242
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   243
            Archive target;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   244
            if (locationToArchive.containsKey(t)) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   245
                target = locationToArchive.get(t);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   246
            } else {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   247
                // special case JDK removed API
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   248
                target = configuration.findClass(t)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   249
                    .orElseGet(() -> REMOVED_JDK_INTERNALS.contains(t)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   250
                                        ? REMOVED_JDK_INTERNALS
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   251
                                        : NOT_FOUND);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   252
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   253
            return locationToArchive.computeIfAbsent(t, _k -> target);
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   254
        }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   255
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   256
        // return classname or package name depending on the level
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   257
        private String getLocationName(Location o) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   258
            if (level == Type.CLASS || level == Type.VERBOSE) {
41164
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents: 39671
diff changeset
   259
                return VersionHelper.get(o.getClassName());
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   260
            } else {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   261
                String pkg = o.getPackageName();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   262
                return pkg.isEmpty() ? "<unnamed>" : pkg;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   263
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   264
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   265
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   266
        @Override
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   267
        public void visit(Location o, Location t) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   268
            Archive targetArchive = findArchive(t);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   269
            if (filter.accepts(o, archive, t, targetArchive)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   270
                addDep(o, t);
28706
a724585645ce 8068937: jdeps shows "not found" if target class has no reference other than its own package
mchung
parents: 25874
diff changeset
   271
                if (archive != targetArchive && !requires.contains(targetArchive)) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   272
                    requires.add(targetArchive);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   273
                }
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   274
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   275
            if (targetArchive.getModule().isNamed()) {
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   276
                Profile p = Profile.getProfile(t.getPackageName());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   277
                if (profile == null || (p != null && p.compareTo(profile) > 0)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   278
                    profile = p;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   279
                }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   280
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   281
        }
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   282
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   283
        private Dep curDep;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   284
        protected Dep addDep(Location o, Location t) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   285
            String origin = getLocationName(o);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   286
            String target = getLocationName(t);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   287
            Archive targetArchive = findArchive(t);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   288
            if (curDep != null &&
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   289
                    curDep.origin().equals(origin) &&
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   290
                    curDep.originArchive() == archive &&
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   291
                    curDep.target().equals(target) &&
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   292
                    curDep.targetArchive() == targetArchive) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   293
                return curDep;
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   294
            }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   295
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   296
            Dep e = new Dep(origin, archive, target, targetArchive);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   297
            if (deps.contains(e)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   298
                for (Dep e1 : deps) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   299
                    if (e.equals(e1)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   300
                        curDep = e1;
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   301
                    }
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   302
                }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   303
            } else {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   304
                deps.add(e);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   305
                curDep = e;
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   306
            }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   307
            return curDep;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents: 16290
diff changeset
   308
        }
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   309
    }
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   310
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   311
    /*
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   312
     * Class-level or package-level dependency
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   313
     */
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   314
    class Dep {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   315
        final String origin;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   316
        final Archive originArchive;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   317
        final String target;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   318
        final Archive targetArchive;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   319
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   320
        Dep(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
   321
            this.origin = origin;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   322
            this.originArchive = originArchive;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   323
            this.target = target;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   324
            this.targetArchive = targetArchive;
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   325
        }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   326
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   327
        String origin() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   328
            return origin;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   329
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   330
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   331
        Archive originArchive() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   332
            return originArchive;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   333
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   334
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   335
        String target() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   336
            return target;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   337
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   338
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   339
        Archive targetArchive() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   340
            return targetArchive;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   341
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   342
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   343
        @Override
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   344
        @SuppressWarnings("unchecked")
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   345
        public boolean equals(Object o) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   346
            if (o instanceof Dep) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   347
                Dep d = (Dep) o;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   348
                return this.origin.equals(d.origin) &&
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   349
                        this.originArchive == d.originArchive &&
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   350
                        this.target.equals(d.target) &&
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   351
                        this.targetArchive == d.targetArchive;
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   352
            }
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   353
            return false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   354
        }
21503
45fc62482cae 8027481: jdeps to handle classes with the same package name and correct profile for javax.crypto.*
mchung
parents: 21046
diff changeset
   355
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   356
        @Override
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 22163
diff changeset
   357
        public int hashCode() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   358
            return Objects.hash(this.origin,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   359
                                this.originArchive,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   360
                                this.target,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   361
                                this.targetArchive);
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   362
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   363
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   364
        public String toString() {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   365
            return String.format("%s (%s) -> %s (%s)%n",
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   366
                    origin, originArchive.getName(),
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   367
                    target, targetArchive.getName());
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   368
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25692
diff changeset
   369
    }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   370
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   371
    static final Jdk8Internals REMOVED_JDK_INTERNALS = new Jdk8Internals();
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   372
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   373
    static class Jdk8Internals extends Module {
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   374
        private final String JDK8_INTERNALS = "/com/sun/tools/jdeps/resources/jdk8_internals.txt";
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   375
        private final Set<String> jdk8Internals;
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   376
        private Jdk8Internals() {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   377
            super("JDK removed internal API");
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   378
            try (InputStream in = JdepsTask.class.getResourceAsStream(JDK8_INTERNALS);
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   379
                 BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   380
                this.jdk8Internals = reader.lines()
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   381
                                          .filter(ln -> !ln.startsWith("#"))
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   382
                                          .collect(Collectors.toSet());
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   383
            } catch (IOException e) {
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   384
                throw new UncheckedIOException(e);
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   385
            }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   386
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   387
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   388
        public boolean contains(Location location) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   389
            String cn = location.getClassName();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   390
            int i = cn.lastIndexOf('.');
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   391
            String pn = i > 0 ? cn.substring(0, i) : "";
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   392
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 38532
diff changeset
   393
            return jdk8Internals.contains(pn);
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   394
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   395
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   396
        @Override
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   397
        public String name() {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   398
            return getName();
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   399
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   400
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   401
        @Override
38532
24f77d64bb1f 8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents: 38524
diff changeset
   402
        public boolean isJDK() {
24f77d64bb1f 8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents: 38524
diff changeset
   403
            return true;
24f77d64bb1f 8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents: 38524
diff changeset
   404
        }
24f77d64bb1f 8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents: 38524
diff changeset
   405
24f77d64bb1f 8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents: 38524
diff changeset
   406
        @Override
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   407
        public boolean isExported(String pn) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   408
            return false;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   409
        }
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   410
    }
16290
b0b4f52de7ea 8006225: tools/jdeps/Basic.java failes with AssertionError
mchung
parents:
diff changeset
   411
}