diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index 2d559cf7..02130286 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -62,8 +62,20 @@ private class Main @Inject constructor( data class RunInfo(val jc: JCommander, val args: Args) + private fun addReposFromContributors(project: Project?) = + pluginInfo.repoContributors.forEach { + it.reposFor(project).forEach { + Kobalt.addRepo(it.toString()) + } + } + public fun run(jc: JCommander, args: Args) : Int { + // + // Add all the repos from repo contributors (at least those that return values without a Project) + // + addReposFromContributors(null) + // // Add all the plugins read in plugin.xml to the Plugins singleton, so that code // in the build file that calls Plugins.findPlugin() can find them (code in the @@ -153,6 +165,12 @@ private class Main @Inject constructor( } } + // + // Now that we have projects, add all the repos from repo contributors that need a Project + // + allProjects.forEach { addReposFromContributors(it) } + + log(2, "Final list of repos:\n " + Kobalt.repos.joinToString("\n ")) if (args.tasks) { // // List of tasks diff --git a/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt b/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt index c1105c10..42ba0d67 100644 --- a/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt @@ -19,7 +19,7 @@ public class Kobalt { "https://jcenter.bintray.com/" ) - val repos = ArrayList(DEFAULT_REPOS) + val repos = HashSet(DEFAULT_REPOS) fun addRepo(repo: String) = repos.add(if (repo.endsWith("/")) repo else repo + "/") diff --git a/src/main/kotlin/com/beust/kobalt/api/KobaltPluginXml.kt b/src/main/kotlin/com/beust/kobalt/api/KobaltPluginXml.kt index 273fb8dc..fe6a6542 100644 --- a/src/main/kotlin/com/beust/kobalt/api/KobaltPluginXml.kt +++ b/src/main/kotlin/com/beust/kobalt/api/KobaltPluginXml.kt @@ -1,10 +1,10 @@ package com.beust.kobalt.api -import com.beust.kobalt.Plugins import com.beust.kobalt.maven.IClasspathDependency import java.io.File import java.io.InputStream import java.io.OutputStream +import java.net.URI import javax.xml.bind.JAXBContext import javax.xml.bind.annotation.XmlElement import javax.xml.bind.annotation.XmlRootElement @@ -62,6 +62,13 @@ interface IInitContributor { fun generateBuildFile(os: OutputStream) } +/** + * Plugins that add their own repos. + */ +interface IRepoContributor { + fun reposFor(project: Project?) : List +} + ///// // XML parsing // @@ -89,6 +96,9 @@ class KobaltPluginXml { @XmlElement(name = "init-contributors") @JvmField var initClassName: ClassNameXml? = null + + @XmlElement(name = "repo-contributors") @JvmField + var repoClassName: ClassNameXml? = null } class ContributorXml { @@ -111,6 +121,7 @@ class PluginInfo(val xml: KobaltPluginXml) { val projectContributors = arrayListOf() val classpathContributors = arrayListOf() val initContributors = arrayListOf() + val repoContributors = arrayListOf() // Future contributors: // compilerArgs @@ -158,6 +169,9 @@ class PluginInfo(val xml: KobaltPluginXml) { xml.initClassName?.className?.forEach { initContributors.add(factory.instanceOf(Class.forName(it)) as IInitContributor) } + xml.repoClassName?.className?.forEach { + repoContributors.add(factory.instanceOf(Class.forName(it)) as IRepoContributor) + } } } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt index 7ab50550..3bc05a40 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt @@ -36,10 +36,16 @@ fun Project.android(init: AndroidConfig.() -> Unit) : AndroidConfig { return pd } +val Project.isAndroid : Boolean + get() = (Kobalt.findPlugin("android") as AndroidPlugin).isAndroid(this) + @Singleton -public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) : BasePlugin(), IClasspathContributor { +public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) + : BasePlugin(), IClasspathContributor, IRepoContributor { override val name = "android" + fun isAndroid(project: Project) = configurations[project.name] != null + override fun apply(project: Project, context: KobaltContext) { super.apply(project, context) log(1, "Applying plug-in Android on project $project") @@ -71,14 +77,18 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) : return version as String } - fun androidHome(project: Project) : String { - var result = configurations[project.name]?.androidHome - if (result == null) { - result = System.getenv("ANDROID_HOME") - if (result == null) { - throw IllegalArgumentException("Neither androidHome nor \$ANDROID_HOME were defined") + fun androidHome(project: Project?) : String { + var result = System.getenv("ANDROID_HOME") + if (project != null) { + configurations[project.name]?.androidHome?.let { + result = it } } + + if (result == null) { + throw IllegalArgumentException("Neither androidHome nor \$ANDROID_HOME were defined") + } + return result } @@ -242,6 +252,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) : private val classpathEntries = HashMultimap.create() + // IClasspathContributor override fun entriesFor(project: Project?): Collection { if (project != null) { return classpathEntries.get(project.name) ?: listOf() @@ -250,4 +261,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) : } } + // IRepoContributor + override fun reposFor(project: Project?) = + listOf(Paths.get(KFiles.joinDir(androidHome(project), "extras", "android", "m2repository")).toUri()) } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 953ef677..3c3f195b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,25 +1,28 @@ - kobalt - com.beust.kobalt.api.ContributorFactory - - com.beust.kobalt.plugin.android.AndroidPlugin - com.beust.kobalt.plugin.application.ApplicationPlugin - com.beust.kobalt.plugin.KobaltDefaultPlugin - com.beust.kobalt.plugin.java.JavaPlugin - com.beust.kobalt.plugin.kotlin.KotlinPlugin - com.beust.kobalt.plugin.packaging.PackagingPlugin - com.beust.kobalt.plugin.publish.PublishPlugin - - - com.beust.kobalt.plugin.android.AndroidPlugin - com.beust.kobalt.plugin.kotlin.KotlinPlugin - - - com.beust.kobalt.plugin.java.JavaPlugin - com.beust.kobalt.plugin.kotlin.KotlinPlugin - - - com.beust.kobalt.plugin.java.JavaBuildGenerator - com.beust.kobalt.plugin.kotlin.KotlinBuildGenerator - + kobalt + com.beust.kobalt.api.ContributorFactory + + com.beust.kobalt.plugin.android.AndroidPlugin + com.beust.kobalt.plugin.application.ApplicationPlugin + com.beust.kobalt.plugin.KobaltDefaultPlugin + com.beust.kobalt.plugin.java.JavaPlugin + com.beust.kobalt.plugin.kotlin.KotlinPlugin + com.beust.kobalt.plugin.packaging.PackagingPlugin + com.beust.kobalt.plugin.publish.PublishPlugin + + + com.beust.kobalt.plugin.android.AndroidPlugin + com.beust.kobalt.plugin.kotlin.KotlinPlugin + + + com.beust.kobalt.plugin.java.JavaPlugin + com.beust.kobalt.plugin.kotlin.KotlinPlugin + + + com.beust.kobalt.plugin.java.JavaBuildGenerator + com.beust.kobalt.plugin.kotlin.KotlinBuildGenerator + + + com.beust.kobalt.plugin.android.AndroidPlugin + \ No newline at end of file