author | tschatzl |
Wed, 11 Sep 2019 10:19:09 +0200 | |
changeset 58081 | 8b08eaf9a0eb |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
45432
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
1 |
/* |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
4 |
* |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
10 |
* |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
15 |
* accompanied this code). |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
16 |
* |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
20 |
* |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
23 |
* questions. |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
24 |
*/ |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
25 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
26 |
package build.tools.jigsaw; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
27 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
28 |
import java.io.IOException; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
29 |
import java.io.OutputStream; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
30 |
import java.io.PrintStream; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
31 |
import java.io.UncheckedIOException; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
32 |
import java.lang.module.ModuleDescriptor; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
33 |
import java.lang.module.ModuleFinder; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
34 |
import java.lang.module.ModuleReference; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
35 |
import java.net.URI; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
36 |
import java.nio.file.FileSystem; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
37 |
import java.nio.file.FileSystems; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
38 |
import java.nio.file.Files; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
39 |
import java.nio.file.Path; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
40 |
import java.nio.file.Paths; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
41 |
import java.nio.file.attribute.BasicFileAttributes; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
42 |
import java.time.LocalDateTime; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
43 |
import java.util.ArrayList; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
44 |
import java.util.Arrays; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
45 |
import java.util.HashMap; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
46 |
import java.util.HashSet; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
47 |
import java.util.List; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
48 |
import java.util.Map; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
49 |
import java.util.Set; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
50 |
import java.util.jar.JarEntry; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
51 |
import java.util.jar.JarFile; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
52 |
import java.util.stream.Collectors; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
53 |
import java.util.stream.Stream; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
54 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
55 |
/** |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
56 |
* Run this tool to generate the JDK internal APIs in the previous releases |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
57 |
* including platform-specific internal APIs. |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
58 |
*/ |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
59 |
public class ListPackages { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
60 |
// Filter non-interesting JAR files |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
61 |
private final static List<String> excludes = Arrays.asList( |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
62 |
"deploy.jar", |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
63 |
"javaws.jar", |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
64 |
"plugin.jar", |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
65 |
"cldrdata.jar", |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
66 |
"localedata.jar" |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
67 |
); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
68 |
private static void usage() { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
69 |
System.out.println("ListPackages [-o <outfile>] [-jdkinternals] <javaHome> [<javaHome>]*"); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
70 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
71 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
72 |
private static final Set<String> EXPORTED_PACKAGES = new HashSet<>(); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
73 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
74 |
public static void main(String... args) throws IOException { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
75 |
List<Path> paths = new ArrayList<>(); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
76 |
Path outFile = null; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
77 |
boolean jdkinternals = false; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
78 |
int i=0; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
79 |
while (i < args.length) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
80 |
String arg = args[i++]; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
81 |
if (arg.equals("-o")) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
82 |
outFile = Paths.get(args[i++]); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
83 |
} else if (arg.equals("-jdkinternals")) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
84 |
jdkinternals = true; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
85 |
} else { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
86 |
Path p = Paths.get(arg); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
87 |
if (Files.notExists(p)) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
88 |
throw new IllegalArgumentException(p + " not exist"); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
89 |
paths.add(p); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
90 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
91 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
92 |
if (paths.isEmpty()) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
93 |
usage(); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
94 |
System.exit(1); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
95 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
96 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
97 |
// Get the exported APIs from the current JDK releases |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
98 |
Path javaHome = Paths.get(System.getProperty("java.home")); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
99 |
ModuleFinder.ofSystem().findAll() |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
100 |
.stream() |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
101 |
.map(ModuleReference::descriptor) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
102 |
.filter(md -> !md.name().equals("jdk.unsupported")) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
103 |
.flatMap(md -> md.exports().stream()) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
104 |
.filter(exp -> !exp.isQualified()) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
105 |
.map(ModuleDescriptor.Exports::source) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
106 |
.forEach(EXPORTED_PACKAGES::add); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
107 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
108 |
ListPackages listPackages = new ListPackages(paths); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
109 |
Stream<String> pkgs = listPackages.packages().stream(); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
110 |
if (jdkinternals) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
111 |
pkgs = pkgs.filter(pn -> !EXPORTED_PACKAGES.contains(pn)); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
112 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
113 |
if (outFile != null) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
114 |
try (OutputStream out = Files.newOutputStream(outFile); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
115 |
PrintStream pw = new PrintStream(out)) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
116 |
write(pw, pkgs); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
117 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
118 |
} else { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
119 |
write(System.out, pkgs); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
120 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
121 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
122 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
123 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
124 |
private static void write(PrintStream pw, Stream<String> packages) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
125 |
pw.println("# This file is auto-generated by ListPackages tool on " + |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
126 |
LocalDateTime.now().toString()); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
127 |
packages.sorted().forEach(pw::println); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
128 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
129 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
130 |
private final Set<String> packages = new HashSet<>(); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
131 |
ListPackages(List<Path> dirs) throws IOException { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
132 |
for (Path p : dirs) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
133 |
packages.addAll(list(p)); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
134 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
135 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
136 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
137 |
Set<String> packages() { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
138 |
return packages; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
139 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
140 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
141 |
private Set<String> list(Path javaHome) throws IOException { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
142 |
Path jrt = javaHome.resolve("lib").resolve("modules"); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
143 |
Path jre = javaHome.resolve("jre"); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
144 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
145 |
if (Files.exists(jrt)) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
146 |
return listModularRuntime(javaHome); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
147 |
} else if (Files.exists(jre.resolve("lib").resolve("rt.jar"))) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
148 |
return listLegacyRuntime(javaHome); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
149 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
150 |
throw new IllegalArgumentException("invalid " + javaHome); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
151 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
152 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
153 |
private Set<String> listModularRuntime(Path javaHome) throws IOException { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
154 |
Map<String, String> env = new HashMap<>(); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
155 |
env.put("java.home", javaHome.toString()); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
156 |
FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), env); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
157 |
Path root = fs.getPath("packages"); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
158 |
return Files.walk(root, 1) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
159 |
.map(Path::getFileName) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
160 |
.map(Path::toString) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
161 |
.collect(Collectors.toSet()); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
162 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
163 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
164 |
private Set<String> listLegacyRuntime(Path javaHome) throws IOException { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
165 |
List<Path> dirs = new ArrayList<>(); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
166 |
Path jre = javaHome.resolve("jre"); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
167 |
Path lib = javaHome.resolve("lib"); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
168 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
169 |
dirs.add(jre.resolve("lib")); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
170 |
dirs.add(jre.resolve("lib").resolve("ext")); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
171 |
dirs.add(lib.resolve("tools.jar")); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
172 |
dirs.add(lib.resolve("jconsole.jar")); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
173 |
Set<String> packages = new HashSet<>(); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
174 |
for (Path d : dirs) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
175 |
Files.find(d, 1, (Path p, BasicFileAttributes attr) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
176 |
-> p.getFileName().toString().endsWith(".jar") && |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
177 |
!excludes.contains(p.getFileName().toString())) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
178 |
.map(ListPackages::walkJarFile) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
179 |
.forEach(packages::addAll); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
180 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
181 |
return packages; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
182 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
183 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
184 |
static Set<String> walkJarFile(Path jarfile) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
185 |
try (JarFile jf = new JarFile(jarfile.toFile())) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
186 |
return jf.stream() |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
187 |
.map(JarEntry::getName) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
188 |
.filter(n -> n.endsWith(".class")) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
189 |
.map(ListPackages::toPackage) |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
190 |
.collect(Collectors.toSet()); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
191 |
} catch (IOException e) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
192 |
throw new UncheckedIOException(e); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
193 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
194 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
195 |
|
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
196 |
static String toPackage(String name) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
197 |
int i = name.lastIndexOf('/'); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
198 |
if (i < 0) { |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
199 |
System.err.format("Warning: unnamed package %s%n", name); |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
200 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
201 |
return i >= 0 ? name.substring(0, i).replace("/", ".") : ""; |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
202 |
} |
a9fcdfee6b98
8181148: Update the jdeps tool to list exported packages instead of just internal APIs
mchung
parents:
diff
changeset
|
203 |
} |