Improve automatic module handling in module graph construction

Add all automatic modules to roots if at least one automatic module is
added, as per
http://cr.openjdk.java.net/~mr/jigsaw/spec/api/java/lang/module/package-summary.html
This commit is contained in:
Alexander Udalov
2017-06-30 18:03:17 +03:00
parent c428505d4d
commit 9199023952
11 changed files with 57 additions and 3 deletions
@@ -172,11 +172,21 @@ internal class ClasspathRootsResolver(
else -> computeDefaultRootModules() + additionalModules
}
// TODO: if at least one automatic module is added, add all automatic modules as per java.lang.module javadoc
val allDependencies = javaModuleGraph.getAllDependencies(rootModules).also { loadedModules ->
report(LOGGING, "Loading modules: $loadedModules")
val allDependencies = javaModuleGraph.getAllDependencies(rootModules).toMutableList()
if (allDependencies.any { moduleName -> javaModuleFinder.findModule(moduleName) is JavaModule.Automatic }) {
// According to java.lang.module javadoc, if at least one automatic module is added to the module graph,
// all observable automatic modules should be added.
// There are no automatic modules in the JDK, so we select all automatic modules out of user modules
for (module in modules) {
if (module is JavaModule.Automatic) {
allDependencies += module.name
}
}
}
report(LOGGING, "Loading modules: $allDependencies")
for (moduleName in allDependencies) {
val module = javaModuleFinder.findModule(moduleName)
if (module == null) {
@@ -0,0 +1,3 @@
package foo;
public class Foo {}
@@ -0,0 +1,3 @@
package bar;
public class Bar {}
@@ -0,0 +1 @@
OK
@@ -0,0 +1,3 @@
module main {
requires autoB;
}
@@ -0,0 +1,6 @@
import foo.Foo
import bar.Bar
fun usage(): String {
return "${Foo()}${Bar()}"
}
@@ -0,0 +1,3 @@
package foo;
public class Foo {}
@@ -0,0 +1,3 @@
package bar;
public class Bar {}
@@ -0,0 +1 @@
OK
@@ -0,0 +1,6 @@
import foo.Foo
import bar.Bar
fun usage(): String {
return "${Foo()}${Bar()}"
}
@@ -198,4 +198,19 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
module("main", listOf(m1, m2))
}
fun testUnnamedAgainstSeveralAutomatic() {
val a = module("autoA")
val b = module("autoB")
// Even though we only add autoA to the module graph, autoB should be added as well because autoA, being automatic,
// transitively requires every other automatic module, and in particular, autoB.
// Furthermore, because autoB is automatic, main should read autoB
module("main", listOf(a, b), addModules = listOf("autoA"))
}
fun testNamedAgainstSeveralAutomatic() {
val a = module("autoA")
val b = module("autoB")
module("main", listOf(a, b))
}
}