mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
IProjectContributor.
This commit is contained in:
parent
5027d48fce
commit
acda49ec84
7 changed files with 64 additions and 35 deletions
|
@ -1,12 +1,8 @@
|
||||||
package com.beust.kobalt.api
|
package com.beust.kobalt.api
|
||||||
|
|
||||||
import com.beust.kobalt.BasePluginTask
|
|
||||||
import com.beust.kobalt.Plugins
|
import com.beust.kobalt.Plugins
|
||||||
import com.beust.kobalt.internal.TaskManager
|
import com.beust.kobalt.internal.TaskManager
|
||||||
import com.beust.kobalt.internal.TaskResult
|
import java.util.*
|
||||||
import com.beust.kobalt.internal.TaskResult2
|
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.concurrent.Callable
|
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
abstract public class BasePlugin : Plugin {
|
abstract public class BasePlugin : Plugin {
|
||||||
|
@ -15,4 +11,11 @@ abstract public class BasePlugin : Plugin {
|
||||||
override var methodTasks = arrayListOf<Plugin.MethodTask>()
|
override var methodTasks = arrayListOf<Plugin.MethodTask>()
|
||||||
override fun accept(project: Project) = true
|
override fun accept(project: Project) = true
|
||||||
var plugins : Plugins by Delegates.notNull()
|
var plugins : Plugins by Delegates.notNull()
|
||||||
|
|
||||||
|
protected val projects = arrayListOf<ProjectDescription>()
|
||||||
|
|
||||||
|
fun addProject(project: Project, dependsOn: Array<out Project>) {
|
||||||
|
projects.add(ProjectDescription(project, dependsOn.toList()))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.beust.kobalt.api
|
package com.beust.kobalt.api
|
||||||
|
|
||||||
import com.beust.kobalt.Plugins
|
import com.beust.kobalt.Plugins
|
||||||
import com.beust.kobalt.misc.Topological
|
|
||||||
import com.google.inject.Injector
|
import com.google.inject.Injector
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
@ -83,21 +82,6 @@ public class Kobalt {
|
||||||
|
|
||||||
val version = properties.getProperty(PROPERTY_KOBALT_VERSION)
|
val version = properties.getProperty(PROPERTY_KOBALT_VERSION)
|
||||||
|
|
||||||
val topologicalProjects = Topological<Project>()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used by projects to specify that they depend on other projects, e.g.
|
|
||||||
* val p = javaProject(project1, project2) { ... }
|
|
||||||
*/
|
|
||||||
fun declareProjectDependencies(project: Project, projects: Array<out Project>) {
|
|
||||||
topologicalProjects.addEdge(project, projects)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the projects sorted topologically.
|
|
||||||
*/
|
|
||||||
fun sortProjects(allProjects: ArrayList<Project>) = topologicalProjects.sort(allProjects)
|
|
||||||
|
|
||||||
fun findPlugin(name: String) = Plugins.findPlugin(name)
|
fun findPlugin(name: String) = Plugins.findPlugin(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/main/kotlin/com/beust/kobalt/api/KobaltPluginFile.kt
Normal file
16
src/main/kotlin/com/beust/kobalt/api/KobaltPluginFile.kt
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.beust.kobalt.api
|
||||||
|
|
||||||
|
import com.beust.kobalt.plugin.java.JavaPlugin
|
||||||
|
import com.beust.kobalt.plugin.kotlin.KotlinPlugin
|
||||||
|
|
||||||
|
class ProjectDescription(val project: Project, val dependsOn: List<Project>)
|
||||||
|
|
||||||
|
interface IProjectContributor {
|
||||||
|
fun projects() : List<ProjectDescription>
|
||||||
|
}
|
||||||
|
|
||||||
|
class KobaltPluginFile {
|
||||||
|
fun <T> instanceOf(c: Class<T>) = Kobalt.INJECTOR.getInstance(c)
|
||||||
|
val projectContributors : List<Class<out IProjectContributor>> =
|
||||||
|
arrayListOf(JavaPlugin::class.java, KotlinPlugin::class.java)
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import com.beust.kobalt.internal.TaskManager
|
||||||
import com.beust.kobalt.internal.TaskResult
|
import com.beust.kobalt.internal.TaskResult
|
||||||
import com.beust.kobalt.internal.TaskResult2
|
import com.beust.kobalt.internal.TaskResult2
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import java.util.ArrayList
|
import java.util.*
|
||||||
|
|
||||||
public interface Plugin {
|
public interface Plugin {
|
||||||
val name: String
|
val name: String
|
||||||
|
|
|
@ -2,13 +2,11 @@ package com.beust.kobalt.kotlin
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.Plugins
|
import com.beust.kobalt.Plugins
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.*
|
||||||
import com.beust.kobalt.api.KobaltContext
|
|
||||||
import com.beust.kobalt.api.Plugin
|
|
||||||
import com.beust.kobalt.api.Project
|
|
||||||
import com.beust.kobalt.api.annotation.Task
|
import com.beust.kobalt.api.annotation.Task
|
||||||
import com.beust.kobalt.maven.KobaltException
|
import com.beust.kobalt.maven.KobaltException
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import com.beust.kobalt.misc.Topological
|
||||||
import com.beust.kobalt.misc.countChar
|
import com.beust.kobalt.misc.countChar
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate
|
import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate
|
||||||
|
@ -22,11 +20,12 @@ import java.net.URL
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
import java.util.*
|
||||||
import java.util.jar.JarInputStream
|
import java.util.jar.JarInputStream
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFiles: List<BuildFile>,
|
public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFiles: List<BuildFile>,
|
||||||
val files: KFiles, val plugins: Plugins) {
|
val files: KFiles, val plugins: Plugins, val kobaltPluginFile: KobaltPluginFile) {
|
||||||
|
|
||||||
interface IFactory {
|
interface IFactory {
|
||||||
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>) : BuildFileCompiler
|
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>) : BuildFileCompiler
|
||||||
|
@ -220,9 +219,27 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
||||||
stream?.close()
|
stream?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we all the projects, sort them topologically
|
//
|
||||||
val result = BuildScriptInfo(Kobalt.sortProjects(projects), classLoader)
|
// Now that the build file has run, fetch all the project contributors, grab the projects from them and sort
|
||||||
|
// them topologically
|
||||||
|
//
|
||||||
|
Topological<Project>().let { topologicalProjects ->
|
||||||
|
val all = hashSetOf<Project>()
|
||||||
|
kobaltPluginFile.projectContributors.forEach { cls ->
|
||||||
|
val ip: IProjectContributor = kobaltPluginFile.instanceOf(cls)
|
||||||
|
val descriptions = ip.projects()
|
||||||
|
descriptions.forEach { pd ->
|
||||||
|
all.add(pd.project)
|
||||||
|
pd.dependsOn.forEach { dependsOn ->
|
||||||
|
topologicalProjects.addEdge(pd.project, dependsOn)
|
||||||
|
all.add(dependsOn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val result = BuildScriptInfo(topologicalProjects.sort(ArrayList(all)), classLoader)
|
||||||
|
|
||||||
observable.onNext(result)
|
observable.onNext(result)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.beust.kobalt.plugin.java
|
package com.beust.kobalt.plugin.java
|
||||||
|
|
||||||
|
import com.beust.kobalt.api.BasePlugin
|
||||||
|
import com.beust.kobalt.api.IProjectContributor
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
|
@ -27,7 +29,8 @@ public class JavaPlugin @Inject constructor(
|
||||||
override val executors: KobaltExecutors,
|
override val executors: KobaltExecutors,
|
||||||
val javaCompiler: JavaCompiler,
|
val javaCompiler: JavaCompiler,
|
||||||
override val jvmCompiler: JvmCompiler)
|
override val jvmCompiler: JvmCompiler)
|
||||||
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors, jvmCompiler) {
|
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors, jvmCompiler),
|
||||||
|
IProjectContributor {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Kobalt.registerCompiler(JavaCompilerInfo())
|
Kobalt.registerCompiler(JavaCompilerInfo())
|
||||||
|
@ -104,13 +107,14 @@ public class JavaPlugin @Inject constructor(
|
||||||
compilerArgs.addAll(args)
|
compilerArgs.addAll(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun projects() = projects
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
public fun javaProject(vararg project: Project, init: JavaProject.() -> Unit): JavaProject {
|
public fun javaProject(vararg project: Project, init: JavaProject.() -> Unit): JavaProject {
|
||||||
return JavaProject().apply {
|
return JavaProject().apply {
|
||||||
init()
|
init()
|
||||||
Kobalt.declareProjectDependencies(this, project)
|
(Kobalt.findPlugin("kotlin") as BasePlugin).addProject(this, project)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.beust.kobalt.plugin.kotlin
|
package com.beust.kobalt.plugin.kotlin
|
||||||
|
|
||||||
|
import com.beust.kobalt.api.BasePlugin
|
||||||
|
import com.beust.kobalt.api.IProjectContributor
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
|
@ -25,7 +27,8 @@ class KotlinPlugin @Inject constructor(
|
||||||
override val dependencyManager: DependencyManager,
|
override val dependencyManager: DependencyManager,
|
||||||
override val executors: KobaltExecutors,
|
override val executors: KobaltExecutors,
|
||||||
override val jvmCompiler: JvmCompiler)
|
override val jvmCompiler: JvmCompiler)
|
||||||
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors, jvmCompiler) {
|
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors, jvmCompiler),
|
||||||
|
IProjectContributor {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Kobalt.registerCompiler(KotlinCompilerInfo())
|
Kobalt.registerCompiler(KotlinCompilerInfo())
|
||||||
|
@ -93,6 +96,8 @@ class KotlinPlugin @Inject constructor(
|
||||||
output = outputDirectory
|
output = outputDirectory
|
||||||
}.compile(project, context)
|
}.compile(project, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun projects() = projects
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +107,7 @@ class KotlinPlugin @Inject constructor(
|
||||||
fun kotlinProject(vararg project: Project, init: KotlinProject.() -> Unit): KotlinProject {
|
fun kotlinProject(vararg project: Project, init: KotlinProject.() -> Unit): KotlinProject {
|
||||||
return KotlinProject().apply {
|
return KotlinProject().apply {
|
||||||
init()
|
init()
|
||||||
Kobalt.declareProjectDependencies(this, project)
|
(Kobalt.findPlugin("kotlin") as BasePlugin).addProject(this, project)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue