langtools/test/tools/jdeps/APIDeps.java
author ksrini
Tue, 24 Dec 2013 09:17:37 -0800
changeset 22448 a85fbad9d687
parent 22007 907f7054db16
child 25442 755ff386d1ac
permissions -rw-r--r--
8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013 Reviewed-by: ksrini Contributed-by: steve.sides@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
     1
/*
22448
a85fbad9d687 8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013
ksrini
parents: 22007
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
     4
 *
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
     8
 *
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    13
 * accompanied this code).
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    14
 *
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    18
 *
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    21
 * questions.
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    22
 */
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    23
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    24
/*
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    25
 * @test
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    26
 * @bug 8015912 8029216
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    27
 * @summary Test -apionly and -jdkinternals options
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    28
 * @build m.Bar m.Foo m.Gee b.B c.C c.I d.D e.E f.F g.G
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    29
 * @run main APIDeps
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    30
 */
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    31
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    32
import java.io.File;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    33
import java.io.IOException;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    34
import java.io.PrintWriter;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    35
import java.io.StringWriter;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    36
import java.nio.file.Path;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    37
import java.nio.file.Paths;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    38
import java.util.*;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    39
import java.util.regex.*;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    40
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    41
public class APIDeps {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    42
    private static boolean symbolFileExist = initProfiles();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    43
    private static boolean initProfiles() {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    44
        // check if ct.sym exists; if not use the profiles.properties file
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    45
        Path home = Paths.get(System.getProperty("java.home"));
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    46
        if (home.endsWith("jre")) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    47
            home = home.getParent();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    48
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    49
        Path ctsym = home.resolve("lib").resolve("ct.sym");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    50
        boolean symbolExists = ctsym.toFile().exists();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    51
        if (!symbolExists) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    52
            Path testSrcProfiles =
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    53
                Paths.get(System.getProperty("test.src", "."), "profiles.properties");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    54
            if (!testSrcProfiles.toFile().exists())
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    55
                throw new Error(testSrcProfiles + " does not exist");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    56
            System.out.format("%s doesn't exist.%nUse %s to initialize profiles info%n",
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    57
                ctsym, testSrcProfiles);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    58
            System.setProperty("jdeps.profiles", testSrcProfiles.toString());
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    59
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    60
        return symbolExists;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    61
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    62
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    63
    public static void main(String... args) throws Exception {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    64
        int errors = 0;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    65
        errors += new APIDeps().run();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    66
        if (errors > 0)
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    67
            throw new Exception(errors + " errors found");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    68
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    69
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    70
    int run() throws IOException {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    71
        File testDir = new File(System.getProperty("test.classes", "."));
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    72
        String testDirBasename = testDir.toPath().getFileName().toString();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    73
        File mDir = new File(testDir, "m");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    74
        // all dependencies
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    75
        test(new File(mDir, "Bar.class"),
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    76
             new String[] {"java.lang.Object", "java.lang.String",
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    77
                           "java.util.Set", "java.util.HashSet",
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    78
                           "java.lang.management.ManagementFactory",
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    79
                           "java.lang.management.RuntimeMXBean",
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    80
                           "b.B", "c.C", "d.D", "f.F", "g.G"},
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    81
             new String[] {"compact1", "compact3", testDirBasename},
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    82
             new String[] {"-classpath", testDir.getPath(), "-verbose", "-P"});
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    83
        test(new File(mDir, "Foo.class"),
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    84
             new String[] {"c.I", "e.E", "f.F", "m.Bar"},
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    85
             new String[] {testDirBasename},
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    86
             new String[] {"-classpath", testDir.getPath(), "-verbose", "-P"});
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    87
        test(new File(mDir, "Gee.class"),
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    88
             new String[] {"g.G", "sun.misc.Lock"},
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    89
             new String[] {testDirBasename, "JDK internal API"},
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
    90
             new String[] {"-classpath", testDir.getPath(), "-verbose"});
22007
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    91
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    92
        // -jdkinternals
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    93
        test(new File(mDir, "Gee.class"),
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    94
             new String[] {"sun.misc.Lock"},
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    95
             new String[] {"JDK internal API"},
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    96
             new String[] {"-jdkinternals"});
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    97
        // -jdkinternals parses all classes on -classpath and the input arguments
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    98
        test(new File(mDir, "Gee.class"),
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
    99
             new String[] {"sun.misc.Lock", "sun.misc.Unsafe"},
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
   100
             new String[] {"JDK internal API"},
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
   101
             new String[] {"-classpath", testDir.getPath(), "-jdkinternals"});
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
   102
907f7054db16 8029216: (jdeps) Provide a specific option to report JDK internal APIs
mchung
parents: 21046
diff changeset
   103
        // parse only APIs
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   104
        // parse only APIs
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   105
        test(mDir,
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   106
             new String[] {"java.lang.Object", "java.lang.String",
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   107
                           "java.util.Set",
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   108
                           "c.C", "d.D", "c.I", "e.E", "m.Bar"},
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   109
             new String[] {"compact1", testDirBasename, mDir.getName()},
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   110
             new String[] {"-classpath", testDir.getPath(), "-verbose", "-P", "-apionly"});
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   111
        return errors;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   112
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   113
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   114
    void test(File file, String[] expect, String[] profiles) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   115
        test(file, expect, profiles, new String[0]);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   116
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   117
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   118
    void test(File file, String[] expect, String[] profiles, String[] options) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   119
        List<String> args = new ArrayList<>(Arrays.asList(options));
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   120
        if (file != null) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   121
            args.add(file.getPath());
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   122
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   123
        checkResult("api-dependencies", expect, profiles,
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   124
                    jdeps(args.toArray(new String[0])));
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   125
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   126
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   127
    Map<String,String> jdeps(String... args) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   128
        StringWriter sw = new StringWriter();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   129
        PrintWriter pw = new PrintWriter(sw);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   130
        System.err.println("jdeps " + Arrays.toString(args));
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   131
        int rc = com.sun.tools.jdeps.Main.run(args, pw);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   132
        pw.close();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   133
        String out = sw.toString();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   134
        if (!out.isEmpty())
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   135
            System.err.println(out);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   136
        if (rc != 0)
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   137
            throw new Error("jdeps failed: rc=" + rc);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   138
        return findDeps(out);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   139
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   140
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   141
    // Pattern used to parse lines
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   142
    private static Pattern linePattern = Pattern.compile(".*\r?\n");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   143
    private static Pattern pattern = Pattern.compile("\\s+ -> (\\S+) +(.*)");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   144
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   145
    // Use the linePattern to break the given String into lines, applying
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   146
    // the pattern to each line to see if we have a match
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   147
    private static Map<String,String> findDeps(String out) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   148
        Map<String,String> result = new HashMap<>();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   149
        Matcher lm = linePattern.matcher(out);  // Line matcher
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   150
        Matcher pm = null;                      // Pattern matcher
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   151
        int lines = 0;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   152
        while (lm.find()) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   153
            lines++;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   154
            CharSequence cs = lm.group();       // The current line
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   155
            if (pm == null)
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   156
                pm = pattern.matcher(cs);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   157
            else
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   158
                pm.reset(cs);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   159
            if (pm.find())
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   160
                result.put(pm.group(1), pm.group(2).trim());
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   161
            if (lm.end() == out.length())
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   162
                break;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   163
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   164
        return result;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   165
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   166
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   167
    void checkResult(String label, String[] expect, Collection<String> found) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   168
        List<String> list = Arrays.asList(expect);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   169
        if (!isEqual(list, found))
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   170
            error("Unexpected " + label + " found: '" + found + "', expected: '" + list + "'");
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   171
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   172
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   173
    void checkResult(String label, String[] expect, String[] profiles, Map<String,String> result) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   174
        // check the dependencies
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   175
        checkResult(label, expect, result.keySet());
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   176
        // check profile information
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   177
        Set<String> values = new TreeSet<>();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   178
        String internal = "JDK internal API";
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   179
        for (String s: result.values()) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   180
            if (s.startsWith(internal)){
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   181
                values.add(internal);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   182
            } else {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   183
                values.add(s);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   184
            }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   185
        }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   186
        checkResult(label, profiles, values);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   187
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   188
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   189
    boolean isEqual(List<String> expected, Collection<String> found) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   190
        if (expected.size() != found.size())
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   191
            return false;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   192
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   193
        List<String> list = new ArrayList<>(found);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   194
        list.removeAll(expected);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   195
        return list.isEmpty();
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   196
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   197
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   198
    void error(String msg) {
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   199
        System.err.println("Error: " + msg);
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   200
        errors++;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   201
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   202
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   203
    int errors;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents:
diff changeset
   204
}