1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Proper assisted injection.

This commit is contained in:
Cedric Beust 2016-09-12 13:22:48 -07:00
parent 8608df4618
commit ffc56002c3
3 changed files with 16 additions and 9 deletions

View file

@ -38,7 +38,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil
val executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil, val settings: KobaltSettings, val executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil, val settings: KobaltSettings,
val incrementalManagerFactory: IncrementalManager.IFactory, val args: Args, val incrementalManagerFactory: IncrementalManager.IFactory, val args: Args,
val aether: KobaltAether, val pomGeneratorFactory: PomGenerator.IFactory, val aether: KobaltAether, val pomGeneratorFactory: PomGenerator.IFactory,
val parallelLogger: ParallelLogger) { val parallelLogger: ParallelLogger, val processedBuildFileFactory: ProcessedBuildFile.IFactory) {
interface IFactory { interface IFactory {
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>, pluginInfo: PluginInfo) : BuildFileCompiler fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>, pluginInfo: PluginInfo) : BuildFileCompiler
@ -167,5 +167,5 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil
* - the URL's of all the plug-ins that were found. * - the URL's of all the plug-ins that were found.
*/ */
private fun parseBuildFile(context: KobaltContext, buildFile: BuildFile) = private fun parseBuildFile(context: KobaltContext, buildFile: BuildFile) =
ProcessedBuildFile(buildFile, context, buildScriptUtil, dependencyManager, files) processedBuildFileFactory.create(buildFile, context)
} }

View file

@ -37,7 +37,8 @@ open class MainModule(val args: Args, val settings: KobaltSettings) : AbstractMo
Pom.IFactory::class.java, Pom.IFactory::class.java,
BuildFileCompiler.IFactory::class.java, BuildFileCompiler.IFactory::class.java,
IncrementalManager.IFactory::class.java, IncrementalManager.IFactory::class.java,
KobaltServer.IFactory::class.java) KobaltServer.IFactory::class.java,
ProcessedBuildFile.IFactory::class.java)
.forEach { .forEach {
install(builder.build(it)) install(builder.build(it))
} }

View file

@ -13,6 +13,8 @@ import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.countChar import com.beust.kobalt.misc.countChar
import com.beust.kobalt.misc.kobaltLog import com.beust.kobalt.misc.kobaltLog
import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate
import com.google.inject.Inject
import com.google.inject.assistedinject.Assisted
import java.io.File import java.io.File
import java.net.URL import java.net.URL
import java.nio.charset.Charset import java.nio.charset.Charset
@ -22,16 +24,20 @@ import java.util.*
/** /**
* Process the given build file (either with kotlinc or through scripting) and return projects and pluginUrls. * Process the given build file (either with kotlinc or through scripting) and return projects and pluginUrls.
*/ */
class ProcessedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val buildScriptUtil: BuildScriptUtil, class ProcessedBuildFile @Inject constructor(@Assisted val buildFile: BuildFile, @Assisted val context: KobaltContext,
val dependencyManager: DependencyManager, val files: KFiles) { val dependencyManager: DependencyManager, val files: KFiles, val compiledBuildFile: CompiledBuildFile) {
interface IFactory {
fun create(buildFile: BuildFile, context: KobaltContext) : ProcessedBuildFile
}
val pluginUrls = arrayListOf<URL>() val pluginUrls = arrayListOf<URL>()
val splitFile = SplitBuildFile(buildFile, context, dependencyManager, files) val splitFile = SplitBuildFile(buildFile, context, dependencyManager, files)
fun compile(): BuildFileCompiler.FindProjectResult { fun compile(): BuildFileCompiler.FindProjectResult {
// Find the projects but also invoke the plugins() directive, which will initialize Plugins.dynamicPlugins // Find the projects but also invoke the plugins() directive, which will initialize Plugins.dynamicPlugins
val projects = CompiledBuildFile(buildScriptUtil, dependencyManager, files) val projects = compiledBuildFile.findProjects(splitFile, context)
.findProjects(splitFile, context)
// All the plug-ins are now in Plugins.dynamicPlugins, download them if they're not already // All the plug-ins are now in Plugins.dynamicPlugins, download them if they're not already
Plugins.dynamicPlugins.forEach { Plugins.dynamicPlugins.forEach {
@ -45,8 +51,8 @@ class ProcessedBuildFile(val buildFile: BuildFile, val context: KobaltContext, v
/** /**
* Compile a build file with kotlinc. * Compile a build file with kotlinc.
*/ */
class CompiledBuildFile(val buildScriptUtil: BuildScriptUtil, val dependencyManager: DependencyManager, class CompiledBuildFile @Inject constructor(val buildScriptUtil: BuildScriptUtil,
val files: KFiles) { val dependencyManager: DependencyManager, val files: KFiles) {
fun findProjects(splitFile: SplitBuildFile, context: KobaltContext): List<Project> { fun findProjects(splitFile: SplitBuildFile, context: KobaltContext): List<Project> {
// //