mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Parse plugin.xml.
This commit is contained in:
parent
4b4f91e07e
commit
77df0afd18
3 changed files with 79 additions and 13 deletions
|
@ -1,10 +1,7 @@
|
|||
package com.beust.kobalt
|
||||
|
||||
import com.beust.jcommander.JCommander
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.api.PluginInfo
|
||||
import com.beust.kobalt.api.PluginInfoDescription
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.internal.TaskManager
|
||||
import com.beust.kobalt.internal.remote.KobaltClient
|
||||
import com.beust.kobalt.internal.remote.KobaltServer
|
||||
|
@ -13,7 +10,6 @@ import com.beust.kobalt.kotlin.BuildFileCompiler
|
|||
import com.beust.kobalt.maven.DepFactory
|
||||
import com.beust.kobalt.maven.Http
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.maven.MavenDependency
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.beust.kobalt.wrapper.Wrapper
|
||||
import com.google.inject.Guice
|
||||
|
@ -21,6 +17,7 @@ import java.io.File
|
|||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import javax.xml.bind.JAXBContext
|
||||
|
||||
public fun main(argv: Array<String>) {
|
||||
val result = mainNoExit(argv)
|
||||
|
@ -72,7 +69,7 @@ private class Main @Inject constructor(
|
|||
val latestVersionFuture = github.latestKobaltVersion
|
||||
benchmark("Build", {
|
||||
println(AsciiArt.banner + Kobalt.version + "\n")
|
||||
// runTest()
|
||||
runTest()
|
||||
result = runWithArgs(jc, args)
|
||||
executors.shutdown()
|
||||
})
|
||||
|
@ -94,9 +91,14 @@ private class Main @Inject constructor(
|
|||
return result
|
||||
}
|
||||
|
||||
|
||||
public fun runTest() {
|
||||
val dep = MavenDependency.create("com.google.inject:guice:4.0:no_aop")
|
||||
println("Name: " + dep)
|
||||
val file = File("src\\main\\resources\\META-INF\\plugin.xml")
|
||||
val jaxbContext = JAXBContext.newInstance(KobaltPluginXml::class.java)
|
||||
|
||||
val kotlinPlugin : KobaltPluginXml = jaxbContext.createUnmarshaller().unmarshal(file) as KobaltPluginXml
|
||||
val pluginInfo = PluginInfo.create(kotlinPlugin)
|
||||
System.out.println(kotlinPlugin.name)
|
||||
}
|
||||
|
||||
private fun runWithArgs(jc: JCommander, args: Args) : Int {
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.beust.kobalt.maven.IClasspathDependency
|
|||
import com.beust.kobalt.plugin.java.JavaPlugin
|
||||
import com.beust.kobalt.plugin.kotlin.KotlinPlugin
|
||||
import java.util.*
|
||||
import javax.xml.bind.annotation.XmlElement
|
||||
import javax.xml.bind.annotation.XmlRootElement
|
||||
|
||||
class ProjectDescription(val project: Project, val dependsOn: List<Project>)
|
||||
|
||||
|
@ -19,6 +21,14 @@ interface IClasspathContributor {
|
|||
fun entriesFor(project: Project) : Collection<IClasspathDependency>
|
||||
}
|
||||
|
||||
interface IFactory {
|
||||
fun <T> instanceOf(c: Class<T>) : T
|
||||
}
|
||||
|
||||
class ContributorFactory : IFactory {
|
||||
override fun <T> instanceOf(c: Class<T>) : T = Kobalt.INJECTOR.getInstance(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* All the information gathered from the various plugin.xml that were collected.
|
||||
*/
|
||||
|
@ -41,12 +51,54 @@ class PluginInfoDescription {
|
|||
/**
|
||||
* Turn the classes found in PluginInfoDescription into concrete objects that plugins can then use.
|
||||
*/
|
||||
class PluginInfo(val description: PluginInfoDescription) {
|
||||
class PluginInfo(val description: PluginInfoDescription?) {
|
||||
val projectContributors = arrayListOf<IProjectContributor>()
|
||||
val classpathContributors = arrayListOf<IClasspathContributor>()
|
||||
|
||||
init {
|
||||
classpathContributors.addAll(description.classpathContributors.map { description.instanceOf(it) })
|
||||
projectContributors.addAll(description.projectContributors.map { description.instanceOf(it) })
|
||||
companion object {
|
||||
fun create(xml: KobaltPluginXml) : PluginInfo {
|
||||
val factory = Class.forName(xml.factoryClassName).newInstance() as IFactory
|
||||
val result = PluginInfo(null)
|
||||
xml.classpathContributors?.className?.forEach {
|
||||
result.classpathContributors.add(factory.instanceOf(Class.forName(it)) as IClasspathContributor)
|
||||
}
|
||||
xml.projectContributors?.className?.forEach {
|
||||
result.projectContributors.add(factory.instanceOf(Class.forName(it)) as IProjectContributor)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
if (description != null) {
|
||||
classpathContributors.addAll(description.classpathContributors.map { description.instanceOf(it) })
|
||||
projectContributors.addAll(description.projectContributors.map { description.instanceOf(it) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ContributorXml {
|
||||
@XmlElement @JvmField
|
||||
val name: String? = null
|
||||
}
|
||||
|
||||
class ContributorsXml {
|
||||
@XmlElement(name = "class-name") @JvmField
|
||||
var className: List<String> = arrayListOf<String>()
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "kobalt-plugin")
|
||||
class KobaltPluginXml {
|
||||
@XmlElement @JvmField
|
||||
var name: String? = null
|
||||
|
||||
@XmlElement(name = "factory-class-name") @JvmField
|
||||
var factoryClassName: String? = null
|
||||
|
||||
@XmlElement(name = "classpath-contributors") @JvmField
|
||||
var classpathContributors : ContributorsXml? = null
|
||||
|
||||
@XmlElement(name = "project-contributors") @JvmField
|
||||
var projectContributors : ContributorsXml? = null
|
||||
}
|
||||
|
||||
|
|
12
src/main/resources/META-INF/plugin.xml
Normal file
12
src/main/resources/META-INF/plugin.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<kobalt-plugin>
|
||||
<name>kobalt</name>
|
||||
<factory-class-name>com.beust.kobalt.api.ContributorFactory</factory-class-name>
|
||||
<classpath-contributors>
|
||||
<class-name>com.beust.kobalt.plugin.android.AndroidPlugin</class-name>
|
||||
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
||||
</classpath-contributors>
|
||||
<project-contributors>
|
||||
<class-name>com.beust.kobalt.plugin.java.JavaPlugin</class-name>
|
||||
<class-name>com.beust.kobalt.plugin.kotlin.KotlinPlugin</class-name>
|
||||
</project-contributors>
|
||||
</kobalt-plugin>
|
Loading…
Add table
Add a link
Reference in a new issue