From ffc56002c359c4ea9aca8e71f0c2f0a0de9a6456 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Mon, 12 Sep 2016 13:22:48 -0700 Subject: [PATCH] Proper assisted injection. --- .../com/beust/kobalt/app/BuildFileCompiler.kt | 4 ++-- .../kotlin/com/beust/kobalt/app/MainModule.kt | 3 ++- ...SplitBuildFile.kt => ProcessedBuildFile.kt} | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) rename src/main/kotlin/com/beust/kobalt/app/{SplitBuildFile.kt => ProcessedBuildFile.kt} (92%) diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index f585ba1b..3a9e8198 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -38,7 +38,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil val executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil, val settings: KobaltSettings, val incrementalManagerFactory: IncrementalManager.IFactory, val args: Args, val aether: KobaltAether, val pomGeneratorFactory: PomGenerator.IFactory, - val parallelLogger: ParallelLogger) { + val parallelLogger: ParallelLogger, val processedBuildFileFactory: ProcessedBuildFile.IFactory) { interface IFactory { fun create(@Assisted("buildFiles") buildFiles: List, 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. */ private fun parseBuildFile(context: KobaltContext, buildFile: BuildFile) = - ProcessedBuildFile(buildFile, context, buildScriptUtil, dependencyManager, files) + processedBuildFileFactory.create(buildFile, context) } diff --git a/src/main/kotlin/com/beust/kobalt/app/MainModule.kt b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt index 26d91453..08403324 100644 --- a/src/main/kotlin/com/beust/kobalt/app/MainModule.kt +++ b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt @@ -37,7 +37,8 @@ open class MainModule(val args: Args, val settings: KobaltSettings) : AbstractMo Pom.IFactory::class.java, BuildFileCompiler.IFactory::class.java, IncrementalManager.IFactory::class.java, - KobaltServer.IFactory::class.java) + KobaltServer.IFactory::class.java, + ProcessedBuildFile.IFactory::class.java) .forEach { install(builder.build(it)) } diff --git a/src/main/kotlin/com/beust/kobalt/app/SplitBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ProcessedBuildFile.kt similarity index 92% rename from src/main/kotlin/com/beust/kobalt/app/SplitBuildFile.kt rename to src/main/kotlin/com/beust/kobalt/app/ProcessedBuildFile.kt index 116d27ac..5ace2c25 100644 --- a/src/main/kotlin/com/beust/kobalt/app/SplitBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ProcessedBuildFile.kt @@ -13,6 +13,8 @@ import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.countChar import com.beust.kobalt.misc.kobaltLog import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate +import com.google.inject.Inject +import com.google.inject.assistedinject.Assisted import java.io.File import java.net.URL 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. */ -class ProcessedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val buildScriptUtil: BuildScriptUtil, - val dependencyManager: DependencyManager, val files: KFiles) { +class ProcessedBuildFile @Inject constructor(@Assisted val buildFile: BuildFile, @Assisted val context: KobaltContext, + val dependencyManager: DependencyManager, val files: KFiles, val compiledBuildFile: CompiledBuildFile) { + + interface IFactory { + fun create(buildFile: BuildFile, context: KobaltContext) : ProcessedBuildFile + } + val pluginUrls = arrayListOf() val splitFile = SplitBuildFile(buildFile, context, dependencyManager, files) fun compile(): BuildFileCompiler.FindProjectResult { // Find the projects but also invoke the plugins() directive, which will initialize Plugins.dynamicPlugins - val projects = CompiledBuildFile(buildScriptUtil, dependencyManager, files) - .findProjects(splitFile, context) + val projects = compiledBuildFile.findProjects(splitFile, context) // All the plug-ins are now in Plugins.dynamicPlugins, download them if they're not already Plugins.dynamicPlugins.forEach { @@ -45,8 +51,8 @@ class ProcessedBuildFile(val buildFile: BuildFile, val context: KobaltContext, v /** * Compile a build file with kotlinc. */ -class CompiledBuildFile(val buildScriptUtil: BuildScriptUtil, val dependencyManager: DependencyManager, - val files: KFiles) { +class CompiledBuildFile @Inject constructor(val buildScriptUtil: BuildScriptUtil, + val dependencyManager: DependencyManager, val files: KFiles) { fun findProjects(splitFile: SplitBuildFile, context: KobaltContext): List { //