Fix parcelize test dependencies on android plugin layoutlib
#KTI-82
This commit is contained in:
committed by
teamcity
parent
049066f8ac
commit
318e001d1b
+8
-21
@@ -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<File> {
|
||||
val kotlinRuntimeJar = PathUtil.kotlinPathsForIdeaPlugin.stdlibPath
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
+8
-16
@@ -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() }
|
||||
|
||||
Reference in New Issue
Block a user