mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Support flavors with the "run" task.
This commit is contained in:
parent
c708b4e730
commit
5dc0cc44ea
4 changed files with 36 additions and 30 deletions
|
@ -1,7 +1,9 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.beust.kobalt.Plugins
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.internal.TaskManager
|
||||
import com.beust.kobalt.internal.Variant
|
||||
import java.util.*
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
|
@ -23,4 +25,26 @@ abstract public class BasePlugin : IPlugin {
|
|||
fun addProject(project: Project, dependsOn: Array<out Project>) {
|
||||
projects.add(ProjectDescription(project, dependsOn.toList()))
|
||||
}
|
||||
|
||||
/**
|
||||
* Register dynamic tasks corresponding to the variants found in the project,e.g. assembleDevDebug,
|
||||
* assembleDevRelease, etc...
|
||||
*/
|
||||
protected fun addVariantTasks(project: Project, taskName: String, runAfter : List<String>,
|
||||
runTask: (Project) -> TaskResult) {
|
||||
project.productFlavors.keys.forEach { pf ->
|
||||
project.buildTypes.keys.forEach { bt ->
|
||||
val variant = Variant(pf, bt)
|
||||
val taskName = variant.toTask(taskName)
|
||||
addTask(project, taskName, taskName,
|
||||
runAfter = runAfter.map { variant.toTask(it) },
|
||||
task = { p: Project ->
|
||||
context.variant = Variant(pf, bt)
|
||||
runTask(project)
|
||||
TaskResult()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,18 +53,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
super.apply(project, context)
|
||||
project.projectProperties.put(BUILD_DIR, project.buildDirectory + File.separator + "classes")
|
||||
project.projectProperties.put(DEPENDENT_PROJECTS, projects())
|
||||
|
||||
project.productFlavors.keys.forEach { pf ->
|
||||
project.buildTypes.keys.forEach { bt ->
|
||||
val taskName = Variant(pf, bt).toTask("compile")
|
||||
addTask(project, taskName, "Compile $taskName",
|
||||
task = { p: Project ->
|
||||
context.variant = Variant(pf, bt)
|
||||
taskCompile(project)
|
||||
TaskResult()
|
||||
})
|
||||
}
|
||||
}
|
||||
addVariantTasks(project, "compile", emptyList(), { taskCompile(project) })
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.beust.kobalt.plugin.application
|
|||
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.api.ConfigPlugin
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.api.ProjectDescription
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
|
@ -42,6 +43,11 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
|
|||
|
||||
override val name = NAME
|
||||
|
||||
override fun apply(project: Project, context: KobaltContext) {
|
||||
super.apply(project, context)
|
||||
addVariantTasks(project, "run", listOf("assemble"), { taskRun(project) })
|
||||
}
|
||||
|
||||
@Task(name = "run", description = "Run the main class", runAfter = arrayOf("assemble"))
|
||||
fun taskRun(project: Project): TaskResult {
|
||||
var result = TaskResult()
|
||||
|
|
|
@ -13,7 +13,6 @@ import com.beust.kobalt.api.annotation.ExportedProjectProperty
|
|||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.glob
|
||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||
import com.beust.kobalt.internal.Variant
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
|
@ -61,21 +60,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
override fun apply(project: Project, context: KobaltContext) {
|
||||
super.apply(project, context)
|
||||
project.projectProperties.put(LIBS_DIR, libsDir(project))
|
||||
|
||||
|
||||
project.productFlavors.keys.forEach { pf ->
|
||||
project.buildTypes.keys.forEach { bt ->
|
||||
val variant = Variant(pf, bt)
|
||||
val taskName = variant.toTask("assemble")
|
||||
addTask(project, taskName, "Assemble $taskName",
|
||||
runAfter = listOf(variant.toTask("compile")),
|
||||
task = { p: Project ->
|
||||
context.variant = Variant(pf, bt)
|
||||
taskAssemble(project)
|
||||
TaskResult()
|
||||
})
|
||||
}
|
||||
}
|
||||
addVariantTasks(project, "assemble", listOf("compile"), { taskAssemble(project) })
|
||||
}
|
||||
|
||||
private fun libsDir(project: Project) = KFiles.makeDir(buildDir(project).path, "libs").path
|
||||
|
@ -210,8 +195,10 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
val fromPath = directory + "/" + includedFile.from
|
||||
if (File(fromPath).exists()) {
|
||||
spec.toFiles(fromPath).forEach { file ->
|
||||
if (!File(fromPath, file.path).exists()) {
|
||||
throw AssertionError("File should exist: $file")
|
||||
File(fromPath, file.path).let {
|
||||
if (! it.exists()) {
|
||||
throw AssertionError("File should exist: $it")
|
||||
}
|
||||
}
|
||||
|
||||
if (!isExcluded(file, excludes)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue