From f5637e5077326759c56aed17800501d7bd99dac1 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 6 Jun 2022 12:30:01 +0300 Subject: [PATCH] [FIR] Look for jar with plugin annotations in system property and by direct path in tests This is needed to make those tests work in JPS, because corresponding system property is set only by gradle --- .../services/PluginAnnotationsProvider.kt | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/plugins/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/services/PluginAnnotationsProvider.kt b/plugins/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/services/PluginAnnotationsProvider.kt index 85f0d472be2..0b480775073 100644 --- a/plugins/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/services/PluginAnnotationsProvider.kt +++ b/plugins/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/services/PluginAnnotationsProvider.kt @@ -15,20 +15,30 @@ import java.io.File import java.io.FilenameFilter class PluginAnnotationsProvider(testServices: TestServices) : EnvironmentConfigurator(testServices) { - - private val firPluginAnnotationsJar: File by lazy { - val firPluginAnnotationsPath = System.getProperty("firPluginAnnotations.path") ?: error("firPluginAnnotations.path system property is not set") - val firPluginAnnotationsFile = File(firPluginAnnotationsPath) - if (!firPluginAnnotationsFile.isFile && - firPluginAnnotationsFile.name.startsWith("plugin-annotations") && - firPluginAnnotationsFile.name.endsWith(".jar") - ) { - error("Can't find fir plugin annotations jar file in firPluginAnnotations.path system property") - } - firPluginAnnotationsFile + companion object { + private const val ANNOTATIONS_JAR_DIR = "plugins/fir-plugin-prototype/plugin-annotations/build/libs/" + private val ANNOTATIONS_JAR_FILTER = FilenameFilter { _, name -> name.startsWith("plugin-annotations") && name.endsWith(".jar") } } override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) { - configuration.addJvmClasspathRoot(firPluginAnnotationsJar) + val pluginAnnotationsJar = findJarFromProperty() + ?: findJarByPath() + ?: error("Jar with annotations does not exist. Please run :plugins:fir-plugin-prototype:plugin-annotations:jar or specify firPluginAnnotations.path system property") + configuration.addJvmClasspathRoot(pluginAnnotationsJar) + } + + private fun findJarByPath(): File? { + val libDir = File(ANNOTATIONS_JAR_DIR) + if (!libDir.exists() || !libDir.isDirectory) return null + return libDir.listFiles(ANNOTATIONS_JAR_FILTER)?.firstOrNull() + } + + private fun findJarFromProperty(): File? { + val firPluginAnnotationsPath = System.getProperty("firPluginAnnotations.path") ?: return null + return File(firPluginAnnotationsPath).takeIf { + it.isFile && + it.name.startsWith("plugin-annotations") && + it.name.endsWith(".jar") + } } }