bld Extension to Create or Modify Properties Files http://github.com/rife2/bld-property-file
Find a file
2023-04-04 09:01:12 -07:00
.github/workflows Added JDK 20 to GitHub workflow 2023-04-02 18:40:15 -07:00
.idea Added calc and modify functions 2023-04-04 09:01:12 -07:00
.vscode Added calc and modify functions 2023-04-04 09:01:12 -07:00
examples Added calc and modify functions 2023-04-04 09:01:12 -07:00
lib/bld Added calc and modify functions 2023-04-04 09:01:12 -07:00
src Added calc and modify functions 2023-04-04 09:01:12 -07:00
.gitignore Added calc and modify functions 2023-04-04 09:01:12 -07:00
bld Updated to RIFE2 1.5.14 2023-04-03 02:20:09 -07:00
bld.bat Updated to RIFE2 1.5.14 2023-04-03 02:20:09 -07:00
LICENSE.txt Initial commit 2023-04-02 15:29:27 -07:00
README.md Added calc and modify functions 2023-04-04 09:01:12 -07:00

Bld Extension to Create or Modify Properties Files

License (3-Clause BSD) Java GitHub CI

An extension for creating or modifying property files with bld. It is inspired by the ant PropertyFile task.

@BuildCommand
public void updateMajor() throws Exception {
    new PropertyFileOperation(this)
            .file("version.properties")
            .entry(new Entry("version.major", Types.INT).defaultValue(0).calc(ADD))
            .entry(new Entry("version.minor").set(0))
            .entry(new Entry("version.patch").set(0))
            .entry(new Entry("build.date", Types.DATE).set("now").pattern("yyyy-MM-dd"))
            .execute();
}

Invoking the updateMajor command, will create the version.properteesfile:

./bld updateMajor ...
# 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:

./bld updateMajor ...
# version.properties
build.date=2023-04-02
version.major=2
version.minor=0
version.patch=0

Property File

The PropertyFileOperation class is used to configure the properties file location, etc.

Function 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 execution to fail on any warnings. No

Entry

The Entry class is used to specify modifications to be made to the properties file.

Function Description
key() The name of the property name/value pair.
set() The value to set the property to, regardless of its previous value.
defaultValue() The initial value to set for the property to, if not already defined.
type() The value datatype, either Types.INT, Types.DATE, or Types.STRING. If none specified, Types.STRING is assumed.
pattern() For Types.INT and Types.DATE only. If present, will parse the value as DecimalFormat or SimpleDateFormat patterns, respectively.
unit() The unit value to be used with Types.DATE calculations. See Units.
  • For convenience the key (and optional type) is first set in the constructor.
  • key is required. value or defaultValue are required except when deleting.
  • For Type.DATE, the now keyword can be used as the property value.

Functions

The following function are available:

Function Example Description
calc() calc(ADD)
calc(v -> v + 1)
calc(SUB)
calc(v -> v - 1)
Perform a calculation with an entry value.
modify() modify("-foo", String::concat)
modify("-foo", (v, s) -> v + s)
modify((v, s) -> v.trim())
Modify an entry value.
delete() delete() Delete an entry.

Units

The following units are available for Types.DATE:

  • Units.MILLISECOND
  • Units.SECOND
  • Units.MINUTE
  • Units.HOUR
  • Units.DAY
  • Units.WEEK
  • Units.MONTH
  • Units.YEAR

Differences with the ant PropertyFile task

  • 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.