mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Better PluginInfo.
This commit is contained in:
parent
01e5afe531
commit
a5bad9b48a
7 changed files with 39 additions and 26 deletions
|
@ -2,6 +2,8 @@ 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.internal.TaskManager
|
||||
import com.beust.kobalt.internal.remote.KobaltClient
|
||||
|
@ -54,7 +56,8 @@ private class Main @Inject constructor(
|
|||
val github: GithubApi,
|
||||
val updateKobalt: UpdateKobalt,
|
||||
val client: KobaltClient,
|
||||
val server: KobaltServer) {
|
||||
val server: KobaltServer,
|
||||
val pluginInfoDescription: PluginInfoDescription) {
|
||||
|
||||
data class RunInfo(val jc: JCommander, val args: Args)
|
||||
|
||||
|
@ -117,8 +120,9 @@ private class Main @Inject constructor(
|
|||
error(buildFile.path.toFile().path + " does not exist")
|
||||
} else {
|
||||
var allProjects = listOf<Project>()
|
||||
val pluginInfo = PluginInfo(pluginInfoDescription)
|
||||
try {
|
||||
allProjects = buildFileCompilerFactory.create(listOf(buildFile)).compileBuildFiles(args)
|
||||
allProjects = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo).compileBuildFiles(args)
|
||||
} catch(ex: Throwable) {
|
||||
// This can happen if the ABI for the build script file changed. Try to wipe .kobalt.
|
||||
log(2, "Couldn't parse preBuildScript.jar: ${ex.message}")
|
||||
|
@ -127,7 +131,8 @@ private class Main @Inject constructor(
|
|||
return 1
|
||||
} else {
|
||||
log(1, "Deleted .kobalt")
|
||||
allProjects = buildFileCompilerFactory.create(listOf(buildFile)).compileBuildFiles(args)
|
||||
allProjects = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo)
|
||||
.compileBuildFiles(args)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,6 @@ import com.beust.kobalt.Plugins
|
|||
|
||||
public class KobaltContext(val args: Args) {
|
||||
fun findPlugin(name: String) = Plugins.findPlugin(name)
|
||||
var pluginFile: KobaltPluginFile? = null
|
||||
// sourceContributors
|
||||
// projectContributors
|
||||
// compilerContributors
|
||||
var pluginInfo: PluginInfo? = null
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,10 @@ interface IClasspathContributor {
|
|||
fun entriesFor(project: Project) : Collection<IClasspathDependency>
|
||||
}
|
||||
|
||||
class KobaltPluginFile {
|
||||
/**
|
||||
* All the information gathered from the various plugin.xml that were collected.
|
||||
*/
|
||||
class PluginInfoDescription {
|
||||
fun <T> instanceOf(c: Class<T>) : T = Kobalt.INJECTOR.getInstance(c)
|
||||
|
||||
val projectContributors : ArrayList<Class<out IProjectContributor>> =
|
||||
|
@ -33,4 +36,17 @@ class KobaltPluginFile {
|
|||
// source files
|
||||
// compilers
|
||||
// --init
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn the classes found in PluginInfoDescription into concrete objects that plugins can then use.
|
||||
*/
|
||||
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) })
|
||||
}
|
||||
}
|
|
@ -55,14 +55,8 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
|
|||
private fun runClasspathContributors(context: KobaltContext?, project: Project) :
|
||||
Collection<IClasspathDependency> {
|
||||
val result = arrayListOf<IClasspathDependency>()
|
||||
val classes : List<Class<out IClasspathContributor>>? = context?.pluginFile?.classpathContributors
|
||||
if (classes != null) {
|
||||
val contributors: List<IClasspathContributor> = classes.map {
|
||||
context?.pluginFile?.instanceOf(it)!!
|
||||
}
|
||||
contributors.forEach { it: IClasspathContributor ->
|
||||
result.addAll(it.entriesFor(project))
|
||||
}
|
||||
context?.pluginInfo?.classpathContributors?.forEach { it: IClasspathContributor ->
|
||||
result.addAll(it.entriesFor(project))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.beust.kobalt.internal.remote
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.api.PluginInfo
|
||||
import com.beust.kobalt.api.PluginInfoDescription
|
||||
import com.beust.kobalt.kotlin.BuildFile
|
||||
import com.beust.kobalt.kotlin.BuildFileCompiler
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
|
@ -10,8 +12,8 @@ import com.beust.kobalt.misc.KobaltExecutors
|
|||
import com.beust.kobalt.misc.log
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
import javax.inject.Inject
|
||||
import java.nio.file.Paths
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* This command returns the list of dependencies for the given buildFile.
|
||||
|
@ -24,11 +26,11 @@ import java.nio.file.Paths
|
|||
*/
|
||||
class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
|
||||
val buildFileCompilerFactory: BuildFileCompiler.IFactory, val args: Args,
|
||||
val dependencyManager: DependencyManager) : ICommand {
|
||||
val dependencyManager: DependencyManager, val pluginInfoDescription: PluginInfoDescription) : ICommand {
|
||||
override val name = "getDependencies"
|
||||
override fun run(sender: ICommandSender, received: JsonObject) {
|
||||
val buildFile = BuildFile(Paths.get(received.get("buildFile").asString), "GetDependenciesCommand")
|
||||
val scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile))
|
||||
val scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile), PluginInfo(pluginInfoDescription))
|
||||
scriptCompiler.observable.subscribe {
|
||||
buildScriptInfo -> if (buildScriptInfo.projects.size > 0) {
|
||||
sender.sendData(toData(buildScriptInfo))
|
||||
|
|
|
@ -25,10 +25,10 @@ import java.util.jar.JarInputStream
|
|||
import javax.inject.Inject
|
||||
|
||||
public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFiles: List<BuildFile>,
|
||||
val files: KFiles, val plugins: Plugins, val kobaltPluginFile: KobaltPluginFile) {
|
||||
@Assisted val pluginInfo: PluginInfo, val files: KFiles, val plugins: Plugins) {
|
||||
|
||||
interface IFactory {
|
||||
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>) : BuildFileCompiler
|
||||
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>, pluginInfo: PluginInfo) : BuildFileCompiler
|
||||
}
|
||||
|
||||
val observable = PublishSubject.create<BuildScriptInfo>()
|
||||
|
@ -37,7 +37,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
|||
|
||||
fun compileBuildFiles(args: Args): List<Project> {
|
||||
val context = KobaltContext(args)
|
||||
context.pluginFile = kobaltPluginFile
|
||||
context.pluginInfo = pluginInfo
|
||||
Kobalt.context = context
|
||||
|
||||
val allProjects = findProjects()
|
||||
|
@ -226,9 +226,8 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
|||
//
|
||||
Topological<Project>().let { topologicalProjects ->
|
||||
val all = hashSetOf<Project>()
|
||||
kobaltPluginFile.projectContributors.forEach { cls ->
|
||||
val ip: IProjectContributor = kobaltPluginFile.instanceOf(cls)
|
||||
val descriptions = ip.projects()
|
||||
pluginInfo.projectContributors.forEach { contributor ->
|
||||
val descriptions = contributor.projects()
|
||||
descriptions.forEach { pd ->
|
||||
all.add(pd.project)
|
||||
pd.dependsOn.forEach { dependsOn ->
|
||||
|
|
|
@ -46,7 +46,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler) :
|
|||
if (accept(project)) {
|
||||
project.compileDependencies.add(FileDependency(androidJar(project).toString()))
|
||||
}
|
||||
context.pluginFile?.classpathContributors?.add(this.javaClass)
|
||||
context.pluginInfo?.classpathContributors?.add(this)
|
||||
|
||||
// TODO: Find a more flexible way of enabling this, e.g. creating a contributor for it
|
||||
(Kobalt.findPlugin("java") as JvmCompilerPlugin).addCompilerArgs("-target", "1.6", "-source", "1.6")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue