mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Support for multiple application{} directives.
Fixes https://github.com/cbeust/kobalt/issues/430.
This commit is contained in:
parent
65f423ffea
commit
93f5c541f4
3 changed files with 41 additions and 36 deletions
|
@ -1,10 +1,11 @@
|
||||||
package com.beust.kobalt.api
|
package com.beust.kobalt.api
|
||||||
|
|
||||||
import com.beust.kobalt.TaskResult
|
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.
|
* Plugins that can run a project (task "run" or "test") should implement this interface.
|
||||||
|
*
|
||||||
|
* Currently not used.
|
||||||
*/
|
*/
|
||||||
interface IRunnerContributor : IContributor, IProjectAffinity {
|
interface IRunnerContributor : IContributor, IProjectAffinity {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -78,7 +78,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
|
||||||
val compilerInterceptors = arrayListOf<ICompilerInterceptor>()
|
val compilerInterceptors = arrayListOf<ICompilerInterceptor>()
|
||||||
val sourceDirectoriesInterceptors = arrayListOf<ISourceDirectoryInterceptor>()
|
val sourceDirectoriesInterceptors = arrayListOf<ISourceDirectoryInterceptor>()
|
||||||
val buildDirectoryInterceptors = arrayListOf<IBuildDirectoryInterceptor>()
|
val buildDirectoryInterceptors = arrayListOf<IBuildDirectoryInterceptor>()
|
||||||
val runnerContributors = arrayListOf<IRunnerContributor>()
|
// val runnerContributors = arrayListOf<IRunnerContributor>()
|
||||||
val testRunnerContributors = arrayListOf<ITestRunnerContributor>()
|
val testRunnerContributors = arrayListOf<ITestRunnerContributor>()
|
||||||
val classpathInterceptors = arrayListOf<IClasspathInterceptor>()
|
val classpathInterceptors = arrayListOf<IClasspathInterceptor>()
|
||||||
val compilerContributors = arrayListOf<ICompilerContributor>()
|
val compilerContributors = arrayListOf<ICompilerContributor>()
|
||||||
|
@ -197,7 +197,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
|
||||||
if (this is IPlugin) plugins.add(this)
|
if (this is IPlugin) plugins.add(this)
|
||||||
if (this is IProjectContributor) projectContributors.add(this)
|
if (this is IProjectContributor) projectContributors.add(this)
|
||||||
if (this is IRepoContributor) repoContributors.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 ISourceDirectoryContributor) sourceDirContributors.add(this)
|
||||||
if (this is ISourceDirectoryInterceptor) sourceDirectoriesInterceptors.add(this)
|
if (this is ISourceDirectoryInterceptor) sourceDirectoriesInterceptors.add(this)
|
||||||
if (this is ITaskContributor) taskContributors.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,
|
listOf(projectContributors, classpathContributors, templateContributors,
|
||||||
repoContributors, compilerFlagContributors, compilerInterceptors,
|
repoContributors, compilerFlagContributors, compilerInterceptors,
|
||||||
sourceDirectoriesInterceptors, buildDirectoryInterceptors,
|
sourceDirectoriesInterceptors, buildDirectoryInterceptors,
|
||||||
runnerContributors, testRunnerContributors, classpathInterceptors,
|
/* runnerContributors, */ testRunnerContributors, classpathInterceptors,
|
||||||
compilerContributors, docContributors, sourceDirContributors,
|
compilerContributors, docContributors, sourceDirContributors,
|
||||||
testSourceDirContributors, buildConfigFieldContributors,
|
testSourceDirContributors, buildConfigFieldContributors,
|
||||||
taskContributors, incrementalTaskContributors, assemblyContributors,
|
taskContributors, incrementalTaskContributors, assemblyContributors,
|
||||||
|
@ -252,7 +252,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
|
||||||
compilerInterceptors.addAll(pluginInfo.compilerInterceptors)
|
compilerInterceptors.addAll(pluginInfo.compilerInterceptors)
|
||||||
sourceDirectoriesInterceptors.addAll(pluginInfo.sourceDirectoriesInterceptors)
|
sourceDirectoriesInterceptors.addAll(pluginInfo.sourceDirectoriesInterceptors)
|
||||||
buildDirectoryInterceptors.addAll(pluginInfo.buildDirectoryInterceptors)
|
buildDirectoryInterceptors.addAll(pluginInfo.buildDirectoryInterceptors)
|
||||||
runnerContributors.addAll(pluginInfo.runnerContributors)
|
// runnerContributors.addAll(pluginInfo.runnerContributors)
|
||||||
testRunnerContributors.addAll(pluginInfo.testRunnerContributors)
|
testRunnerContributors.addAll(pluginInfo.testRunnerContributors)
|
||||||
classpathInterceptors.addAll(pluginInfo.classpathInterceptors)
|
classpathInterceptors.addAll(pluginInfo.classpathInterceptors)
|
||||||
compilerContributors.addAll(pluginInfo.compilerContributors)
|
compilerContributors.addAll(pluginInfo.compilerContributors)
|
||||||
|
|
|
@ -6,9 +6,7 @@ import com.beust.kobalt.Plugins
|
||||||
import com.beust.kobalt.TaskResult
|
import com.beust.kobalt.TaskResult
|
||||||
import com.beust.kobalt.api.*
|
import com.beust.kobalt.api.*
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
import com.beust.kobalt.api.annotation.Task
|
|
||||||
import com.beust.kobalt.archive.Archives
|
import com.beust.kobalt.archive.Archives
|
||||||
import com.beust.kobalt.internal.ActorUtils
|
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.maven.aether.Scope
|
import com.beust.kobalt.maven.aether.Scope
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
@ -22,6 +20,9 @@ import com.google.inject.Singleton
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class ApplicationConfig {
|
class ApplicationConfig {
|
||||||
|
@Directive
|
||||||
|
var taskName: String = "run"
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
var mainClass: String? = null
|
var mainClass: String? = null
|
||||||
|
|
||||||
|
@ -43,10 +44,10 @@ fun Project.application(init: ApplicationConfig.() -> Unit): ApplicationConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<ApplicationConfig>,
|
class ApplicationPlugin @Inject constructor(val configActor: ConfigsActor<ApplicationConfig>,
|
||||||
val executors: KobaltExecutors, val nativeManager: NativeManager,
|
val executors: KobaltExecutors, val nativeManager: NativeManager,
|
||||||
val dependencyManager: DependencyManager, val taskContributor : TaskContributor, val jvm: Jvm)
|
val dependencyManager: DependencyManager, val taskContributor : TaskContributor, val jvm: Jvm)
|
||||||
: BasePlugin(), IRunnerContributor, ITaskContributor, IConfigActor<ApplicationConfig> by configActor {
|
: BasePlugin(), ITaskContributor, IConfigsActor<ApplicationConfig> by configActor {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PLUGIN_NAME = "Application"
|
const val PLUGIN_NAME = "Application"
|
||||||
|
@ -56,49 +57,52 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
|
||||||
|
|
||||||
override fun apply(project: Project, context: KobaltContext) {
|
override fun apply(project: Project, context: KobaltContext) {
|
||||||
super.apply(project, context)
|
super.apply(project, context)
|
||||||
taskContributor.addVariantTasks(this, project, context, "run", group = "run", dependsOn = listOf("install"),
|
// taskContributor.addVariantTasks(this, project, context, "run", group = "run", dependsOn = listOf("install"),
|
||||||
runTask = { taskRun(project) })
|
// runTask = { taskRun(project) })
|
||||||
}
|
|
||||||
|
|
||||||
@Task(name = "run", description = "Run the main class", group = "run", dependsOn = arrayOf("install"))
|
configurationFor(project)?.let { configs ->
|
||||||
fun taskRun(project: Project): TaskResult {
|
configs.forEach { config ->
|
||||||
val runContributor = ActorUtils.selectAffinityActor(project, context,
|
taskManager.addTask(this, project, config.taskName,
|
||||||
context.pluginInfo.runnerContributors)
|
description = "Run the class " + config.mainClass,
|
||||||
if (runContributor != null && runContributor.affinity(project, context) > 0) {
|
group = "run",
|
||||||
return runContributor.run(project, context,
|
dependsOn = listOf("install"),
|
||||||
dependencyManager.dependencies(project, context, listOf(Scope.RUNTIME)))
|
task = { run(project, context, config) })
|
||||||
} 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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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<PackageConfig>, jarName: String): Boolean {
|
private fun isFatJar(packages: List<PackageConfig>, jarName: String): Boolean {
|
||||||
val foundJar = packages.flatMap { it.jars }.filter { jarName.endsWith(it.name) }
|
val foundJar = packages.flatMap { it.jars }.filter { jarName.endsWith(it.name) }
|
||||||
return foundJar.size == 1 && foundJar[0].fatJar
|
return foundJar.size == 1 && foundJar[0].fatJar
|
||||||
}
|
}
|
||||||
|
|
||||||
// IRunContributor
|
private fun run(project: Project, context: KobaltContext, config: ApplicationConfig): TaskResult {
|
||||||
|
|
||||||
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<IClasspathDependency>): TaskResult {
|
|
||||||
var result = TaskResult()
|
|
||||||
if (project.nativeDependencies.any()) {
|
if (project.nativeDependencies.any()) {
|
||||||
nativeManager.installLibraries(project)
|
nativeManager.installLibraries(project)
|
||||||
}
|
}
|
||||||
configurationFor(project)?.let { config ->
|
|
||||||
|
val result =
|
||||||
if (config.mainClass != null) {
|
if (config.mainClass != null) {
|
||||||
result = runJarFile(project, context, config)
|
runJarFile(project, context, config)
|
||||||
} else {
|
} else {
|
||||||
throw KobaltException("No \"mainClass\" specified in the application{} part of project ${project.name}")
|
throw KobaltException("No \"mainClass\" specified in the application{} part of project ${project.name}")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue