Added taskName and dependsOn parameters.
This commit is contained in:
parent
9d78094586
commit
2517aabd97
6 changed files with 159 additions and 62 deletions
39
README.md
39
README.md
|
@ -8,7 +8,7 @@ The PropertyFile plug-in provides an optional task for editing [property files](
|
||||||
import net.thauvin.erik.kobalt.plugin.propertyfile.*
|
import net.thauvin.erik.kobalt.plugin.propertyfile.*
|
||||||
|
|
||||||
val bs = buildScript {
|
val bs = buildScript {
|
||||||
plugins("net.thauvin.erik:kobalt-property-file:")
|
plugins("net.thauvin.erik:kobalt-property-file:0.9.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
val p = project {
|
val p = project {
|
||||||
|
@ -92,6 +92,43 @@ The rules used when setting a property value are:
|
||||||
|
|
||||||
Operations occur after the rules are evaluated.
|
Operations occur after the rules are evaluated.
|
||||||
|
|
||||||
|
|
||||||
|
## taskName
|
||||||
|
|
||||||
|
Additionally, you can specify a task name to easily identify multiple `propertyFile` tasks.
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
propertyFile {
|
||||||
|
taskName = "updateMinor"
|
||||||
|
file = "version.properties"
|
||||||
|
entry(key = "product.build.minor", type = Types.INT, operation = Operations.ADD)
|
||||||
|
}
|
||||||
|
|
||||||
|
propertyFile {
|
||||||
|
taskName = "updatePatch"
|
||||||
|
file = "version.properties"
|
||||||
|
entry(key = "product.build.patch", type = Types.INT, operation = Operations.ADD)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./kobaltw updateMinor
|
||||||
|
./kobaltw updatePatch
|
||||||
|
```
|
||||||
|
|
||||||
|
## dependsOn
|
||||||
|
|
||||||
|
|
||||||
|
By default the `propertyFile` task has no dependencies, use the `dependsOn` parameter to change the dependencies:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
propertyFile {
|
||||||
|
dependsOn = listOf("assemble", "run")
|
||||||
|
file = "version.properties"
|
||||||
|
entry(key = "product.build.date" , type = Types.DATE, value = "now")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Differences with the [ant PropertyFile task](https://ant.apache.org/manual/Tasks/propertyfile.html)
|
## Differences with the [ant PropertyFile task](https://ant.apache.org/manual/Tasks/propertyfile.html)
|
||||||
|
|
||||||
* The comments and layout of the original property file will not be preserved.
|
* The comments and layout of the original property file will not be preserved.
|
||||||
|
|
37
clean.sh
Normal file
37
clean.sh
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
DEBUG=false
|
||||||
|
|
||||||
|
rm="rm -rf"
|
||||||
|
|
||||||
|
if [ "$DEBUG" = true ]; then
|
||||||
|
rm="echo rm -rf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
buildkt="kobalt/src/Build.kt"
|
||||||
|
|
||||||
|
name=$(cat $buildkt | grep -m 1 "name = " | cut -d"\"" -f 2)
|
||||||
|
group=$(cat $buildkt | grep -m 1 "group = " | cut -d"\"" -f 2)
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
version=$(cat $buildkt | grep -m 1 "version = " | cut -d"\"" -f 2)
|
||||||
|
else
|
||||||
|
version="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
maven="/k/maven/repository/${group//.//}/${name}/${version}"
|
||||||
|
kobalt="$HOME/.kobalt/cache/${group//.//}/${name}/${version}"
|
||||||
|
localRepo="$HOME/.kobalt/localMavenRepo/${group//.//}/${name}/${version}"
|
||||||
|
|
||||||
|
read -p "Delete version ${version}? " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
for dir in "$kobalt" "$maven" "$localRepo"; do
|
||||||
|
if [ -d "$dir" ]; then
|
||||||
|
echo -e "Deleting : \e[32;1m$dir\e[0m"
|
||||||
|
$rm "$dir"
|
||||||
|
else
|
||||||
|
echo -e "Not Found: \e[31;1m$dir\e[0m"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
|
@ -4,11 +4,11 @@ import com.beust.kobalt.plugin.application.*
|
||||||
import com.beust.kobalt.plugin.kotlin.*
|
import com.beust.kobalt.plugin.kotlin.*
|
||||||
import net.thauvin.erik.kobalt.plugin.propertyfile.*
|
import net.thauvin.erik.kobalt.plugin.propertyfile.*
|
||||||
|
|
||||||
// ./kobaltw propertyFile
|
// ./kobaltw propertyFile antExamples
|
||||||
|
|
||||||
val bs = buildScript {
|
val bs = buildScript {
|
||||||
//repos(file("K:/maven/repository"))
|
repos(localMaven())
|
||||||
plugins("net.thauvin.erik:kobalt-property-file:")
|
plugins("net.thauvin.erik:kobalt-property-file:0.9.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
val p = project {
|
val p = project {
|
||||||
|
@ -52,6 +52,17 @@ val p = project {
|
||||||
// Set date to now, then add a month
|
// Set date to now, then add a month
|
||||||
entry(key = "date.nextMonth", value = "now", type = Types.DATE)
|
entry(key = "date.nextMonth", value = "now", type = Types.DATE)
|
||||||
entry(key = "date.nextMonth", value = "0", type = Types.DATE, unit = Units.MONTH, operation = Operations.ADD)
|
entry(key = "date.nextMonth", value = "0", type = Types.DATE, unit = Units.MONTH, operation = Operations.ADD)
|
||||||
|
}
|
||||||
|
|
||||||
|
propertyFile {
|
||||||
|
// task name
|
||||||
|
taskName = "antExamples"
|
||||||
|
|
||||||
|
// dependencies
|
||||||
|
dependsOn = listOf("run")
|
||||||
|
|
||||||
|
// parameters
|
||||||
|
file = "version.properties"
|
||||||
|
|
||||||
// Examples from: https://ant.apache.org/manual/Tasks/propertyfile.html
|
// Examples from: https://ant.apache.org/manual/Tasks/propertyfile.html
|
||||||
entry(key = "akey", value = "avalue")
|
entry(key = "akey", value = "avalue")
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
import com.beust.kobalt.*
|
import com.beust.kobalt.buildScript
|
||||||
|
import com.beust.kobalt.localMaven
|
||||||
import com.beust.kobalt.plugin.packaging.assemble
|
import com.beust.kobalt.plugin.packaging.assemble
|
||||||
import com.beust.kobalt.plugin.publish.autoGitTag
|
import com.beust.kobalt.plugin.publish.autoGitTag
|
||||||
import com.beust.kobalt.plugin.publish.bintray
|
import com.beust.kobalt.plugin.publish.bintray
|
||||||
|
import com.beust.kobalt.profile
|
||||||
|
import com.beust.kobalt.project
|
||||||
import net.thauvin.erik.kobalt.plugin.versioneye.versionEye
|
import net.thauvin.erik.kobalt.plugin.versioneye.versionEye
|
||||||
import org.apache.maven.model.*
|
import org.apache.maven.model.Developer
|
||||||
|
import org.apache.maven.model.License
|
||||||
val semver = "0.9.0"
|
import org.apache.maven.model.Model
|
||||||
|
import org.apache.maven.model.Scm
|
||||||
|
|
||||||
val bs = buildScript {
|
val bs = buildScript {
|
||||||
repos(file("k:/maven/repository"))
|
repos(localMaven())
|
||||||
plugins("net.thauvin.erik:kobalt-versioneye:", "net.thauvin.erik:kobalt-maven-local:")
|
plugins("net.thauvin.erik:kobalt-versioneye:", "net.thauvin.erik:kobalt-maven-local:")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +23,7 @@ val p = project {
|
||||||
name = "kobalt-property-file"
|
name = "kobalt-property-file"
|
||||||
group = "net.thauvin.erik"
|
group = "net.thauvin.erik"
|
||||||
artifactId = name
|
artifactId = name
|
||||||
version = semver
|
version = "0.9.1"
|
||||||
|
|
||||||
pom = Model().apply {
|
pom = Model().apply {
|
||||||
description = "PropertyFile plug-in for the Kobalt build system."
|
description = "PropertyFile plug-in for the Kobalt build system."
|
||||||
|
@ -41,7 +45,8 @@ val p = project {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile("com.beust:$kobaltDependency:")
|
compileOnly("com.beust:$kobaltDependency:")
|
||||||
|
compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.2-4")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependenciesTest {
|
dependenciesTest {
|
||||||
|
|
|
@ -35,7 +35,6 @@ 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.misc.error
|
import com.beust.kobalt.misc.error
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
@ -46,9 +45,9 @@ import java.nio.file.Paths
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<PropertyFileConfig>,
|
class PropertyFilePlugin @Inject constructor(val taskContributor: TaskContributor,
|
||||||
val taskContributor: TaskContributor) :
|
val configActor: ConfigsActor<PropertyFileConfig>) :
|
||||||
BasePlugin(), ITaskContributor, IConfigActor<PropertyFileConfig> by configActor {
|
BasePlugin(), ITaskContributor, IConfigsActor<PropertyFileConfig> by configActor {
|
||||||
|
|
||||||
// ITaskContributor
|
// ITaskContributor
|
||||||
override fun tasksFor(project: Project, context: KobaltContext): List<DynamicTask> {
|
override fun tasksFor(project: Project, context: KobaltContext): List<DynamicTask> {
|
||||||
|
@ -62,14 +61,21 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<Proper
|
||||||
override val name = NAME
|
override val name = NAME
|
||||||
|
|
||||||
override fun apply(project: Project, context: KobaltContext) {
|
override fun apply(project: Project, context: KobaltContext) {
|
||||||
super.apply(project, context)
|
configurationFor(project)?.let { configs ->
|
||||||
taskContributor.addVariantTasks(this, project, context, NAME, group = "other",
|
configs.forEach { config ->
|
||||||
runTask = { propertyFile(project) })
|
taskManager.addTask(this, project, config.taskName,
|
||||||
|
description = "Edit a property file.",
|
||||||
|
group = "Other",
|
||||||
|
dependsOn = config.dependsOn,
|
||||||
|
task = { propertyFile(config) })
|
||||||
|
taskContributor.addVariantTasks(this, project, context, config.taskName,
|
||||||
|
dependsOn = config.dependsOn,
|
||||||
|
runTask = { propertyFile(config) })
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Task(name = "propertyFile", description = "Edit a property file.")
|
fun propertyFile(config: PropertyFileConfig): TaskResult {
|
||||||
fun propertyFile(project: Project): TaskResult {
|
|
||||||
configurationFor(project)?.let { config ->
|
|
||||||
if (config.file.isBlank()) {
|
if (config.file.isBlank()) {
|
||||||
error("Please specify a property file name.")
|
error("Please specify a property file name.")
|
||||||
return TaskResult(!config.failOnWarning)
|
return TaskResult(!config.failOnWarning)
|
||||||
|
@ -121,7 +127,6 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<Proper
|
||||||
p.store(output, config.comment)
|
p.store(output, config.comment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return TaskResult()
|
return TaskResult()
|
||||||
}
|
}
|
||||||
|
@ -150,10 +155,12 @@ data class Entry(
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
class PropertyFileConfig {
|
class PropertyFileConfig {
|
||||||
|
var taskName: String = "propertyFile"
|
||||||
var file: String = ""
|
var file: String = ""
|
||||||
var comment: String? = null
|
var comment: String? = null
|
||||||
var failOnWarning: Boolean = false
|
var failOnWarning: Boolean = false
|
||||||
val entries = arrayListOf<Entry>()
|
val entries = arrayListOf<Entry>()
|
||||||
|
var dependsOn = listOf<String>()
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
fun entry(
|
fun entry(
|
||||||
|
|
|
@ -35,7 +35,7 @@ import com.beust.kobalt.misc.warn
|
||||||
import java.text.*
|
import java.text.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class Utils {
|
class Utils private constructor() {
|
||||||
companion object {
|
companion object {
|
||||||
private val calendarFields = mapOf(
|
private val calendarFields = mapOf(
|
||||||
Units.MILLISECOND to Calendar.MILLISECOND,
|
Units.MILLISECOND to Calendar.MILLISECOND,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue