Pill: Support Android tests
This commit is contained in:
@@ -77,6 +77,8 @@ class JpsCompatiblePlugin : Plugin<Project> {
|
||||
if (project == project.rootProject) {
|
||||
project.tasks.create("pill") {
|
||||
doLast { pill(project) }
|
||||
TaskUtils.useAndroidSdk(this)
|
||||
TaskUtils.useAndroidJar(this)
|
||||
}
|
||||
|
||||
project.tasks.create("unpill") {
|
||||
@@ -195,17 +197,31 @@ class JpsCompatiblePlugin : Plugin<Project> {
|
||||
junitConfiguration.apply {
|
||||
getOrCreateChild("option", "name" to "WORKING_DIRECTORY").setAttribute("value", "file://\$PROJECT_DIR\$")
|
||||
getOrCreateChild("option", "name" to "VM_PARAMETERS").also { vmParams ->
|
||||
val ideaHomePathOptionKey = "-Didea.home.path="
|
||||
val ideaHomePathOption = ideaHomePathOptionKey + platformDirProjectRelative
|
||||
|
||||
val existingOptions = vmParams.getAttributeValue("value", "")
|
||||
var options = vmParams.getAttributeValue("value", "")
|
||||
.split(' ')
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotEmpty() && !it.startsWith(ideaHomePathOptionKey) }
|
||||
.filter { it.isNotEmpty() }
|
||||
|
||||
val newOptions = existingOptions.joinToString(" ") + " " + ideaHomePathOption
|
||||
fun addOrReplaceOptionValue(name: String, value: Any) {
|
||||
options = options.filter { !it.startsWith("-D$name=") } + listOf("-D$name=$value")
|
||||
}
|
||||
|
||||
vmParams.setAttribute("value", newOptions)
|
||||
val robolectricClasspath = project.rootProject
|
||||
.project(":plugins:android-extensions-compiler")
|
||||
.configurations.getByName("robolectricClasspath")
|
||||
.files.joinToString(File.pathSeparator)
|
||||
|
||||
val androidJarPath = project.configurations.getByName("androidJar").singleFile
|
||||
val androidSdkPath = project.configurations.getByName("androidSdk").singleFile
|
||||
|
||||
addOrReplaceOptionValue("idea.home.path", platformDirProjectRelative)
|
||||
addOrReplaceOptionValue("ideaSdk.androidPlugin.path", platformDirProjectRelative + "/plugins/android/lib")
|
||||
addOrReplaceOptionValue("robolectric.classpath", robolectricClasspath)
|
||||
|
||||
addOrReplaceOptionValue("android.sdk", "\$PROJECT_DIR\$/" + androidSdkPath.toRelativeString(projectDir))
|
||||
addOrReplaceOptionValue("android.jar", "\$PROJECT_DIR\$/" + androidJarPath.toRelativeString(projectDir))
|
||||
|
||||
vmParams.setAttribute("value", options.joinToString(" "))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,17 @@ private inline fun String.isFirstChar(f: (Char) -> Boolean) = isNotEmpty() && f(
|
||||
inline fun <reified T : Task> Project.getOrCreateTask(taskName: String, body: T.() -> Unit): T =
|
||||
(tasks.findByName(taskName)?.let { it as T } ?: task<T>(taskName)).apply { body() }
|
||||
|
||||
private fun Test.useAndroidConfiguration(systemPropertyName: String, configName: String) {
|
||||
object TaskUtils {
|
||||
fun useAndroidSdk(task: Task) {
|
||||
task.useAndroidConfiguration(systemPropertyName = "android.sdk", configName = "androidSdk")
|
||||
}
|
||||
|
||||
fun useAndroidJar(task: Task) {
|
||||
task.useAndroidConfiguration(systemPropertyName = "android.jar", configName = "androidJar")
|
||||
}
|
||||
}
|
||||
|
||||
private fun Task.useAndroidConfiguration(systemPropertyName: String, configName: String) {
|
||||
val configuration = with(project) {
|
||||
configurations.getOrCreate(configName)
|
||||
.also {
|
||||
@@ -96,15 +106,18 @@ private fun Test.useAndroidConfiguration(systemPropertyName: String, configName:
|
||||
}
|
||||
|
||||
dependsOn(configuration)
|
||||
doFirst {
|
||||
systemProperty(systemPropertyName, configuration.singleFile.canonicalPath)
|
||||
|
||||
if (this is Test) {
|
||||
doFirst {
|
||||
systemProperty(systemPropertyName, configuration.singleFile.canonicalPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Test.useAndroidSdk() {
|
||||
useAndroidConfiguration(systemPropertyName = "android.sdk", configName = "androidSdk")
|
||||
fun Task.useAndroidSdk() {
|
||||
TaskUtils.useAndroidSdk(this)
|
||||
}
|
||||
|
||||
fun Test.useAndroidJar() {
|
||||
useAndroidConfiguration(systemPropertyName = "android.jar", configName = "androidJar")
|
||||
fun Task.useAndroidJar() {
|
||||
TaskUtils.useAndroidJar(this)
|
||||
}
|
||||
Reference in New Issue
Block a user