81 // create the visit stack to get us started
82 Deque<ModuleDescriptor> q = new ArrayDeque<>();
83 for (String root : roots) {
84
85 // find root module
86 ModuleReference mref = findWithBeforeFinder(root);
87 if (mref == null) {
88 if (parent.findModule(root).isPresent()) {
89 // in parent, nothing to do
90 continue;
91 }
92 mref = findWithAfterFinder(root);
93 if (mref == null) {
94 fail("Module %s not found", root);
95 }
96 }
97
98 if (TRACE) {
99 trace("Root module %s located", root);
100 if (mref.location().isPresent())
101 trace(" (%s)", mref.location().get());
102 }
103
104 assert mref.descriptor().name().equals(root);
105 nameToReference.put(root, mref);
106 q.push(mref.descriptor());
107 }
108
109 resolve(q);
110
111 if (TRACE) {
112 long duration = System.currentTimeMillis() - start;
113 Set<String> names = nameToReference.keySet();
114 trace("Resolver completed in %s ms", duration);
115 names.stream().sorted().forEach(name -> trace(" %s", name));
116 }
117
118 return this;
119 }
120
121 /**
140 if (mref == null) {
141 if (parent.findModule(dn).isPresent())
142 continue;
143
144 mref = findWithAfterFinder(dn);
145 if (mref == null) {
146 fail("Module %s not found, required by %s",
147 dn, descriptor.name());
148 }
149 }
150
151 if (!nameToReference.containsKey(dn)) {
152 nameToReference.put(dn, mref);
153 q.offer(mref.descriptor());
154 resolved.add(mref.descriptor());
155
156 if (TRACE) {
157 trace("Module %s located, required by %s",
158 dn, descriptor.name());
159 if (mref.location().isPresent())
160 trace(" (%s)", mref.location().get());
161 }
162 }
163
164 }
165
166 resolved.add(descriptor);
167 }
168
169 return resolved;
170 }
171
172 /**
173 * Augments the set of resolved modules with modules induced by the
174 * service-use relation.
175 */
176 Resolver resolveUses() {
177
178 long start = trace_start("Bind");
179
180 // Scan the finders for all available service provider modules. As
215
216 // Where there is a consumer of a service then resolve all modules
217 // that provide an implementation of that service
218 do {
219 for (ModuleDescriptor descriptor : candidateConsumers) {
220 if (!descriptor.uses().isEmpty()) {
221 for (String service : descriptor.uses()) {
222 Set<ModuleReference> mrefs = availableProviders.get(service);
223 if (mrefs != null) {
224 for (ModuleReference mref : mrefs) {
225 ModuleDescriptor provider = mref.descriptor();
226 if (!provider.equals(descriptor)) {
227
228 trace("Module %s provides %s, used by %s",
229 provider.name(), service, descriptor.name());
230
231 String pn = provider.name();
232 if (!nameToReference.containsKey(pn)) {
233
234 if (TRACE && mref.location().isPresent())
235 trace(" (%s)", mref.location().get());
236
237 nameToReference.put(pn, mref);
238 q.push(provider);
239 }
240 }
241 }
242 }
243 }
244 }
245 }
246
247 candidateConsumers = resolve(q);
248
249 } while (!candidateConsumers.isEmpty());
250
251
252 if (TRACE) {
253 long duration = System.currentTimeMillis() - start;
254 Set<String> names = nameToReference.keySet();
255 trace("Bind completed in %s ms", duration);
417 .add(Objects.toString(osArch, "*"))
418 .add(Objects.toString(osVersion, "*"))
419 .toString();
420
421 }
422
423
424 /**
425 * Checks the hashes in the module descriptor to ensure that they match
426 * the hash of the dependency's module reference.
427 */
428 private void checkHashes() {
429
430 for (ModuleReference mref : nameToReference.values()) {
431 ModuleDescriptor descriptor = mref.descriptor();
432
433 // get map of module names to hash
434 Optional<Hasher.DependencyHashes> ohashes = descriptor.hashes();
435 if (!ohashes.isPresent())
436 continue;
437 Hasher.DependencyHashes hashes = ohashes.get();
438
439 // check dependences
440 for (ModuleDescriptor.Requires d : descriptor.requires()) {
441 String dn = d.name();
442 String recordedHash = hashes.hashFor(dn);
443
444 if (recordedHash != null) {
445
446 ModuleReference other = nameToReference.get(dn);
447 if (other == null) {
448 other = parent.findModule(dn)
449 .map(ResolvedModule::reference)
450 .orElse(null);
451 }
452 if (other == null)
453 throw new InternalError(dn + " not found");
454
455 String actualHash = other.computeHash(hashes.algorithm());
456 if (actualHash == null)
457 fail("Unable to compute the hash of module %s", dn);
|
81 // create the visit stack to get us started
82 Deque<ModuleDescriptor> q = new ArrayDeque<>();
83 for (String root : roots) {
84
85 // find root module
86 ModuleReference mref = findWithBeforeFinder(root);
87 if (mref == null) {
88 if (parent.findModule(root).isPresent()) {
89 // in parent, nothing to do
90 continue;
91 }
92 mref = findWithAfterFinder(root);
93 if (mref == null) {
94 fail("Module %s not found", root);
95 }
96 }
97
98 if (TRACE) {
99 trace("Root module %s located", root);
100 if (mref.location().isPresent())
101 trace(" (%s)", mref.location().getWhenPresent());
102 }
103
104 assert mref.descriptor().name().equals(root);
105 nameToReference.put(root, mref);
106 q.push(mref.descriptor());
107 }
108
109 resolve(q);
110
111 if (TRACE) {
112 long duration = System.currentTimeMillis() - start;
113 Set<String> names = nameToReference.keySet();
114 trace("Resolver completed in %s ms", duration);
115 names.stream().sorted().forEach(name -> trace(" %s", name));
116 }
117
118 return this;
119 }
120
121 /**
140 if (mref == null) {
141 if (parent.findModule(dn).isPresent())
142 continue;
143
144 mref = findWithAfterFinder(dn);
145 if (mref == null) {
146 fail("Module %s not found, required by %s",
147 dn, descriptor.name());
148 }
149 }
150
151 if (!nameToReference.containsKey(dn)) {
152 nameToReference.put(dn, mref);
153 q.offer(mref.descriptor());
154 resolved.add(mref.descriptor());
155
156 if (TRACE) {
157 trace("Module %s located, required by %s",
158 dn, descriptor.name());
159 if (mref.location().isPresent())
160 trace(" (%s)", mref.location().getWhenPresent());
161 }
162 }
163
164 }
165
166 resolved.add(descriptor);
167 }
168
169 return resolved;
170 }
171
172 /**
173 * Augments the set of resolved modules with modules induced by the
174 * service-use relation.
175 */
176 Resolver resolveUses() {
177
178 long start = trace_start("Bind");
179
180 // Scan the finders for all available service provider modules. As
215
216 // Where there is a consumer of a service then resolve all modules
217 // that provide an implementation of that service
218 do {
219 for (ModuleDescriptor descriptor : candidateConsumers) {
220 if (!descriptor.uses().isEmpty()) {
221 for (String service : descriptor.uses()) {
222 Set<ModuleReference> mrefs = availableProviders.get(service);
223 if (mrefs != null) {
224 for (ModuleReference mref : mrefs) {
225 ModuleDescriptor provider = mref.descriptor();
226 if (!provider.equals(descriptor)) {
227
228 trace("Module %s provides %s, used by %s",
229 provider.name(), service, descriptor.name());
230
231 String pn = provider.name();
232 if (!nameToReference.containsKey(pn)) {
233
234 if (TRACE && mref.location().isPresent())
235 trace(" (%s)", mref.location().getWhenPresent());
236
237 nameToReference.put(pn, mref);
238 q.push(provider);
239 }
240 }
241 }
242 }
243 }
244 }
245 }
246
247 candidateConsumers = resolve(q);
248
249 } while (!candidateConsumers.isEmpty());
250
251
252 if (TRACE) {
253 long duration = System.currentTimeMillis() - start;
254 Set<String> names = nameToReference.keySet();
255 trace("Bind completed in %s ms", duration);
417 .add(Objects.toString(osArch, "*"))
418 .add(Objects.toString(osVersion, "*"))
419 .toString();
420
421 }
422
423
424 /**
425 * Checks the hashes in the module descriptor to ensure that they match
426 * the hash of the dependency's module reference.
427 */
428 private void checkHashes() {
429
430 for (ModuleReference mref : nameToReference.values()) {
431 ModuleDescriptor descriptor = mref.descriptor();
432
433 // get map of module names to hash
434 Optional<Hasher.DependencyHashes> ohashes = descriptor.hashes();
435 if (!ohashes.isPresent())
436 continue;
437 Hasher.DependencyHashes hashes = ohashes.getWhenPresent();
438
439 // check dependences
440 for (ModuleDescriptor.Requires d : descriptor.requires()) {
441 String dn = d.name();
442 String recordedHash = hashes.hashFor(dn);
443
444 if (recordedHash != null) {
445
446 ModuleReference other = nameToReference.get(dn);
447 if (other == null) {
448 other = parent.findModule(dn)
449 .map(ResolvedModule::reference)
450 .orElse(null);
451 }
452 if (other == null)
453 throw new InternalError(dn + " not found");
454
455 String actualHash = other.computeHash(hashes.algorithm());
456 if (actualHash == null)
457 fail("Unable to compute the hash of module %s", dn);
|