Support -Xmodule-path and -Xadd-modules command line arguments
#KT-18598 In Progress #KT-18599 Fixed
This commit is contained in:
+13
-4
@@ -39,6 +39,8 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() {
|
||||
return File(testDataDirectory, "${getTestName(true)}.$extension")
|
||||
}
|
||||
|
||||
class JavaCompilationError : AssertionError("Java files are not compiled successfully")
|
||||
|
||||
/**
|
||||
* Compiles all sources (.java and .kt) under the directory named [libraryName] to [destination].
|
||||
* [destination] should be either a path to the directory under [tmpdir], or a path to the resulting .jar file (also under [tmpdir]).
|
||||
@@ -50,10 +52,15 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() {
|
||||
libraryName: String,
|
||||
destination: File = File(tmpdir, "$libraryName.jar"),
|
||||
additionalOptions: List<String> = emptyList(),
|
||||
compileJava: (sourceDir: File, javaFiles: List<File>, outputDir: File) -> Boolean = { _, javaFiles, outputDir ->
|
||||
KotlinTestUtils.compileJavaFiles(javaFiles, listOf("-d", outputDir.path))
|
||||
},
|
||||
checkKotlinOutput: (String) -> Unit = { actual -> assertEquals(normalizeOutput("" to ExitCode.OK), actual) },
|
||||
vararg extraClassPath: File
|
||||
): File {
|
||||
val javaFiles = FileUtil.findFilesByMask(JAVA_FILES, File(testDataDirectory, libraryName))
|
||||
val kotlinFiles = FileUtil.findFilesByMask(KOTLIN_FILES, File(testDataDirectory, libraryName))
|
||||
val sourceDir = File(testDataDirectory, libraryName)
|
||||
val javaFiles = FileUtil.findFilesByMask(JAVA_FILES, sourceDir)
|
||||
val kotlinFiles = FileUtil.findFilesByMask(KOTLIN_FILES, sourceDir)
|
||||
assert(javaFiles.isNotEmpty() || kotlinFiles.isNotEmpty()) { "There should be either .kt or .java files in the directory" }
|
||||
|
||||
val isJar = destination.name.endsWith(".jar")
|
||||
@@ -61,12 +68,14 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() {
|
||||
val outputDir = if (isJar) File(tmpdir, "output-$libraryName") else destination
|
||||
if (kotlinFiles.isNotEmpty()) {
|
||||
val output = compileKotlin(libraryName, outputDir, extraClassPath.toList(), K2JVMCompiler(), additionalOptions, expectedFileName = null)
|
||||
assertEquals(normalizeOutput("" to ExitCode.OK), normalizeOutput(output))
|
||||
checkKotlinOutput(normalizeOutput(output))
|
||||
}
|
||||
|
||||
if (javaFiles.isNotEmpty()) {
|
||||
outputDir.mkdirs()
|
||||
KotlinTestUtils.compileJavaFiles(javaFiles, listOf("-d", outputDir.path))
|
||||
if (!compileJava(sourceDir, javaFiles, outputDir)) {
|
||||
throw JavaCompilationError()
|
||||
}
|
||||
}
|
||||
|
||||
if (isJar) {
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.jvm.compiler
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import java.io.File
|
||||
|
||||
class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
||||
override val testDataPath: String
|
||||
get() = "compiler/testData/javaModules/"
|
||||
|
||||
private fun module(
|
||||
name: String,
|
||||
modulePath: List<File> = emptyList(),
|
||||
addModules: List<String> = emptyList()
|
||||
): File {
|
||||
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return File("<test-skipped>")
|
||||
|
||||
val paths = modulePath.joinToString(separator = File.pathSeparator) { it.path }
|
||||
|
||||
val kotlinOptions = mutableListOf(
|
||||
"-jdk-home", jdk9Home.path,
|
||||
"-Xmodule-path=$paths"
|
||||
)
|
||||
if (addModules.isNotEmpty()) {
|
||||
kotlinOptions += "-Xadd-modules=${addModules.joinToString()}"
|
||||
}
|
||||
|
||||
return compileLibrary(
|
||||
name,
|
||||
additionalOptions = kotlinOptions,
|
||||
compileJava = { _, javaFiles, outputDir ->
|
||||
val javaOptions = mutableListOf(
|
||||
"-d", outputDir.path,
|
||||
"--module-path", paths
|
||||
)
|
||||
if (addModules.isNotEmpty()) {
|
||||
javaOptions += "--add-modules"
|
||||
javaOptions += addModules.joinToString()
|
||||
}
|
||||
KotlinTestUtils.compileJavaFilesExternallyWithJava9(javaFiles, javaOptions)
|
||||
},
|
||||
checkKotlinOutput = { actual ->
|
||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "$name.txt"), actual)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun testSimple() {
|
||||
val a = module("moduleA")
|
||||
module("moduleB", listOf(a))
|
||||
}
|
||||
|
||||
fun testSimpleUseNonExportedPackage() {
|
||||
val a = module("moduleA")
|
||||
module("moduleB", listOf(a))
|
||||
}
|
||||
|
||||
fun testDependOnManyModules() {
|
||||
val a = module("moduleA")
|
||||
val b = module("moduleB")
|
||||
val c = module("moduleC")
|
||||
module("moduleD", listOf(a, b, c))
|
||||
}
|
||||
|
||||
fun testUnnamedDependsOnNamed() {
|
||||
val a = module("moduleA")
|
||||
module("moduleB", listOf(a), listOf("moduleA"))
|
||||
|
||||
// Also check that -Xadd-modules=ALL-MODULE-PATH has the same effect as -Xadd-module=moduleA, i.e. adds moduleA to the roots
|
||||
module("moduleB", listOf(a), listOf("ALL-MODULE-PATH"))
|
||||
}
|
||||
|
||||
fun testAllModulePathAndNamedModule() {
|
||||
try {
|
||||
module("main", addModules = listOf("ALL-MODULE-PATH"))
|
||||
}
|
||||
catch (e: JavaCompilationError) {
|
||||
// Java compilation should fail, it's expected
|
||||
}
|
||||
}
|
||||
|
||||
fun testJdkModulesFromNamed() {
|
||||
module("main")
|
||||
}
|
||||
|
||||
fun testJdkModulesFromUnnamed() {
|
||||
module("main")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user