author | serb |
Sat, 09 Jun 2018 13:33:35 -0700 | |
changeset 50647 | a98ff7c2103d |
parent 47216 | 71c04702a3d5 |
child 52650 | c16b6cc93272 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package com.sun.tools.jdeps; |
|
26 |
||
38524 | 27 |
import static com.sun.tools.jdeps.JdepsTask.*; |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
28 |
import static com.sun.tools.jdeps.Analyzer.*; |
38524 | 29 |
import static com.sun.tools.jdeps.JdepsFilter.DEFAULT_FILTER; |
36526 | 30 |
|
31 |
import java.io.IOException; |
|
32 |
import java.io.PrintWriter; |
|
38524 | 33 |
import java.io.UncheckedIOException; |
34 |
import java.lang.module.ModuleDescriptor; |
|
35 |
import java.lang.module.ModuleDescriptor.Exports; |
|
36 |
import java.lang.module.ModuleDescriptor.Provides; |
|
37 |
import java.lang.module.ModuleDescriptor.Requires; |
|
38 |
import java.lang.module.ModuleFinder; |
|
36526 | 39 |
import java.nio.file.Files; |
40 |
import java.nio.file.Path; |
|
38524 | 41 |
import java.nio.file.Paths; |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
42 |
import java.util.Collections; |
38524 | 43 |
import java.util.Comparator; |
36526 | 44 |
import java.util.HashMap; |
38524 | 45 |
import java.util.List; |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
46 |
import java.util.Locale; |
36526 | 47 |
import java.util.Map; |
48 |
import java.util.Optional; |
|
49 |
import java.util.Set; |
|
50 |
import java.util.function.Function; |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
51 |
import java.util.stream.Collectors; |
36526 | 52 |
import java.util.stream.Stream; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
53 |
import static java.util.stream.Collectors.*; |
36526 | 54 |
|
38524 | 55 |
|
36526 | 56 |
public class ModuleInfoBuilder { |
38524 | 57 |
final JdepsConfiguration configuration; |
58 |
final Path outputdir; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
59 |
final boolean open; |
38524 | 60 |
|
36526 | 61 |
final DependencyFinder dependencyFinder; |
62 |
final Analyzer analyzer; |
|
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
63 |
|
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
64 |
// an input JAR file (loaded as an automatic module for analysis) |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
65 |
// maps to a normal module to generate module-info.java |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
66 |
final Map<Module, Module> automaticToNormalModule; |
38524 | 67 |
public ModuleInfoBuilder(JdepsConfiguration configuration, |
68 |
List<String> args, |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
69 |
Path outputdir, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
70 |
boolean open) { |
38524 | 71 |
this.configuration = configuration; |
72 |
this.outputdir = outputdir; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
73 |
this.open = open; |
38524 | 74 |
|
75 |
this.dependencyFinder = new DependencyFinder(configuration, DEFAULT_FILTER); |
|
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
76 |
this.analyzer = new Analyzer(configuration, Type.CLASS, DEFAULT_FILTER); |
38524 | 77 |
|
78 |
// add targets to modulepath if it has module-info.class |
|
79 |
List<Path> paths = args.stream() |
|
80 |
.map(fn -> Paths.get(fn)) |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
81 |
.collect(toList()); |
38524 | 82 |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
83 |
// automatic module to convert to normal module |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
84 |
this.automaticToNormalModule = ModuleFinder.of(paths.toArray(new Path[0])) |
38524 | 85 |
.findAll().stream() |
86 |
.map(configuration::toModule) |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
87 |
.collect(toMap(Function.identity(), Function.identity())); |
38524 | 88 |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
89 |
Optional<Module> om = automaticToNormalModule.keySet().stream() |
38524 | 90 |
.filter(m -> !m.descriptor().isAutomatic()) |
91 |
.findAny(); |
|
92 |
if (om.isPresent()) { |
|
93 |
throw new UncheckedBadArgs(new BadArgs("err.genmoduleinfo.not.jarfile", |
|
94 |
om.get().getPathName())); |
|
95 |
} |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
96 |
if (automaticToNormalModule.isEmpty()) { |
38524 | 97 |
throw new UncheckedBadArgs(new BadArgs("err.invalid.path", args)); |
98 |
} |
|
36526 | 99 |
} |
100 |
||
38524 | 101 |
public boolean run() throws IOException { |
102 |
try { |
|
103 |
// pass 1: find API dependencies |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
104 |
Map<Archive, Set<Archive>> requiresTransitive = computeRequiresTransitive(); |
38524 | 105 |
|
106 |
// pass 2: analyze all class dependences |
|
107 |
dependencyFinder.parse(automaticModules().stream()); |
|
108 |
||
109 |
analyzer.run(automaticModules(), dependencyFinder.locationToArchive()); |
|
110 |
||
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
111 |
boolean missingDeps = false; |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
112 |
for (Module m : automaticModules()) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
113 |
Set<Archive> apiDeps = requiresTransitive.containsKey(m) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
114 |
? requiresTransitive.get(m) |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
115 |
: Collections.emptySet(); |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
116 |
|
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
117 |
Path file = outputdir.resolve(m.name()).resolve("module-info.java"); |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
118 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
119 |
// computes requires and requires transitive |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
120 |
Module normalModule = toNormalModule(m, apiDeps); |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
121 |
if (normalModule != null) { |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
122 |
automaticToNormalModule.put(m, normalModule); |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
123 |
|
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
124 |
// generate module-info.java |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
125 |
System.out.format("writing to %s%n", file); |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
126 |
writeModuleInfo(file, normalModule.descriptor()); |
38524 | 127 |
} else { |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
128 |
// find missing dependences |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
129 |
System.out.format("Missing dependence: %s not generated%n", file); |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
130 |
missingDeps = true; |
38524 | 131 |
} |
38530 | 132 |
} |
133 |
||
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
134 |
return !missingDeps; |
38524 | 135 |
} finally { |
136 |
dependencyFinder.shutdown(); |
|
137 |
} |
|
138 |
} |
|
139 |
||
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
140 |
boolean notFound(Archive m) { |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
141 |
return m == NOT_FOUND || m == REMOVED_JDK_INTERNALS; |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
142 |
} |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
143 |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
144 |
private Module toNormalModule(Module module, Set<Archive> requiresTransitive) |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
145 |
throws IOException |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
146 |
{ |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
147 |
// done analysis |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
148 |
module.close(); |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
149 |
|
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
150 |
if (analyzer.requires(module).anyMatch(this::notFound)) { |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
151 |
// missing dependencies |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
152 |
return null; |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
153 |
} |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
154 |
|
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
155 |
Map<String, Boolean> requires = new HashMap<>(); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
156 |
requiresTransitive.stream() |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
157 |
.map(Archive::getModule) |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
158 |
.forEach(m -> requires.put(m.name(), Boolean.TRUE)); |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
159 |
|
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
160 |
analyzer.requires(module) |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
161 |
.map(Archive::getModule) |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
162 |
.forEach(d -> requires.putIfAbsent(d.name(), Boolean.FALSE)); |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
163 |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
164 |
return module.toNormalModule(requires); |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
165 |
} |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
166 |
|
38524 | 167 |
/** |
168 |
* Returns the stream of resulting modules |
|
169 |
*/ |
|
170 |
Stream<Module> modules() { |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
171 |
return automaticToNormalModule.values().stream(); |
38524 | 172 |
} |
173 |
||
174 |
/** |
|
175 |
* Returns the stream of resulting ModuleDescriptors |
|
176 |
*/ |
|
177 |
public Stream<ModuleDescriptor> descriptors() { |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
178 |
return automaticToNormalModule.entrySet().stream() |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
179 |
.map(Map.Entry::getValue) |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
180 |
.map(Module::descriptor); |
38524 | 181 |
} |
182 |
||
183 |
void visitMissingDeps(Analyzer.Visitor visitor) { |
|
184 |
automaticModules().stream() |
|
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
185 |
.filter(m -> analyzer.requires(m).anyMatch(this::notFound)) |
38524 | 186 |
.forEach(m -> { |
187 |
analyzer.visitDependences(m, visitor, Analyzer.Type.VERBOSE); |
|
188 |
}); |
|
189 |
} |
|
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
190 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
191 |
void writeModuleInfo(Path file, ModuleDescriptor md) { |
38524 | 192 |
try { |
38532
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
193 |
Files.createDirectories(file.getParent()); |
24f77d64bb1f
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
mchung
parents:
38530
diff
changeset
|
194 |
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(file))) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
195 |
printModuleInfo(pw, md); |
38524 | 196 |
} |
197 |
} catch (IOException e) { |
|
198 |
throw new UncheckedIOException(e); |
|
199 |
} |
|
200 |
} |
|
201 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
202 |
private void printModuleInfo(PrintWriter writer, ModuleDescriptor md) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
203 |
writer.format("%smodule %s {%n", open ? "open " : "", md.name()); |
38524 | 204 |
|
205 |
Map<String, Module> modules = configuration.getModules(); |
|
45684
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
206 |
|
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
207 |
// first print requires |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
208 |
Set<Requires> reqs = md.requires().stream() |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
209 |
.filter(req -> !req.name().equals("java.base") && req.modifiers().isEmpty()) |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
210 |
.collect(Collectors.toSet()); |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
211 |
reqs.stream() |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
212 |
.sorted(Comparator.comparing(Requires::name)) |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
213 |
.forEach(req -> writer.format(" requires %s;%n", |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
214 |
toString(req.modifiers(), req.name()))); |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
215 |
if (!reqs.isEmpty()) { |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
216 |
writer.println(); |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
217 |
} |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
218 |
|
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
219 |
// requires transitive |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
220 |
reqs = md.requires().stream() |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
221 |
.filter(req -> !req.name().equals("java.base") && !req.modifiers().isEmpty()) |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
222 |
.collect(Collectors.toSet()); |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
223 |
reqs.stream() |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
224 |
.sorted(Comparator.comparing(Requires::name)) |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
225 |
.forEach(req -> writer.format(" requires %s;%n", |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
226 |
toString(req.modifiers(), req.name()))); |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
227 |
if (!reqs.isEmpty()) { |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
228 |
writer.println(); |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
229 |
} |
38524 | 230 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
231 |
if (!open) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
232 |
md.exports().stream() |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
233 |
.peek(exp -> { |
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
234 |
if (exp.isQualified()) |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
235 |
throw new InternalError(md.name() + " qualified exports: " + exp); |
45684
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
236 |
}) |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
237 |
.sorted(Comparator.comparing(Exports::source)) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
238 |
.forEach(exp -> writer.format(" exports %s;%n", exp.source())); |
45684
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
239 |
|
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
240 |
if (!md.exports().isEmpty()) { |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
241 |
writer.println(); |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
242 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
243 |
} |
38524 | 244 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
245 |
md.provides().stream() |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
246 |
.sorted(Comparator.comparing(Provides::service)) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
247 |
.map(p -> p.providers().stream() |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
248 |
.map(impl -> " " + impl.replace('$', '.')) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
249 |
.collect(joining(",\n", |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
250 |
String.format(" provides %s with%n", |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
251 |
p.service().replace('$', '.')), |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
252 |
";"))) |
45684
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
253 |
.forEach(writer::println); |
38524 | 254 |
|
45684
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
255 |
if (!md.provides().isEmpty()) { |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
256 |
writer.println(); |
2c5f2779c3d1
8182416: Clean up module-info.java like move requires transitive adjacent to exports
mchung
parents:
43767
diff
changeset
|
257 |
} |
38524 | 258 |
writer.println("}"); |
259 |
} |
|
260 |
||
261 |
private Set<Module> automaticModules() { |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
262 |
return automaticToNormalModule.keySet(); |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
263 |
} |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
264 |
|
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
265 |
/** |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
266 |
* Returns a string containing the given set of modifiers and label. |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
267 |
*/ |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
268 |
private static <M> String toString(Set<M> mods, String what) { |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
269 |
return (Stream.concat(mods.stream().map(e -> e.toString().toLowerCase(Locale.US)), |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
270 |
Stream.of(what))) |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42407
diff
changeset
|
271 |
.collect(Collectors.joining(" ")); |
36526 | 272 |
} |
273 |
||
274 |
/** |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
275 |
* Compute 'requires transitive' dependences by analyzing API dependencies |
36526 | 276 |
*/ |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
277 |
private Map<Archive, Set<Archive>> computeRequiresTransitive() |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
278 |
throws IOException |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38532
diff
changeset
|
279 |
{ |
38524 | 280 |
// parse the input modules |
281 |
dependencyFinder.parseExportedAPIs(automaticModules().stream()); |
|
36526 | 282 |
|
38524 | 283 |
return dependencyFinder.dependences(); |
36526 | 284 |
} |
285 |
} |