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") + } } }