author | stefank |
Thu, 07 Jun 2018 10:11:36 +0200 | |
changeset 50621 | 4216de02077e |
parent 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 |
/* |
50027 | 2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
45156
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; |
50027 | 29 |
import java.io.PrintWriter; |
30 |
import java.io.Writer; |
|
31 |
import java.nio.charset.Charset; |
|
32 |
import java.nio.file.Files; |
|
33 |
import java.nio.file.Path; |
|
34 |
import java.nio.file.Paths; |
|
35 |
import java.util.ArrayDeque; |
|
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
36 |
import java.util.Arrays; |
50027 | 37 |
import java.util.Deque; |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
38 |
import java.util.HashSet; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
39 |
import java.util.LinkedList; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
40 |
import java.util.List; |
50027 | 41 |
import java.util.Locale; |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
42 |
import java.util.Set; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
43 |
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
|
44 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
import javax.tools.JavaCompiler; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
48 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
49 |
import com.sun.tools.javac.api.JavacTaskImpl; |
47364 | 50 |
import com.sun.tools.javac.api.JavacTool; |
50027 | 51 |
import com.sun.tools.javac.code.Source; |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
52 |
import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
50027 | 53 |
import com.sun.tools.javac.jvm.Target; |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
54 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
55 |
/** |
50027 | 56 |
* Write reflexive transitive closure of the given modules along their requires transitive edges into |
57 |
* file <version>/system-modules in the specified directory. |
|
45156
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 |
public class TransitiveDependencies { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
60 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
61 |
private static void help() { |
50027 | 62 |
System.err.println("java TransitiveDependencies <target-directory> <module-source-path> <root-modules>"); |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
63 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
64 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
65 |
public static void main(String... args) throws IOException { |
50027 | 66 |
if (args.length < 2) { |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
67 |
help(); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
68 |
return ; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
69 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
70 |
|
47364 | 71 |
JavaCompiler compiler = JavacTool.create(); |
50027 | 72 |
List<String> options = List.of("-source", Source.DEFAULT.name, |
73 |
"-target", Target.DEFAULT.name, |
|
74 |
"-proc:only", |
|
75 |
"--system", "none", |
|
76 |
"--module-source-path", args[1], |
|
77 |
"--add-modules", Arrays.stream(args) |
|
78 |
.skip(2) |
|
79 |
.collect(Collectors.joining(","))); |
|
80 |
List<String> jlObjectList = List.of("java.lang.Object"); |
|
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45156
diff
changeset
|
81 |
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
|
82 |
task.enter(); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
83 |
Elements elements = task.getElements(); |
50027 | 84 |
Deque<String> todo = new ArrayDeque<>(); |
85 |
Arrays.stream(args).skip(2).forEach(todo::add); |
|
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
86 |
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
|
87 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
88 |
while (!todo.isEmpty()) { |
50027 | 89 |
String current = todo.removeFirst(); |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
90 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
91 |
if (!allModules.add(current)) |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
92 |
continue; |
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 |
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
|
95 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
96 |
if (mod == null) { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
97 |
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
|
98 |
} |
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 |
//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
|
101 |
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
|
102 |
if (rd.isTransitive()) { |
50027 | 103 |
todo.offerLast(rd.getDependency().getQualifiedName().toString()); |
45156
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 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
106 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
107 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
108 |
allModules.add("java.base"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
109 |
allModules.add("jdk.unsupported"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
110 |
|
50027 | 111 |
String version = |
112 |
Integer.toString(Integer.parseInt(Source.DEFAULT.name), Character.MAX_RADIX); |
|
113 |
version = version.toUpperCase(Locale.ROOT); |
|
114 |
||
115 |
Path targetFile = Paths.get(args[0]).resolve(version).resolve("system-modules"); |
|
116 |
||
117 |
Files.createDirectories(targetFile.getParent()); |
|
118 |
||
119 |
try (Writer w = Files.newBufferedWriter(targetFile); |
|
120 |
PrintWriter out = new PrintWriter(w)) { |
|
121 |
allModules.stream() |
|
122 |
.sorted() |
|
123 |
.forEach(out::println); |
|
124 |
} |
|
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
125 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
126 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff
changeset
|
127 |
} |