mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
AndroidPlugin is now a repo contributor.
This commit is contained in:
parent
e580c3f7bd
commit
41904c0c75
5 changed files with 81 additions and 32 deletions
|
@ -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
|
||||
|
|
|
@ -19,7 +19,7 @@ public class Kobalt {
|
|||
"https://jcenter.bintray.com/"
|
||||
)
|
||||
|
||||
val repos = ArrayList<String>(DEFAULT_REPOS)
|
||||
val repos = HashSet<String>(DEFAULT_REPOS)
|
||||
|
||||
fun addRepo(repo: String) = repos.add(if (repo.endsWith("/")) repo else repo + "/")
|
||||
|
||||
|
|
|
@ -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<URI>
|
||||
}
|
||||
|
||||
/////
|
||||
// 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<IProjectContributor>()
|
||||
val classpathContributors = arrayListOf<IClasspathContributor>()
|
||||
val initContributors = arrayListOf<IInitContributor>()
|
||||
val repoContributors = arrayListOf<IRepoContributor>()
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
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<String, IClasspathDependency>()
|
||||
|
||||
// IClasspathContributor
|
||||
override fun entriesFor(project: Project?): Collection<IClasspathDependency> {
|
||||
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())
|
||||
}
|
||||
|
|
|
@ -22,4 +22,7 @@
|
|||
<class-name>com.beust.kobalt.plugin.java.JavaBuildGenerator</class-name>
|
||||
<class-name>com.beust.kobalt.plugin.kotlin.KotlinBuildGenerator</class-name>
|
||||
</init-contributors>
|
||||
<repo-contributors>
|
||||
<class-name>com.beust.kobalt.plugin.android.AndroidPlugin</class-name>
|
||||
</repo-contributors>
|
||||
</kobalt-plugin>
|
Loading…
Add table
Add a link
Reference in a new issue