Use test classpath for annotations.jar search
Got unstable behaviour in 202 test because of setting idea.home.path during the compiler execution.
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.psi
|
package org.jetbrains.kotlin.psi
|
||||||
|
|
||||||
import com.intellij.lang.html.HTMLLanguage
|
import com.intellij.lang.html.HTMLLanguage
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.testFramework.LightProjectDescriptor
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import org.intellij.lang.regexp.RegExpLanguage
|
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.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.net.URLClassLoader
|
||||||
|
|
||||||
@RunWith(JUnit3WithIdeaConfigurationRunner::class)
|
@RunWith(JUnit3WithIdeaConfigurationRunner::class)
|
||||||
class KotlinLibInjectionTest : AbstractInjectionTest() {
|
class KotlinLibInjectionTest : AbstractInjectionTest() {
|
||||||
override fun setUp() {
|
|
||||||
super.setUp()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFunInjection() = assertInjectionPresent(
|
fun testFunInjection() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
import injection.html
|
import injection.html
|
||||||
@@ -45,13 +43,25 @@ class KotlinLibInjectionTest : AbstractInjectionTest() {
|
|||||||
doInjectionPresentTest(text, languageId = languageId, unInjectShouldBePresent = false)
|
doInjectionPresentTest(text, languageId = languageId, unInjectShouldBePresent = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun getProjectDescriptor(): LightProjectDescriptor {
|
override fun getProjectDescriptor(): LightProjectDescriptor {
|
||||||
val ideaSdkPath = System.getProperty("idea.home.path")?.takeIf { File(it).isDirectory }
|
val urls = (ApplicationManager::class.java.classLoader as? URLClassLoader)?.urLs
|
||||||
?: throw RuntimeException("Unable to get a valid path from 'idea.home.path' property, please point it to the Idea location")
|
?: 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(
|
return SdkAndMockLibraryProjectDescriptor(
|
||||||
PluginTestCaseBase.getTestDataPathBase() + "/injection/lib/", false, false, false, true,
|
PluginTestCaseBase.getTestDataPathBase() + "/injection/lib/", false, false, false, true,
|
||||||
listOf(File(ideaSdkPath, "lib/annotations.jar").absolutePath)
|
listOf(libFile.absolutePath)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user