author | vasya |
Mon, 14 Dec 2015 20:18:19 +0100 | |
changeset 34752 | 9c262a013456 |
parent 30846 | 2b3f379840f0 |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
30843
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
1 |
/* |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
4 |
* |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
8 |
* |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
14 |
* |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
18 |
* |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
22 |
*/ |
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
30846
diff
changeset
|
23 |
|
30843
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
24 |
import java.io.IOException; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
25 |
import java.io.OutputStream; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
26 |
import java.io.PrintWriter; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
27 |
import java.nio.file.Paths; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
28 |
import java.util.ArrayList; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
29 |
import java.util.Arrays; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
30 |
import java.util.HashMap; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
31 |
import java.util.HashSet; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
32 |
import java.util.LinkedHashSet; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
33 |
import java.util.List; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
34 |
import java.util.Locale; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
35 |
import java.util.Map; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
36 |
import java.util.Set; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
37 |
import java.util.function.Supplier; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
38 |
import java.util.stream.Collectors; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
39 |
import java.util.stream.Stream; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
40 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
41 |
/** |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
42 |
* @test |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
43 |
* @bug 8080608 |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
44 |
* @summary Test that jdeps verbose output has a summary line when dependencies |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
45 |
* are found within the same archive. For each testcase, compare the |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
46 |
* result obtained from jdeps with the expected result. |
30846 | 47 |
* @modules jdk.jdeps/com.sun.tools.jdeps |
30843
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
48 |
* @build use.indirect.DontUseUnsafe2 |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
49 |
* @build use.indirect.UseUnsafeIndirectly |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
50 |
* @build use.indirect2.DontUseUnsafe3 |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
51 |
* @build use.indirect2.UseUnsafeIndirectly2 |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
52 |
* @build use.unsafe.DontUseUnsafe |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
53 |
* @build use.unsafe.UseClassWithUnsafe |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
54 |
* @build use.unsafe.UseUnsafeClass |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
55 |
* @build use.unsafe.UseUnsafeClass2 |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
56 |
* @run main JdepsDependencyClosure --test:0 |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
57 |
* @run main JdepsDependencyClosure --test:1 |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
58 |
* @run main JdepsDependencyClosure --test:2 |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
59 |
* @run main JdepsDependencyClosure --test:3 |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
60 |
*/ |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
61 |
public class JdepsDependencyClosure { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
62 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
63 |
static boolean VERBOSE = false; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
64 |
static boolean COMPARE_TEXT = true; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
65 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
66 |
static final String JDEPS_SUMMARY_TEXT_FORMAT = "%s -> %s%n"; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
67 |
static final String JDEPS_VERBOSE_TEXT_FORMAT = " %-50s -> %-50s %s%n"; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
68 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
69 |
/** |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
70 |
* Helper class used to store arguments to pass to |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
71 |
* {@code JdepsDependencyClosure.test} as well as expected |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
72 |
* results. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
73 |
*/ |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
74 |
static class TestCaseData { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
75 |
final Map<String, Set<String>> expectedDependencies; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
76 |
final String expectedText; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
77 |
final String[] args; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
78 |
final boolean closure; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
79 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
80 |
TestCaseData(Map<String, Set<String>> expectedDependencies, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
81 |
String expectedText, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
82 |
boolean closure, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
83 |
String[] args) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
84 |
this.expectedDependencies = expectedDependencies; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
85 |
this.expectedText = expectedText; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
86 |
this.closure = closure; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
87 |
this.args = args; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
88 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
89 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
90 |
public void test() { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
91 |
if (expectedDependencies != null) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
92 |
String format = closure |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
93 |
? "Running (closure): jdeps %s %s %s %s" |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
94 |
: "Running: jdeps %s %s %s %s"; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
95 |
System.out.println(String.format(format, (Object[])args)); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
96 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
97 |
JdepsDependencyClosure.test(args, expectedDependencies, expectedText, closure); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
98 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
99 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
100 |
/** |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
101 |
* Make a new test case data to invoke jdeps and test its output. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
102 |
* @param pattern The pattern that will passed through to jdeps -e |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
103 |
* This is expected to match only one class. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
104 |
* @param arcPath The archive to analyze. A jar or a class directory. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
105 |
* @param classes For each reported archive dependency couple, the |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
106 |
* expected list of classes in the source that will |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
107 |
* be reported as having a dependency on the class |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
108 |
* in the target that matches the given pattern. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
109 |
* @param dependencies For each archive dependency couple, a singleton list |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
110 |
* containing the name of the class in the target that |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
111 |
* matches the pattern. It is expected that the pattern |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
112 |
* will match only one class in the target. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
113 |
* If the pattern matches several classes the |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
114 |
* expected text may no longer match the jdeps output. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
115 |
* @param archives A list of archive dependency couple in the form |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
116 |
* {{sourceName1, sourcePath1, targetDescription1, targetPath1} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
117 |
* {sourceName2, sourcePath2, targetDescription2, targetPath2} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
118 |
* ... } |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
119 |
* For a JDK module - e.g. java.base, the targetDescription |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
120 |
* is usually something like "JDK internal API (java.base)" |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
121 |
* and the targetPath is usually the module name "java.base". |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
122 |
* @param closure Whether jdeps should be recursively invoked to build |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
123 |
* the closure. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
124 |
* @return An instance of TestCaseData containing all the information |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
125 |
* needed to perform the jdeps invokation and test its output. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
126 |
*/ |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
127 |
public static TestCaseData make(String pattern, String arcPath, String[][] classes, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
128 |
String[][] dependencies, String[][] archives, boolean closure) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
129 |
final String[] args = new String[] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
130 |
"-e", pattern, "-v", arcPath |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
131 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
132 |
Map<String, Set<String>> expected = new HashMap<>(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
133 |
String expectedText = ""; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
134 |
for (int i=0; i<classes.length; i++) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
135 |
final int index = i; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
136 |
expectedText += Stream.of(classes[i]) |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
137 |
.map((cn) -> String.format(JDEPS_VERBOSE_TEXT_FORMAT, cn, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
138 |
dependencies[index][0], archives[index][2])) |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
139 |
.reduce(String.format(JDEPS_SUMMARY_TEXT_FORMAT, archives[i][0], |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
140 |
archives[index][3]), (s1,s2) -> s1.concat(s2)); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
141 |
for (String cn : classes[index]) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
142 |
expected.putIfAbsent(cn, new HashSet<>()); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
143 |
expected.get(cn).add(dependencies[index][0]); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
144 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
145 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
146 |
return new TestCaseData(expected, expectedText, closure, args); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
147 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
148 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
149 |
public static TestCaseData valueOf(String[] args) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
150 |
if (args.length == 1 && args[0].startsWith("--test:")) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
151 |
// invoked from jtreg. build test case data for selected test. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
152 |
int index = Integer.parseInt(args[0].substring("--test:".length())); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
153 |
if (index >= dataSuppliers.size()) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
154 |
throw new RuntimeException("No such test case: " + index |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
155 |
+ " - available testcases are [0.." |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
156 |
+ (dataSuppliers.size()-1) + "]"); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
157 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
158 |
return dataSuppliers.get(index).get(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
159 |
} else { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
160 |
// invoked in standalone. just take the given argument |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
161 |
// and perform no validation on the output (except that it |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
162 |
// must start with a summary line) |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
163 |
return new TestCaseData(null, null, true, args); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
164 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
165 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
166 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
167 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
168 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
169 |
static TestCaseData makeTestCaseOne() { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
170 |
final String arcPath = System.getProperty("test.classes", "build/classes"); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
171 |
final String arcName = Paths.get(arcPath).getFileName().toString(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
172 |
final String[][] classes = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
173 |
{"use.indirect2.UseUnsafeIndirectly2", "use.unsafe.UseClassWithUnsafe"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
174 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
175 |
final String[][] dependencies = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
176 |
{"use.unsafe.UseUnsafeClass"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
177 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
178 |
final String[][] archives = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
179 |
{arcName, arcPath, arcName, arcPath}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
180 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
181 |
return TestCaseData.make("use.unsafe.UseUnsafeClass", arcPath, classes, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
182 |
dependencies, archives, false); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
183 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
184 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
185 |
static TestCaseData makeTestCaseTwo() { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
186 |
String arcPath = System.getProperty("test.classes", "build/classes"); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
187 |
String arcName = Paths.get(arcPath).getFileName().toString(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
188 |
String[][] classes = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
189 |
{"use.unsafe.UseUnsafeClass", "use.unsafe.UseUnsafeClass2"} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
190 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
191 |
String[][] dependencies = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
192 |
{"sun.misc.Unsafe"} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
193 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
194 |
String[][] archive = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
195 |
{arcName, arcPath, "JDK internal API (java.base)", "java.base"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
196 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
197 |
return TestCaseData.make("sun.misc.Unsafe", arcPath, classes, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
198 |
dependencies, archive, false); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
199 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
200 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
201 |
static TestCaseData makeTestCaseThree() { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
202 |
final String arcPath = System.getProperty("test.classes", "build/classes"); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
203 |
final String arcName = Paths.get(arcPath).getFileName().toString(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
204 |
final String[][] classes = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
205 |
{"use.indirect2.UseUnsafeIndirectly2", "use.unsafe.UseClassWithUnsafe"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
206 |
{"use.indirect.UseUnsafeIndirectly"} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
207 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
208 |
final String[][] dependencies = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
209 |
{"use.unsafe.UseUnsafeClass"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
210 |
{"use.unsafe.UseClassWithUnsafe"} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
211 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
212 |
final String[][] archives = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
213 |
{arcName, arcPath, arcName, arcPath}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
214 |
{arcName, arcPath, arcName, arcPath} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
215 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
216 |
return TestCaseData.make("use.unsafe.UseUnsafeClass", arcPath, classes, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
217 |
dependencies, archives, true); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
218 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
219 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
220 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
221 |
static TestCaseData makeTestCaseFour() { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
222 |
final String arcPath = System.getProperty("test.classes", "build/classes"); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
223 |
final String arcName = Paths.get(arcPath).getFileName().toString(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
224 |
final String[][] classes = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
225 |
{"use.unsafe.UseUnsafeClass", "use.unsafe.UseUnsafeClass2"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
226 |
{"use.indirect2.UseUnsafeIndirectly2", "use.unsafe.UseClassWithUnsafe"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
227 |
{"use.indirect.UseUnsafeIndirectly"} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
228 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
229 |
final String[][] dependencies = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
230 |
{"sun.misc.Unsafe"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
231 |
{"use.unsafe.UseUnsafeClass"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
232 |
{"use.unsafe.UseClassWithUnsafe"} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
233 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
234 |
final String[][] archives = new String[][] { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
235 |
{arcName, arcPath, "JDK internal API (java.base)", "java.base"}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
236 |
{arcName, arcPath, arcName, arcPath}, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
237 |
{arcName, arcPath, arcName, arcPath} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
238 |
}; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
239 |
return TestCaseData.make("sun.misc.Unsafe", arcPath, classes, dependencies, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
240 |
archives, true); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
241 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
242 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
243 |
static final List<Supplier<TestCaseData>> dataSuppliers = Arrays.asList( |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
244 |
JdepsDependencyClosure::makeTestCaseOne, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
245 |
JdepsDependencyClosure::makeTestCaseTwo, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
246 |
JdepsDependencyClosure::makeTestCaseThree, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
247 |
JdepsDependencyClosure::makeTestCaseFour |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
248 |
); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
249 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
250 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
251 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
252 |
/** |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
253 |
* The OutputStreamParser is used to parse the format of jdeps. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
254 |
* It is thus dependent on that format. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
255 |
*/ |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
256 |
static class OutputStreamParser extends OutputStream { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
257 |
// OutputStreamParser will populate this map: |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
258 |
// |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
259 |
// For each archive, a list of class in where dependencies where |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
260 |
// found... |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
261 |
final Map<String, Set<String>> deps; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
262 |
final StringBuilder text = new StringBuilder(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
263 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
264 |
StringBuilder[] lines = { new StringBuilder(), new StringBuilder() }; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
265 |
int line = 0; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
266 |
int sepi = 0; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
267 |
char[] sep; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
268 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
269 |
public OutputStreamParser(Map<String, Set<String>> deps) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
270 |
this.deps = deps; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
271 |
this.sep = System.getProperty("line.separator").toCharArray(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
272 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
273 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
274 |
@Override |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
275 |
public void write(int b) throws IOException { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
276 |
lines[line].append((char)b); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
277 |
if (b == sep[sepi]) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
278 |
if (++sepi == sep.length) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
279 |
text.append(lines[line]); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
280 |
if (lines[0].toString().startsWith(" ")) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
281 |
throw new RuntimeException("Bad formatting: " |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
282 |
+ "summary line missing for\n"+lines[0]); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
283 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
284 |
// Usually the output looks like that: |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
285 |
// <archive-1> -> java.base |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
286 |
// <class-1> -> <dependency> <dependency description> |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
287 |
// <class-2> -> <dependency> <dependency description> |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
288 |
// ... |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
289 |
// <archive-2> -> java.base |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
290 |
// <class-3> -> <dependency> <dependency description> |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
291 |
// <class-4> -> <dependency> <dependency description> |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
292 |
// ... |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
293 |
// |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
294 |
// We want to keep the <archive> line in lines[0] |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
295 |
// and have the ith <class-i> line in lines[1] |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
296 |
if (line == 1) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
297 |
// we have either a <class> line or an <archive> line. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
298 |
String line1 = lines[0].toString(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
299 |
String line2 = lines[1].toString(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
300 |
if (line2.startsWith(" ")) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
301 |
// we have a class line, record it. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
302 |
parse(line1, line2); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
303 |
// prepare for next <class> line. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
304 |
lines[1] = new StringBuilder(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
305 |
} else { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
306 |
// We have an archive line: We are switching to the next archive. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
307 |
// put the new <archive> line in lines[0], and prepare |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
308 |
// for reading the next <class> line |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
309 |
lines[0] = lines[1]; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
310 |
lines[1] = new StringBuilder(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
311 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
312 |
} else { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
313 |
// we just read the first <archive> line. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
314 |
// prepare to read <class> lines. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
315 |
line = 1; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
316 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
317 |
sepi = 0; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
318 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
319 |
} else { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
320 |
sepi = 0; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
321 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
322 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
323 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
324 |
// Takes a couple of lines, where line1 is an <archive> line and |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
325 |
// line 2 is a <class> line. Parses the line to extract the archive |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
326 |
// name and dependent class name, and record them in the map... |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
327 |
void parse(String line1, String line2) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
328 |
String archive = line1.substring(0, line1.indexOf(" -> ")); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
329 |
int l2ArrowIndex = line2.indexOf(" -> "); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
330 |
String className = line2.substring(2, l2ArrowIndex).replace(" ", ""); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
331 |
String depdescr = line2.substring(l2ArrowIndex + 4); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
332 |
String depclass = depdescr.substring(0, depdescr.indexOf(" ")); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
333 |
deps.computeIfAbsent(archive, (k) -> new HashSet<>()); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
334 |
deps.get(archive).add(className); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
335 |
if (VERBOSE) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
336 |
System.out.println(archive+": "+className+" depends on "+depclass); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
337 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
338 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
339 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
340 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
341 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
342 |
/** |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
343 |
* The main method. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
344 |
* |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
345 |
* Can be run in two modes: |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
346 |
* <ul> |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
347 |
* <li>From jtreg: expects 1 argument in the form {@code --test:<test-nb>}</li> |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
348 |
* <li>From command line: expected syntax is {@code -e <pattern> -v jar [jars..]}</li> |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
349 |
* </ul> |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
350 |
* <p>When called from the command line this method will call jdeps recursively |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
351 |
* to build a closure of the dependencies on {@code <pattern>} and print a summary. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
352 |
* <p>When called from jtreg - it will call jdeps either once only or |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
353 |
* recursively depending on the pattern. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
354 |
* @param args either {@code --test:<test-nb>} or {@code -e <pattern> -v jar [jars..]}. |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
355 |
*/ |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
356 |
public static void main(String[] args) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
357 |
runWithLocale(Locale.ENGLISH, TestCaseData.valueOf(args)::test); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
358 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
359 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
360 |
private static void runWithLocale(Locale loc, Runnable run) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
361 |
final Locale defaultLocale = Locale.getDefault(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
362 |
Locale.setDefault(loc); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
363 |
try { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
364 |
run.run(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
365 |
} finally { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
366 |
Locale.setDefault(defaultLocale); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
367 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
368 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
369 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
370 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
371 |
public static void test(String[] args, Map<String, Set<String>> expected, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
372 |
String expectedText, boolean closure) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
373 |
try { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
374 |
doTest(args, expected, expectedText, closure); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
375 |
} catch (Throwable t) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
376 |
try { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
377 |
printDiagnostic(args, expectedText, t, closure); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
378 |
} catch(Throwable tt) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
379 |
throw t; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
380 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
381 |
throw t; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
382 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
383 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
384 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
385 |
static class TextFormatException extends RuntimeException { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
386 |
final String expected; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
387 |
final String actual; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
388 |
TextFormatException(String message, String expected, String actual) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
389 |
super(message); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
390 |
this.expected = expected; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
391 |
this.actual = actual; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
392 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
393 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
394 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
395 |
public static void printDiagnostic(String[] args, String expectedText, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
396 |
Throwable t, boolean closure) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
397 |
if (expectedText != null || t instanceof TextFormatException) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
398 |
System.err.println("===== TEST FAILED ======="); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
399 |
System.err.println("command: " + Stream.of(args) |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
400 |
.reduce("jdeps", (s1,s2) -> s1.concat(" ").concat(s2))); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
401 |
System.err.println("===== Expected Output ======="); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
402 |
System.err.append(expectedText); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
403 |
System.err.println("===== Command Output ======="); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
404 |
if (t instanceof TextFormatException) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
405 |
System.err.print(((TextFormatException)t).actual); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
406 |
} else { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
407 |
com.sun.tools.jdeps.Main.run(args, new PrintWriter(System.err)); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
408 |
if (closure) System.err.println("... (closure not available) ..."); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
409 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
410 |
System.err.println("============================="); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
411 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
412 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
413 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
414 |
public static void doTest(String[] args, Map<String, Set<String>> expected, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
415 |
String expectedText, boolean closure) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
416 |
if (args.length < 3 || !"-e".equals(args[0]) || !"-v".equals(args[2])) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
417 |
System.err.println("Syntax: -e <classname> -v [list of jars or directories]"); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
418 |
return; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
419 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
420 |
Map<String, Map<String, Set<String>>> alldeps = new HashMap<>(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
421 |
String depName = args[1]; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
422 |
List<String> search = new ArrayList<>(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
423 |
search.add(depName); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
424 |
Set<String> searched = new LinkedHashSet<>(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
425 |
StringBuilder text = new StringBuilder(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
426 |
while(!search.isEmpty()) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
427 |
args[1] = search.remove(0); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
428 |
if (VERBOSE) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
429 |
System.out.println("Looking for " + args[1]); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
430 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
431 |
searched.add(args[1]); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
432 |
Map<String, Set<String>> deps = |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
433 |
alldeps.computeIfAbsent(args[1], (k) -> new HashMap<>()); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
434 |
OutputStreamParser parser = new OutputStreamParser(deps); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
435 |
PrintWriter writer = new PrintWriter(parser); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
436 |
com.sun.tools.jdeps.Main.run(args, writer); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
437 |
if (VERBOSE) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
438 |
System.out.println("Found: " + deps.values().stream() |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
439 |
.flatMap(s -> s.stream()).collect(Collectors.toSet())); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
440 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
441 |
if (expectedText != null) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
442 |
text.append(parser.text.toString()); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
443 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
444 |
search.addAll(deps.values().stream() |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
445 |
.flatMap(s -> s.stream()) |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
446 |
.filter(k -> !searched.contains(k)) |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
447 |
.collect(Collectors.toSet())); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
448 |
if (!closure) break; |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
449 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
450 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
451 |
// Print summary... |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
452 |
final Set<String> classes = alldeps.values().stream() |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
453 |
.flatMap((m) -> m.values().stream()) |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
454 |
.flatMap(s -> s.stream()).collect(Collectors.toSet()); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
455 |
Map<String, Set<String>> result = new HashMap<>(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
456 |
for (String c : classes) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
457 |
Set<String> archives = new HashSet<>(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
458 |
Set<String> dependencies = new HashSet<>(); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
459 |
for (String d : alldeps.keySet()) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
460 |
Map<String, Set<String>> m = alldeps.get(d); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
461 |
for (String a : m.keySet()) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
462 |
Set<String> s = m.get(a); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
463 |
if (s.contains(c)) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
464 |
archives.add(a); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
465 |
dependencies.add(d); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
466 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
467 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
468 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
469 |
result.put(c, dependencies); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
470 |
System.out.println(c + " " + archives + " depends on " + dependencies); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
471 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
472 |
|
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
473 |
// If we're in jtreg, then check result (expectedText != null) |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
474 |
if (expectedText != null && COMPARE_TEXT) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
475 |
//text.append(String.format("%n")); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
476 |
if (text.toString().equals(expectedText)) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
477 |
System.out.println("SUCCESS - got expected text"); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
478 |
} else { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
479 |
throw new TextFormatException("jdeps output is not as expected", |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
480 |
expectedText, text.toString()); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
481 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
482 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
483 |
if (expected != null) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
484 |
if (expected.equals(result)) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
485 |
System.out.println("SUCCESS - found expected dependencies"); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
486 |
} else if (expectedText == null) { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
487 |
throw new RuntimeException("Bad dependencies: Expected " + expected |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
488 |
+ " but found " + result); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
489 |
} else { |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
490 |
throw new TextFormatException("Bad dependencies: Expected " |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
491 |
+ expected |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
492 |
+ " but found " + result, |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
493 |
expectedText, text.toString()); |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
494 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
495 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
496 |
} |
6e378856c5a2
8080608: Missing archive name from jdeps -v -e output if no dependency on other JAR
dfuchs
parents:
diff
changeset
|
497 |
} |