Add annotations-jar to compiler tests via KotlinStandardLibrariesPathProvider

to customize it outside kotlin repo
This commit is contained in:
Ilya Kirillov
2022-09-16 16:16:52 +02:00
parent 51cece4741
commit a74b5dbcad
2 changed files with 9 additions and 2 deletions
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.jvm.configureStandardLibs import org.jetbrains.kotlin.cli.jvm.configureStandardLibs
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.test.util.KtTestUtil
import java.io.File import java.io.File
import java.lang.ref.SoftReference import java.lang.ref.SoftReference
import java.net.URL import java.net.URL
@@ -66,6 +67,11 @@ abstract class KotlinStandardLibrariesPathProvider : TestService {
*/ */
abstract fun jvmAnnotationsForTests(): File abstract fun jvmAnnotationsForTests(): File
/**
* compiler/testData/mockJDK/jre/lib/annotations.jar
*/
abstract fun getAnnotationsJar(): File
fun getRuntimeJarClassLoader(): ClassLoader = synchronized(this) { fun getRuntimeJarClassLoader(): ClassLoader = synchronized(this) {
var loader = runtimeJarClassLoader.get() var loader = runtimeJarClassLoader.get()
if (loader == null) { if (loader == null) {
@@ -101,6 +107,7 @@ object StandardLibrariesPathProviderForKotlinProject : KotlinStandardLibrariesPa
override fun kotlinTestJarForTests(): File = ForTestCompileRuntime.kotlinTestJarForTests() override fun kotlinTestJarForTests(): File = ForTestCompileRuntime.kotlinTestJarForTests()
override fun scriptRuntimeJarForTests(): File = ForTestCompileRuntime.scriptRuntimeJarForTests() override fun scriptRuntimeJarForTests(): File = ForTestCompileRuntime.scriptRuntimeJarForTests()
override fun jvmAnnotationsForTests(): File = ForTestCompileRuntime.jvmAnnotationsForTests() override fun jvmAnnotationsForTests(): File = ForTestCompileRuntime.jvmAnnotationsForTests()
override fun getAnnotationsJar(): File = KtTestUtil.getAnnotationsJar()
} }
object EnvironmentBasedStandardLibrariesPathProvider : KotlinStandardLibrariesPathProvider() { object EnvironmentBasedStandardLibrariesPathProvider : KotlinStandardLibrariesPathProvider() {
@@ -125,6 +132,7 @@ object EnvironmentBasedStandardLibrariesPathProvider : KotlinStandardLibrariesPa
override fun kotlinTestJarForTests(): File = getFile(KOTLIN_TEST_PROP) override fun kotlinTestJarForTests(): File = getFile(KOTLIN_TEST_PROP)
override fun scriptRuntimeJarForTests(): File = getFile(KOTLIN_SCRIPT_RUNTIME_PROP) override fun scriptRuntimeJarForTests(): File = getFile(KOTLIN_SCRIPT_RUNTIME_PROP)
override fun jvmAnnotationsForTests(): File = getFile(KOTLIN_ANNOTATIONS_JVM_PROP) override fun jvmAnnotationsForTests(): File = getFile(KOTLIN_ANNOTATIONS_JVM_PROP)
override fun getAnnotationsJar(): File = getFile(KOTLIN_ANNOTATIONS_JVM_PROP)
} }
val TestServices.standardLibrariesPathProvider: KotlinStandardLibrariesPathProvider by TestServices.testServiceAccessor() val TestServices.standardLibrariesPathProvider: KotlinStandardLibrariesPathProvider by TestServices.testServiceAccessor()
@@ -122,12 +122,11 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
if (configurationKind.withReflection) { if (configurationKind.withReflection) {
files.add(provider.reflectJarForTests()) files.add(provider.reflectJarForTests())
} }
files.add(KtTestUtil.getAnnotationsJar()) files.add(provider.getAnnotationsJar())
if (JvmEnvironmentConfigurationDirectives.STDLIB_JDK8 in directives) { if (JvmEnvironmentConfigurationDirectives.STDLIB_JDK8 in directives) {
files.add(provider.runtimeJarForTestsWithJdk8()) files.add(provider.runtimeJarForTestsWithJdk8())
} }
files.add(KtTestUtil.getAnnotationsJar())
return files return files
} }