diff --git a/TODO b/TODO index f8958bde..9d72a5b3 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,6 @@ To do: -- --dryRun +- provided scope - ProjectGenerator: support migration from pom.xml (starting with dependencies) - Generate .idea and other IDEA files - Make files appear in download list automatically on bintray (undocumented API) @@ -22,6 +22,7 @@ To do: Done: +- --dryRun - --checkVersions: displays which plugins have a newer version than the one specified in the build - Make it possible to target jar for individual projects: ./kobaltw kobalt:uploadJcenter - --buildFile doesn't use the local .kobalt directory diff --git a/src/main/kotlin/com/beust/kobalt/Args.kt b/src/main/kotlin/com/beust/kobalt/Args.kt index 1e454d72..dbe2d1b5 100644 --- a/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/src/main/kotlin/com/beust/kobalt/Args.kt @@ -9,6 +9,10 @@ class Args { @Parameter(names = arrayOf("-bf", "--buildFile"), description = "The build file") var buildFile: String? = null + @Parameter(names = arrayOf("--dryRun"), description = "Display all the tasks that will get run without " + + "actually running them") + var dryRun: Boolean = false + @Parameter(names = arrayOf("--tasks"), description = "Display the tasks available for this build") var tasks: Boolean = false diff --git a/src/main/kotlin/com/beust/kobalt/BuildScript.kt b/src/main/kotlin/com/beust/kobalt/BuildScript.kt index 118f0c1d..8e744ab3 100644 --- a/src/main/kotlin/com/beust/kobalt/BuildScript.kt +++ b/src/main/kotlin/com/beust/kobalt/BuildScript.kt @@ -23,9 +23,9 @@ fun plugins(vararg dependency : IClasspathDependency) { @Directive fun plugins(vararg dependencies : String) { - val executor = INJECTOR.getInstance(KobaltExecutors::class.java) + val executor = Kobalt.INJECTOR.getInstance(KobaltExecutors::class.java) .newExecutor("BuildScript", 5) - val factory = INJECTOR.getInstance(DepFactory::class.java) + val factory = Kobalt.INJECTOR.getInstance(DepFactory::class.java) dependencies.forEach { Plugins.dynamicPlugins.add(factory.create(it, executor)) } diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index 9b033365..9ec2cc5f 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -13,15 +13,24 @@ import com.beust.kobalt.plugin.publish.JCenterApi import com.beust.kobalt.plugin.publish.UnauthenticatedJCenterApi import com.beust.kobalt.wrapper.Wrapper import com.google.inject.Guice +import com.google.inject.Injector import java.io.File import java.nio.file.Paths import java.util.* import javax.inject.Inject -val INJECTOR = Guice.createInjector(MainModule()) +private fun parseArgs(argv: Array): Main.RunInfo { + val args = Args() + val result = JCommander(args) + result.parse(*argv) + KobaltLogger.LOG_LEVEL = args.log + return Main.RunInfo(result, args) +} public fun main(argv: Array) { - INJECTOR.getInstance(Main::class.java).run(argv) + val (jc, args) = parseArgs(argv) + Kobalt.INJECTOR = Guice.createInjector(MainModule(args)) + Kobalt.INJECTOR.getInstance(Main::class.java).run(jc, args) } private class Main @Inject constructor( @@ -34,17 +43,15 @@ private class Main @Inject constructor( val localRepo: LocalRepo, val depFactory: DepFactory, val checkVersions: CheckVersions, - val jcenter: UnauthenticatedJCenterApi, val github: GithubApi) : KobaltLogger { data class RunInfo(val jc: JCommander, val args: Args) - public fun run(argv: Array) { + public fun run(jc: JCommander, args: Args) { benchmark("Build", { println(Banner.get() + Kobalt.version + "\n") // runTest() - val (jc, args) = parseArgs(argv) runWithArgs(jc, args) executors.shutdown() debug("All done") @@ -84,14 +91,6 @@ private class Main @Inject constructor( println("Sorted: ${sorted}") } - private fun parseArgs(argv: Array): RunInfo { - val args = Args() - val result = JCommander(args) - result.parse(*argv) - KobaltLogger.LOG_LEVEL = args.log - return RunInfo(result, args) - } - private val SCRIPT_JAR = "buildScript.jar" private fun runWithArgs(jc: JCommander, args: Args) { diff --git a/src/main/kotlin/com/beust/kobalt/Plugins.kt b/src/main/kotlin/com/beust/kobalt/Plugins.kt index 4fd68e90..a2aa7d4a 100644 --- a/src/main/kotlin/com/beust/kobalt/Plugins.kt +++ b/src/main/kotlin/com/beust/kobalt/Plugins.kt @@ -64,7 +64,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider) { - addPluginInstance(INJECTOR.getInstance(pluginClass)) + addPluginInstance(Kobalt.INJECTOR.getInstance(pluginClass)) } private fun addPluginInstance(plugin: Plugin) { @@ -80,7 +80,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider = arrayListOf() public fun registerCompiler(c: ICompilerInfo) { diff --git a/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt index 1b336e67..b1adfec3 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.internal +import com.beust.kobalt.Args import com.beust.kobalt.Plugins import com.beust.kobalt.api.PluginTask import com.beust.kobalt.api.Project @@ -16,7 +17,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -public class TaskManager @Inject constructor(val plugins: Plugins) : KobaltLogger { +public class TaskManager @Inject constructor(val plugins: Plugins, val args: Args) : KobaltLogger { private val dependentTaskMap = TreeMultimap.create() /** @@ -132,7 +133,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins) : KobaltLogge override public fun createWorkers(nodes: List): List> { val result = arrayListOf>() nodes.forEach { - result.add(TaskWorker(arrayListOf(it))) + result.add(TaskWorker(arrayListOf(it), args.dryRun)) } return result } @@ -144,7 +145,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins) : KobaltLogge } } -class TaskWorker(val tasks: List) : IWorker, KobaltLogger { +class TaskWorker(val tasks: List, val dryRun: Boolean) : IWorker, KobaltLogger { // override fun compareTo(other: IWorker2): Int { // return priority.compareTo(other.priority) // } @@ -157,7 +158,7 @@ class TaskWorker(val tasks: List) : IWorker, KobaltLogge } var success = true tasks.forEach { - val tr = it.call() + val tr = if (dryRun) TaskResult() else it.call() success = success and tr.success } return TaskResult2(success, tasks.get(0)) diff --git a/src/main/kotlin/com/beust/kobalt/maven/MavenDependency.kt b/src/main/kotlin/com/beust/kobalt/maven/MavenDependency.kt index 209f310a..64532afb 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/MavenDependency.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/MavenDependency.kt @@ -1,8 +1,7 @@ package com.beust.kobalt.maven -import com.beust.kobalt.INJECTOR +import com.beust.kobalt.api.Kobalt import com.beust.kobalt.misc.* -import com.google.common.base.CharMatcher import com.google.inject.Key import com.google.inject.assistedinject.Assisted import java.io.File @@ -51,8 +50,8 @@ public class MavenDependency @Inject constructor(override @Assisted("groupId") v // } companion object { - val executor = INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java)) - val depFactory = INJECTOR.getInstance(DepFactory::class.java) + val executor = Kobalt.INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java)) + val depFactory = Kobalt.INJECTOR.getInstance(DepFactory::class.java) fun create(id: String, ex: ExecutorService = executor) : IClasspathDependency { return depFactory.create(id, ex) diff --git a/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt b/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt index 8981abf2..ab2076dd 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.misc +import com.beust.kobalt.Args import com.beust.kobalt.kotlin.ScriptCompiler import com.beust.kobalt.maven.ArtifactFetcher import com.beust.kobalt.maven.LocalRepo @@ -8,6 +9,7 @@ import com.beust.kobalt.maven.PomGenerator import com.beust.kobalt.plugin.publish.JCenterApi import com.google.inject.AbstractModule import com.google.inject.BindingAnnotation +import com.google.inject.Provider import com.google.inject.TypeLiteral import com.google.inject.assistedinject.FactoryModuleBuilder import java.lang.annotation.RetentionPolicy @@ -24,7 +26,7 @@ import java.util.concurrent.ExecutorService @Retention(AnnotationRetention.RUNTIME) annotation class DependencyExecutor -public open class MainModule : AbstractModule() { +public open class MainModule(val args: Args) : AbstractModule() { val executors = KobaltExecutors() open fun configureTest() { @@ -49,6 +51,9 @@ public open class MainModule : AbstractModule() { bind(object: TypeLiteral() {}).toInstance(executors) bind(object: TypeLiteral() {}).annotatedWith(DependencyExecutor::class.java) .toInstance(executors.dependencyExecutor) + bind(Args::class.java).toProvider(object : Provider { + override fun get(): Args? = args + }) // bindListener(Matchers.any(), object: TypeListener { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 8f1c05b0..a8a9142c 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -1,6 +1,6 @@ package com.beust.kobalt.plugin.kotlin; -import com.beust.kobalt.INJECTOR +import com.beust.kobalt.api.Kobalt import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.TaskResult import com.beust.kobalt.maven.* @@ -81,7 +81,7 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){ } fun kotlinCompilePrivate(ini: KConfiguration.() -> Unit) : KConfiguration { - val result = INJECTOR.getInstance(KConfiguration::class.java) + val result = Kobalt.INJECTOR.getInstance(KConfiguration::class.java) result.ini() return result } diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index b01aac0d..0f0ed4e0 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=0.146 \ No newline at end of file +kobalt.version=0.147 \ No newline at end of file diff --git a/src/test/kotlin/com/beust/kobalt/TestModule.kt b/src/test/kotlin/com/beust/kobalt/TestModule.kt index 94b2f531..50c24caf 100644 --- a/src/test/kotlin/com/beust/kobalt/TestModule.kt +++ b/src/test/kotlin/com/beust/kobalt/TestModule.kt @@ -1,13 +1,14 @@ package com.beust.kobalt import com.beust.kobalt.maven.LocalRepo +import com.beust.kobalt.misc.MainModule import com.beust.kobalt.plugin.java.SystemProperties import com.google.inject.Scopes import java.io.File class TestLocalRepo: LocalRepo(localRepo = SystemProperties.homeDir + File.separatorChar + ".kobalt-test") -public class TestModule : com.beust.kobalt.misc.MainModule() { +public class TestModule(args: Args) : MainModule(args) { override fun configureTest() { bind(LocalRepo::class.java).to(TestLocalRepo::class.java).`in`(Scopes.SINGLETON) } diff --git a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt index 900fc24f..257ed04c 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.maven +import com.beust.kobalt.Args import com.beust.kobalt.TestModule import com.beust.kobalt.misc.DependencyExecutor import com.beust.kobalt.misc.MainModule @@ -11,9 +12,10 @@ import javax.inject.Inject @org.testng.annotations.Guice(modules = arrayOf(TestModule::class)) public class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder, - @DependencyExecutor val executor: ExecutorService){ + @DependencyExecutor val executor: ExecutorService, + val args: Args){ - val INJECTOR = Guice.createInjector(MainModule()) + val INJECTOR = Guice.createInjector(MainModule(args)) @Test public fun mavenMetadata() {