mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -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)
|
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 {
|
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
|
// 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
|
// 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) {
|
if (args.tasks) {
|
||||||
//
|
//
|
||||||
// List of tasks
|
// List of tasks
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class Kobalt {
|
||||||
"https://jcenter.bintray.com/"
|
"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 + "/")
|
fun addRepo(repo: String) = repos.add(if (repo.endsWith("/")) repo else repo + "/")
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.beust.kobalt.api
|
package com.beust.kobalt.api
|
||||||
|
|
||||||
import com.beust.kobalt.Plugins
|
|
||||||
import com.beust.kobalt.maven.IClasspathDependency
|
import com.beust.kobalt.maven.IClasspathDependency
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
import java.net.URI
|
||||||
import javax.xml.bind.JAXBContext
|
import javax.xml.bind.JAXBContext
|
||||||
import javax.xml.bind.annotation.XmlElement
|
import javax.xml.bind.annotation.XmlElement
|
||||||
import javax.xml.bind.annotation.XmlRootElement
|
import javax.xml.bind.annotation.XmlRootElement
|
||||||
|
@ -62,6 +62,13 @@ interface IInitContributor {
|
||||||
fun generateBuildFile(os: OutputStream)
|
fun generateBuildFile(os: OutputStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plugins that add their own repos.
|
||||||
|
*/
|
||||||
|
interface IRepoContributor {
|
||||||
|
fun reposFor(project: Project?) : List<URI>
|
||||||
|
}
|
||||||
|
|
||||||
/////
|
/////
|
||||||
// XML parsing
|
// XML parsing
|
||||||
//
|
//
|
||||||
|
@ -89,6 +96,9 @@ class KobaltPluginXml {
|
||||||
|
|
||||||
@XmlElement(name = "init-contributors") @JvmField
|
@XmlElement(name = "init-contributors") @JvmField
|
||||||
var initClassName: ClassNameXml? = null
|
var initClassName: ClassNameXml? = null
|
||||||
|
|
||||||
|
@XmlElement(name = "repo-contributors") @JvmField
|
||||||
|
var repoClassName: ClassNameXml? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContributorXml {
|
class ContributorXml {
|
||||||
|
@ -111,6 +121,7 @@ class PluginInfo(val xml: KobaltPluginXml) {
|
||||||
val projectContributors = arrayListOf<IProjectContributor>()
|
val projectContributors = arrayListOf<IProjectContributor>()
|
||||||
val classpathContributors = arrayListOf<IClasspathContributor>()
|
val classpathContributors = arrayListOf<IClasspathContributor>()
|
||||||
val initContributors = arrayListOf<IInitContributor>()
|
val initContributors = arrayListOf<IInitContributor>()
|
||||||
|
val repoContributors = arrayListOf<IRepoContributor>()
|
||||||
|
|
||||||
// Future contributors:
|
// Future contributors:
|
||||||
// compilerArgs
|
// compilerArgs
|
||||||
|
@ -158,6 +169,9 @@ class PluginInfo(val xml: KobaltPluginXml) {
|
||||||
xml.initClassName?.className?.forEach {
|
xml.initClassName?.className?.forEach {
|
||||||
initContributors.add(factory.instanceOf(Class.forName(it)) as IInitContributor)
|
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
|
return pd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val Project.isAndroid : Boolean
|
||||||
|
get() = (Kobalt.findPlugin("android") as AndroidPlugin).isAndroid(this)
|
||||||
|
|
||||||
@Singleton
|
@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"
|
override val name = "android"
|
||||||
|
|
||||||
|
fun isAndroid(project: Project) = configurations[project.name] != null
|
||||||
|
|
||||||
override fun apply(project: Project, context: KobaltContext) {
|
override fun apply(project: Project, context: KobaltContext) {
|
||||||
super.apply(project, context)
|
super.apply(project, context)
|
||||||
log(1, "Applying plug-in Android on project $project")
|
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
|
return version as String
|
||||||
}
|
}
|
||||||
|
|
||||||
fun androidHome(project: Project) : String {
|
fun androidHome(project: Project?) : String {
|
||||||
var result = configurations[project.name]?.androidHome
|
var result = System.getenv("ANDROID_HOME")
|
||||||
if (result == null) {
|
if (project != null) {
|
||||||
result = System.getenv("ANDROID_HOME")
|
configurations[project.name]?.androidHome?.let {
|
||||||
if (result == null) {
|
result = it
|
||||||
throw IllegalArgumentException("Neither androidHome nor \$ANDROID_HOME were defined")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
throw IllegalArgumentException("Neither androidHome nor \$ANDROID_HOME were defined")
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,6 +252,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) :
|
||||||
|
|
||||||
private val classpathEntries = HashMultimap.create<String, IClasspathDependency>()
|
private val classpathEntries = HashMultimap.create<String, IClasspathDependency>()
|
||||||
|
|
||||||
|
// IClasspathContributor
|
||||||
override fun entriesFor(project: Project?): Collection<IClasspathDependency> {
|
override fun entriesFor(project: Project?): Collection<IClasspathDependency> {
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
return classpathEntries.get(project.name) ?: listOf()
|
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())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,28 @@
|
||||||
<kobalt-plugin>
|
<kobalt-plugin>
|
||||||
<name>kobalt</name>
|
<name>kobalt</name>
|
||||||
<factory-class-name>com.beust.kobalt.api.ContributorFactory</factory-class-name>
|
<factory-class-name>com.beust.kobalt.api.ContributorFactory</factory-class-name>
|
||||||
<plugins>
|
<plugins>
|
||||||
<class-name>com.beust.kobalt.plugin.android.AndroidPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.android.AndroidPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.application.ApplicationPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.application.ApplicationPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.KobaltDefaultPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.KobaltDefaultPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.packaging.PackagingPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.packaging.PackagingPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.publish.PublishPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.publish.PublishPlugin</class-name>
|
||||||
</plugins>
|
</plugins>
|
||||||
<classpath-contributors>
|
<classpath-contributors>
|
||||||
<class-name>com.beust.kobalt.plugin.android.AndroidPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.android.AndroidPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
||||||
</classpath-contributors>
|
</classpath-contributors>
|
||||||
<project-contributors>
|
<project-contributors>
|
||||||
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
||||||
</project-contributors>
|
</project-contributors>
|
||||||
<init-contributors>
|
<init-contributors>
|
||||||
<class-name>com.beust.kobalt.plugin.java.JavaBuildGenerator</class-name>
|
<class-name>com.beust.kobalt.plugin.java.JavaBuildGenerator</class-name>
|
||||||
<class-name>com.beust.kobalt.plugin.kotlin.KotlinBuildGenerator</class-name>
|
<class-name>com.beust.kobalt.plugin.kotlin.KotlinBuildGenerator</class-name>
|
||||||
</init-contributors>
|
</init-contributors>
|
||||||
|
<repo-contributors>
|
||||||
|
<class-name>com.beust.kobalt.plugin.android.AndroidPlugin</class-name>
|
||||||
|
</repo-contributors>
|
||||||
</kobalt-plugin>
|
</kobalt-plugin>
|
Loading…
Add table
Add a link
Reference in a new issue