Skip to content

Latest commit

 

History

History
executable file
·
120 lines (92 loc) · 9.83 KB

README.md

File metadata and controls

executable file
·
120 lines (92 loc) · 9.83 KB

bld Extension to Create or Modify Properties Files

License Java bld Release Snapshot GitHub CI

To install, please refer to the extensions documentation.

To create or modifying property files with bld, add the follwing to your build file:

@BuildCommand
public void updateMajor() throws Exception {
    new PropertyFileOperation()
            .fromProject(this)
            .file("version.properties")
            .entry(new EntryInt("version.major").defaultValue(0).calc(ADD))
            .entry(new EntryInt("version.minor").set(0))
            .entry(new EntryInt("version.patch").set(0))
            .entry(new EntryDate("build.date").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 a String property.

Function Description/Example
defaultValue() The value to be used if the property doesn't exist.
delete() Delete the property.
modify() modify("-foo", String::concat)
modify("-foo", (v, s) -> v + s)
modify((v, s) -> v.trim())
pattern() If present, will parse the value as a Formatter pattern.
set() The value to set the property to, regardless of its previous value.

EntryDate

The EntryDate class is used to specify modifications to a date property.

Function Description/Example
calc() calc(ADD)
calc(v -> v + 1)
calc(SUB)
calc(v -> v - 1)
delete() Delete the property.
now() Set the entry to the current date/time.
pattern() If present, will parse the value as a DateTimeFormatter pattern.
set() The Calendar, Date, or java.time value to set the property to, regardless of its previous value.
unit() The unit to be used calculations. See Units.
  • set or now are required.

Units

The following Units are available:

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

EntryInt

The EntryInt class is used to specify modifications to a integer property.

Function Description/Example
defaultValue() The value to be used if the property doesn't exist.
calc() calc(ADD)
calc(v -> v + 1)
calc(SUB)
calc(v -> v - 1)
delete() Delete the property.
pattern() If present, will parse the value as a DecimalFormat pattern.
set() The integer value to set the property to, regardless of its previous value.

It is inspired by the ant PropertyFile task.