Skip to content

Commit

Permalink
Build: fix finding layout-api jar in parcelize box test due to platfo…
Browse files Browse the repository at this point in the history
…rm change
  • Loading branch information
demiurg906 committed Nov 28, 2020
1 parent cc1a0bf commit e251a9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ abstract class AbstractParcelBoxTest : CodegenTestCase() {
companion object {
val LIBRARY_KT = File("plugins/android-extensions/android-extensions-compiler/testData/parcel/boxLib.kt")

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

val layoutlibJar: File by lazy {
File(androidPluginPath).listFiles { _, name ->
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 layoutlibApiJar: File by lazy {
File(androidPluginPath).listFiles { _, name ->
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'")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ abstract class AbstractParcelizeIrBoxTest : AbstractParcelizeBoxTest() {
abstract class AbstractParcelizeBoxTest : CodegenTestCase() {
companion object {
val LIBRARY_KT = File("plugins/parcelize/parcelize-compiler/testData/boxLib.kt")
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 = "^$pattern-[0-9\\.]+\\.jar$".toRegex()
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: \n${File(androidPluginPath).list().orEmpty().asList()}")
Expand Down

0 comments on commit e251a9b

Please sign in to comment.