tidy up dockerActive property & check
This commit is contained in:
parent
562296aa96
commit
002aa9b5fb
3 changed files with 28 additions and 9 deletions
|
|
@ -2,9 +2,11 @@ package dev.adamko.geedeecee
|
||||||
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.file.DirectoryProperty
|
import org.gradle.api.file.DirectoryProperty
|
||||||
import org.gradle.api.logging.LogLevel
|
import org.gradle.api.logging.LogLevel
|
||||||
import org.gradle.api.provider.ListProperty
|
import org.gradle.api.provider.ListProperty
|
||||||
|
import org.gradle.api.provider.Property
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
import org.gradle.api.tasks.InputDirectory
|
import org.gradle.api.tasks.InputDirectory
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
|
@ -15,19 +17,26 @@ abstract class GDCCommandTask @Inject constructor(
|
||||||
private val executor: ExecOperations
|
private val executor: ExecOperations
|
||||||
) : DefaultTask() {
|
) : DefaultTask() {
|
||||||
|
|
||||||
init {
|
|
||||||
super.setGroup(GDCPlugin.GCD_TASK_GROUP)
|
|
||||||
description = "Run a docker-compose command."
|
|
||||||
|
|
||||||
logging.captureStandardOutput(LogLevel.LIFECYCLE)
|
|
||||||
}
|
|
||||||
|
|
||||||
@get:InputDirectory
|
@get:InputDirectory
|
||||||
abstract val workingDir: DirectoryProperty
|
abstract val workingDir: DirectoryProperty
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
abstract val separatedArgs: ListProperty<String>
|
abstract val separatedArgs: ListProperty<String>
|
||||||
|
|
||||||
|
@get:Input
|
||||||
|
abstract val dockerActive: Property<Boolean>
|
||||||
|
|
||||||
|
init {
|
||||||
|
super.setGroup(GDCPlugin.GCD_TASK_GROUP)
|
||||||
|
description = "Run a docker-compose command."
|
||||||
|
|
||||||
|
enabledIf {
|
||||||
|
it.dockerActive.orNull == true
|
||||||
|
}
|
||||||
|
|
||||||
|
logging.captureStandardOutput(LogLevel.LIFECYCLE)
|
||||||
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun dockerCompose() {
|
fun dockerCompose() {
|
||||||
val separatedArgs: List<String> = separatedArgs.get()
|
val separatedArgs: List<String> = separatedArgs.get()
|
||||||
|
|
@ -45,4 +54,13 @@ abstract class GDCCommandTask @Inject constructor(
|
||||||
parseSpaceSeparatedArgs("docker-compose $args")
|
parseSpaceSeparatedArgs("docker-compose $args")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private inline fun <reified T: Task> T.enabledIf(crossinline spec: (T) -> Boolean) {
|
||||||
|
onlyIf {
|
||||||
|
require(it is T)
|
||||||
|
spec(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ abstract class GDCPlugin @Inject constructor(
|
||||||
target.tasks.withType<GDCCommandTask>().configureEach {
|
target.tasks.withType<GDCCommandTask>().configureEach {
|
||||||
workingDir.convention(gdcSettings.srcDir)
|
workingDir.convention(gdcSettings.srcDir)
|
||||||
dependsOn(dockerComposeEnvUpdate)
|
dependsOn(dockerComposeEnvUpdate)
|
||||||
|
dockerActive.set(gdcSettings.dockerActive)
|
||||||
}
|
}
|
||||||
|
|
||||||
val assembleTasks = target.tasks.matching { LifecycleBasePlugin.ASSEMBLE_TASK_NAME == it.name }
|
val assembleTasks = target.tasks.matching { LifecycleBasePlugin.ASSEMBLE_TASK_NAME == it.name }
|
||||||
|
|
@ -89,7 +90,7 @@ abstract class GDCPlugin @Inject constructor(
|
||||||
dotEnv.put("KAFKATORIO_VERSION", composeProjectVersion)
|
dotEnv.put("KAFKATORIO_VERSION", composeProjectVersion)
|
||||||
dotEnv.put("REGISTRY_HOST", containerRegistryHost)
|
dotEnv.put("REGISTRY_HOST", containerRegistryHost)
|
||||||
|
|
||||||
enabled.convention(isDockerActive())
|
dockerActive.convention(isDockerActive())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ interface GDCSettings {
|
||||||
val dotEnv: MapProperty<String, String>
|
val dotEnv: MapProperty<String, String>
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
val enabled: Property<Boolean>
|
val dockerActive: Property<Boolean>
|
||||||
|
|
||||||
// @Suppress("PropertyName", "FunctionName")
|
// @Suppress("PropertyName", "FunctionName")
|
||||||
// abstract class DotEnv(
|
// abstract class DotEnv(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue