From 90605dcafc8dcc54fb536dbdb7b8d4cce7b87860 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 18 Apr 2017 16:01:54 -0700 Subject: [PATCH] Added failOnWarning parameter. --- README.md | 10 ++-- .../plugin/propertyfile/PropertyFilePlugin.kt | 52 ++++++++++--------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 0739a5d..79f3964 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,11 @@ To invoke the `propertyFile` task: ## Parameters -Attribute | Description | Required -:---------|:--------------------------------------------------------|:-------- -`file` | The location of the property files to edit. | Yes -`comment` | Comment to be inserted at the top of the property file. | No +Attribute | Description | Required +:---------------|:--------------------------------------------------------|:-------- +`file` | The location of the property files to edit. | Yes +`comment` | Comment to be inserted at the top of the property file. | No +`failOnWarning` | If set to `true`, the task will fail on any warnings. | No ## Entry @@ -94,4 +95,5 @@ Operations occur after the rules are evaluated. ## 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 `jdkproperties` parameter is not implemented. * The default `Types.DATE` pattern is `yyyy-MM-dd HH:mm` and not `yyyy/MM/dd HH:mm`. \ No newline at end of file diff --git a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/propertyfile/PropertyFilePlugin.kt b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/propertyfile/PropertyFilePlugin.kt index 7d9bbab..6dcdc14 100644 --- a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/propertyfile/PropertyFilePlugin.kt +++ b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/propertyfile/PropertyFilePlugin.kt @@ -83,7 +83,7 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor if (config.file.isBlank()) { error("Please specify a property file name.") - return TaskResult() + return TaskResult(!config.failOnWarning) } else { // Load properties val p = Properties() @@ -95,34 +95,35 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor if (entry.key.isBlank()) { error("An entry key must be specified.") - return TaskResult() + 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 -> result = processDate(p, entry) - Types.INT -> result = processInt(p, entry) - else -> result = processString(p, entry) + Types.DATE -> success = processDate(p, entry) + Types.INT -> success = processInt(p, entry) + else -> success = processString(p, entry) } } } } - // @TODO maybe just warn and keep on going? - if (!result.success) { - return result + if (config.failOnWarning && !success) { + return TaskResult(success) } } @@ -136,15 +137,12 @@ class PropertyFilePlugin @Inject constructor(val configActor: ConfigActor): String { + private fun currentValue(value: String?, newValue: String?, default: String?, operation: Operations): String { var result: String? = null if (operation == Operations.SET) { @@ -273,7 +276,7 @@ data class Entry( var value: String? = null, var default: String? = null, var type: Types = Types.STRING, - var operation: Enum = Operations.SET, + var operation: Operations = Operations.SET, var pattern: String = "", var unit: Units = Units.DAY) @@ -281,6 +284,7 @@ data class Entry( class PropertyFileConfig { var file: String = "" var comment: String? = null + var failOnWarning: Boolean = false val entries = arrayListOf() @Suppress("unused") @@ -289,7 +293,7 @@ class PropertyFileConfig { value: String? = null, default: String? = null, type: Types = Types.STRING, - operation: Enum = Operations.SET, + operation: Operations = Operations.SET, pattern: String = "", unit: Units = Units.DAY) { if (key.isNotEmpty()) entries.add(Entry(key, value, default, type, operation, pattern, unit))