Test: download android sdk using sdk-manager-plugin

This commit is contained in:
Alexey Tsvetkov
2016-03-24 15:57:45 +03:00
parent c686c7fb91
commit 157c5009f0
7 changed files with 40 additions and 52 deletions
@@ -74,8 +74,8 @@ abstract class BaseGradleIT {
/** /**
* @see [ThreadTracker] * @see [ThreadTracker]
*/ */
val assertThreadLeaks: Boolean = true val assertThreadLeaks: Boolean = true,
) val androidHome: File? = null)
open inner class Project(val projectName: String, val wrapperVersion: String = "1.4", val minLogLevel: LogLevel = LogLevel.DEBUG) { open inner class Project(val projectName: String, val wrapperVersion: String = "1.4", val minLogLevel: LogLevel = LogLevel.DEBUG) {
open val resourcesRoot = File(resourcesRootFile, "testProject/$projectName") open val resourcesRoot = File(resourcesRootFile, "testProject/$projectName")
@@ -97,8 +97,9 @@ abstract class BaseGradleIT {
val compiledJavaSources: Iterable<File> by lazy { javaSourcesListRegex.findAll(output).asIterable().flatMap { it.groups[1]!!.value.split(" ").filter { it.endsWith(".java", ignoreCase = true) }.map { File(it).canonicalFile } } } val compiledJavaSources: Iterable<File> by lazy { javaSourcesListRegex.findAll(output).asIterable().flatMap { it.groups[1]!!.value.split(" ").filter { it.endsWith(".java", ignoreCase = true) }.map { File(it).canonicalFile } } }
} }
fun Project.build(vararg tasks: String, options: BuildOptions = defaultBuildOptions(), check: CompiledProject.() -> Unit) { fun Project.build(vararg params: String, options: BuildOptions = defaultBuildOptions(), check: CompiledProject.() -> Unit) {
val cmd = createBuildCommand(tasks, options) val cmd = createBuildCommand(params, options)
val env = createEnvironmentVariablesMap(options)
if (options.withDaemon) { if (options.withDaemon) {
prepareDaemon(wrapperVersion) prepareDaemon(wrapperVersion)
@@ -106,16 +107,12 @@ abstract class BaseGradleIT {
println("<=== Test build: ${this.projectName} $cmd ===>") println("<=== Test build: ${this.projectName} $cmd ===>")
runAndCheck(cmd, check)
}
private fun Project.runAndCheck(cmd: List<String>, check: CompiledProject.() -> Unit) {
val projectDir = File(workingDir, projectName) val projectDir = File(workingDir, projectName)
if (!projectDir.exists()) { if (!projectDir.exists()) {
setupWorkingDir() setupWorkingDir()
} }
val result = runProcess(cmd, projectDir) val result = runProcess(cmd, projectDir, env)
CompiledProject(this, result.output, result.exitCode).check() CompiledProject(this, result.output, result.exitCode).check()
} }
@@ -217,6 +214,13 @@ abstract class BaseGradleIT {
options.incremental?.let { add("-Pkotlin.incremental=$it") } options.incremental?.let { add("-Pkotlin.incremental=$it") }
} }
private fun Project.createEnvironmentVariablesMap(options: BuildOptions): Map<String, String> =
hashMapOf<String, String>().apply {
val sdkDir = options.androidHome
if (sdkDir != null) {
sdkDir.parentFile.mkdirs()
put("ANDROID_HOME", sdkDir.canonicalPath)
}
} }
private fun String.normalize() = this.lineSequence().joinToString(SYSTEM_LINE_SEPARATOR) private fun String.normalize() = this.lineSequence().joinToString(SYSTEM_LINE_SEPARATOR)
@@ -1,17 +1,20 @@
package org.jetbrains.kotlin.gradle package org.jetbrains.kotlin.gradle
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import java.io.File
@Ignore("Requires Android SDK") private const val DEFAULT_GRADLE_VERSION = "2.3"
class KotlinAndroidGradleIT : BaseGradleIT() {
class KotlinAndroidGradleCLIOnly : BaseGradleIT() {
override fun defaultBuildOptions() = override fun defaultBuildOptions() =
BuildOptions(withDaemon = true, assertThreadLeaks = false) BuildOptions(withDaemon = true,
assertThreadLeaks = false,
androidHome = File("../../../dependencies/android-sdk-for-tests"))
@Test @Test
fun testSimpleCompile() { fun testSimpleCompile() {
val project = Project("AndroidProject", "2.3") val project = Project("AndroidProject", DEFAULT_GRADLE_VERSION)
project.build("build") { project.build("build") {
assertSuccessful() assertSuccessful()
@@ -58,7 +61,7 @@ class KotlinAndroidGradleIT : BaseGradleIT() {
@Test @Test
fun testModuleNameAndroid() { fun testModuleNameAndroid() {
val project = Project("AndroidProject", "2.3") val project = Project("AndroidProject", DEFAULT_GRADLE_VERSION)
project.build("build") { project.build("build") {
assertContains( assertContains(
@@ -20,8 +20,9 @@ Executing process was ${if (isSuccessful) "successful" else "unsuccessful"}
""" """
} }
fun runProcess(cmd: List<String>, workingDir: File): ProcessRunResult { fun runProcess(cmd: List<String>, workingDir: File, environmentVariables: Map<String, String> = mapOf()): ProcessRunResult {
val builder = ProcessBuilder(cmd) val builder = ProcessBuilder(cmd)
builder.environment().putAll(environmentVariables)
builder.directory(workingDir) builder.directory(workingDir)
// redirectErrorStream merges stdout and stderr, so it can be get from process.inputStream // redirectErrorStream merges stdout and stderr, so it can be get from process.inputStream
builder.redirectErrorStream(true) builder.redirectErrorStream(true)
@@ -1,15 +1,4 @@
buildscript { apply plugin: 'android-sdk-manager'
repositories {
mavenCentral()
maven {
url 'file://' + pathToKotlinPlugin
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT'
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
@@ -1,16 +1,5 @@
buildscript { apply plugin: 'android-sdk-manager'
repositories { apply plugin: 'com.android.application'
mavenCentral()
maven {
url 'file://' + pathToKotlinPlugin
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT'
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
repositories { repositories {
@@ -1 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript {
repositories {
mavenCentral()
maven {
url 'file://' + pathToKotlinPlugin
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT'
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}
@@ -1,10 +0,0 @@
# This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=C:/Program Files (x86)/Android/android-studio-0.5.1/sdk