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.*
|
||||
|
||||
val bs = buildScript {
|
||||
plugins("net.thauvin.erik:kobalt-property-file:")
|
||||
plugins("net.thauvin.erik:kobalt-property-file:0.9.1")
|
||||
}
|
||||
|
||||
val p = project {
|
||||
|
@ -92,6 +92,43 @@ The rules used when setting a property value are:
|
|||
|
||||
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)
|
||||
|
||||
* 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 net.thauvin.erik.kobalt.plugin.propertyfile.*
|
||||
|
||||
// ./kobaltw propertyFile
|
||||
// ./kobaltw propertyFile antExamples
|
||||
|
||||
val bs = buildScript {
|
||||
//repos(file("K:/maven/repository"))
|
||||
plugins("net.thauvin.erik:kobalt-property-file:")
|
||||
repos(localMaven())
|
||||
plugins("net.thauvin.erik:kobalt-property-file:0.9.1")
|
||||
}
|
||||
|
||||
val p = project {
|
||||
|
@ -52,6 +52,17 @@ val p = project {
|
|||
// Set date to now, then add a month
|
||||
entry(key = "date.nextMonth", value = "now", type = Types.DATE)
|
||||
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
|
||||
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.publish.autoGitTag
|
||||
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 org.apache.maven.model.*
|
||||
|
||||
val semver = "0.9.0"
|
||||
import org.apache.maven.model.Developer
|
||||
import org.apache.maven.model.License
|
||||
import org.apache.maven.model.Model
|
||||
import org.apache.maven.model.Scm
|
||||
|
||||
val bs = buildScript {
|
||||
repos(file("k:/maven/repository"))
|
||||
repos(localMaven())
|
||||
plugins("net.thauvin.erik:kobalt-versioneye:", "net.thauvin.erik:kobalt-maven-local:")
|
||||
}
|
||||
|
||||
|
@ -19,7 +23,7 @@ val p = project {
|
|||
name = "kobalt-property-file"
|
||||
group = "net.thauvin.erik"
|
||||
artifactId = name
|
||||
version = semver
|
||||
version = "0.9.1"
|
||||
|
||||
pom = Model().apply {
|
||||
description = "PropertyFile plug-in for the Kobalt build system."
|
||||
|
@ -41,7 +45,8 @@ val p = project {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile("com.beust:$kobaltDependency:")
|
||||
compileOnly("com.beust:$kobaltDependency:")
|
||||
compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.2-4")
|
||||
}
|
||||
|
||||
dependenciesTest {
|
||||
|
|
|
@ -35,7 +35,6 @@ 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.misc.error
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.google.inject.Inject
|
||||
|
@ -46,9 +45,9 @@ import java.nio.file.Paths
|
|||
import java.util.*
|
||||
|
||||
@Singleton
|
||||
class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<PropertyFileConfig>,
|
||||
val taskContributor: TaskContributor) :
|
||||
BasePlugin(), ITaskContributor, IConfigActor<PropertyFileConfig> by configActor {
|
||||
class PropertyFilePlugin @Inject constructor(val taskContributor: TaskContributor,
|
||||
val configActor: ConfigsActor<PropertyFileConfig>) :
|
||||
BasePlugin(), ITaskContributor, IConfigsActor<PropertyFileConfig> by configActor {
|
||||
|
||||
// ITaskContributor
|
||||
override fun tasksFor(project: Project, context: KobaltContext): List<DynamicTask> {
|
||||
|
@ -62,65 +61,71 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor<Proper
|
|||
override val name = NAME
|
||||
|
||||
override fun apply(project: Project, context: KobaltContext) {
|
||||
super.apply(project, context)
|
||||
taskContributor.addVariantTasks(this, project, context, NAME, group = "other",
|
||||
runTask = { propertyFile(project) })
|
||||
configurationFor(project)?.let { configs ->
|
||||
configs.forEach { config ->
|
||||
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(project: Project): TaskResult {
|
||||
configurationFor(project)?.let { config ->
|
||||
if (config.file.isBlank()) {
|
||||
error("Please specify a property file name.")
|
||||
return TaskResult(!config.failOnWarning)
|
||||
} else {
|
||||
// Load properties
|
||||
val p = Properties()
|
||||
Paths.get(config.file).let { path ->
|
||||
if (path.toFile().exists()) {
|
||||
Files.newInputStream(path).use {
|
||||
p.load(it)
|
||||
}
|
||||
fun propertyFile(config: PropertyFileConfig): TaskResult {
|
||||
if (config.file.isBlank()) {
|
||||
error("Please specify a property file name.")
|
||||
return TaskResult(!config.failOnWarning)
|
||||
} else {
|
||||
// Load properties
|
||||
val p = Properties()
|
||||
Paths.get(config.file).let { path ->
|
||||
if (path.toFile().exists()) {
|
||||
Files.newInputStream(path).use {
|
||||
p.load(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var success = true
|
||||
var success = true
|
||||
|
||||
// Process entries
|
||||
config.entries.forEach { entry ->
|
||||
if (entry.key.isBlank()) {
|
||||
error("An entry key must be specified.")
|
||||
success = false
|
||||
} else {
|
||||
with(entry) {
|
||||
if (value == null && default == null && operation != Operations.DELETE) {
|
||||
warn("An entry value or default must be specified: $key")
|
||||
success = false
|
||||
} else if (type == Types.STRING && (operation == Operations.SUBTRACT)) {
|
||||
warn("Subtraction is not supported for String properties: $key")
|
||||
success = false
|
||||
} else if (operation == Operations.DELETE) {
|
||||
p.remove(entry.key)
|
||||
} else {
|
||||
when (type) {
|
||||
Types.DATE -> success = Utils.processDate(p, entry)
|
||||
Types.INT -> success = Utils.processInt(p, entry)
|
||||
else -> success = Utils.processString(p, entry)
|
||||
}
|
||||
// Process entries
|
||||
config.entries.forEach { entry ->
|
||||
if (entry.key.isBlank()) {
|
||||
error("An entry key must be specified.")
|
||||
success = false
|
||||
} else {
|
||||
with(entry) {
|
||||
if (value == null && default == null && operation != Operations.DELETE) {
|
||||
warn("An entry value or default must be specified: $key")
|
||||
success = false
|
||||
} else if (type == Types.STRING && (operation == Operations.SUBTRACT)) {
|
||||
warn("Subtraction is not supported for String properties: $key")
|
||||
success = false
|
||||
} else if (operation == Operations.DELETE) {
|
||||
p.remove(entry.key)
|
||||
} else {
|
||||
when (type) {
|
||||
Types.DATE -> success = Utils.processDate(p, entry)
|
||||
Types.INT -> success = Utils.processInt(p, entry)
|
||||
else -> success = Utils.processString(p, entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.failOnWarning && !success) {
|
||||
return TaskResult(success)
|
||||
}
|
||||
}
|
||||
|
||||
// Save properties
|
||||
FileOutputStream(config.file).use { output ->
|
||||
p.store(output, config.comment)
|
||||
if (config.failOnWarning && !success) {
|
||||
return TaskResult(success)
|
||||
}
|
||||
}
|
||||
|
||||
// Save properties
|
||||
FileOutputStream(config.file).use { output ->
|
||||
p.store(output, config.comment)
|
||||
}
|
||||
}
|
||||
|
||||
return TaskResult()
|
||||
|
@ -150,10 +155,12 @@ data class Entry(
|
|||
|
||||
@Directive
|
||||
class PropertyFileConfig {
|
||||
var taskName: String = "propertyFile"
|
||||
var file: String = ""
|
||||
var comment: String? = null
|
||||
var failOnWarning: Boolean = false
|
||||
val entries = arrayListOf<Entry>()
|
||||
var dependsOn = listOf<String>()
|
||||
|
||||
@Suppress("unused")
|
||||
fun entry(
|
||||
|
|
|
@ -35,7 +35,7 @@ import com.beust.kobalt.misc.warn
|
|||
import java.text.*
|
||||
import java.util.*
|
||||
|
||||
class Utils {
|
||||
class Utils private constructor() {
|
||||
companion object {
|
||||
private val calendarFields = mapOf(
|
||||
Units.MILLISECOND to Calendar.MILLISECOND,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue