mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Move the core plugins into plugins.xml.
This commit is contained in:
parent
23d9924242
commit
23cb52cacf
6 changed files with 38 additions and 38 deletions
|
@ -64,6 +64,13 @@ private class Main @Inject constructor(
|
||||||
|
|
||||||
public fun run(jc: JCommander, args: Args) : Int {
|
public fun run(jc: JCommander, args: Args) : Int {
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
// build file do not have access to the KobaltContext).
|
||||||
|
//
|
||||||
|
pluginInfo.plugins.forEach { Plugins.addPluginInstance(it) }
|
||||||
|
|
||||||
if (args.client) {
|
if (args.client) {
|
||||||
client.run()
|
client.run()
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -11,13 +11,7 @@ import com.beust.kobalt.maven.LocalRepo
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.beust.kobalt.plugin.DefaultPlugin
|
import com.beust.kobalt.plugin.KobaltDefaultPlugin
|
||||||
import com.beust.kobalt.plugin.android.AndroidPlugin
|
|
||||||
import com.beust.kobalt.plugin.application.ApplicationPlugin
|
|
||||||
import com.beust.kobalt.plugin.java.JavaPlugin
|
|
||||||
import com.beust.kobalt.plugin.kotlin.KotlinPlugin
|
|
||||||
import com.beust.kobalt.plugin.packaging.PackagingPlugin
|
|
||||||
import com.beust.kobalt.plugin.publish.PublishPlugin
|
|
||||||
import com.google.inject.Provider
|
import com.google.inject.Provider
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
|
@ -44,25 +38,10 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider<Tas
|
||||||
addPluginInstance(Kobalt.INJECTOR.getInstance(pluginClass))
|
addPluginInstance(Kobalt.INJECTOR.getInstance(pluginClass))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addPluginInstance(plugin: Plugin) {
|
fun addPluginInstance(plugin: Plugin) {
|
||||||
pluginMap.put(plugin.name, plugin)
|
pluginMap.put(plugin.name, plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
|
||||||
arrayListOf<Class<out Plugin>>(
|
|
||||||
DefaultPlugin::class.java,
|
|
||||||
JavaPlugin::class.java,
|
|
||||||
KotlinPlugin::class.java,
|
|
||||||
PackagingPlugin::class.java,
|
|
||||||
PublishPlugin::class.java,
|
|
||||||
AndroidPlugin::class.java,
|
|
||||||
ApplicationPlugin::class.java
|
|
||||||
// AptPlugin::class.java
|
|
||||||
).map {
|
|
||||||
addPluginInstance(Kobalt.INJECTOR.getInstance(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val plugins : List<Plugin>
|
val plugins : List<Plugin>
|
||||||
get() = ArrayList(pluginMap.values)
|
get() = ArrayList(pluginMap.values)
|
||||||
|
|
||||||
|
@ -71,7 +50,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider<Tas
|
||||||
*/
|
*/
|
||||||
val dynamicPlugins : ArrayList<IClasspathDependency> = arrayListOf()
|
val dynamicPlugins : ArrayList<IClasspathDependency> = arrayListOf()
|
||||||
|
|
||||||
val defaultPlugin : Plugin get() = findPlugin(DefaultPlugin.NAME)!!
|
val defaultPlugin : Plugin get() = findPlugin(KobaltDefaultPlugin.NAME)!!
|
||||||
|
|
||||||
fun findPlugin(name: String) : Plugin? = pluginMap[name]
|
fun findPlugin(name: String) : Plugin? = pluginMap[name]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
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
|
||||||
|
@ -74,17 +75,20 @@ class KobaltPluginXml {
|
||||||
@XmlElement @JvmField
|
@XmlElement @JvmField
|
||||||
var name: String? = null
|
var name: String? = null
|
||||||
|
|
||||||
|
@XmlElement(name = "plugins") @JvmField
|
||||||
|
var plugins : ClassNameXml? = null
|
||||||
|
|
||||||
@XmlElement(name = "factory-class-name") @JvmField
|
@XmlElement(name = "factory-class-name") @JvmField
|
||||||
var factoryClassName: String? = null
|
var factoryClassName: String? = null
|
||||||
|
|
||||||
@XmlElement(name = "classpath-contributors") @JvmField
|
@XmlElement(name = "classpath-contributors") @JvmField
|
||||||
var classpathContributors : ContributorsXml? = null
|
var classpathClassName: ClassNameXml? = null
|
||||||
|
|
||||||
@XmlElement(name = "project-contributors") @JvmField
|
@XmlElement(name = "project-contributors") @JvmField
|
||||||
var projectContributors : ContributorsXml? = null
|
var projectClassName: ClassNameXml? = null
|
||||||
|
|
||||||
@XmlElement(name = "init-contributors") @JvmField
|
@XmlElement(name = "init-contributors") @JvmField
|
||||||
var initContributors : ContributorsXml? = null
|
var initClassName: ClassNameXml? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContributorXml {
|
class ContributorXml {
|
||||||
|
@ -92,7 +96,7 @@ class ContributorXml {
|
||||||
val name: String? = null
|
val name: String? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContributorsXml {
|
class ClassNameXml {
|
||||||
@XmlElement(name = "class-name") @JvmField
|
@XmlElement(name = "class-name") @JvmField
|
||||||
var className: List<String> = arrayListOf()
|
var className: List<String> = arrayListOf()
|
||||||
}
|
}
|
||||||
|
@ -103,6 +107,7 @@ class ContributorsXml {
|
||||||
* needs to access plug-in info can then just inject a PluginInfo object.
|
* needs to access plug-in info can then just inject a PluginInfo object.
|
||||||
*/
|
*/
|
||||||
class PluginInfo(val xml: KobaltPluginXml) {
|
class PluginInfo(val xml: KobaltPluginXml) {
|
||||||
|
val plugins = arrayListOf<Plugin>()
|
||||||
val projectContributors = arrayListOf<IProjectContributor>()
|
val projectContributors = arrayListOf<IProjectContributor>()
|
||||||
val classpathContributors = arrayListOf<IClasspathContributor>()
|
val classpathContributors = arrayListOf<IClasspathContributor>()
|
||||||
val initContributors = arrayListOf<IInitContributor>()
|
val initContributors = arrayListOf<IInitContributor>()
|
||||||
|
@ -141,13 +146,16 @@ class PluginInfo(val xml: KobaltPluginXml) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val factory = Class.forName(xml.factoryClassName).newInstance() as IFactory
|
val factory = Class.forName(xml.factoryClassName).newInstance() as IFactory
|
||||||
xml.classpathContributors?.className?.forEach {
|
xml.plugins?.className?.forEach {
|
||||||
|
plugins.add(factory.instanceOf(Class.forName(it)) as Plugin)
|
||||||
|
}
|
||||||
|
xml.classpathClassName?.className?.forEach {
|
||||||
classpathContributors.add(factory.instanceOf(Class.forName(it)) as IClasspathContributor)
|
classpathContributors.add(factory.instanceOf(Class.forName(it)) as IClasspathContributor)
|
||||||
}
|
}
|
||||||
xml.projectContributors?.className?.forEach {
|
xml.projectClassName?.className?.forEach {
|
||||||
projectContributors.add(factory.instanceOf(Class.forName(it)) as IProjectContributor)
|
projectContributors.add(factory.instanceOf(Class.forName(it)) as IProjectContributor)
|
||||||
}
|
}
|
||||||
xml.initContributors?.className?.forEach {
|
xml.initClassName?.className?.forEach {
|
||||||
initContributors.add(factory.instanceOf(Class.forName(it)) as IInitContributor)
|
initContributors.add(factory.instanceOf(Class.forName(it)) as IInitContributor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,7 @@ import com.beust.kobalt.api.PluginInfo
|
||||||
import com.beust.kobalt.kotlin.BuildFileCompiler
|
import com.beust.kobalt.kotlin.BuildFileCompiler
|
||||||
import com.beust.kobalt.maven.*
|
import com.beust.kobalt.maven.*
|
||||||
import com.beust.kobalt.plugin.publish.JCenterApi
|
import com.beust.kobalt.plugin.publish.JCenterApi
|
||||||
import com.google.inject.AbstractModule
|
import com.google.inject.*
|
||||||
import com.google.inject.BindingAnnotation
|
|
||||||
import com.google.inject.Provider
|
|
||||||
import com.google.inject.TypeLiteral
|
|
||||||
import com.google.inject.assistedinject.FactoryModuleBuilder
|
import com.google.inject.assistedinject.FactoryModuleBuilder
|
||||||
import java.util.concurrent.ExecutorService
|
import java.util.concurrent.ExecutorService
|
||||||
|
|
||||||
|
@ -54,7 +51,7 @@ public open class MainModule(val args: Args) : AbstractModule() {
|
||||||
})
|
})
|
||||||
bind(PluginInfo::class.java).toProvider(object: Provider<PluginInfo> {
|
bind(PluginInfo::class.java).toProvider(object: Provider<PluginInfo> {
|
||||||
override fun get(): PluginInfo? = PluginInfo.readKobaltPluginXml()
|
override fun get(): PluginInfo? = PluginInfo.readKobaltPluginXml()
|
||||||
})
|
}).`in`(Singleton::class.java)
|
||||||
|
|
||||||
|
|
||||||
// bindListener(Matchers.any(), object: TypeListener {
|
// bindListener(Matchers.any(), object: TypeListener {
|
||||||
|
|
|
@ -7,9 +7,9 @@ import javax.inject.Singleton
|
||||||
* This plugin is used to gather tasks defined in build files, since these tasks don't really belong to any plugin.
|
* This plugin is used to gather tasks defined in build files, since these tasks don't really belong to any plugin.
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class DefaultPlugin : BasePlugin() {
|
public class KobaltDefaultPlugin : BasePlugin() {
|
||||||
companion object {
|
companion object {
|
||||||
public val NAME = "Default"
|
public val NAME = "Kobalt default"
|
||||||
}
|
}
|
||||||
|
|
||||||
override val name: String get() = NAME
|
override val name: String get() = NAME
|
|
@ -1,6 +1,15 @@
|
||||||
<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>
|
||||||
|
<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.KobaltDefaultPlugin</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.packaging.PackagingPlugin</class-name>
|
||||||
|
<class-name>com.beust.kobalt.plugin.publish.PublishPlugin</class-name>
|
||||||
|
</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>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue