diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt index 5ab88cb0..f8c28b52 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt @@ -1,10 +1,11 @@ package com.beust.kobalt.api import com.beust.kobalt.TaskResult -import com.beust.kobalt.api.IClasspathDependency /** * Plugins that can run a project (task "run" or "test") should implement this interface. + * + * Currently not used. */ interface IRunnerContributor : IContributor, IProjectAffinity { /** diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt index 59b3b894..d8ca3555 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt @@ -78,7 +78,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?, val compilerInterceptors = arrayListOf() val sourceDirectoriesInterceptors = arrayListOf() val buildDirectoryInterceptors = arrayListOf() - val runnerContributors = arrayListOf() +// val runnerContributors = arrayListOf() val testRunnerContributors = arrayListOf() val classpathInterceptors = arrayListOf() val compilerContributors = arrayListOf() @@ -197,7 +197,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?, if (this is IPlugin) plugins.add(this) if (this is IProjectContributor) projectContributors.add(this) if (this is IRepoContributor) repoContributors.add(this) - if (this is IRunnerContributor) runnerContributors.add(this) +// if (this is IRunnerContributor) runnerContributors.add(this) if (this is ISourceDirectoryContributor) sourceDirContributors.add(this) if (this is ISourceDirectoryInterceptor) sourceDirectoriesInterceptors.add(this) if (this is ITaskContributor) taskContributors.add(this) @@ -225,7 +225,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?, listOf(projectContributors, classpathContributors, templateContributors, repoContributors, compilerFlagContributors, compilerInterceptors, sourceDirectoriesInterceptors, buildDirectoryInterceptors, - runnerContributors, testRunnerContributors, classpathInterceptors, + /* runnerContributors, */ testRunnerContributors, classpathInterceptors, compilerContributors, docContributors, sourceDirContributors, testSourceDirContributors, buildConfigFieldContributors, taskContributors, incrementalTaskContributors, assemblyContributors, @@ -252,7 +252,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?, compilerInterceptors.addAll(pluginInfo.compilerInterceptors) sourceDirectoriesInterceptors.addAll(pluginInfo.sourceDirectoriesInterceptors) buildDirectoryInterceptors.addAll(pluginInfo.buildDirectoryInterceptors) - runnerContributors.addAll(pluginInfo.runnerContributors) +// runnerContributors.addAll(pluginInfo.runnerContributors) testRunnerContributors.addAll(pluginInfo.testRunnerContributors) classpathInterceptors.addAll(pluginInfo.classpathInterceptors) compilerContributors.addAll(pluginInfo.compilerContributors) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt index 9fc0b027..5c8de7c2 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -6,9 +6,7 @@ import com.beust.kobalt.Plugins import com.beust.kobalt.TaskResult import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive -import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.archive.Archives -import com.beust.kobalt.internal.ActorUtils import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.aether.Scope import com.beust.kobalt.misc.KFiles @@ -22,6 +20,9 @@ import com.google.inject.Singleton import java.io.File class ApplicationConfig { + @Directive + var taskName: String = "run" + @Directive var mainClass: String? = null @@ -43,10 +44,10 @@ fun Project.application(init: ApplicationConfig.() -> Unit): ApplicationConfig { } @Singleton -class ApplicationPlugin @Inject constructor(val configActor: ConfigActor, +class ApplicationPlugin @Inject constructor(val configActor: ConfigsActor, val executors: KobaltExecutors, val nativeManager: NativeManager, val dependencyManager: DependencyManager, val taskContributor : TaskContributor, val jvm: Jvm) - : BasePlugin(), IRunnerContributor, ITaskContributor, IConfigActor by configActor { + : BasePlugin(), ITaskContributor, IConfigsActor by configActor { companion object { const val PLUGIN_NAME = "Application" @@ -56,49 +57,52 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor 0) { - return runContributor.run(project, context, - dependencyManager.dependencies(project, context, listOf(Scope.RUNTIME))) - } else { - context.logger.log(project.name, 1, - "Couldn't find a runner for project ${project.name}. Please make sure" + - " your build file contains " + - "an application{} directive with a mainClass=... in it") - return TaskResult() + configurationFor(project)?.let { configs -> + configs.forEach { config -> + taskManager.addTask(this, project, config.taskName, + description = "Run the class " + config.mainClass, + group = "run", + dependsOn = listOf("install"), + task = { run(project, context, config) }) + } } } +// fun taskRun(project: Project, config: ApplicationConfig): TaskResult { +// val runContributor = ActorUtils.selectAffinityActor(project, context, +// context.pluginInfo.runnerContributors) +// if (runContributor != null && runContributor.affinity(project, context) > 0) { +// return runContributor.run(project, context, +// dependencyManager.dependencies(project, context, listOf(Scope.RUNTIME))) +// } else { +// context.logger.log(project.name, 1, +// "Couldn't find a runner for project ${project.name}. Please make sure" + +// " your build file contains " + +// "an application{} directive with a mainClass=... in it") +// return TaskResult() +// } +// } + private fun isFatJar(packages: List, jarName: String): Boolean { val foundJar = packages.flatMap { it.jars }.filter { jarName.endsWith(it.name) } return foundJar.size == 1 && foundJar[0].fatJar } - // IRunContributor - - override fun affinity(project: Project, context: KobaltContext): Int { - return if (configurationFor(project) != null) IAffinity.DEFAULT_POSITIVE_AFFINITY else 0 - } - - override fun run(project: Project, context: KobaltContext, classpath: List): TaskResult { - var result = TaskResult() + private fun run(project: Project, context: KobaltContext, config: ApplicationConfig): TaskResult { if (project.nativeDependencies.any()) { nativeManager.installLibraries(project) } - configurationFor(project)?.let { config -> + + val result = if (config.mainClass != null) { - result = runJarFile(project, context, config) + runJarFile(project, context, config) } else { throw KobaltException("No \"mainClass\" specified in the application{} part of project ${project.name}") } - } + return result }