author | alanb |
Sat, 21 May 2016 08:01:03 +0100 | |
changeset 38457 | 3d019217e322 |
parent 37779 | 7c84df693837 |
child 42338 | a60f280f803c |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2014, 2016, 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 |
||
26 |
package java.lang.module; |
|
27 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
28 |
import java.io.PrintStream; |
36511 | 29 |
import java.util.Collection; |
30 |
import java.util.Collections; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.Map; |
|
33 |
import java.util.Objects; |
|
34 |
import java.util.Optional; |
|
35 |
import java.util.Set; |
|
36 |
import java.util.stream.Collectors; |
|
37 |
||
38 |
/** |
|
39 |
* The configuration that is the result of resolution or resolution with |
|
40 |
* service binding. |
|
41 |
* |
|
42 |
* <h2><a name="resolution">Resolution</a></h2> |
|
43 |
* |
|
44 |
* <p> Resolution is the process of computing the transitive closure of a set |
|
45 |
* of root modules over a set of observable modules by resolving the |
|
46 |
* dependences expressed by {@code requires} clauses. |
|
47 |
* |
|
48 |
* The <em>dependence graph</em> is augmented with edges that take account of |
|
49 |
* implicitly declared dependences ({@code requires public}) to create a |
|
50 |
* <em>readability graph</em>. A {@code Configuration} encapsulates the |
|
51 |
* resulting graph of {@link ResolvedModule resolved modules}. |
|
52 |
* |
|
53 |
* <p> Suppose we have the following observable modules: </p> |
|
54 |
* <pre> {@code |
|
55 |
* module m1 { requires m2; } |
|
56 |
* module m2 { requires public m3; } |
|
57 |
* module m3 { } |
|
58 |
* module m4 { } |
|
59 |
* } </pre> |
|
60 |
* |
|
61 |
* <p> If the module {@code m1} is resolved then the resulting configuration |
|
62 |
* contains three modules ({@code m1}, {@code m2}, {@code m3}). The edges in |
|
63 |
* its readability graph are: </p> |
|
64 |
* <pre> {@code |
|
65 |
* m1 --> m2 (meaning m1 reads m2) |
|
66 |
* m1 --> m3 |
|
67 |
* m2 --> m3 |
|
68 |
* } </pre> |
|
69 |
* |
|
70 |
* <p> Resolution is an additive process. When computing the transitive closure |
|
71 |
* then the dependence relation may include dependences on modules in parent |
|
72 |
* configurations. The result is a <em>relative configuration</em> that is |
|
73 |
* relative to a parent configuration and where the readability graph may have |
|
74 |
* edges from modules in the configuration to modules in a parent configuration. |
|
75 |
* </p> |
|
76 |
* |
|
77 |
* <p> Suppose we have the following observable modules: </p> |
|
78 |
* <pre> {@code |
|
79 |
* module m1 { requires m2; requires java.xml; } |
|
80 |
* module m2 { } |
|
81 |
* } </pre> |
|
82 |
* |
|
83 |
* <p> If module {@code m1} is resolved with the configuration for the {@link |
|
84 |
* java.lang.reflect.Layer#boot() boot} layer as the parent then the resulting |
|
85 |
* configuration contains two modules ({@code m1}, {@code m2}). The edges in |
|
86 |
* its readability graph are: |
|
87 |
* <pre> {@code |
|
88 |
* m1 --> m2 |
|
89 |
* m1 --> java.xml |
|
90 |
* } </pre> |
|
91 |
* where module {@code java.xml} is in the parent configuration. For |
|
92 |
* simplicity, this example omits the implicitly declared dependence on the |
|
93 |
* {@code java.base} module. |
|
94 |
* |
|
95 |
* <a name="automaticmoduleresolution"></a> |
|
96 |
* <p> {@link ModuleDescriptor#isAutomatic() Automatic} modules receive special |
|
97 |
* treatment during resolution. Each automatic module is resolved so that it |
|
98 |
* reads all other modules in the configuration and all parent configurations. |
|
99 |
* Each automatic module is also resolved as if it {@code requires public} all |
|
100 |
* other automatic modules in the configuration (and all automatic modules in |
|
101 |
* parent configurations). </p> |
|
102 |
||
103 |
* <h2><a name="servicebinding">Service binding</a></h2> |
|
104 |
* |
|
105 |
* <p> Service binding is the process of augmenting a graph of resolved modules |
|
106 |
* from the set of observable modules induced by the service-use dependence |
|
107 |
* ({@code uses} and {@code provides} clauses). Any module that was not |
|
108 |
* previously in the graph requires resolution to compute its transitive |
|
109 |
* closure. Service binding is an iterative process in that adding a module |
|
110 |
* that satisfies some service-use dependence may introduce new service-use |
|
111 |
* dependences. </p> |
|
112 |
* |
|
113 |
* <p> Suppose we have the following observable modules: </p> |
|
114 |
* <pre> {@code |
|
115 |
* module m1 { exports p; uses p.S; } |
|
116 |
* module m2 { requires m1; provides p.S with p2.S2; } |
|
117 |
* module m3 { requires m1; requires m4; provides p.S with p3.S3; } |
|
118 |
* module m4 { } |
|
119 |
* } </pre> |
|
120 |
* |
|
121 |
* <p> If the module {@code m1} is resolved then the resulting graph of modules |
|
122 |
* has one module ({@code m1}). If the graph is augmented with modules induced |
|
123 |
* by the service-use dependence relation then the configuration will contain |
|
124 |
* four modules ({@code m1}, {@code m2}, {@code m3}, {@code m4}). The edges in |
|
125 |
* its readability graph are: </p> |
|
126 |
* <pre> {@code |
|
127 |
* m2 --> m1 |
|
128 |
* m3 --> m1 |
|
129 |
* m3 --> m4 |
|
130 |
* } </pre> |
|
131 |
* <p> The edges in the conceptual service-use graph are: </p> |
|
132 |
* <pre> {@code |
|
133 |
* m1 --> m2 (meaning m1 uses a service that is provided by m2) |
|
134 |
* m1 --> m3 |
|
135 |
* } </pre> |
|
136 |
* |
|
137 |
* <p> If this configuration is instantiated as a {@code Layer}, and if code in |
|
138 |
* module {@code m1} uses {@link java.util.ServiceLoader ServiceLoader} to |
|
139 |
* iterate over implementations of {@code p.S.class}, then it will iterate over |
|
140 |
* an instance of {@code p2.S2} and {@code p3.S3}. </p> |
|
141 |
* |
|
142 |
* <h3> Example </h3> |
|
143 |
* |
|
144 |
* <p> The following example uses the {@code resolveRequires} method to resolve |
|
145 |
* a module named <em>myapp</em> with the configuration for the boot layer as |
|
146 |
* the parent configuration. It prints the name of each resolved module and |
|
147 |
* the names of the modules that each module reads. </p> |
|
148 |
* |
|
149 |
* <pre>{@code |
|
150 |
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3); |
|
151 |
* |
|
152 |
* Configuration parent = Layer.boot().configuration(); |
|
153 |
* |
|
154 |
* Configuration cf = parent.resolveRequires(finder, |
|
38457
3d019217e322
8152650: ModuleFinder.compose should accept varargs
alanb
parents:
37779
diff
changeset
|
155 |
* ModuleFinder.of(), |
36511 | 156 |
* Set.of("myapp")); |
157 |
* cf.modules().forEach(m -> { |
|
158 |
* System.out.format("%s -> %s%n", |
|
159 |
* m.name(), |
|
160 |
* m.reads().stream() |
|
161 |
* .map(ResolvedModule::name) |
|
162 |
* .collect(Collectors.joining(", "))); |
|
163 |
* }); |
|
164 |
* }</pre> |
|
165 |
* |
|
166 |
* @since 9 |
|
167 |
* @see java.lang.reflect.Layer |
|
168 |
*/ |
|
169 |
public final class Configuration { |
|
170 |
||
171 |
// @see Configuration#empty() |
|
172 |
private static final Configuration EMPTY_CONFIGURATION = new Configuration(); |
|
173 |
||
174 |
private final Configuration parent; |
|
175 |
||
176 |
private final Map<ResolvedModule, Set<ResolvedModule>> graph; |
|
177 |
private final Set<ResolvedModule> modules; |
|
178 |
private final Map<String, ResolvedModule> nameToModule; |
|
179 |
||
180 |
private Configuration() { |
|
181 |
this.parent = null; |
|
182 |
this.graph = Collections.emptyMap(); |
|
183 |
this.modules = Collections.emptySet(); |
|
184 |
this.nameToModule = Collections.emptyMap(); |
|
185 |
} |
|
186 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
187 |
private Configuration(Configuration parent, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
188 |
Resolver resolver, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
189 |
boolean check) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
190 |
{ |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
191 |
Map<ResolvedModule, Set<ResolvedModule>> g = resolver.finish(this, check); |
36511 | 192 |
|
193 |
Map<String, ResolvedModule> nameToModule = new HashMap<>(); |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
194 |
for (ResolvedModule resolvedModule : g.keySet()) { |
36511 | 195 |
nameToModule.put(resolvedModule.name(), resolvedModule); |
196 |
} |
|
197 |
||
198 |
this.parent = parent; |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
199 |
this.graph = g; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
200 |
this.modules = Collections.unmodifiableSet(g.keySet()); |
36511 | 201 |
this.nameToModule = Collections.unmodifiableMap(nameToModule); |
202 |
} |
|
203 |
||
204 |
||
205 |
/** |
|
206 |
* Resolves a collection of root modules, with this configuration as its |
|
207 |
* parent, to create a new configuration. |
|
208 |
* |
|
209 |
* <p> Each root module is located using the given {@code before} module |
|
210 |
* finder. If a module is not found then it is located in the parent |
|
211 |
* configuration as if by invoking the {@link #findModule(String) |
|
212 |
* findModule} method. If not found then the module is located using the |
|
213 |
* given {@code after} module finder. The same search order is used to |
|
214 |
* locate transitive dependences. Root modules or dependences that are |
|
215 |
* located in a parent configuration are resolved no further and are not |
|
216 |
* included in the resulting configuration. </p> |
|
217 |
* |
|
218 |
* <p> When all modules have been resolved then the resulting dependency |
|
219 |
* graph is checked to ensure that it does not contain cycles. A |
|
220 |
* readability graph is constructed and then, in conjunction with the |
|
221 |
* module exports and service use, checked for consistency. </p> |
|
222 |
* |
|
223 |
* <p> Resolution and the (post-resolution) consistency checks may fail for |
|
224 |
* following reasons: </p> |
|
225 |
* |
|
226 |
* <ul> |
|
227 |
* <li><p> A root module, or a direct or transitive dependency, is not |
|
228 |
* found. </p></li> |
|
229 |
* |
|
230 |
* <li><p> An error occurs when attempting to find a module. |
|
231 |
* Possible errors include I/O errors, errors detected parsing a module |
|
232 |
* descriptor ({@code module-info.class}) or two versions of the same |
|
233 |
* module are found in the same directory. </p></li> |
|
234 |
* |
|
235 |
* <li><p> A cycle is detected, say where module {@code m1} requires |
|
236 |
* module {@code m2} and {@code m2} requires {@code m1}. </p></li> |
|
237 |
* |
|
238 |
* <li><p> Two or more modules in the configuration export the same |
|
239 |
* package to a module that reads both. This includes the case where a |
|
240 |
* module {@code M} containing package {@code p} reads another module |
|
241 |
* that exports {@code p} to {@code M}. </p></li> |
|
242 |
* |
|
243 |
* <li><p> A module {@code M} declares that it "{@code uses p.S}" or |
|
244 |
* "{@code provides p.S with ...}" but package {@code p} is neither in |
|
245 |
* module {@code M} nor exported to {@code M} by any module that |
|
246 |
* {@code M} reads. </p></li> |
|
247 |
* |
|
248 |
* <li><p> A module {@code M} declares that it |
|
249 |
* "{@code provides ... with q.T}" but package {@code q} is not in |
|
250 |
* module {@code M}. </p></li> |
|
251 |
* |
|
252 |
* <li><p> Two or more modules in the configuration are specific to |
|
253 |
* different {@link ModuleDescriptor#osName() operating systems}, |
|
254 |
* {@link ModuleDescriptor#osArch() architectures}, or {@link |
|
255 |
* ModuleDescriptor#osVersion() versions}. </p></li> |
|
256 |
* |
|
257 |
* <li><p> Other implementation specific checks, for example referential |
|
258 |
* integrity checks to ensure that different versions of tighly coupled |
|
259 |
* modules cannot be combined in the same configuration. </p></li> |
|
260 |
* |
|
261 |
* </ul> |
|
262 |
* |
|
263 |
* @param before |
|
264 |
* The <em>before</em> module finder to find modules |
|
265 |
* @param after |
|
266 |
* The <em>after</em> module finder to locate modules when not |
|
267 |
* located by the {@code before} module finder or in parent |
|
268 |
* configurations |
|
269 |
* @param roots |
|
270 |
* The possibly-empty collection of module names of the modules |
|
271 |
* to resolve |
|
272 |
* |
|
273 |
* @return The configuration that is the result of resolving the given |
|
274 |
* root modules |
|
275 |
* |
|
276 |
* @throws ResolutionException |
|
277 |
* If resolution or the post-resolution checks fail for any of the |
|
278 |
* reasons listed |
|
279 |
* @throws SecurityException |
|
280 |
* If locating a module is denied by the security manager |
|
281 |
*/ |
|
282 |
public Configuration resolveRequires(ModuleFinder before, |
|
283 |
ModuleFinder after, |
|
284 |
Collection<String> roots) |
|
285 |
{ |
|
286 |
Objects.requireNonNull(before); |
|
287 |
Objects.requireNonNull(after); |
|
288 |
Objects.requireNonNull(roots); |
|
289 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
290 |
Resolver resolver = new Resolver(before, this, after, null); |
36511 | 291 |
resolver.resolveRequires(roots); |
292 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
293 |
return new Configuration(this, resolver, true); |
36511 | 294 |
} |
295 |
||
296 |
||
297 |
/** |
|
298 |
* Resolves a collection of root modules, with service binding, and with |
|
299 |
* this configuration as its parent, to create a new configuration. |
|
300 |
* |
|
301 |
* <p> This method works exactly as specified by {@link #resolveRequires |
|
302 |
* resolveRequires} except that the graph of resolved modules is augmented |
|
303 |
* with modules induced by the service-use dependence relation. </p> |
|
304 |
* |
|
305 |
* <p> More specifically, the root modules are resolved as if by calling |
|
306 |
* {@code resolveRequires}. The resolved modules, and all modules in the |
|
307 |
* parent configurations, with {@link ModuleDescriptor#uses() service |
|
308 |
* dependences} are then examined. All modules found by the given module |
|
309 |
* finders that {@link ModuleDescriptor#provides() provide} an |
|
310 |
* implementation of one or more of the service types are added to the |
|
311 |
* module graph and then resolved as if by calling the {@code |
|
312 |
* resolveRequires} method. Adding modules to the module graph may |
|
313 |
* introduce new service-use dependences and so the process works |
|
314 |
* iteratively until no more modules are added. </p> |
|
315 |
* |
|
316 |
* <p> As service binding involves resolution then it may fail with {@link |
|
317 |
* ResolutionException} for exactly the same reasons specified in |
|
318 |
* {@code resolveRequires}. </p> |
|
319 |
* |
|
320 |
* @param before |
|
321 |
* The <em>before</em> module finder to find modules |
|
322 |
* @param after |
|
323 |
* The <em>after</em> module finder to locate modules when not |
|
324 |
* located by the {@code before} module finder or in parent |
|
325 |
* configurations |
|
326 |
* @param roots |
|
327 |
* The possibly-empty collection of module names of the modules |
|
328 |
* to resolve |
|
329 |
* |
|
330 |
* @return The configuration that is the result of resolving the given |
|
331 |
* root modules |
|
332 |
* |
|
333 |
* @throws ResolutionException |
|
334 |
* If resolution or the post-resolution checks fail for any of the |
|
335 |
* reasons listed |
|
336 |
* @throws SecurityException |
|
337 |
* If locating a module is denied by the security manager |
|
338 |
*/ |
|
339 |
public Configuration resolveRequiresAndUses(ModuleFinder before, |
|
340 |
ModuleFinder after, |
|
341 |
Collection<String> roots) |
|
342 |
{ |
|
343 |
Objects.requireNonNull(before); |
|
344 |
Objects.requireNonNull(after); |
|
345 |
Objects.requireNonNull(roots); |
|
346 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
347 |
Resolver resolver = new Resolver(before, this, after, null); |
36511 | 348 |
resolver.resolveRequires(roots).resolveUses(); |
349 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
350 |
return new Configuration(this, resolver, true); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
351 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
352 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
353 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
354 |
/** |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
355 |
* Resolves a collection of root modules, with service binding, and with |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
356 |
* the empty configuration as its parent. The post resolution checks |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
357 |
* are optionally run. |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
358 |
* |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
359 |
* This method is used to create the configuration for the boot layer. |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
360 |
*/ |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
361 |
static Configuration resolveRequiresAndUses(ModuleFinder finder, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
362 |
Collection<String> roots, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
363 |
boolean check, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
364 |
PrintStream traceOutput) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
365 |
{ |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
366 |
Configuration parent = empty(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
367 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
368 |
Resolver resolver |
38457
3d019217e322
8152650: ModuleFinder.compose should accept varargs
alanb
parents:
37779
diff
changeset
|
369 |
= new Resolver(finder, parent, ModuleFinder.of(), traceOutput); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
370 |
resolver.resolveRequires(roots).resolveUses(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
371 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
372 |
return new Configuration(parent, resolver, check); |
36511 | 373 |
} |
374 |
||
375 |
||
376 |
/** |
|
377 |
* Returns the <em>empty</em> configuration. The empty configuration does |
|
378 |
* not contain any modules and does not have a parent. |
|
379 |
* |
|
380 |
* @return The empty configuration |
|
381 |
*/ |
|
382 |
public static Configuration empty() { |
|
383 |
return EMPTY_CONFIGURATION; |
|
384 |
} |
|
385 |
||
386 |
||
387 |
/** |
|
388 |
* Returns this configuration's parent unless this is the {@linkplain #empty |
|
389 |
* empty configuration}, which has no parent. |
|
390 |
* |
|
391 |
* @return This configuration's parent |
|
392 |
*/ |
|
393 |
public Optional<Configuration> parent() { |
|
394 |
return Optional.ofNullable(parent); |
|
395 |
} |
|
396 |
||
397 |
||
398 |
/** |
|
399 |
* Returns an immutable set of the resolved modules in this configuration. |
|
400 |
* |
|
401 |
* @return A possibly-empty unmodifiable set of the resolved modules |
|
402 |
* in this configuration |
|
403 |
*/ |
|
404 |
public Set<ResolvedModule> modules() { |
|
405 |
return modules; |
|
406 |
} |
|
407 |
||
408 |
||
409 |
/** |
|
410 |
* Finds a resolved module in this configuration, or if not in this |
|
411 |
* configuration, the {@linkplain #parent parent} configurations. |
|
412 |
* |
|
413 |
* @param name |
|
414 |
* The module name of the resolved module to find |
|
415 |
* |
|
416 |
* @return The resolved module with the given name or an empty {@code |
|
417 |
* Optional} if there isn't a module with this name in this |
|
418 |
* configuration or any parent configuration |
|
419 |
*/ |
|
420 |
public Optional<ResolvedModule> findModule(String name) { |
|
421 |
Objects.requireNonNull(name); |
|
422 |
if (parent == null) |
|
423 |
return Optional.empty(); |
|
424 |
ResolvedModule m = nameToModule.get(name); |
|
425 |
if (m != null) |
|
426 |
return Optional.of(m); |
|
427 |
return parent().flatMap(x -> x.findModule(name)); |
|
428 |
} |
|
429 |
||
430 |
||
431 |
Set<ModuleDescriptor> descriptors() { |
|
432 |
if (modules.isEmpty()) { |
|
433 |
return Collections.emptySet(); |
|
434 |
} else { |
|
435 |
return modules.stream() |
|
436 |
.map(ResolvedModule::reference) |
|
437 |
.map(ModuleReference::descriptor) |
|
438 |
.collect(Collectors.toSet()); |
|
439 |
} |
|
440 |
} |
|
441 |
||
442 |
Set<ResolvedModule> reads(ResolvedModule m) { |
|
443 |
return Collections.unmodifiableSet(graph.get(m)); |
|
444 |
} |
|
445 |
||
446 |
/** |
|
447 |
* Returns a string describing this configuration. |
|
448 |
* |
|
449 |
* @return A string describing this configuration |
|
450 |
*/ |
|
451 |
@Override |
|
452 |
public String toString() { |
|
453 |
return modules().stream() |
|
454 |
.map(ResolvedModule::name) |
|
455 |
.collect(Collectors.joining(", ")); |
|
456 |
} |
|
457 |
} |