author | erikj |
Thu, 19 Oct 2017 14:16:45 +0200 | |
changeset 47364 | 6b3389375f31 |
parent 47275 | b4c8426fe105 |
child 50027 | 69aadf0c1e69 |
permissions | -rw-r--r-- |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
1 |
/* |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
4 |
* |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
10 |
* |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
15 |
* accompanied this code). |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
16 |
* |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
20 |
* |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
23 |
* questions. |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
24 |
*/ |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
25 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
26 |
package build.tools.symbolgenerator; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
27 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
28 |
import java.io.IOException; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
29 |
import java.util.Arrays; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
30 |
import java.util.HashSet; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
31 |
import java.util.LinkedList; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
32 |
import java.util.List; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
33 |
import java.util.Set; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
34 |
import java.util.stream.Collectors; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
35 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
36 |
import javax.lang.model.element.ModuleElement.RequiresDirective; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
37 |
import javax.lang.model.util.Elements; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
38 |
import javax.tools.JavaCompiler; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
39 |
import javax.tools.ToolProvider; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
40 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.api.JavacTaskImpl; |
47364 | 42 |
import com.sun.tools.javac.api.JavacTool; |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
43 |
import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
44 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
45 |
/** |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
46 |
* Print reflexive transitive closure of the given modules along their requires transitive edges. |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
47 |
*/ |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
48 |
public class TransitiveDependencies { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
49 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
50 |
private static void help() { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
51 |
System.err.println("java TransitiveDependencies <module-source-path> <root-modules>"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
52 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
53 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
54 |
public static void main(String... args) throws IOException { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
55 |
if (args.length < 1) { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
56 |
help(); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
57 |
return ; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
58 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
59 |
|
47364 | 60 |
JavaCompiler compiler = JavacTool.create(); |
47275 | 61 |
List<String> options = Arrays.asList("-source", "10", |
62 |
"-target", "10", |
|
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45156
diff
changeset
|
63 |
"-proc:only", |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
64 |
"--system", "none", |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
65 |
"--module-source-path", args[0], |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
66 |
"--add-modules", Arrays.stream(args) |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
67 |
.skip(1) |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
68 |
.collect(Collectors.joining(","))); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
69 |
List<String> jlObjectList = Arrays.asList("java.lang.Object"); |
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45156
diff
changeset
|
70 |
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, null, null, options, jlObjectList, null); |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
71 |
task.enter(); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
72 |
Elements elements = task.getElements(); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
73 |
List<String> todo = new LinkedList<>(); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
74 |
Arrays.stream(args).skip(1).forEach(todo::add); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
75 |
Set<String> allModules = new HashSet<>(); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
76 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
77 |
while (!todo.isEmpty()) { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
78 |
String current = todo.remove(0); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
79 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
80 |
if (!allModules.add(current)) |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
81 |
continue; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
82 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
83 |
ModuleSymbol mod = (ModuleSymbol) elements.getModuleElement(current); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
84 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
85 |
if (mod == null) { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
86 |
throw new IllegalStateException("Missing: " + current); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
87 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
88 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
89 |
//use the internal structure to avoid unnecesarily completing the symbol using the UsesProvidesVisitor: |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
90 |
for (RequiresDirective rd : mod.requires) { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
91 |
if (rd.isTransitive()) { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
92 |
todo.add(rd.getDependency().getQualifiedName().toString()); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
93 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
94 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
95 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
96 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
97 |
allModules.add("java.base"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
98 |
allModules.add("jdk.unsupported"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
99 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
100 |
allModules.stream() |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
101 |
.sorted() |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
102 |
.forEach(System.out::println); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
103 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
104 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
105 |
} |