From 639f43893eb07648ae7a93e6e6cfe9ff5f8a5198 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 18 Apr 2017 09:31:57 -0700 Subject: [PATCH] More cleanup. --- README.md | 46 ++++++++++--------- example/kobalt/src/Build.kt | 6 ++- .../plugin/propertyfile/PropertyFilePlugin.kt | 1 - 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 176f8ad..0739a5d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PropertyFile plug-in for [Kobalt](http://beust.com/kobalt/home/index.html) -[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![Build Status](https://travis-ci.org/ethauvin/kobalt-property-file.svg?branch=master)](https://travis-ci.org/ethauvin/kobalt-property-file) +[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![Build Status](https://travis-ci.org/ethauvin/kobalt-property-file.svg?branch=master)](https://travis-ci.org/ethauvin/kobalt-property-file) The PropertyFile plug-in provides an optional task for editing [property files](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html). It is inspired by the [ant PropertyFile task](https://ant.apache.org/manual/Tasks/propertyfile.html). @@ -17,9 +17,9 @@ val p = project { propertyFile { file = "version.properties" comment = "##Generated file - do not modify!" - entry(key = "product.build.major", type = Types.INT, value = "3") + entry(key = "product.build.major", value = "3") entry(key = "product.build.minor", type = Types.INT, operation = Operations.ADD) - entry(key = "product.build.patch", type = Types.INT, value = "0") + entry(key = "product.build.patch", value = "0") entry(key = "product.build.date" , type = Types.DATE, value = "now") } } @@ -41,17 +41,19 @@ Attribute | Description | Required ## Entry -The `entry` function is used to specify modifications to be made to the property file. +The `entry` function is used to specify edits to be made to the property file. -Attribute | Description | Required -:-----------|:----------------------------------------------------------------------------------------------------------------- |:---------------------------------------------- -`key` | The name of the property name/value pair. | Yes, unless `operation` is `Operations.DELETE` -`value` | The value of the property. | Yes, unless `operation` is `Operations.DELETE` -`default` | The initial value to set for the property if not already defined. For `Type.DATE`, the `now` keyword can be used. | Yes, unless `operation` is `Operations.DELETE` -`type` | Tread the value as `Types.INT`, `Types.DATE`, or `Types.STRING` (default). | No -`operation` | See [operations](#operations). | No -`pattern` | For `Types.INT` and `Types.DATE` only. If present, will parse the value as [DecimalFormat](https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html) or [SimpleDateFormat](https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html) patterns, respectively. | No -`unit` | The unit value to be applied to `Operations.ADD` and `Operations.SUBTRACT` for `Types.DATE`. See [Units](#units). | No +Attribute | Description +:-----------|:----------------------------------------------------------------------------------------------------------------- +`key` | The name of the property name/value pair. +`value` | The value of the property. +`default` | The initial value to set for the property if not already defined. For `Type.DATE`, the `now` keyword can be used. +`type` | Tread the value as `Types.INT`, `Types.DATE`, or `Types.STRING`. If none specified, `Types.STRING` is assumed. +`operation` | See [operations](#operations). +`pattern` | For `Types.INT` and `Types.DATE` only. If present, will parse the value as [DecimalFormat](https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html) or [SimpleDateFormat](https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html) patterns, respectively. +`unit` | The unit value to be applied to `Operations.ADD` and `Operations.SUBTRACT` for `Types.DATE`. See [Units](#units). + +`key` is required. `value` or `default` are required unless the `operation` is `Operations.DELETE`. ## Operations @@ -61,21 +63,21 @@ Operation | Description :---------------------|:------------------------------------------------------------------------- `Operations.ADD` | Adds a value to an entry. `Operations.DELETE` | Deletes an entry. -`Operations.SET` | Sets the entry value. This is the default. +`Operations.SET` | Sets the entry value. This is the default operation. `Operations.SUBTRACT` | Subtracts a value from the entry. For `Types.INT` and `Types.DATE` only. ## Units The following units are available for `Types.DATE` with `Operations.ADD` and `Operations.SUBTRACT`: -* Units.MILLISECOND -* Units.SECOND -* Units.MINUTE -* Units.HOUR -* Units.DAY -* Units.WEEK -* Units.MONTH -* Units.YEAR +* `Units.MILLISECOND` +* `Units.SECOND` +* `Units.MINUTE` +* `Units.HOUR` +* `Units.DAY` +* `Units.WEEK` +* `Units.MONTH` +* `Units.YEAR` ## Rules diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt index 8f18b2a..89bed99 100644 --- a/example/kobalt/src/Build.kt +++ b/example/kobalt/src/Build.kt @@ -4,6 +4,8 @@ import com.beust.kobalt.plugin.application.* import com.beust.kobalt.plugin.kotlin.* import net.thauvin.erik.kobalt.plugin.propertyfile.* +// ./kobaltw propertyFile + val bs = buildScript { plugins(file("../libs/kobalt-property-file-0.1.0.jar")) } @@ -39,6 +41,8 @@ val p = project { entry(key = "version.dateISO", value = "now", type = Types.DATE, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ") entry(key = "date.nextMonth", value = "now", type = Types.DATE) entry(key = "date.nextMonth", value = "0", type = Types.DATE, unit = Units.MONTH, operation = Operations.ADD) + + // examples from: https://ant.apache.org/manual/Tasks/propertyfile.html entry(key = "akey", value = "avalue") entry(key = "adate", type = Types.DATE, value = "now") entry(key = "anint", type = Types.INT, default = "0", operation = Operations.ADD) @@ -48,6 +52,6 @@ val p = project { operation = Operations.SUBTRACT, value = "1") entry(key = "formated.tomorrow", type = Types.DATE, default = "now", pattern = "DDD", operation = Operations.ADD, value = "1") - entry(key = "progress", default = "", operation = Operations.ADD, value = "1") + entry(key = "progress", default = "", operation = Operations.ADD, value = ".") } } 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 91ad828..7d9bbab 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 @@ -264,7 +264,6 @@ enum class Operations { ADD, DELETE, SET, SUBTRACT } - enum class Units { MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR }