--- a/jdk/src/java.base/share/classes/java/lang/module/Resolver.java Thu Apr 06 17:01:03 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/module/Resolver.java Fri Apr 07 08:05:54 2017 +0000
@@ -28,7 +28,6 @@
import java.io.PrintStream;
import java.lang.module.ModuleDescriptor.Provides;
import java.lang.module.ModuleDescriptor.Requires.Modifier;
-import java.lang.reflect.Layer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
@@ -67,6 +66,9 @@
// maps module name to module reference
private final Map<String, ModuleReference> nameToReference = new HashMap<>();
+ // true if all automatic modules have been found
+ private boolean haveAllAutomaticModules;
+
// module constraints on target platform
private String osName;
private String osArch;
@@ -171,6 +173,21 @@
ModuleDescriptor descriptor = q.poll();
assert nameToReference.containsKey(descriptor.name());
+ // if the module is an automatic module then all automatic
+ // modules need to be resolved
+ if (descriptor.isAutomatic() && !haveAllAutomaticModules) {
+ addFoundAutomaticModules().forEach(mref -> {
+ ModuleDescriptor other = mref.descriptor();
+ q.offer(other);
+ if (isTracing()) {
+ trace("Automatic module %s located, required by %s",
+ other.name(), descriptor.name());
+ mref.location().ifPresent(uri -> trace(" (%s)", uri));
+ }
+ });
+ haveAllAutomaticModules = true;
+ }
+
// process dependences
for (ModuleDescriptor.Requires requires : descriptor.requires()) {
@@ -199,10 +216,15 @@
if (!nameToReference.containsKey(dn)) {
addFoundModule(mref);
q.offer(mref.descriptor());
- resolved.add(mref.descriptor());
if (isTracing()) {
- trace("Module %s located, required by %s",
+ String prefix;
+ if (mref.descriptor().isAutomatic()) {
+ prefix = "Automatic module";
+ } else {
+ prefix = "Module";
+ }
+ trace(prefix + " %s located, required by %s",
dn, descriptor.name());
mref.location().ifPresent(uri -> trace(" (%s)", uri));
}
@@ -250,7 +272,7 @@
// the initial set of modules that may use services
Set<ModuleDescriptor> initialConsumers;
- if (Layer.boot() == null) {
+ if (ModuleLayer.boot() == null) {
initialConsumers = new HashSet<>();
} else {
initialConsumers = parents.stream()
@@ -301,6 +323,21 @@
return this;
}
+ /**
+ * Add all automatic modules that have not already been found to the
+ * nameToReference map.
+ */
+ private Set<ModuleReference> addFoundAutomaticModules() {
+ Set<ModuleReference> result = new HashSet<>();
+ findAll().forEach(mref -> {
+ String mn = mref.descriptor().name();
+ if (mref.descriptor().isAutomatic() && !nameToReference.containsKey(mn)) {
+ addFoundModule(mref);
+ result.add(mref);
+ }
+ });
+ return result;
+ }
/**
* Add the module to the nameToReference map. Also check any constraints on
@@ -534,7 +571,7 @@
// need "requires transitive" from the modules in parent configurations
// as there may be selected modules that have a dependency on modules in
// the parent configuration.
- if (Layer.boot() == null) {
+ if (ModuleLayer.boot() == null) {
g2 = new HashMap<>(capacity);
} else {
g2 = parents.stream()