Remove usages of com.intellij.* utils from kotlin-build-common, KT-31106

As Gradle may under certain conditions reorder the buildscript
classpath artifacts, we need to ensure that the `kotlin-build-common`
module, which duplicates some of the classes that are shaded and packed
into `kotlin-compiler-embeddable`, does not call `com.intellij.*`
classes.

Replace the `com.intellij.*` utils that were called on the execution
path with our own implementations.

Issue #KT-31106 Fixed
This commit is contained in:
Sergey Igushkin
2019-04-22 15:10:55 +03:00
parent 09d7f4015b
commit d456ae58b6
5 changed files with 68 additions and 11 deletions
@@ -963,4 +963,36 @@ class KotlinGradleIT : BaseGradleIT() {
assertContains("Required com.example.compilation 'bar'")
}
}
@Test
fun testLoadCompilerEmbeddableAfterOtherKotlinArtifacts() = with(Project("simpleProject")) {
setupWorkingDir()
val buildscriptClasspathPrefix = "buildscript-classpath = "
gradleBuildScript().appendText(
"\n" + """
println "$buildscriptClasspathPrefix" + Arrays.toString(buildscript.classLoader.getURLs())
""".trimIndent()
)
// get the classpath, then reorder it so that kotlin-compiler-embeddable is loaded after all other JARs
lateinit var classpath: List<String>
build {
val classpathLine = output.lines().single { buildscriptClasspathPrefix in it }
classpath = classpathLine.substringAfter(buildscriptClasspathPrefix).removeSurrounding("[", "]").split(", ")
}
gradleBuildScript().modify {
val reorderedClasspath = run {
val (kotlinCompilerEmbeddable, others) = classpath.partition { "kotlin-compiler-embeddable" in it }
others + kotlinCompilerEmbeddable
}
val newClasspathString = "classpath files(\n" + reorderedClasspath.joinToString(",\n") { "'$it'" } + "\n)"
it.checkedReplace("classpath \"org.jetbrains.kotlin:kotlin-gradle-plugin:${'$'}kotlin_version\"", newClasspathString)
}
build("compileKotlin") {
assertSuccessful()
}
}
}