1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

androidHome fix.

This commit is contained in:
Cedric Beust 2015-11-07 14:54:15 -08:00
parent 41904c0c75
commit 00a22e4d25

View file

@ -20,6 +20,7 @@ import com.google.common.collect.HashMultimap
import com.google.inject.Inject import com.google.inject.Inject
import com.google.inject.Singleton import com.google.inject.Singleton
import java.io.File import java.io.File
import java.net.URI
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
@ -77,7 +78,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
return version as String return version as String
} }
fun androidHome(project: Project?) : String { fun androidHomeNoThrows(project: Project?): String? {
var result = System.getenv("ANDROID_HOME") var result = System.getenv("ANDROID_HOME")
if (project != null) { if (project != null) {
configurations[project.name]?.androidHome?.let { configurations[project.name]?.androidHome?.let {
@ -85,13 +86,12 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
} }
} }
if (result == null) {
throw IllegalArgumentException("Neither androidHome nor \$ANDROID_HOME were defined")
}
return result return result
} }
fun androidHome(project: Project?) = androidHomeNoThrows(project) ?:
throw IllegalArgumentException("Neither androidHome nor \$ANDROID_HOME were defined")
fun androidJar(project: Project): Path = fun androidJar(project: Project): Path =
Paths.get(androidHome(project), "platforms", "android-${compileSdkVersion(project)}", "android.jar") Paths.get(androidHome(project), "platforms", "android-${compileSdkVersion(project)}", "android.jar")
@ -127,6 +127,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
init { init {
directory = cwd directory = cwd
} }
fun call(args: List<String>) = run(arrayListOf(aaptCommand) + args) fun call(args: List<String>) = run(arrayListOf(aaptCommand) + args)
} }
@ -254,14 +255,20 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
// IClasspathContributor // IClasspathContributor
override fun entriesFor(project: Project?): Collection<IClasspathDependency> { override fun entriesFor(project: Project?): Collection<IClasspathDependency> {
if (project != null) { return if (project != null) {
return classpathEntries.get(project.name) ?: listOf() classpathEntries.get(project.name) ?: listOf()
} else { } else {
return listOf() listOf()
} }
} }
// IRepoContributor // IRepoContributor
override fun reposFor(project: Project?) = override fun reposFor(project: Project?): List<URI> {
listOf(Paths.get(KFiles.joinDir(androidHome(project), "extras", "android", "m2repository")).toUri()) val home = androidHomeNoThrows(project)
return if (home != null) {
listOf(Paths.get(KFiles.joinDir(home, "extras", "android", "m2repository")).toUri())
} else {
emptyList()
}
}
} }