Add CLI test for K/javac project with K/J interdependency
Yet this test fails if JavacWrapper does not add Kotlin output dir to classpath
This commit is contained in:
@@ -170,10 +170,10 @@ class JavacWrapper(
|
|||||||
setClassPathForCompilation(outDir)
|
setClassPathForCompilation(outDir)
|
||||||
makeOutputDirectoryClassesVisible()
|
makeOutputDirectoryClassesVisible()
|
||||||
|
|
||||||
context.get(Log.outKey)?.println(
|
val outputPath =
|
||||||
"Compiling $javaFilesNumber Java source files" +
|
// Includes a hack with 'takeIf' for CLI test, to have stable string here (independent from random test directory)
|
||||||
" to [${fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path}]"
|
fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path?.takeIf { "compilerProject_test" !in it } ?: "test directory"
|
||||||
)
|
context.get(Log.outKey)?.print("Compiling $javaFilesNumber Java source files to [$outputPath]")
|
||||||
compile(fileObjects)
|
compile(fileObjects)
|
||||||
errorCount() == 0
|
errorCount() == 0
|
||||||
}
|
}
|
||||||
@@ -340,7 +340,7 @@ class JavacWrapper(
|
|||||||
private fun makeOutputDirectoryClassesVisible() {
|
private fun makeOutputDirectoryClassesVisible() {
|
||||||
// TODO: below we have a hacky part with a purpose
|
// TODO: below we have a hacky part with a purpose
|
||||||
// to make already analyzed classes visible by Javac without reading them again.
|
// to make already analyzed classes visible by Javac without reading them again.
|
||||||
// However, it does not work as it should (but some tests depend on this code fragment)
|
// This works (and necessary!) when javac has "-proc:none" argument, so works without APT
|
||||||
val reader = ClassReader.instance(context)
|
val reader = ClassReader.instance(context)
|
||||||
val names = Names.instance(context)
|
val names = Names.instance(context)
|
||||||
val outDirName = fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path ?: ""
|
val outDirName = fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path ?: ""
|
||||||
@@ -368,6 +368,9 @@ class JavacWrapper(
|
|||||||
private fun setClassPathForCompilation(outDir: File?) = apply {
|
private fun setClassPathForCompilation(outDir: File?) = apply {
|
||||||
(outDir ?: outputDirectory)?.let { outputDir ->
|
(outDir ?: outputDirectory)?.let { outputDir ->
|
||||||
if (outputDir.exists()) {
|
if (outputDir.exists()) {
|
||||||
|
// This line is necessary for e.g. CliTestGenerated.jvm.javacKotlinJavaInterdependency to work
|
||||||
|
// In general, it makes compiled Kotlin classes from the module visible for javac
|
||||||
|
// It's necessary when javac work with APT (without -proc:none flag)
|
||||||
fileManager.setLocation(CLASS_PATH, fileManager.getLocation(CLASS_PATH) + outputDir)
|
fileManager.setLocation(CLASS_PATH, fileManager.getLocation(CLASS_PATH) + outputDir)
|
||||||
}
|
}
|
||||||
outputDir.mkdirs()
|
outputDir.mkdirs()
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
$TESTDATA_DIR$/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.kt
|
||||||
|
$TESTDATA_DIR$/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.java
|
||||||
|
-Xuse-javac
|
||||||
|
-Xcompile-java
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
info: compiling 1 Java source files to [test directory]
|
||||||
|
OK
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public class ClassWithTypeParameter<T extends KotlinInterface> {
|
||||||
|
|
||||||
|
public ClassWithTypeParameter(T kotlinInterface) {}
|
||||||
|
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
interface KotlinInterface
|
||||||
|
|
||||||
|
class Impl1 : KotlinInterface
|
||||||
|
|
||||||
|
class Impl2 : KotlinInterface
|
||||||
|
|
||||||
|
class Impl3 : KotlinInterface
|
||||||
|
|
||||||
|
fun getProducer1() = Impl1().let(::ClassWithTypeParameter)
|
||||||
|
|
||||||
|
fun getProducer2() = Impl2().let(::ClassWithTypeParameter)
|
||||||
|
|
||||||
|
fun getProducer3() = Impl3().let(::ClassWithTypeParameter)
|
||||||
@@ -346,6 +346,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
runTest("compiler/testData/cli/jvm/javaSrcWrongPackage.args");
|
runTest("compiler/testData/cli/jvm/javaSrcWrongPackage.args");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("javacKotlinJavaInterdependency.args")
|
||||||
|
public void testJavacKotlinJavaInterdependency() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/javacKotlinJavaInterdependency.args");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("jdkPathDoesNotExist.args")
|
@TestMetadata("jdkPathDoesNotExist.args")
|
||||||
public void testJdkPathDoesNotExist() throws Exception {
|
public void testJdkPathDoesNotExist() throws Exception {
|
||||||
runTest("compiler/testData/cli/jvm/jdkPathDoesNotExist.args");
|
runTest("compiler/testData/cli/jvm/jdkPathDoesNotExist.args");
|
||||||
|
|||||||
Reference in New Issue
Block a user