langtools/test/tools/jdeps/DotFileTest.java
author gtriantafill
Fri, 22 Aug 2014 07:38:42 -0700
changeset 26300 a1dfa0b11526
parent 25874 83c19f00452c
child 27579 d1a63c99cdd5
permissions -rw-r--r--
8055053: [TESTBUG] runtime/NMT/VirtualAllocCommitUncommitRecommit.java fails Reviewed-by: ctornqvi, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
     1
/*
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
     4
 *
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
     8
 *
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    13
 * accompanied this code).
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    14
 *
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    18
 *
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    21
 * questions.
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    22
 */
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    23
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    24
/*
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    25
 * @test
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    26
 * @bug 8003562
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    27
 * @summary Basic tests for jdeps -dotoutput option
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    28
 * @build Test p.Foo p.Bar javax.activity.NotCompactProfile
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    29
 * @run main DotFileTest
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    30
 */
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    31
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    32
import java.io.File;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    33
import java.io.IOException;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    34
import java.io.PrintWriter;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    35
import java.io.StringWriter;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    36
import java.nio.file.DirectoryStream;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    37
import java.nio.file.Files;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    38
import java.nio.file.Path;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    39
import java.nio.file.Paths;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    40
import java.util.*;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    41
import java.util.regex.*;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    42
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    43
public class DotFileTest {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    44
    private static boolean symbolFileExist = initProfiles();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    45
    private static boolean initProfiles() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    46
        // check if ct.sym exists; if not use the profiles.properties file
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    47
        Path home = Paths.get(System.getProperty("java.home"));
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    48
        if (home.endsWith("jre")) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    49
            home = home.getParent();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    50
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    51
        Path ctsym = home.resolve("lib").resolve("ct.sym");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    52
        boolean symbolExists = ctsym.toFile().exists();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    53
        if (!symbolExists) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    54
            Path testSrcProfiles =
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    55
                Paths.get(System.getProperty("test.src", "."), "profiles.properties");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    56
            if (!testSrcProfiles.toFile().exists())
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    57
                throw new Error(testSrcProfiles + " does not exist");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    58
            System.out.format("%s doesn't exist.%nUse %s to initialize profiles info%n",
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    59
                ctsym, testSrcProfiles);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    60
            System.setProperty("jdeps.profiles", testSrcProfiles.toString());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    61
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    62
        return symbolExists;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    63
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    64
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    65
    public static void main(String... args) throws Exception {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    66
        int errors = 0;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    67
        errors += new DotFileTest().run();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    68
        if (errors > 0)
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    69
            throw new Exception(errors + " errors found");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    70
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    71
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    72
    final Path dir;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    73
    final Path dotoutput;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    74
    DotFileTest() {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    75
        this.dir = Paths.get(System.getProperty("test.classes", "."));
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    76
        this.dotoutput = dir.resolve("dots");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    77
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    78
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    79
    int run() throws IOException {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    80
        File testDir = dir.toFile();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    81
        // test a .class file
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    82
        test(new File(testDir, "Test.class"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    83
             new String[] {"java.lang", "p"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    84
             new String[] {"compact1", "not found"});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    85
        // test a directory
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    86
        // also test non-SE javax.activity class dependency
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    87
        test(new File(testDir, "p"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    88
             new String[] {"java.lang", "java.util", "java.lang.management", "javax.activity", "javax.crypto"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    89
             new String[] {"compact1", "compact1", "compact3", testDir.getName(), "compact1"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    90
             new String[] {"-classpath", testDir.getPath()});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    91
        // test class-level dependency output
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    92
        test(new File(testDir, "Test.class"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    93
             new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    94
             new String[] {"compact1", "compact1", "not found", "not found"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    95
             new String[] {"-verbose:class"});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    96
        // test -filter:none option
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    97
        test(new File(testDir, "p"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    98
             new String[] {"java.lang", "java.util", "java.lang.management", "javax.activity", "javax.crypto", "p"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
    99
             new String[] {"compact1", "compact1", "compact3", testDir.getName(), "compact1", "p"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   100
             new String[] {"-classpath", testDir.getPath(), "-verbose:package", "-filter:none"});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   101
        // test -filter:archive option
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   102
        test(new File(testDir, "p"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   103
             new String[] {"java.lang", "java.util", "java.lang.management", "javax.activity", "javax.crypto"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   104
             new String[] {"compact1", "compact1", "compact3", testDir.getName(), "compact1"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   105
             new String[] {"-classpath", testDir.getPath(), "-verbose:package", "-filter:archive"});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   106
        // test -p option
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   107
        test(new File(testDir, "Test.class"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   108
             new String[] {"p.Foo", "p.Bar"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   109
             new String[] {"not found", "not found"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   110
             new String[] {"-verbose:class", "-p", "p"});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   111
        // test -e option
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   112
        test(new File(testDir, "Test.class"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   113
             new String[] {"p.Foo", "p.Bar"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   114
             new String[] {"not found", "not found"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   115
             new String[] {"-verbose:class", "-e", "p\\..*"});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   116
        test(new File(testDir, "Test.class"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   117
             new String[] {"java.lang"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   118
             new String[] {"compact1"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   119
             new String[] {"-verbose:package", "-e", "java\\.lang\\..*"});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   120
        // test -classpath options
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   121
        test(new File(testDir, "Test.class"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   122
             new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   123
             new String[] {"compact1", "compact1", testDir.getName(), testDir.getName()},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   124
             new String[] {"-v", "-classpath", testDir.getPath()});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   125
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   126
        testSummary(new File(testDir, "Test.class"),
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   127
             new String[] {"java.base", testDir.getName()},
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   128
             new String[] {"compact1", ""},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   129
             new String[] {"-classpath", testDir.getPath()});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   130
        testSummary(new File(testDir, "Test.class"),
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   131
             new String[] {"java.lang", "p"},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   132
             new String[] {"compact1", testDir.getName()},
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   133
             new String[] {"-v", "-classpath", testDir.getPath()});
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   134
        return errors;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   135
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   136
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   137
    void test(File file, String[] expect, String[] profiles) throws IOException {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   138
        test(file, expect, profiles, new String[0]);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   139
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   140
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   141
    void test(File file, String[] expect, String[] profiles, String[] options)
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   142
        throws IOException
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   143
    {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   144
        Path dotfile = dotoutput.resolve(file.toPath().getFileName().toString() + ".dot");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   145
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   146
        List<String> args = new ArrayList<>(Arrays.asList(options));
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   147
        args.add("-dotoutput");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   148
        args.add(dotoutput.toString());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   149
        if (file != null) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   150
            args.add(file.getPath());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   151
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   152
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   153
        Map<String,String> result = jdeps(args, dotfile);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   154
        checkResult("dependencies", expect, result.keySet());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   155
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   156
        // with -P option
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   157
        List<String> argsWithDashP = new ArrayList<>();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   158
        argsWithDashP.add("-dotoutput");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   159
        argsWithDashP.add(dotoutput.toString());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   160
        argsWithDashP.add("-P");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   161
        argsWithDashP.addAll(args);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   162
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   163
        result = jdeps(argsWithDashP, dotfile);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   164
        checkResult("profiles", expect, profiles, result);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   165
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   166
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   167
    void testSummary(File file, String[] expect, String[] profiles, String[] options)
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   168
        throws IOException
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   169
    {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   170
        Path dotfile = dotoutput.resolve("summary.dot");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   171
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   172
        List<String> args = new ArrayList<>(Arrays.asList(options));
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   173
        args.add("-dotoutput");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   174
        args.add(dotoutput.toString());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   175
        if (file != null) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   176
            args.add(file.getPath());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   177
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   178
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   179
        Map<String,String> result = jdeps(args, dotfile);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   180
        checkResult("dependencies", expect, result.keySet());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   181
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   182
        // with -P option
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   183
        List<String> argsWithDashP = new ArrayList<>();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   184
        argsWithDashP.add("-dotoutput");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   185
        argsWithDashP.add(dotoutput.toString());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   186
        argsWithDashP.add("-P");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   187
        argsWithDashP.addAll(args);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   188
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   189
        result = jdeps(argsWithDashP, dotfile);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   190
        checkResult("profiles", expect, profiles, result);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   191
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   192
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   193
    Map<String,String> jdeps(List<String> args, Path dotfile) throws IOException {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   194
        if (Files.exists(dotoutput)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   195
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(dotoutput)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   196
                for (Path p : stream) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   197
                    Files.delete(p);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   198
                }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   199
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   200
            Files.delete(dotoutput);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   201
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   202
        // invoke jdeps
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   203
        StringWriter sw = new StringWriter();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   204
        PrintWriter pw = new PrintWriter(sw);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   205
        System.err.println("jdeps " + args);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   206
        int rc = com.sun.tools.jdeps.Main.run(args.toArray(new String[0]), pw);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   207
        pw.close();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   208
        String out = sw.toString();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   209
        if (!out.isEmpty())
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   210
            System.err.println(out);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   211
        if (rc != 0)
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   212
            throw new Error("jdeps failed: rc=" + rc);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   213
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   214
        // check output files
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   215
        if (Files.notExists(dotfile)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   216
            throw new RuntimeException(dotfile + " doesn't exist");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   217
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   218
        return parse(dotfile);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   219
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   220
    private static Pattern pattern = Pattern.compile("(.*) -> +([^ ]*) (.*)");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   221
    private Map<String,String> parse(Path outfile) throws IOException {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   222
        Map<String,String> result = new LinkedHashMap<>();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   223
        for (String line : Files.readAllLines(outfile)) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   224
            line = line.replace('"', ' ').replace(';', ' ');
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   225
            Matcher pm = pattern.matcher(line);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   226
            if (pm.find()) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   227
                String origin = pm.group(1).trim();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   228
                String target = pm.group(2).trim();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   229
                String module = pm.group(3).replace('(', ' ').replace(')', ' ').trim();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   230
                result.put(target, module);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   231
            }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   232
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   233
        return result;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   234
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   235
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   236
    void checkResult(String label, String[] expect, Collection<String> found) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   237
        List<String> list = Arrays.asList(expect);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   238
        if (!isEqual(list, found))
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   239
            error("Unexpected " + label + " found: '" + found + "', expected: '" + list + "'");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   240
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   241
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   242
    void checkResult(String label, String[] expect, String[] profiles, Map<String,String> result) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   243
        if (expect.length != profiles.length)
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   244
            error("Invalid expected names and profiles");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   245
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   246
        // check the dependencies
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   247
        checkResult(label, expect, result.keySet());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   248
        // check profile information
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   249
        checkResult(label, profiles, result.values());
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   250
        for (int i=0; i < expect.length; i++) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   251
            String profile = result.get(expect[i]);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   252
            if (!profile.equals(profiles[i]))
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   253
                error("Unexpected profile: '" + profile + "', expected: '" + profiles[i] + "'");
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   254
        }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   255
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   256
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   257
    boolean isEqual(List<String> expected, Collection<String> found) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   258
        if (expected.size() != found.size())
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   259
            return false;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   260
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   261
        List<String> list = new ArrayList<>(found);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   262
        list.removeAll(expected);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   263
        return list.isEmpty();
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   264
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   265
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   266
    void error(String msg) {
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   267
        System.err.println("Error: " + msg);
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   268
        errors++;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   269
    }
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   270
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   271
    int errors;
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
diff changeset
   272
}