diff --git a/plugins/android-extensions/android-extensions-compiler/test/org/jetbrains/kotlin/android/parcel/AbstractParcelBoxTest.kt b/plugins/android-extensions/android-extensions-compiler/test/org/jetbrains/kotlin/android/parcel/AbstractParcelBoxTest.kt index 779bef94a97..f30042bc7d2 100644 --- a/plugins/android-extensions/android-extensions-compiler/test/org/jetbrains/kotlin/android/parcel/AbstractParcelBoxTest.kt +++ b/plugins/android-extensions/android-extensions-compiler/test/org/jetbrains/kotlin/android/parcel/AbstractParcelBoxTest.kt @@ -30,25 +30,17 @@ abstract class AbstractParcelBoxTest : CodegenTestCase() { private fun String.withoutAndroidPrefix(): String = removePrefix("studio.android.sdktools.") - private val androidPluginPath: String by lazy { - System.getProperty("ideaSdk.androidPlugin.path")?.takeIf { File(it).isDirectory } - ?: throw RuntimeException("Unable to get a valid path from 'ideaSdk.androidPlugin.path' property, please point it to the Idea android plugin location") + private fun getLayoutLibFile(property: String): File { + val layoutLibFile = File(System.getProperty(property)) + if (!layoutLibFile.isFile) { + error("Can't find jar file in $property system property") + } + return layoutLibFile } - val layoutlibJar: File by lazy { - File(androidPluginPath).listFiles { _, rawName -> - val name = rawName.withoutAndroidPrefix() - name.startsWith("layoutlib-") && name.endsWith(".jar") - && !name.startsWith("layoutlib-api-") && !name.startsWith("layoutlib-loader") - }?.firstOrNull() ?: error("Unable to locate layoutlib jar in '$androidPluginPath'") - } + val layoutlibJar: File by lazy { getLayoutLibFile("layoutLib.path") } - val layoutlibApiJar: File by lazy { - File(androidPluginPath).listFiles { _, rawName -> - val name = rawName.withoutAndroidPrefix() - name.startsWith("layoutlib-api-") && name.endsWith(".jar") - }?.firstOrNull() ?: error("Unable to locate layoutlib-api jar in '$androidPluginPath'") - } + val layoutlibApiJar: File by lazy { getLayoutLibFile("layoutLibApi.path") } private val JUNIT_GENERATED_TEST_CLASS_BYTES by lazy { constructSyntheticTestClass() } private const val JUNIT_GENERATED_TEST_CLASS_FQNAME = "test.JunitTest" @@ -113,11 +105,6 @@ abstract class AbstractParcelBoxTest : CodegenTestCase() { } } - private val androidPluginPath: String by lazy { - System.getProperty("ideaSdk.androidPlugin.path")?.takeIf { File(it).isDirectory } - ?: throw RuntimeException("Unable to get a valid path from 'ideaSdk.androidPlugin.path' property, please point it to the Idea android plugin location") - } - private fun getClasspathForTest(): List { val kotlinRuntimeJar = PathUtil.kotlinPathsForIdeaPlugin.stdlibPath diff --git a/plugins/parcelize/parcelize-compiler/build.gradle.kts b/plugins/parcelize/parcelize-compiler/build.gradle.kts index 94926c1d9c3..42364e96e57 100644 --- a/plugins/parcelize/parcelize-compiler/build.gradle.kts +++ b/plugins/parcelize/parcelize-compiler/build.gradle.kts @@ -9,6 +9,8 @@ plugins { val robolectricClasspath by configurations.creating val parcelizeRuntimeForTests by configurations.creating +val layoutLib by configurations.creating +val layoutLibApi by configurations.creating dependencies { testApi(intellijCoreDep()) { includeJars("intellij-core") } @@ -71,6 +73,9 @@ dependencies { parcelizeRuntimeForTests(project(":plugins:parcelize:parcelize-runtime")) { isTransitive = false } parcelizeRuntimeForTests(project(":kotlin-android-extensions-runtime")) { isTransitive = false } + + layoutLib("org.jetbrains.intellij.deps.android.tools:layoutlib:26.5.0") { isTransitive = false } + layoutLibApi("com.android.tools.layoutlib:layoutlib-api:26.5.0") { isTransitive = false } } val generationRoot = projectDir.resolve("tests-gen") @@ -111,6 +116,8 @@ projectTest(jUnitMode = JUnitMode.JUnit5) { doFirst { systemProperty("parcelizeRuntime.classpath", parcelizeRuntimeForTestsProvider.get()) systemProperty("robolectric.classpath", robolectricClasspathProvider.get()) + systemProperty("layoutLib.path", layoutLib.singleFile.canonicalPath) + systemProperty("layoutLibApi.path", layoutLibApi.singleFile.canonicalPath) } doLast { println(filter) diff --git a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/services/ParcelizeRuntimeClasspathProvider.kt b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/services/ParcelizeRuntimeClasspathProvider.kt index 97498b39bee..4c36459a251 100644 --- a/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/services/ParcelizeRuntimeClasspathProvider.kt +++ b/plugins/parcelize/parcelize-compiler/tests/org/jetbrains/kotlin/parcelize/test/services/ParcelizeRuntimeClasspathProvider.kt @@ -21,25 +21,17 @@ import java.io.File class ParcelizeRuntimeClasspathProvider(testServices: TestServices) : RuntimeClasspathProvider(testServices) { companion object { - val layoutlibJar: File by lazy { getLayoutLibFile("layoutlib(-jre[0-9]+)?") } - val layoutlibApiJar: File by lazy { getLayoutLibFile("layoutlib-api") } + val layoutlibJar: File by lazy { getLayoutLibFile("layoutLib.path") } + val layoutlibApiJar: File by lazy { getLayoutLibFile("layoutLibApi.path") } private const val ANDROID_TOOLS_PREFIX = "studio.android.sdktools." - private val androidPluginPath: String by lazy { - System.getProperty("ideaSdk.androidPlugin.path")?.takeIf { File(it).isDirectory } - ?: throw RuntimeException("Unable to get a valid path from 'ideaSdk.androidPlugin.path' property, please point it to the Idea android plugin location") - } - - private fun getLayoutLibFile(pattern: String): File { - val nameRegex = """^(${ANDROID_TOOLS_PREFIX})?$pattern-[0-9.]+\.jar$""".toRegex() - return File(androidPluginPath).listFiles().orEmpty().singleOrNull { it.name.matches(nameRegex) } - ?: error( - """ - Can't find file for pattern $nameRegex in ${androidPluginPath}. - Available files: ${File(androidPluginPath).list().orEmpty().asList()} - """.trimIndent() - ) + private fun getLayoutLibFile(property: String): File { + val layoutLibFile = File(System.getProperty(property)) + if (!layoutLibFile.isFile) { + error("Can't find jar file in $property system property") + } + return layoutLibFile } private val JUNIT_GENERATED_TEST_CLASS_BYTES by lazy { constructSyntheticTestClass() }