Load module-info.class from multi-release jars' META-INF/versions/
This commit is contained in:
@@ -109,7 +109,10 @@ internal class ClasspathRootsResolver(
|
||||
}
|
||||
|
||||
private fun modularBinaryRoot(root: VirtualFile, automaticModuleName: () -> String): JavaModule? {
|
||||
val moduleInfoFile = root.findChild(PsiJavaModule.MODULE_INFO_CLS_FILE)
|
||||
val moduleInfoFile =
|
||||
root.findChild(PsiJavaModule.MODULE_INFO_CLS_FILE)
|
||||
?: root.takeIf { it.fileSystem.protocol == StandardFileSystems.JAR_PROTOCOL }
|
||||
?.findFileByRelativePath(MULTI_RELEASE_MODULE_INFO_CLS_FILE)
|
||||
return if (moduleInfoFile != null) {
|
||||
val moduleInfo = JavaModuleInfo.read(moduleInfoFile) ?: return null
|
||||
JavaModule.Explicit(moduleInfo, root, moduleInfoFile, isBinary = true)
|
||||
@@ -209,4 +212,8 @@ internal class ClasspathRootsResolver(
|
||||
if (file == null) null else CompilerMessageLocation.create(MessageUtil.virtualFileToPath(file))
|
||||
)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val MULTI_RELEASE_MODULE_INFO_CLS_FILE = "META-INF/versions/9/${PsiJavaModule.MODULE_INFO_CLS_FILE}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package foo;
|
||||
|
||||
public class Foo {}
|
||||
@@ -0,0 +1,3 @@
|
||||
module library {
|
||||
exports foo;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,3 @@
|
||||
module main {
|
||||
requires library;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import foo.Foo
|
||||
|
||||
fun usage(): String {
|
||||
val f: Foo = Foo()
|
||||
return f.toString()
|
||||
}
|
||||
+3
-1
@@ -150,6 +150,8 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() {
|
||||
|
||||
companion object {
|
||||
private val KOTLIN_FILES = Pattern.compile(".*\\.kt$")
|
||||
private val JAVA_FILES = Pattern.compile(".*\\.java$")
|
||||
|
||||
@JvmStatic
|
||||
protected val JAVA_FILES = Pattern.compile(".*\\.java$")!!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.jvm.compiler
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import java.io.File
|
||||
|
||||
@@ -62,6 +63,22 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "$moduleName.txt"), actual)
|
||||
}
|
||||
|
||||
private fun createMultiReleaseJar(jdk9Home: File, destination: File, mainRoot: File, java9Root: File): File {
|
||||
val command = listOf<String>(
|
||||
File(jdk9Home, "bin/jar").path,
|
||||
"--create", "--file=$destination",
|
||||
"-C", mainRoot.path, ".",
|
||||
"--release", "9",
|
||||
"-C", java9Root.path, "."
|
||||
)
|
||||
|
||||
val process = ProcessBuilder().command(command).inheritIO().start()
|
||||
process.waitFor()
|
||||
assertEquals("'jar' did not finish successfully", 0, process.exitValue())
|
||||
|
||||
return destination
|
||||
}
|
||||
|
||||
fun testSimple() {
|
||||
val a = module("moduleA")
|
||||
module("moduleB", listOf(a))
|
||||
@@ -149,4 +166,20 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
||||
checkKotlinOutput = checkKotlinOutput("moduleB")
|
||||
)
|
||||
}
|
||||
|
||||
fun testMultiReleaseLibrary() {
|
||||
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return
|
||||
|
||||
val librarySrc = FileUtil.findFilesByMask(JAVA_FILES, File(testDataDirectory, "library"))
|
||||
val libraryOut = File(tmpdir, "out")
|
||||
KotlinTestUtils.compileJavaFilesExternallyWithJava9(librarySrc, listOf("-d", libraryOut.path))
|
||||
|
||||
val libraryOut9 = File(tmpdir, "out9")
|
||||
libraryOut9.mkdirs()
|
||||
File(libraryOut, "module-info.class").renameTo(File(libraryOut9, "module-info.class"))
|
||||
|
||||
val libraryJar = createMultiReleaseJar(jdk9Home, File(tmpdir, "library.jar"), libraryOut, libraryOut9)
|
||||
|
||||
module("main", listOf(libraryJar))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user