Compare commits
No commits in common. "00cd80894d2db9681c7faccbd2550d37427b50a9" and "26f0709562a1c0331a09ff817eef3d223818cb09" have entirely different histories.
00cd80894d
...
26f0709562
25 changed files with 187 additions and 250 deletions
4
.github/workflows/bld.yml
vendored
4
.github/workflows/bld.yml
vendored
|
@ -8,7 +8,7 @@ jobs:
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
java-version: [ 17, 19, 20 ]
|
java-version: [ 17, 19 ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout source repository
|
- name: Checkout source repository
|
||||||
|
@ -19,7 +19,7 @@ jobs:
|
||||||
- name: Set up JDK ${{ matrix.java-version }}
|
- name: Set up JDK ${{ matrix.java-version }}
|
||||||
uses: actions/setup-java@v3
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: 'zulu'
|
distribution: 'temurin'
|
||||||
java-version: ${{ matrix.java-version }}
|
java-version: ${{ matrix.java-version }}
|
||||||
|
|
||||||
- name: Grant execute permission for bld
|
- name: Grant execute permission for bld
|
||||||
|
|
4
.idea/libraries/bld.xml
generated
4
.idea/libraries/bld.xml
generated
|
@ -2,11 +2,11 @@
|
||||||
<library name="bld">
|
<library name="bld">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.rife2/dist/rife2-1.5.14.jar!/" />
|
<root url="jar://$USER_HOME$/.rife2/dist/rife2-1.5.11.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="jar://$USER_HOME$/.rife2/dist/rife2-1.5.14-sources.jar!/" />
|
<root url="jar://$USER_HOME$/.rife2/dist/rife2-1.5.11-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
<excluded>
|
||||||
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
||||||
|
|
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -5,7 +5,7 @@
|
||||||
"type": "java",
|
"type": "java",
|
||||||
"name": "Run Main",
|
"name": "Run Main",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mainClass": "rife.bld.extension.propertyfile.PropertyFileOperation"
|
"mainClass": "rife.bld.extension.propertyFile.PropertyFileOperation"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "java",
|
"type": "java",
|
||||||
|
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -7,7 +7,7 @@
|
||||||
],
|
],
|
||||||
"java.configuration.updateBuildConfiguration": "automatic",
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"${HOME}/.rife2/dist/rife2-1.5.14.jar",
|
"${HOME}/.rife2/dist/rife2-1.5.11.jar",
|
||||||
"lib/compile/*.jar",
|
"lib/compile/*.jar",
|
||||||
"lib/runtime/*.jar",
|
"lib/runtime/*.jar",
|
||||||
"lib/test/*.jar"
|
"lib/test/*.jar"
|
||||||
|
|
91
README.md
91
README.md
|
@ -3,6 +3,7 @@
|
||||||
[](http://opensource.org/licenses/BSD-3-Clause)
|
[](http://opensource.org/licenses/BSD-3-Clause)
|
||||||
[](https://github.com/rife2/bld-property-file/actions/workflows/bld.yml)
|
[](https://github.com/rife2/bld-property-file/actions/workflows/bld.yml)
|
||||||
|
|
||||||
|
|
||||||
An extension for creating or modifying [property files](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) with [bld](https://github.com/rife2/rife2/wiki/What-Is-Bld). It is inspired by the [ant PropertyFile task](https://ant.apache.org/manual/Tasks/propertyfile.html).
|
An extension for creating or modifying [property files](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) with [bld](https://github.com/rife2/rife2/wiki/What-Is-Bld). It is inspired by the [ant PropertyFile task](https://ant.apache.org/manual/Tasks/propertyfile.html).
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
@ -10,80 +11,54 @@ An extension for creating or modifying [property files](https://docs.oracle.com/
|
||||||
public void updateMajor() throws Exception {
|
public void updateMajor() throws Exception {
|
||||||
new PropertyFileOperation(this)
|
new PropertyFileOperation(this)
|
||||||
.file("version.properties")
|
.file("version.properties")
|
||||||
.entry(new Entry("version.major").defaultValue(0).type(Types.INT).operation(Operations.ADD))
|
.entry(new Entry("version.major").defaultValue(1).type(Types.INT).operation(Operations.ADD))
|
||||||
.entry(new Entry("version.minor").value(0))
|
.entry(new Entry("version.minor").value(0))
|
||||||
.entry(new Entry("version.patch").value(0))
|
.entry(new Entry("version.patch").value(0))
|
||||||
.entry(new Entry("build.date").value("now").pattern("yyyy-MM-dd").type(Types.DATE))
|
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
Invoking the `updateMajor` command, will create the `version.propertees`file:
|
|
||||||
|
To invoke the `updateMajor` command:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./bld updateMajor ...
|
./bld updateMajor
|
||||||
```
|
```
|
||||||
|
|
||||||
```ini
|
## PropertyFileOperation
|
||||||
# version.properties
|
|
||||||
build.date=2023-04-02
|
|
||||||
version.major=1
|
|
||||||
version.minor=0
|
|
||||||
version.patch=0
|
|
||||||
```
|
|
||||||
|
|
||||||
Invoking the `updateMajor` command again, will increase the `version.major` property:
|
Attribute | Description | Required
|
||||||
|
:---------------|:----------------------------------------------------------|:--------
|
||||||
```sh
|
`file` | The location of the properties files to modify. | Yes
|
||||||
./bld updateMajor ...
|
`comment` | Comment to be inserted at the top of the properties file. | No
|
||||||
```
|
`failOnWarning` | If set to `true`, will fail on any warnings. | No
|
||||||
|
|
||||||
```ini
|
|
||||||
# version.properties
|
|
||||||
build.date=2023-04-02
|
|
||||||
version.major=2
|
|
||||||
version.minor=0
|
|
||||||
version.patch=0
|
|
||||||
```
|
|
||||||
|
|
||||||
- [View Examples](https://github.com/rife2/bld-property-file/tree/master/examples)
|
|
||||||
|
|
||||||
## Property File
|
|
||||||
|
|
||||||
The `PropertyFileOperation` class is used to configure the [properties file](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) location, etc.
|
|
||||||
|
|
||||||
| Attribute | Description | Required |
|
|
||||||
|:----------------|:-----------------------------------------------------------------|:---------|
|
|
||||||
| `file` | The location of the properties files to modify. | Yes |
|
|
||||||
| `comment` | Comment to be inserted at the top of the properties file. | No |
|
|
||||||
| `failOnWarning` | If set to `true`, will cause executiion to fail on any warnings. | No |
|
|
||||||
|
|
||||||
## Entry
|
## Entry
|
||||||
|
|
||||||
The `Entry` class is used to specify modifications to be made to the [properties file](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html).
|
The `entry` function is used to specify edits to be made to the properties file.
|
||||||
|
|
||||||
| Attribute | Description |
|
Attribute | Description
|
||||||
|:---------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
:-----------|:-----------------------------------------------------------------------------------------------------------------
|
||||||
| `key` | The name of the property name/value pair. |
|
`key` | The name of the property name/value pair.
|
||||||
| `value` | The value of the property. |
|
`value` | The value of the property.
|
||||||
| `defaultVlaue` | The initial value to set for the property if not already defined. For `Type.DATE`, the `now` keyword can be used. |
|
`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. |
|
`type` | Tread the value as `Types.INT`, `Types.DATE`, or `Types.STRING`. If none specified, `Types.STRING` is assumed.
|
||||||
| `operation` | See [operations](#operations). |
|
`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. |
|
`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). |
|
`unit` | The unit value to be applied to `Operations.ADD` and `Operations.SUBTRACT` for `Types.DATE`. See [Units](#units).
|
||||||
|
|
||||||
`key` is required. `value` or `defaultValue` are required unless the `operation` is `Operations.DELETE`.
|
`key` is required. `value` or `default` are required unless the `operation` is `Operations.DELETE`.
|
||||||
|
|
||||||
## Operations
|
## Operations
|
||||||
|
|
||||||
The following operations are available:
|
The following operations are available:
|
||||||
|
|
||||||
| Operation | Description |
|
Operation | Description
|
||||||
|:-----------------------|:--------------------------------------------------------------------------|
|
:---------------------|:-------------------------------------------------------------------------
|
||||||
| `Operations.ADD` | Adds a value to an entry. |
|
`Operations.ADD` | Adds a value to an entry.
|
||||||
| `Operations.DELETE` | Deletes an entry. |
|
`Operations.DELETE` | Deletes an entry.
|
||||||
| `Operations.SET` | Sets the entry value. This is the default operation. |
|
`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. |
|
`Operations.SUBTRACT` | Subtracts a value from the entry. For `Types.INT` and `Types.DATE` only.
|
||||||
|
|
||||||
## Units
|
## Units
|
||||||
|
|
||||||
|
@ -103,10 +78,10 @@ The following units are available for `Types.DATE` with `Operations.ADD` and `Op
|
||||||
The rules used when setting a property value are:
|
The rules used when setting a property value are:
|
||||||
|
|
||||||
* If only `value` is specified, the property is set to it regardless of its previous value.
|
* If only `value` is specified, the property is set to it regardless of its previous value.
|
||||||
* If only `defaultValue` is specified and the property previously existed, it is unchanged.
|
* If only `default` is specified and the property previously existed, it is unchanged.
|
||||||
* If only `defaultValue` is specified and the property did not exist, the property is set to `defaultValue`.
|
* If only `default` is specified and the property did not exist, the property is set to `default`.
|
||||||
* If `value` and `defaultValue` are both specified and the property previously existed, the property is set to `value`.
|
* If `value` and `default` are both specified and the property previously existed, the property is set to `value`.
|
||||||
* If `value` and `defaultValue` are both specified and the property did not exist, the property is set to `defaultValue`.
|
* If `value` and `default` are both specified and the property did not exist, the property is set to `default`.
|
||||||
|
|
||||||
Operations occur after the rules are evaluated.
|
Operations occur after the rules are evaluated.
|
||||||
|
|
||||||
|
@ -114,4 +89,4 @@ Operations occur after the rules are evaluated.
|
||||||
|
|
||||||
* 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.
|
||||||
* The `jdkproperties` parameter is not implemented.
|
* The `jdkproperties` parameter is not implemented.
|
||||||
* The default `Types.DATE` pattern is `yyyy-MM-dd HH:mm` and not `yyyy/MM/dd HH:mm`.
|
* The default `Entry.Types.DATE` pattern is `yyyy-MM-dd HH:mm` and not `yyyy/MM/dd HH:mm`.
|
2
bld
2
bld
|
@ -1,2 +1,2 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
java -jar "$(dirname "$0")/lib/bld/bld-wrapper.jar" "$0" --build rife.bld.extension.propertyfile.PropertyFileBuild "$@"
|
java -jar "$(dirname "$0")/lib/bld/bld-wrapper.jar" "$0" --build rife.bld.extension.propertyFile.PropertyFileBuild "$@"
|
2
bld.bat
2
bld.bat
|
@ -1,4 +1,4 @@
|
||||||
@echo off
|
@echo off
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
java -jar "%DIRNAME%/lib/bld/bld-wrapper.jar" "%0" --build rife.bld.extension.propertyfile.PropertyFileBuild %*
|
java -jar "%DIRNAME%/lib/bld/bld-wrapper.jar" "%0" --build rife.bld.extension.propertyFile.PropertyFileBuild %*
|
10
examples/.idea/libraries/bld.xml
generated
10
examples/.idea/libraries/bld.xml
generated
|
@ -2,15 +2,15 @@
|
||||||
<library name="bld">
|
<library name="bld">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.rife2/dist/rife2-1.5.14.jar!/" />
|
<root url="jar://$USER_HOME$/.rife2/dist/rife2-1.5.11.jar!/" />
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="jar://$USER_HOME$/.rife2/dist/rife2-1.5.14-sources.jar!/" />
|
<root url="jar://$USER_HOME$/.rife2/dist/rife2-1.5.11-sources.jar!/" />
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
|
<excluded>
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
||||||
|
</excluded>
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
|
||||||
</library>
|
</library>
|
||||||
|
|
6
examples/.idea/misc.xml
generated
6
examples/.idea/misc.xml
generated
|
@ -1,11 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="EntryPointsManager">
|
|
||||||
<pattern value="com.example.PropertyFileExampleBuild" />
|
|
||||||
<pattern value="com.example.PropertyFileExampleBuild" method="updateMajor" />
|
|
||||||
<pattern value="com.example.PropertyFileExampleBuild" method="updateMinor" />
|
|
||||||
<pattern value="com.example.PropertyFileExampleBuild" method="updatePatch" />
|
|
||||||
</component>
|
|
||||||
<component name="PDMPlugin">
|
<component name="PDMPlugin">
|
||||||
<option name="skipTestSources" value="false" />
|
<option name="skipTestSources" value="false" />
|
||||||
</component>
|
</component>
|
||||||
|
|
2
examples/.vscode/settings.json
vendored
2
examples/.vscode/settings.json
vendored
|
@ -7,7 +7,7 @@
|
||||||
],
|
],
|
||||||
"java.configuration.updateBuildConfiguration": "automatic",
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"${HOME}/.rife2/dist/rife2-1.5.14.jar",
|
"${HOME}/.rife2/dist/rife2-1.5.11.jar",
|
||||||
"lib/compile/*.jar",
|
"lib/compile/*.jar",
|
||||||
"lib/runtime/*.jar",
|
"lib/runtime/*.jar",
|
||||||
"lib/test/*.jar"
|
"lib/test/*.jar"
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
## Compile
|
## Compile
|
||||||
|
|
||||||
First make sure the project up-to-date and compiled:
|
First make sure the project is compiled, by issuing the following command:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
./bld download compile
|
./bld compile
|
||||||
```
|
```
|
||||||
## Run
|
## Run
|
||||||
|
|
||||||
|
@ -16,10 +16,11 @@ To run the examples, issue one of the following command or combination there off
|
||||||
./bld updateMinor run
|
./bld updateMinor run
|
||||||
./bld updatePatch run
|
./bld updatePatch run
|
||||||
```
|
```
|
||||||
Upon execution, the `version.properties` file will be created and displayed:
|
Upon execution, the content of the `verison.properties` file will be displayed, reflecting the modification to the
|
||||||
|
`version.major`, `version.minor` or `version.patch` properties.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
./bld updateMajor run
|
./bld updatePatch run
|
||||||
```
|
```
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
@ -27,28 +28,8 @@ Upon execution, the `version.properties` file will be created and displayed:
|
||||||
| version.properties |
|
| version.properties |
|
||||||
+---------------------------+
|
+---------------------------+
|
||||||
#
|
#
|
||||||
#Sun Apr 02 23:51:39 PDT 2023
|
#Sun Apr 02 17:19:10 PDT 2023
|
||||||
build.date=2023-04-02
|
|
||||||
version.major=1
|
version.major=1
|
||||||
version.minor=0
|
version.minor=0
|
||||||
version.patch=0
|
version.patch=1
|
||||||
```
|
|
||||||
|
|
||||||
Subsequent commands will reflect the modifications to the
|
|
||||||
`version.major`, `version.minor` or `version.patch` properties:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
./bld upatePatch run
|
|
||||||
```
|
|
||||||
|
|
||||||
```shell
|
|
||||||
+---------------------------+
|
|
||||||
| version.properties |
|
|
||||||
+---------------------------+
|
|
||||||
#
|
|
||||||
#Sun Apr 02 23:55:09 PDT 2023
|
|
||||||
build.date=2023-04-02
|
|
||||||
version.major=1
|
|
||||||
version.minor=0
|
|
||||||
version.patch=10
|
|
||||||
```
|
```
|
||||||
|
|
Binary file not shown.
|
@ -1,6 +1,7 @@
|
||||||
#Sun Apr 02 10:32:44 PDT 2023
|
#Sun Apr 02 10:32:44 PDT 2023
|
||||||
bld.extension=com.uwyn.rife2:bld-property-file:0.9.0
|
bld.extension=com.uwyn.rife2:bld-property-file:0.9.0
|
||||||
bld.repositories=MAVEN_LOCAL,https\://repo1.maven.org/maven2/
|
bld.repositories=https\://repo1.maven.org/maven2/,/home/erik/.m2/repository
|
||||||
bld.downloadExtensionSources=true
|
|
||||||
rife2.downloadLocation=
|
rife2.downloadLocation=
|
||||||
rife2.version=1.5.14
|
rife2.version=1.5.11
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@ package com.example;
|
||||||
|
|
||||||
import rife.bld.BuildCommand;
|
import rife.bld.BuildCommand;
|
||||||
import rife.bld.Project;
|
import rife.bld.Project;
|
||||||
import rife.bld.extension.propertyfile.Entry;
|
import rife.bld.extension.propertyFile.Entry;
|
||||||
import rife.bld.extension.propertyfile.Entry.Operations;
|
import rife.bld.extension.propertyFile.Entry.Operations;
|
||||||
import rife.bld.extension.propertyfile.Entry.Types;
|
import rife.bld.extension.propertyFile.Entry.Types;
|
||||||
import rife.bld.extension.propertyfile.PropertyFileOperation;
|
import rife.bld.extension.propertyFile.PropertyFileOperation;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import static rife.bld.dependencies.Repository.SONATYPE_SNAPSHOTS;
|
||||||
import static rife.bld.dependencies.Scope.test;
|
import static rife.bld.dependencies.Scope.test;
|
||||||
|
|
||||||
public class PropertyFileExampleBuild extends Project {
|
public class PropertyFileExampleBuild extends Project {
|
||||||
final Entry buildDateEntry = new Entry("build.date").value("now").pattern("yyyy-MM-dd").type(Types.DATE);
|
|
||||||
|
|
||||||
public PropertyFileExampleBuild() {
|
public PropertyFileExampleBuild() {
|
||||||
pkg = "com.example";
|
pkg = "com.example";
|
||||||
|
@ -34,48 +33,30 @@ public class PropertyFileExampleBuild extends Project {
|
||||||
new PropertyFileExampleBuild().start(args);
|
new PropertyFileExampleBuild().start(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Updates major version")
|
@BuildCommand
|
||||||
public void updateMajor() throws Exception {
|
public void updateMajor() throws Exception {
|
||||||
new PropertyFileOperation(this)
|
new PropertyFileOperation(this)
|
||||||
.file("version.properties")
|
.file("version.properties")
|
||||||
// set the major version to 1 if it doesn't exist, increase by 1
|
.entry(new Entry("version.major").defaultValue(1).type(Types.INT).operation(Operations.ADD))
|
||||||
.entry(new Entry("version.major").defaultValue(0).type(Types.INT).operation(Operations.ADD))
|
|
||||||
// set the minor version to 0
|
|
||||||
.entry(new Entry("version.minor").value(0))
|
.entry(new Entry("version.minor").value(0))
|
||||||
// set the patch version to 0
|
|
||||||
.entry(new Entry("version.patch").value(0))
|
.entry(new Entry("version.patch").value(0))
|
||||||
// set the build date to the current date
|
|
||||||
.entry(buildDateEntry)
|
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Updates minor version")
|
@BuildCommand
|
||||||
public void updateMinor() throws Exception {
|
public void updateMinor() throws Exception {
|
||||||
new PropertyFileOperation(this)
|
new PropertyFileOperation(this)
|
||||||
.file("version.properties")
|
.file("version.properties")
|
||||||
// set the major version to 1 if it doesn't exist
|
.entry(new Entry("version.minor").defaultValue(0).type(Types.INT).operation(Operations.ADD))
|
||||||
.entry(new Entry("version.major").defaultValue(1))
|
|
||||||
// set the minor version to 0 if it doesn't exist, increase by 1
|
|
||||||
.entry(new Entry("version.minor").defaultValue(-1).type(Types.INT).operation(Operations.ADD))
|
|
||||||
// set the patch version to 0
|
|
||||||
.entry(new Entry("version.patch").value(0))
|
.entry(new Entry("version.patch").value(0))
|
||||||
// set the build date to the current date
|
|
||||||
.entry(buildDateEntry)
|
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Updates patch version")
|
@BuildCommand
|
||||||
public void updatePatch() throws Exception {
|
public void updatePatch() throws Exception {
|
||||||
new PropertyFileOperation(this)
|
new PropertyFileOperation(this)
|
||||||
.file("version.properties")
|
.file("version.properties")
|
||||||
// set the major version to 1 if it doesn't exist
|
.entry(new Entry("version.patch").defaultValue(0).type(Types.INT).operation(Operations.ADD))
|
||||||
.entry(new Entry("version.major").defaultValue(1))
|
|
||||||
// set the minor version to 0 if it doesn't exist
|
|
||||||
.entry(new Entry("version.minor").defaultValue(0))
|
|
||||||
// set the patch version to 10 if it doesn't exist, increase by 10
|
|
||||||
.entry(new Entry("version.patch").defaultValue(0).type(Types.INT).operation(Operations.ADD).value(10))
|
|
||||||
// set the build date to the current date
|
|
||||||
.entry(buildDateEntry)
|
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ public class PropertyFileExampleMain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getMessage() {
|
public String getMessage() {
|
||||||
return "Hello World!";
|
return "Hello World!";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,9 +2,9 @@ package com.example;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class PropertyFileExampleTest {
|
public class PropertyFileExampleTest {
|
||||||
@Test
|
@Test
|
||||||
void verifyHello() {
|
void verifyHello() {
|
||||||
assertEquals("Hello World!", new PropertyFileExampleMain().getMessage());
|
assertEquals("Hello World!", new PropertyFileExampleMain().getMessage());
|
||||||
|
|
5
examples/version.properties
Normal file
5
examples/version.properties
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#
|
||||||
|
#Sun Apr 02 17:19:10 PDT 2023
|
||||||
|
version.major=1
|
||||||
|
version.minor=0
|
||||||
|
version.patch=1
|
Binary file not shown.
|
@ -1,2 +1,2 @@
|
||||||
#Sat Apr 01 10:09:33 PDT 2023
|
#Sat Apr 01 10:09:33 PDT 2023
|
||||||
rife2.version=1.5.14
|
rife2.version=1.5.11
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package rife.bld.extension.propertyfile;
|
package rife.bld.extension.propertyFile;
|
||||||
|
|
||||||
import rife.bld.Project;
|
import rife.bld.Project;
|
||||||
import rife.bld.publish.PublishDeveloper;
|
import rife.bld.publish.PublishDeveloper;
|
||||||
|
@ -35,7 +35,7 @@ public class PropertyFileBuild extends Project {
|
||||||
downloadSources = true;
|
downloadSources = true;
|
||||||
repositories = List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS);
|
repositories = List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS);
|
||||||
scope(compile)
|
scope(compile)
|
||||||
.include(dependency("com.uwyn.rife2", "rife2", version(1, 5, 15)));
|
.include(dependency("com.uwyn.rife2", "rife2", version(1, 5, 11)));
|
||||||
scope(test)
|
scope(test)
|
||||||
.include(dependency("org.jsoup", "jsoup", version(1, 15, 4)))
|
.include(dependency("org.jsoup", "jsoup", version(1, 15, 4)))
|
||||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 9, 2)))
|
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 9, 2)))
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package rife.bld.extension.propertyfile;
|
package rife.bld.extension.propertyFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Declares the edits to be made to a {@link java.util.Properties Properties} file.</p>
|
* <p>Declares the edits to be made to a {@link java.util.Properties Properties} file.</p>
|
||||||
|
@ -174,8 +174,6 @@ public class Entry {
|
||||||
*
|
*
|
||||||
* @param key the {@link java.util.Properties property} key
|
* @param key the {@link java.util.Properties property} key
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public Entry key(String key) {
|
public Entry key(String key) {
|
||||||
setKey(key);
|
setKey(key);
|
||||||
return this;
|
return this;
|
||||||
|
@ -186,7 +184,6 @@ public class Entry {
|
||||||
*
|
*
|
||||||
* @param value the {@link java.util.Properties property} value
|
* @param value the {@link java.util.Properties property} value
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public Entry value(Object value) {
|
public Entry value(Object value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
setValue(String.valueOf(value));
|
setValue(String.valueOf(value));
|
||||||
|
@ -203,7 +200,6 @@ public class Entry {
|
||||||
*
|
*
|
||||||
* @param defaultValue the default value
|
* @param defaultValue the default value
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public Entry defaultValue(Object defaultValue) {
|
public Entry defaultValue(Object defaultValue) {
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
setDefaultValue(String.valueOf(defaultValue));
|
setDefaultValue(String.valueOf(defaultValue));
|
||||||
|
@ -228,7 +224,6 @@ public class Entry {
|
||||||
*
|
*
|
||||||
* @param operation the entry {@link Operations Operation}
|
* @param operation the entry {@link Operations Operation}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public Entry operation(Operations operation) {
|
public Entry operation(Operations operation) {
|
||||||
setOperation(operation);
|
setOperation(operation);
|
||||||
return this;
|
return this;
|
||||||
|
@ -252,7 +247,6 @@ public class Entry {
|
||||||
*
|
*
|
||||||
* @param unit the {@link Units unit}
|
* @param unit the {@link Units unit}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public Entry unit(Units unit) {
|
public Entry unit(Units unit) {
|
||||||
setUnit(unit);
|
setUnit(unit);
|
||||||
return this;
|
return this;
|
|
@ -14,11 +14,11 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package rife.bld.extension.propertyfile;
|
package rife.bld.extension.propertyFile;
|
||||||
|
|
||||||
import rife.bld.Project;
|
import rife.bld.Project;
|
||||||
import rife.bld.extension.propertyfile.Entry.Operations;
|
import rife.bld.extension.propertyFile.Entry.Operations;
|
||||||
import rife.bld.extension.propertyfile.Entry.Types;
|
import rife.bld.extension.propertyFile.Entry.Types;
|
||||||
import rife.bld.operations.AbstractOperation;
|
import rife.bld.operations.AbstractOperation;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -50,7 +50,6 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
*
|
*
|
||||||
* @param entry the {@link Entry entry}
|
* @param entry the {@link Entry entry}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public PropertyFileOperation entry(Entry entry) {
|
public PropertyFileOperation entry(Entry entry) {
|
||||||
entries.add(entry);
|
entries.add(entry);
|
||||||
return this;
|
return this;
|
||||||
|
@ -61,7 +60,6 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
*
|
*
|
||||||
* @param file the file to be edited
|
* @param file the file to be edited
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public PropertyFileOperation file(String file) {
|
public PropertyFileOperation file(String file) {
|
||||||
this.file = new File(file);
|
this.file = new File(file);
|
||||||
return this;
|
return this;
|
||||||
|
@ -72,7 +70,6 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
*
|
*
|
||||||
* @param file the file to be edited
|
* @param file the file to be edited
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public PropertyFileOperation file(File file) {
|
public PropertyFileOperation file(File file) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
return this;
|
return this;
|
||||||
|
@ -83,7 +80,6 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
*
|
*
|
||||||
* @param failOnWarning if set to {@code true}, the task will fail on any warnings.
|
* @param failOnWarning if set to {@code true}, the task will fail on any warnings.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public PropertyFileOperation failOnWarning(boolean failOnWarning) {
|
public PropertyFileOperation failOnWarning(boolean failOnWarning) {
|
||||||
this.failOnWarning = failOnWarning;
|
this.failOnWarning = failOnWarning;
|
||||||
return this;
|
return this;
|
||||||
|
@ -94,16 +90,14 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
*
|
*
|
||||||
* @param comment the header comment
|
* @param comment the header comment
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public PropertyFileOperation comment(String comment) {
|
public PropertyFileOperation comment(String comment) {
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the modification(s) to the {@link java.util.Properties properties} file.
|
* Performs the edits to the {@link java.util.Properties properties} file.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
if (project == null) {
|
if (project == null) {
|
||||||
throw new IOException("A project must be specified.");
|
throw new IOException("A project must be specified.");
|
||||||
|
@ -111,14 +105,13 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
throw new IOException("A properties file location must be specified.");
|
throw new IOException("A properties file location must be specified.");
|
||||||
}
|
}
|
||||||
var commandName = project.getCurrentCommandName();
|
|
||||||
var success = false;
|
var success = false;
|
||||||
var properties = new Properties();
|
var properties = new Properties();
|
||||||
success = PropertyFileUtils.loadProperties(commandName, file, properties);
|
success = PropertyFileUtils.loadProperties(file, properties);
|
||||||
if (success) {
|
if (success) {
|
||||||
for (var entry : entries) {
|
for (var entry : entries) {
|
||||||
if (entry.getKey().isBlank()) {
|
if (entry.getKey().isBlank()) {
|
||||||
PropertyFileUtils.warn(commandName, "At least one entry key must specified.");
|
PropertyFileUtils.warn("At least one entry key must specified.");
|
||||||
success = false;
|
success = false;
|
||||||
} else {
|
} else {
|
||||||
var key = entry.getKey();
|
var key = entry.getKey();
|
||||||
|
@ -126,19 +119,17 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
var defaultValue = entry.getDefaultValue();
|
var defaultValue = entry.getDefaultValue();
|
||||||
if ((value == null || value.isBlank()) && (defaultValue == null || defaultValue.isBlank())
|
if ((value == null || value.isBlank()) && (defaultValue == null || defaultValue.isBlank())
|
||||||
&& entry.getOperation() != Operations.DELETE) {
|
&& entry.getOperation() != Operations.DELETE) {
|
||||||
PropertyFileUtils.warn(commandName, "An entry value or default must be specified: " + key);
|
PropertyFileUtils.warn("An entry value or default must be specified: " + key);
|
||||||
success = false;
|
success = false;
|
||||||
} else if (entry.getType() == Types.STRING && entry.getOperation() == Operations.SUBTRACT) {
|
} else if (entry.getType() == Types.STRING && entry.getOperation() == Operations.SUBTRACT) {
|
||||||
PropertyFileUtils.warn(commandName, "Subtraction is not supported for String properties: " + key);
|
PropertyFileUtils.warn("Subtraction is not supported for String properties: " + key);
|
||||||
success = false;
|
success = false;
|
||||||
} else if (entry.getOperation() == Operations.DELETE) {
|
} else if (entry.getOperation() == Operations.DELETE) {
|
||||||
properties.remove(key);
|
properties.remove(key);
|
||||||
} else {
|
} else {
|
||||||
switch (entry.getType()) {
|
switch (entry.getType()) {
|
||||||
case DATE ->
|
case DATE -> success = PropertyFileUtils.processDate(properties, entry, failOnWarning);
|
||||||
success = PropertyFileUtils.processDate(commandName, properties, entry, failOnWarning);
|
case INT -> success = PropertyFileUtils.processInt(properties, entry, failOnWarning);
|
||||||
case INT ->
|
|
||||||
success = PropertyFileUtils.processInt(commandName, properties, entry, failOnWarning);
|
|
||||||
default -> success = PropertyFileUtils.processString(properties, entry);
|
default -> success = PropertyFileUtils.processString(properties, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,10 +14,10 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package rife.bld.extension.propertyfile;
|
package rife.bld.extension.propertyFile;
|
||||||
|
|
||||||
import rife.bld.extension.propertyfile.Entry.Operations;
|
import rife.bld.extension.propertyFile.Entry.Operations;
|
||||||
import rife.bld.extension.propertyfile.Entry.Units;
|
import rife.bld.extension.propertyFile.Entry.Units;
|
||||||
import rife.tools.Localization;
|
import rife.tools.Localization;
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.IIOException;
|
||||||
|
@ -62,12 +62,11 @@ public final class PropertyFileUtils {
|
||||||
/**
|
/**
|
||||||
* Processes a date {@link Properties property}.
|
* Processes a date {@link Properties property}.
|
||||||
*
|
*
|
||||||
* @param command the issuing command
|
|
||||||
* @param p the {@link Properties property}
|
* @param p the {@link Properties property}
|
||||||
* @param entry the {@link Entry} containing the {@link Properties property} edits
|
* @param entry the {@link Entry} containing the {@link Properties property} edits
|
||||||
* @return {@code true} if successful
|
* @return {@code true} if successful
|
||||||
*/
|
*/
|
||||||
public static boolean processDate(String command, Properties p, Entry entry, boolean failOnWarning) {
|
public static boolean processDate(Properties p, Entry entry, boolean failOnWarning) {
|
||||||
var success = true;
|
var success = true;
|
||||||
var cal = Calendar.getInstance();
|
var cal = Calendar.getInstance();
|
||||||
var value = PropertyFileUtils.currentValue(p.getProperty(entry.getKey()), entry.getValue(),
|
var value = PropertyFileUtils.currentValue(p.getProperty(entry.getKey()), entry.getValue(),
|
||||||
|
@ -86,8 +85,7 @@ public final class PropertyFileUtils {
|
||||||
try {
|
try {
|
||||||
cal.setTime(fmt.parse(value));
|
cal.setTime(fmt.parse(value));
|
||||||
} catch (ParseException pe) {
|
} catch (ParseException pe) {
|
||||||
warn(command, "Non-date value for \"" + entry.getKey() + "\" --> " + pe.getMessage(),
|
warn("Date parse exception for: " + entry.getKey() + " --> " + pe.getMessage(), pe, failOnWarning);
|
||||||
pe, failOnWarning);
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,12 +99,10 @@ public final class PropertyFileUtils {
|
||||||
offset *= -1;
|
offset *= -1;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
warn(command, "Non-date value for \"" + entry.getKey() + "\" --> " + nfe.getMessage(), nfe,
|
warn("Non-integer value for: " + entry.getKey() + " --> " + nfe.getMessage(), nfe, failOnWarning);
|
||||||
failOnWarning);
|
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection MagicConstant
|
|
||||||
cal.add(calendarFields.getOrDefault(entry.getUnit(), Calendar.DATE), offset);
|
cal.add(calendarFields.getOrDefault(entry.getUnit(), Calendar.DATE), offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,15 +158,25 @@ public final class PropertyFileUtils {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that the given value is an integer.
|
||||||
|
*
|
||||||
|
* @param value the value
|
||||||
|
* @return the parsed value
|
||||||
|
* @throws NumberFormatException if the value could not be parsed as an integer
|
||||||
|
*/
|
||||||
|
static String parseInt(String value) throws NumberFormatException {
|
||||||
|
return String.valueOf(Integer.parseInt(value));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes an integer {@link Properties property}.
|
* Processes an integer {@link Properties property}.
|
||||||
*
|
*
|
||||||
* @param command the issuing command
|
|
||||||
* @param p the {@link Properties property}
|
* @param p the {@link Properties property}
|
||||||
* @param entry the {@link Entry} containing the {@link Properties property} edits
|
* @param entry the {@link Entry} containing the {@link Properties property} edits
|
||||||
* @return {@code true} if successful
|
* @return {@code true} if successful
|
||||||
*/
|
*/
|
||||||
public static boolean processInt(String command, Properties p, Entry entry, boolean failOnWarning) {
|
public static boolean processInt(Properties p, Entry entry, boolean failOnWarning) {
|
||||||
var success = true;
|
var success = true;
|
||||||
int intValue;
|
int intValue;
|
||||||
try {
|
try {
|
||||||
|
@ -181,13 +187,13 @@ public final class PropertyFileUtils {
|
||||||
if (value.isBlank()) {
|
if (value.isBlank()) {
|
||||||
intValue = fmt.parse("0").intValue();
|
intValue = fmt.parse("0").intValue();
|
||||||
} else {
|
} else {
|
||||||
intValue = fmt.parse(value).intValue();
|
intValue = fmt.parse(parseInt(value)).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.getOperation() != Entry.Operations.SET) {
|
if (entry.getOperation() != Entry.Operations.SET) {
|
||||||
var opValue = 1;
|
var opValue = 1;
|
||||||
if (entry.getValue() != null) {
|
if (entry.getValue() != null) {
|
||||||
opValue = fmt.parse(entry.getValue()).intValue();
|
opValue = fmt.parse(parseInt(entry.getValue())).intValue();
|
||||||
}
|
}
|
||||||
if (entry.getOperation() == Entry.Operations.ADD) {
|
if (entry.getOperation() == Entry.Operations.ADD) {
|
||||||
intValue += opValue;
|
intValue += opValue;
|
||||||
|
@ -196,9 +202,11 @@ public final class PropertyFileUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.setProperty(entry.getKey(), fmt.format(intValue));
|
p.setProperty(entry.getKey(), fmt.format(intValue));
|
||||||
} catch (NumberFormatException | ParseException e) {
|
} catch (NumberFormatException nfe) {
|
||||||
warn(command, "Non-integer value for \"" + entry.getKey() + "\" --> " + e.getMessage(), e,
|
warn("Number format exception for: " + entry.getKey() + " --> " + nfe.getMessage(), nfe, failOnWarning);
|
||||||
failOnWarning);
|
success = false;
|
||||||
|
} catch (ParseException pe) {
|
||||||
|
warn("Number parsing exception for: " + entry.getKey() + " --> " + pe.getMessage(), pe, failOnWarning);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,29 +238,27 @@ public final class PropertyFileUtils {
|
||||||
/**
|
/**
|
||||||
* Logs a warning.
|
* Logs a warning.
|
||||||
*
|
*
|
||||||
* @param command the issuing command
|
|
||||||
* @param message the message to log
|
* @param message the message to log
|
||||||
*/
|
*/
|
||||||
static void warn(String command, String message) {
|
static void warn(String message) {
|
||||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
if (LOGGER.isLoggable(Level.WARNING)) {
|
||||||
LOGGER.warning('[' + command + "] " + message);
|
LOGGER.warning(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a warning.
|
* Logs a warning.
|
||||||
*
|
*
|
||||||
* @param command The command name
|
|
||||||
* @param message the message log
|
* @param message the message log
|
||||||
* @param e the related exception
|
* @param e the related exception
|
||||||
* @param failOnWarning skips logging the exception if set to {@code false}
|
* @param failOnWarning skips logging the exception if set to {@code false}
|
||||||
*/
|
*/
|
||||||
static void warn(String command, String message, Exception e, boolean failOnWarning) {
|
static void warn(String message, Exception e, boolean failOnWarning) {
|
||||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
if (LOGGER.isLoggable(Level.WARNING)) {
|
||||||
if (failOnWarning) {
|
if (failOnWarning) {
|
||||||
LOGGER.log(Level.WARNING, '[' + command + "] " + message, e);
|
LOGGER.log(Level.WARNING, message, e);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warning('[' + command + "] " + message);
|
LOGGER.warning(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,24 +266,26 @@ public final class PropertyFileUtils {
|
||||||
/**
|
/**
|
||||||
* Loads a {@link Properties properties} file.
|
* Loads a {@link Properties properties} file.
|
||||||
*
|
*
|
||||||
* @param command the issuing command
|
|
||||||
* @param file the file location.
|
* @param file the file location.
|
||||||
* @param p the {@link Properties properties} to load into.
|
* @param p the {@link Properties properties} to load into.
|
||||||
* @return {@code true} if successful
|
* @return {@code true} if successful
|
||||||
*/
|
*/
|
||||||
public static boolean loadProperties(String command, File file, Properties p) {
|
public static boolean loadProperties(File file, Properties p) {
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try (var propStream = Files.newInputStream(file.toPath(), StandardOpenOption.READ)) {
|
try (var propStream = Files.newInputStream(file.toPath(), StandardOpenOption.READ)) {
|
||||||
p.load(propStream);
|
p.load(propStream);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
warn(command, "Could not load properties file: " + ioe.getMessage(), ioe, true);
|
warn("Could not load properties file: " + ioe.getMessage(), ioe, true);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
warn("The '" + file + "' properties file could not be found.");
|
||||||
|
success = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn(command, "Please specify the properties file location.");
|
warn("Please specify the properties file location.");
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package rife.bld.extension.propertyfile;
|
package rife.bld.extension.propertyFile;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import rife.tools.Localization;
|
import rife.tools.Localization;
|
||||||
|
@ -36,52 +36,65 @@ import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
*/
|
*/
|
||||||
class PropertyFileUtilsTest {
|
class PropertyFileUtilsTest {
|
||||||
final Properties p = new Properties();
|
final Properties p = new Properties();
|
||||||
final String t = "test";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void currentValueTest() {
|
void currentValueTest() {
|
||||||
String prev = "previous";
|
String prev;
|
||||||
String value = "value";
|
String value;
|
||||||
String defaultValue = "defaultValue";
|
String defaultValue = null;
|
||||||
var operation = Entry.Operations.SET;
|
var operation = Entry.Operations.SET;
|
||||||
|
|
||||||
// If only value is specified, the property is set to it regardless of its previous value.
|
// If only value is specified, the property is set to it regardless of its previous value.
|
||||||
assertThat(PropertyFileUtils.currentValue(prev, value, null, operation))
|
prev = "previous";
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo(value);
|
value = "value";
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo(value);
|
||||||
|
|
||||||
// If only defaultValue is specified and the property previously existed, it is unchanged.
|
// If only defaultValue is specified and the property previously existed, it is unchanged.
|
||||||
assertThat(PropertyFileUtils.currentValue(prev, null, defaultValue, operation))
|
prev = "previous";
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo(prev);
|
value = null;
|
||||||
|
defaultValue = "defaultValue";
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo(prev);
|
||||||
|
|
||||||
// If only defaultValue is specified and the property did not exist, the property is set to defaultValue.
|
// If only defaultValue is specified and the property did not exist, the property is set to defaultValue.
|
||||||
assertThat(PropertyFileUtils.currentValue(null, null, defaultValue, operation))
|
prev = null;
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo(defaultValue);
|
defaultValue = "defaultValue";
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo(defaultValue);
|
||||||
|
|
||||||
// If value and defaultValue are both specified and the property previously existed, the property is set to value.
|
// If value and defaultValue are both specified and the property previously existed, the property is set to value.
|
||||||
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation))
|
prev = "previous";
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo(value);
|
value = "value";
|
||||||
|
defaultValue = "defaultValue";
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo(value);
|
||||||
|
|
||||||
// If value and defaultValue are both specified and the property did not exist, the property is set to defaultValue.
|
// If value and defaultValue are both specified and the property did not exist, the property is set to defaultValue.
|
||||||
assertThat(PropertyFileUtils.currentValue(null, value, defaultValue, operation))
|
prev = null;
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo(defaultValue);
|
value = "value";
|
||||||
|
defaultValue = "defaultValue";
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo(defaultValue);
|
||||||
|
|
||||||
// ADD
|
// ADD
|
||||||
operation = Entry.Operations.ADD;
|
operation = Entry.Operations.ADD;
|
||||||
|
|
||||||
assertThat(PropertyFileUtils.currentValue(null, value, defaultValue, operation))
|
value = "value";
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo(defaultValue);
|
defaultValue = "defaultValue";
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo(defaultValue);
|
||||||
|
|
||||||
assertThat(PropertyFileUtils.currentValue(prev, value, null, operation))
|
prev = "prev";
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo(prev);
|
value = "value";
|
||||||
|
defaultValue = null;
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo(prev);
|
||||||
|
|
||||||
assertThat(PropertyFileUtils.currentValue(null, value, null, operation))
|
prev = null;
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo("");
|
value = "value";
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo("");
|
||||||
|
|
||||||
assertThat(PropertyFileUtils.currentValue(null, value, defaultValue, operation))
|
value = "value";
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo(defaultValue);
|
defaultValue = "defaultValue";
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo(defaultValue);
|
||||||
|
|
||||||
assertThat(PropertyFileUtils.currentValue(null, null, null, operation))
|
value = null;
|
||||||
.as(String.format("currentValue(%s,%s,%s,%s)", prev, value, defaultValue, operation)).isEqualTo("");
|
defaultValue = null;
|
||||||
|
assertThat(PropertyFileUtils.currentValue(prev, value, defaultValue, operation)).as("currentValue(prev,value,defaultValue,operation)").isEqualTo("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -102,38 +115,38 @@ class PropertyFileUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
void processIntTest() {
|
void processIntTest() {
|
||||||
var entry = new Entry("version.patch").value("a").type(Entry.Types.INT);
|
var entry = new Entry("version.patch").value("a").type(Entry.Types.INT);
|
||||||
assertThat(PropertyFileUtils.processInt(t, p, entry, false)).as("parseInt(entry.getKey(), a)");
|
assertThat(PropertyFileUtils.processInt(p, entry, false)).as("parseInt(entry.getKey(), a)");
|
||||||
|
|
||||||
// ADD
|
// ADD
|
||||||
entry.setOperation(Entry.Operations.ADD);
|
entry.setOperation(Entry.Operations.ADD);
|
||||||
|
|
||||||
entry.setValue("1");
|
entry.setValue("1");
|
||||||
entry.setDefaultValue("-1");
|
entry.setDefaultValue("-1");
|
||||||
PropertyFileUtils.processInt(t, p, entry, true);
|
PropertyFileUtils.processInt(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0)").isEqualTo("0");
|
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0)").isEqualTo("0");
|
||||||
|
|
||||||
entry.setKey("anint");
|
entry.setKey("anint");
|
||||||
entry.setValue(null);
|
entry.setValue(null);
|
||||||
entry.setDefaultValue("0");
|
entry.setDefaultValue("0");
|
||||||
PropertyFileUtils.processInt(t, p, entry, true);
|
PropertyFileUtils.processInt(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 1)").isEqualTo("1");
|
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 1)").isEqualTo("1");
|
||||||
PropertyFileUtils.processInt(t, p, entry, true);
|
PropertyFileUtils.processInt(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 2)").isEqualTo("2");
|
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 2)").isEqualTo("2");
|
||||||
|
|
||||||
entry.setKey("formated.int");
|
entry.setKey("formated.int");
|
||||||
entry.setValue(null);
|
entry.setValue(null);
|
||||||
entry.setDefaultValue("0013");
|
entry.setDefaultValue("0013");
|
||||||
entry.setPattern("0000");
|
entry.setPattern("0000");
|
||||||
PropertyFileUtils.processInt(t, p, entry, true);
|
PropertyFileUtils.processInt(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0014)").isEqualTo("0014");
|
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0014)").isEqualTo("0014");
|
||||||
PropertyFileUtils.processInt(t, p, entry, true);
|
PropertyFileUtils.processInt(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0015)").isEqualTo("0015");
|
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0015)").isEqualTo("0015");
|
||||||
|
|
||||||
entry.setKey("formated.int");
|
entry.setKey("formated.int");
|
||||||
entry.setValue("2");
|
entry.setValue("2");
|
||||||
entry.setDefaultValue("0013");
|
entry.setDefaultValue("0013");
|
||||||
entry.setPattern("0000");
|
entry.setPattern("0000");
|
||||||
PropertyFileUtils.processInt(t, p, entry, true);
|
PropertyFileUtils.processInt(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0017)").isEqualTo("0017");
|
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0017)").isEqualTo("0017");
|
||||||
|
|
||||||
// SUBTRACT
|
// SUBTRACT
|
||||||
|
@ -141,7 +154,7 @@ class PropertyFileUtilsTest {
|
||||||
entry.setValue(null);
|
entry.setValue(null);
|
||||||
entry.setDefaultValue("0013");
|
entry.setDefaultValue("0013");
|
||||||
entry.setPattern("0000");
|
entry.setPattern("0000");
|
||||||
PropertyFileUtils.processInt(t, p, entry, true);
|
PropertyFileUtils.processInt(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0016)").isEqualTo("0016");
|
assertThat(p.getProperty(entry.getKey())).as("processInt(entry.getKey(), 0016)").isEqualTo("0016");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,36 +165,36 @@ class PropertyFileUtilsTest {
|
||||||
var dayInt = Integer.parseInt(day);
|
var dayInt = Integer.parseInt(day);
|
||||||
|
|
||||||
entry.setValue("a");
|
entry.setValue("a");
|
||||||
assertThat(PropertyFileUtils.processDate(t, p, entry, false)).as("processDate(entry.getKey(), a)").isFalse();
|
assertThat(PropertyFileUtils.processDate(p, entry, false)).as("processDate(entry.getKey(), a)").isFalse();
|
||||||
|
|
||||||
entry.setValue("99");
|
entry.setValue("99");
|
||||||
PropertyFileUtils.processDate(t, p, entry, true);
|
PropertyFileUtils.processDate(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), 99)").isEqualTo("99");
|
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), 99)").isEqualTo("99");
|
||||||
|
|
||||||
entry.setValue("now");
|
entry.setValue("now");
|
||||||
PropertyFileUtils.processDate(t, p, entry, true);
|
PropertyFileUtils.processDate(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now)").isEqualTo(day);
|
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now)").isEqualTo(day);
|
||||||
|
|
||||||
// ADD
|
// ADD
|
||||||
entry.setOperation(Entry.Operations.ADD);
|
entry.setOperation(Entry.Operations.ADD);
|
||||||
|
|
||||||
entry.setValue("1");
|
entry.setValue("1");
|
||||||
PropertyFileUtils.processDate(t, p, entry, true);
|
PropertyFileUtils.processDate(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now+1)").isEqualTo(String.valueOf(dayInt + 1));
|
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now+1)").isEqualTo(String.valueOf(dayInt + 1));
|
||||||
|
|
||||||
entry.setValue("2");
|
entry.setValue("2");
|
||||||
PropertyFileUtils.processDate(t, p, entry, true);
|
PropertyFileUtils.processDate(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now+3)").isEqualTo(String.valueOf(dayInt + 3));
|
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now+3)").isEqualTo(String.valueOf(dayInt + 3));
|
||||||
|
|
||||||
// SUBTRACT
|
// SUBTRACT
|
||||||
entry.setOperation(Entry.Operations.SUBTRACT);
|
entry.setOperation(Entry.Operations.SUBTRACT);
|
||||||
entry.setValue("3");
|
entry.setValue("3");
|
||||||
PropertyFileUtils.processDate(t, p, entry, true);
|
PropertyFileUtils.processDate(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now-3)").isEqualTo(String.valueOf(dayInt));
|
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now-3)").isEqualTo(String.valueOf(dayInt));
|
||||||
|
|
||||||
entry.setOperation(Entry.Operations.SUBTRACT);
|
entry.setOperation(Entry.Operations.SUBTRACT);
|
||||||
entry.setValue("2");
|
entry.setValue("2");
|
||||||
PropertyFileUtils.processDate(t, p, entry, true);
|
PropertyFileUtils.processDate(p, entry, true);
|
||||||
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now-2)").isEqualTo(String.valueOf(dayInt - 2));
|
assertThat(p.getProperty(entry.getKey())).as("processDate(entry.getKey(), now-2)").isEqualTo(String.valueOf(dayInt - 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +210,7 @@ class PropertyFileUtilsTest {
|
||||||
assertThatCode(() -> PropertyFileUtils.saveProperties(tmp, "Generated file - do not modify!", p))
|
assertThatCode(() -> PropertyFileUtils.saveProperties(tmp, "Generated file - do not modify!", p))
|
||||||
.as("save properties").doesNotThrowAnyException();
|
.as("save properties").doesNotThrowAnyException();
|
||||||
|
|
||||||
assertThat(PropertyFileUtils.loadProperties(t, tmp, p)).as("load properties").isTrue();
|
assertThat(PropertyFileUtils.loadProperties(tmp, p)).as("load properties").isTrue();
|
||||||
|
|
||||||
assertThat(p.getProperty(test)).as("read property").isEqualTo(test);
|
assertThat(p.getProperty(test)).as("read property").isEqualTo(test);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue