Compare commits
5 commits
2b5f29a016
...
b8cd4925a3
Author | SHA1 | Date | |
---|---|---|---|
b8cd4925a3 | |||
bd27eac071 | |||
3db6ca026d | |||
f2eeb1f1f9 | |||
09cdfea6b8 |
14 changed files with 162 additions and 81 deletions
|
@ -3,3 +3,17 @@
|
||||||
```console
|
```console
|
||||||
./bld compile run
|
./bld compile run
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Update Version Properties
|
||||||
|
|
||||||
|
```console
|
||||||
|
./bld update-major run
|
||||||
|
./bld update-minor run
|
||||||
|
./bld update-patch run
|
||||||
|
```
|
||||||
|
|
||||||
|
# Delete Version Properties
|
||||||
|
|
||||||
|
```console
|
||||||
|
./bld delete-version run
|
||||||
|
```
|
Binary file not shown.
|
@ -1,6 +1,6 @@
|
||||||
#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.5
|
|
||||||
bld.repositories=MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
|
||||||
bld.downloadExtensionSources=true
|
bld.downloadExtensionSources=true
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
|
bld.extension=com.uwyn.rife2:bld-property-file:0.9.6-SNAPSHOT
|
||||||
|
bld.repositories=MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.version=1.9.1
|
bld.version=1.9.1
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class PropertyFileExampleBuild extends Project {
|
||||||
new PropertyFileExampleBuild().start(args);
|
new PropertyFileExampleBuild().start(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Updates major version")
|
@BuildCommand(value = "update-major", summary = "Updates major version")
|
||||||
public void updateMajor() throws Exception {
|
public void updateMajor() throws Exception {
|
||||||
new PropertyFileOperation()
|
new PropertyFileOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
|
@ -66,7 +66,7 @@ public class PropertyFileExampleBuild extends Project {
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Updates minor version")
|
@BuildCommand(value = "update-minor", summary = "Updates minor version")
|
||||||
public void updateMinor() throws Exception {
|
public void updateMinor() throws Exception {
|
||||||
new PropertyFileOperation()
|
new PropertyFileOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
|
@ -82,7 +82,7 @@ public class PropertyFileExampleBuild extends Project {
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Updates patch version")
|
@BuildCommand(value = "update-patch", summary = "Updates patch version")
|
||||||
public void updatePatch() throws Exception {
|
public void updatePatch() throws Exception {
|
||||||
new PropertyFileOperation()
|
new PropertyFileOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
|
@ -98,7 +98,7 @@ public class PropertyFileExampleBuild extends Project {
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Updates the release")
|
@BuildCommand(value = "update-release", summary = "Updates the release")
|
||||||
public void updateRelease() throws Exception {
|
public void updateRelease() throws Exception {
|
||||||
new PropertyFileOperation()
|
new PropertyFileOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
|
@ -110,7 +110,7 @@ public class PropertyFileExampleBuild extends Project {
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Delete version properties")
|
@BuildCommand(value = "delete-version", summary = "Delete version properties")
|
||||||
public void deleteVersion() throws Exception {
|
public void deleteVersion() throws Exception {
|
||||||
new PropertyFileOperation()
|
new PropertyFileOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
|
|
Binary file not shown.
|
@ -1,7 +1,7 @@
|
||||||
bld.downloadExtensionJavadoc=false
|
bld.downloadExtensionJavadoc=false
|
||||||
bld.downloadExtensionSources=true
|
bld.downloadExtensionSources=true
|
||||||
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.9
|
|
||||||
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
|
|
||||||
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
|
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
|
||||||
|
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.0
|
||||||
|
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.version=1.9.1
|
bld.version=1.9.1
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class Entry extends EntryBase {
|
||||||
* @return the entry
|
* @return the entry
|
||||||
*/
|
*/
|
||||||
public Entry delete() {
|
public Entry delete() {
|
||||||
setDelete(true);
|
setDelete();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,15 @@ import java.util.function.IntFunction;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("PMD.DataClass")
|
@SuppressWarnings("PMD.DataClass")
|
||||||
public class EntryBase {
|
public class EntryBase {
|
||||||
private IntFunction<Integer> calc;
|
private IntFunction<Integer> calc_;
|
||||||
private Object defaultValue;
|
private Object defaultValue_;
|
||||||
private boolean isDelete;
|
private boolean isDelete_;
|
||||||
private String key;
|
private String key_;
|
||||||
private BiFunction<String, String, String> modify;
|
private String modifyValue_ = "";
|
||||||
private String modifyValue = "";
|
private BiFunction<String, String, String> modify_;
|
||||||
private Object newValue;
|
private Object newValue_;
|
||||||
private String pattern = "";
|
private String pattern_ = "";
|
||||||
private EntryDate.Units unit = EntryDate.Units.DAY;
|
private EntryDate.Units unit_ = EntryDate.Units.DAY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link EntryBase entry}.
|
* Creates a new {@link EntryBase entry}.
|
||||||
|
@ -44,7 +44,7 @@ public class EntryBase {
|
||||||
* @param key the required property key
|
* @param key the required property key
|
||||||
*/
|
*/
|
||||||
public EntryBase(String key) {
|
public EntryBase(String key) {
|
||||||
this.key = key;
|
key_ = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,7 @@ public class EntryBase {
|
||||||
* @return the calc function
|
* @return the calc function
|
||||||
*/
|
*/
|
||||||
protected IntFunction<Integer> getCalc() {
|
protected IntFunction<Integer> getCalc() {
|
||||||
return calc;
|
return calc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +62,7 @@ public class EntryBase {
|
||||||
* @return the default value
|
* @return the default value
|
||||||
*/
|
*/
|
||||||
protected Object getDefaultValue() {
|
protected Object getDefaultValue() {
|
||||||
return defaultValue;
|
return defaultValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,7 +71,7 @@ public class EntryBase {
|
||||||
* @return the key
|
* @return the key
|
||||||
*/
|
*/
|
||||||
protected String getKey() {
|
protected String getKey() {
|
||||||
return key;
|
return key_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,16 +80,16 @@ public class EntryBase {
|
||||||
* @return the modify function
|
* @return the modify function
|
||||||
*/
|
*/
|
||||||
protected BiFunction<String, String, String> getModify() {
|
protected BiFunction<String, String, String> getModify() {
|
||||||
return modify;
|
return modify_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value to be used in the {@link #modify} function.
|
* Returns the value to be used in the {@link #modify_} function.
|
||||||
*
|
*
|
||||||
* @return the modify value
|
* @return the modify value
|
||||||
*/
|
*/
|
||||||
protected String getModifyValue() {
|
protected String getModifyValue() {
|
||||||
return modifyValue;
|
return modifyValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,7 +98,7 @@ public class EntryBase {
|
||||||
* @return the new value
|
* @return the new value
|
||||||
*/
|
*/
|
||||||
public Object getNewValue() {
|
public Object getNewValue() {
|
||||||
return newValue;
|
return newValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,7 +107,7 @@ public class EntryBase {
|
||||||
* @return the pattern
|
* @return the pattern
|
||||||
*/
|
*/
|
||||||
protected String getPattern() {
|
protected String getPattern() {
|
||||||
return pattern;
|
return pattern_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,7 +116,7 @@ public class EntryBase {
|
||||||
* @return the unit
|
* @return the unit
|
||||||
*/
|
*/
|
||||||
protected EntryDate.Units getUnit() {
|
protected EntryDate.Units getUnit() {
|
||||||
return unit;
|
return unit_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,7 +125,7 @@ public class EntryBase {
|
||||||
* @return {@code true} or {@code false}
|
* @return {@code true} or {@code false}
|
||||||
*/
|
*/
|
||||||
protected boolean isDelete() {
|
protected boolean isDelete() {
|
||||||
return isDelete;
|
return isDelete_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,7 +136,7 @@ public class EntryBase {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public EntryBase key(String key) {
|
public EntryBase key(String key) {
|
||||||
setKey(key);
|
key_ = key;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ public class EntryBase {
|
||||||
* @param calc the calc function
|
* @param calc the calc function
|
||||||
*/
|
*/
|
||||||
protected void setCalc(IntFunction<Integer> calc) {
|
protected void setCalc(IntFunction<Integer> calc) {
|
||||||
this.calc = calc;
|
calc_ = calc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,16 +155,14 @@ public class EntryBase {
|
||||||
* @param defaultValue the default value
|
* @param defaultValue the default value
|
||||||
*/
|
*/
|
||||||
protected void setDefaultValue(Object defaultValue) {
|
protected void setDefaultValue(Object defaultValue) {
|
||||||
this.defaultValue = defaultValue;
|
defaultValue_ = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether the {@link java.util.Properties property} should be deleted.
|
* Sets the {@link java.util.Properties property} to be deleted.
|
||||||
*
|
|
||||||
* @param delete {@code true} or {@code false}
|
|
||||||
*/
|
*/
|
||||||
protected void setDelete(boolean delete) {
|
protected void setDelete() {
|
||||||
isDelete = delete;
|
isDelete_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,7 +171,7 @@ public class EntryBase {
|
||||||
* @param key the {@link java.util.Properties property} key
|
* @param key the {@link java.util.Properties property} key
|
||||||
*/
|
*/
|
||||||
protected void setKey(String key) {
|
protected void setKey(String key) {
|
||||||
this.key = key;
|
key_ = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -182,7 +180,7 @@ public class EntryBase {
|
||||||
* @param modify the modify function
|
* @param modify the modify function
|
||||||
*/
|
*/
|
||||||
protected void setModify(BiFunction<String, String, String> modify) {
|
protected void setModify(BiFunction<String, String, String> modify) {
|
||||||
this.modify = modify;
|
modify_ = modify;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -192,8 +190,8 @@ public class EntryBase {
|
||||||
* @param modify the modify function
|
* @param modify the modify function
|
||||||
*/
|
*/
|
||||||
protected void setModify(String value, BiFunction<String, String, String> modify) {
|
protected void setModify(String value, BiFunction<String, String, String> modify) {
|
||||||
this.modifyValue = value;
|
modifyValue_ = value;
|
||||||
this.modify = modify;
|
modify_ = modify;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,7 +200,7 @@ public class EntryBase {
|
||||||
* @param value the modify value.
|
* @param value the modify value.
|
||||||
*/
|
*/
|
||||||
protected void setModifyValue(String value) {
|
protected void setModifyValue(String value) {
|
||||||
this.modifyValue = value;
|
modifyValue_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,7 +209,7 @@ public class EntryBase {
|
||||||
* @param newValue the new value
|
* @param newValue the new value
|
||||||
*/
|
*/
|
||||||
public void setNewValue(Object newValue) {
|
public void setNewValue(Object newValue) {
|
||||||
this.newValue = newValue;
|
newValue_ = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -221,7 +219,7 @@ public class EntryBase {
|
||||||
* @param pattern the pattern
|
* @param pattern the pattern
|
||||||
*/
|
*/
|
||||||
protected void setPattern(String pattern) {
|
protected void setPattern(String pattern) {
|
||||||
this.pattern = pattern;
|
pattern_ = pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,6 +228,6 @@ public class EntryBase {
|
||||||
* @param unit the {@link EntryDate.Units unit}
|
* @param unit the {@link EntryDate.Units unit}
|
||||||
*/
|
*/
|
||||||
protected void setUnit(EntryDate.Units unit) {
|
protected void setUnit(EntryDate.Units unit) {
|
||||||
this.unit = unit;
|
unit_ = unit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class EntryDate extends EntryBase {
|
||||||
* @return this instance
|
* @return this instance
|
||||||
*/
|
*/
|
||||||
public EntryDate delete() {
|
public EntryDate delete() {
|
||||||
setDelete(true);
|
setDelete();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class EntryInt extends EntryBase {
|
||||||
* @return this instance
|
* @return this instance
|
||||||
*/
|
*/
|
||||||
public EntryInt delete() {
|
public EntryInt delete() {
|
||||||
setDelete(true);
|
setDelete();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,11 @@ import java.util.Properties;
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class PropertyFileOperation extends AbstractOperation<PropertyFileOperation> {
|
public class PropertyFileOperation extends AbstractOperation<PropertyFileOperation> {
|
||||||
private final List<EntryBase> entries = new ArrayList<>();
|
private final List<EntryBase> entries_ = new ArrayList<>();
|
||||||
private String comment = "";
|
private String comment_ = "";
|
||||||
private boolean failOnWarning;
|
private boolean failOnWarning_;
|
||||||
private File file;
|
private File file_;
|
||||||
private BaseProject project;
|
private BaseProject project_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the comment to be inserted at the top of the {@link java.util.Properties} file.
|
* Sets the comment to be inserted at the top of the {@link java.util.Properties} file.
|
||||||
|
@ -43,9 +43,8 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
* @param comment the header comment
|
* @param comment the header comment
|
||||||
* @return this instance
|
* @return this instance
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public PropertyFileOperation comment(String comment) {
|
public PropertyFileOperation comment(String comment) {
|
||||||
this.comment = comment;
|
comment_ = comment;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public PropertyFileOperation entry(EntryBase entry) {
|
public PropertyFileOperation entry(EntryBase entry) {
|
||||||
entries.add(entry);
|
entries_.add(entry);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,18 +66,18 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
var commandName = project.getCurrentCommandName();
|
var commandName = project_.getCurrentCommandName();
|
||||||
var properties = new Properties();
|
var properties = new Properties();
|
||||||
var success = false;
|
var success = false;
|
||||||
|
|
||||||
if (file == null) {
|
if (file_ == null) {
|
||||||
PropertyFileUtils.warn(commandName, "A properties file must be specified.");
|
PropertyFileUtils.warn(commandName, "A properties file must be specified.");
|
||||||
} else {
|
} else {
|
||||||
success = PropertyFileUtils.loadProperties(commandName, file, properties);
|
success = PropertyFileUtils.loadProperties(commandName, 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, "An entry key must specified.");
|
PropertyFileUtils.warn(commandName, "An entry key must specified.");
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,9 +93,9 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
PropertyFileUtils.warn(commandName, "An entry must be set or have a default value: " + key);
|
PropertyFileUtils.warn(commandName, "An entry must be set or have a default value: " + key);
|
||||||
} else {
|
} else {
|
||||||
if (entry instanceof EntryDate) {
|
if (entry instanceof EntryDate) {
|
||||||
success = PropertyFileUtils.processDate(commandName, properties, (EntryDate) entry, failOnWarning);
|
success = PropertyFileUtils.processDate(commandName, properties, (EntryDate) entry, failOnWarning_);
|
||||||
} else if (entry instanceof EntryInt) {
|
} else if (entry instanceof EntryInt) {
|
||||||
success = PropertyFileUtils.processInt(commandName, properties, (EntryInt) entry, failOnWarning);
|
success = PropertyFileUtils.processInt(commandName, properties, (EntryInt) entry, failOnWarning_);
|
||||||
} else {
|
} else {
|
||||||
success = PropertyFileUtils.processString(properties, (Entry) entry);
|
success = PropertyFileUtils.processString(properties, (Entry) entry);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +105,7 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
PropertyFileUtils.saveProperties(file, comment, properties);
|
PropertyFileUtils.saveProperties(file_, comment_, properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,9 +115,8 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
* @param failOnWarning if set to {@code true}, the execution will fail on any warnings.
|
* @param failOnWarning if set to {@code true}, the execution will fail on any warnings.
|
||||||
* @return this instance
|
* @return this instance
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public PropertyFileOperation failOnWarning(boolean failOnWarning) {
|
public PropertyFileOperation failOnWarning(boolean failOnWarning) {
|
||||||
this.failOnWarning = failOnWarning;
|
failOnWarning_ = failOnWarning;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,9 +126,8 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
* @param file the file to be edited
|
* @param file the file to be edited
|
||||||
* @return this instance
|
* @return this instance
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public PropertyFileOperation file(File file) {
|
public PropertyFileOperation file(File file) {
|
||||||
this.file = file;
|
file_ = file;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,9 +137,8 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
* @param file the file to be edited
|
* @param file the file to be edited
|
||||||
* @return this instance
|
* @return this instance
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public PropertyFileOperation file(String file) {
|
public PropertyFileOperation file(String file) {
|
||||||
this.file = new File(file);
|
file_ = new File(file);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +149,7 @@ public class PropertyFileOperation extends AbstractOperation<PropertyFileOperati
|
||||||
* @return this instance
|
* @return this instance
|
||||||
*/
|
*/
|
||||||
public PropertyFileOperation fromProject(BaseProject project) {
|
public PropertyFileOperation fromProject(BaseProject project) {
|
||||||
this.project = project;
|
project_ = project;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,12 +104,10 @@ public final class PropertyFileUtils {
|
||||||
public static boolean processDate(String command, Properties p, EntryDate entry, boolean failOnWarning)
|
public static boolean processDate(String command, Properties p, EntryDate entry, boolean failOnWarning)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
var success = true;
|
var success = true;
|
||||||
var value = currentValue(null, entry.getDefaultValue(),
|
var value = currentValue(null, entry.getDefaultValue(), entry.getNewValue());
|
||||||
entry.getNewValue());
|
|
||||||
|
|
||||||
var pattern = entry.getPattern();
|
var pattern = entry.getPattern();
|
||||||
|
|
||||||
String parsedValue = String.valueOf(value);
|
var parsedValue = String.valueOf(value);
|
||||||
if (pattern != null && !pattern.isBlank()) {
|
if (pattern != null && !pattern.isBlank()) {
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
|
|
||||||
|
@ -239,6 +237,7 @@ public final class PropertyFileUtils {
|
||||||
* @param entry the {@link Entry} containing the {@link Properties property} edits
|
* @param entry the {@link Entry} containing the {@link Properties property} edits
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("SameReturnValue")
|
||||||
public static boolean processString(Properties p, Entry entry) {
|
public static boolean processString(Properties p, Entry entry) {
|
||||||
var value = currentValue(p.getProperty(entry.getKey()), entry.getDefaultValue(), entry.getNewValue());
|
var value = currentValue(p.getProperty(entry.getKey()), entry.getDefaultValue(), entry.getNewValue());
|
||||||
|
|
||||||
|
@ -290,6 +289,7 @@ public final class PropertyFileUtils {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"PMD.SignatureDeclareThrowsException"})
|
@SuppressWarnings({"PMD.SignatureDeclareThrowsException"})
|
||||||
static void warn(String command, String message, Exception e, boolean failOnWarning) throws Exception {
|
static void warn(String command, String message, Exception e, boolean failOnWarning) throws Exception {
|
||||||
|
LOGGER.warning("ahah");
|
||||||
if (failOnWarning) {
|
if (failOnWarning) {
|
||||||
LOGGER.log(Level.SEVERE, '[' + command + "] " + message, e);
|
LOGGER.log(Level.SEVERE, '[' + command + "] " + message, e);
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023-Copyright $today.yearamp;#36;today.year the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package rife.bld.extension.propertyfile;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import rife.bld.Project;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static rife.bld.extension.propertyfile.Calc.ADD;
|
||||||
|
|
||||||
|
class PropertyFileOperationTest {
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||||
|
void testExecute() throws Exception {
|
||||||
|
var tmpFile = File.createTempFile("property-file-", "properties");
|
||||||
|
tmpFile.deleteOnExit();
|
||||||
|
|
||||||
|
new PropertyFileOperation()
|
||||||
|
.fromProject(new Project())
|
||||||
|
.file(tmpFile)
|
||||||
|
.comment("This is a comment")
|
||||||
|
.failOnWarning(true)
|
||||||
|
.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();
|
||||||
|
|
||||||
|
var p = new Properties();
|
||||||
|
p.load(Files.newInputStream(tmpFile.toPath()));
|
||||||
|
|
||||||
|
assertThat(p.getProperty("version.major")).as("major").isEqualTo("1");
|
||||||
|
assertThat(p.getProperty("version.minor")).as("minor").isEqualTo("0");
|
||||||
|
assertThat(p.getProperty("version.patch")).as("patch").isEqualTo("0");
|
||||||
|
assertThat(p.getProperty("build.date")).as("date")
|
||||||
|
.isEqualTo(LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||||
|
|
||||||
|
new PropertyFileOperation()
|
||||||
|
.fromProject(new Project())
|
||||||
|
.file(tmpFile.getAbsolutePath())
|
||||||
|
.entry(new EntryInt("version.major").calc(c -> c + 2))
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
p.load(Files.newInputStream(tmpFile.toPath()));
|
||||||
|
assertThat(p.getProperty("version.major")).as("major+2").isEqualTo("3");
|
||||||
|
|
||||||
|
new PropertyFileOperation()
|
||||||
|
.fromProject(new Project())
|
||||||
|
.file(tmpFile)
|
||||||
|
.entry(new EntryInt("build.date").delete())
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
p.clear();
|
||||||
|
p.load(Files.newInputStream(tmpFile.toPath()));
|
||||||
|
|
||||||
|
assertThat(p.getProperty("build.date")).as("dalete build.date").isNull();
|
||||||
|
assertThat(p).as("version keys").containsKeys("version.major", "version.minor", "version.patch");
|
||||||
|
}
|
||||||
|
}
|
|
@ -58,7 +58,6 @@ class PropertyFileUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
|
||||||
void parseDateSub() throws Exception {
|
void parseDateSub() throws Exception {
|
||||||
var entryDate = newEntryDate();
|
var entryDate = newEntryDate();
|
||||||
entryDate.setCalc(SUB);
|
entryDate.setCalc(SUB);
|
||||||
|
@ -84,7 +83,6 @@ class PropertyFileUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
|
||||||
void parseIntSubTest() throws Exception {
|
void parseIntSubTest() throws Exception {
|
||||||
var entryInt = newEntryInt();
|
var entryInt = newEntryInt();
|
||||||
entryInt.calc(SUB);
|
entryInt.calc(SUB);
|
||||||
|
@ -148,7 +146,6 @@ class PropertyFileUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
|
||||||
void parseTimeTest() throws Exception {
|
void parseTimeTest() throws Exception {
|
||||||
var entry = new EntryDate("time").pattern("m");
|
var entry = new EntryDate("time").pattern("m");
|
||||||
var time = LocalTime.now();
|
var time = LocalTime.now();
|
||||||
|
@ -165,7 +162,6 @@ class PropertyFileUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
|
||||||
void processDateAddTest() throws Exception {
|
void processDateAddTest() throws Exception {
|
||||||
var entryDate = newEntryDate();
|
var entryDate = newEntryDate();
|
||||||
entryDate.setCalc(ADD);
|
entryDate.setCalc(ADD);
|
||||||
|
@ -189,7 +185,6 @@ class PropertyFileUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
|
||||||
void processIntAddTest() throws Exception {
|
void processIntAddTest() throws Exception {
|
||||||
var entryInt = newEntryInt();
|
var entryInt = newEntryInt();
|
||||||
entryInt.calc(ADD);
|
entryInt.calc(ADD);
|
||||||
|
@ -233,7 +228,6 @@ class PropertyFileUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
|
||||||
void savePropertiesTest() throws Exception {
|
void savePropertiesTest() throws Exception {
|
||||||
var p = new Properties();
|
var p = new Properties();
|
||||||
var test = "test";
|
var test = "test";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue