From 0db7806dec66b5f107e0d5b50cebf4cf6ffa6804 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sat, 11 Jul 2020 13:16:49 +0300 Subject: [PATCH] Use test classpath for annotations.jar search Got unstable behaviour in 202 test because of setting idea.home.path during the compiler execution. --- .../kotlin/psi/KotlinLibInjectionTest.kt | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/psi/KotlinLibInjectionTest.kt b/idea/tests/org/jetbrains/kotlin/psi/KotlinLibInjectionTest.kt index 5c4a28194fb..5d8ed49e320 100644 --- a/idea/tests/org/jetbrains/kotlin/psi/KotlinLibInjectionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/psi/KotlinLibInjectionTest.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.psi import com.intellij.lang.html.HTMLLanguage +import com.intellij.openapi.application.ApplicationManager import com.intellij.testFramework.LightProjectDescriptor import org.intellij.lang.annotations.Language import org.intellij.lang.regexp.RegExpLanguage @@ -14,13 +15,10 @@ import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner import org.junit.runner.RunWith import java.io.File +import java.net.URLClassLoader @RunWith(JUnit3WithIdeaConfigurationRunner::class) class KotlinLibInjectionTest : AbstractInjectionTest() { - override fun setUp() { - super.setUp() - } - fun testFunInjection() = assertInjectionPresent( """ import injection.html @@ -45,13 +43,25 @@ class KotlinLibInjectionTest : AbstractInjectionTest() { doInjectionPresentTest(text, languageId = languageId, unInjectShouldBePresent = false) } - override fun getProjectDescriptor(): LightProjectDescriptor { - val ideaSdkPath = System.getProperty("idea.home.path")?.takeIf { File(it).isDirectory } - ?: throw RuntimeException("Unable to get a valid path from 'idea.home.path' property, please point it to the Idea location") + val urls = (ApplicationManager::class.java.classLoader as? URLClassLoader)?.urLs + ?: error("Can't find path urls in classloader") + + val libName = "annotations.jar" + val libCandidates = urls + .map { it.path.replace("\\", "/") } + .filter { it.endsWith("/$libName") } + + val libPath = libCandidates.singleOrNull() + ?: error("Can't find single $libName in classpath among $libCandidates") + + val libFile = File(libPath).also { file -> + require(file.exists()) { "Can't find library: ${file.absolutePath}" } + } + return SdkAndMockLibraryProjectDescriptor( PluginTestCaseBase.getTestDataPathBase() + "/injection/lib/", false, false, false, true, - listOf(File(ideaSdkPath, "lib/annotations.jar").absolutePath) + listOf(libFile.absolutePath) ) } }