diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index d91f848..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/libraries/bld.xml b/.idea/libraries/bld.xml index 3409629..7aa10eb 100644 --- a/.idea/libraries/bld.xml +++ b/.idea/libraries/bld.xml @@ -2,11 +2,11 @@ - + - + diff --git a/.vscode/settings.json b/.vscode/settings.json index 122fc60..ba59365 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ ], "java.configuration.updateBuildConfiguration": "automatic", "java.project.referencedLibraries": [ - "${HOME}/.rife2/dist/rife2-1.5.20.jar", + "${HOME}/.rife2/dist/rife2-1.5.19.jar", "lib/compile/*.jar", "lib/runtime/*.jar", "lib/test/*.jar" diff --git a/README.md b/README.md index b124109..ad25797 100755 --- a/README.md +++ b/README.md @@ -11,8 +11,7 @@ An extension for creating or modifying [property files](https://docs.oracle.com/ ```java @BuildCommand public void updateMajor() throws Exception { - new PropertyFileOperation() - .fromProject(this) + new PropertyFileOperation(this) .file("version.properties") .entry(new EntryInt("version.major").defaultValue(0).calc(ADD)) .entry(new EntryInt("version.minor").set(0)) diff --git a/config/pmd.xml b/config/pmd.xml deleted file mode 100644 index 3dc68dc..0000000 --- a/config/pmd.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - Erik's Ruleset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/.idea/libraries/bld.xml b/examples/.idea/libraries/bld.xml index 081d064..970a359 100644 --- a/examples/.idea/libraries/bld.xml +++ b/examples/.idea/libraries/bld.xml @@ -2,12 +2,12 @@ - + - + diff --git a/examples/.vscode/settings.json b/examples/.vscode/settings.json index 122fc60..ba59365 100644 --- a/examples/.vscode/settings.json +++ b/examples/.vscode/settings.json @@ -7,7 +7,7 @@ ], "java.configuration.updateBuildConfiguration": "automatic", "java.project.referencedLibraries": [ - "${HOME}/.rife2/dist/rife2-1.5.20.jar", + "${HOME}/.rife2/dist/rife2-1.5.19.jar", "lib/compile/*.jar", "lib/runtime/*.jar", "lib/test/*.jar" diff --git a/examples/lib/bld/bld-wrapper.jar b/examples/lib/bld/bld-wrapper.jar index 2780742..7cc21a1 100644 Binary files a/examples/lib/bld/bld-wrapper.jar and b/examples/lib/bld/bld-wrapper.jar differ diff --git a/examples/lib/bld/bld-wrapper.properties b/examples/lib/bld/bld-wrapper.properties index 5ebf190..5cd8e32 100644 --- a/examples/lib/bld/bld-wrapper.properties +++ b/examples/lib/bld/bld-wrapper.properties @@ -1,6 +1,6 @@ #Sun Apr 02 10:32:44 PDT 2023 -bld.extension=com.uwyn.rife2:bld-property-file:0.9.2-SNAPSHOT -bld.repositories=MAVEN_LOCAL,MAVEN_LOCAL,RIFE2_RELEASES,RIFE2_SNAPSHOTS +bld.extension=com.uwyn.rife2:bld-property-file:0.9.1 +bld.repositories=MAVEN_LOCAL,RIFE2_RELEASES bld.downloadExtensionSources=true rife2.downloadLocation= -rife2.version=1.5.20 \ No newline at end of file +rife2.version=1.5.19 \ No newline at end of file diff --git a/examples/src/bld/java/com/example/PropertyFileExampleBuild.java b/examples/src/bld/java/com/example/PropertyFileExampleBuild.java index 5aa8900..615caa2 100644 --- a/examples/src/bld/java/com/example/PropertyFileExampleBuild.java +++ b/examples/src/bld/java/com/example/PropertyFileExampleBuild.java @@ -39,8 +39,7 @@ public class PropertyFileExampleBuild extends Project { @BuildCommand(summary = "Updates major version") public void updateMajor() throws Exception { - new PropertyFileOperation() - .fromProject(this) + new PropertyFileOperation(this) .file("version.properties") // set the major version to 1 if it doesn't exist, increase by 1 .entry(new EntryInt("version.major").defaultValue(0).calc(ADD)) @@ -55,8 +54,7 @@ public class PropertyFileExampleBuild extends Project { @BuildCommand(summary = "Updates minor version") public void updateMinor() throws Exception { - new PropertyFileOperation() - .fromProject(this) + new PropertyFileOperation(this) .file("version.properties") // set the major version to 1 if it doesn't exist .entry(new EntryInt("version.major").defaultValue(1)) @@ -71,8 +69,7 @@ public class PropertyFileExampleBuild extends Project { @BuildCommand(summary = "Updates patch version") public void updatePatch() throws Exception { - new PropertyFileOperation() - .fromProject(this) + new PropertyFileOperation(this) .file("version.properties") // set the major version to 1 if it doesn't exist .entry(new EntryInt("version.major").defaultValue(1)) @@ -87,8 +84,7 @@ public class PropertyFileExampleBuild extends Project { @BuildCommand(summary = "Updates the release") public void updateRelease() throws Exception { - new PropertyFileOperation() - .fromProject(this) + new PropertyFileOperation(this) .file("version.properties") // set the release to current date/time .entry(new EntryDate("release").now().pattern("yyyyMMddHHmmss")) @@ -99,8 +95,7 @@ public class PropertyFileExampleBuild extends Project { @BuildCommand(summary = "Delete version properties") public void deleteVersion() throws Exception { - new PropertyFileOperation() - .fromProject(this) + new PropertyFileOperation(this) .file("version.properties") .entry(new Entry("version.major").delete()) .entry(new Entry("version.minor").delete()) diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar index 6474664..fed125f 100644 Binary files a/lib/bld/bld-wrapper.jar and b/lib/bld/bld-wrapper.jar differ diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index f5e3e99..26178d3 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -1,6 +1,2 @@ -bld.downloadExtensionJavadoc=false -bld.downloadExtensionSources=true -bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.1-SNAPSHOT -bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES -rife2.downloadLocation= -rife2.version=1.5.20 +#Sat Apr 01 10:09:33 PDT 2023 +rife2.version=1.5.19 diff --git a/src/bld/java/rife/bld/extension/propertyfile/PropertyFileBuild.java b/src/bld/java/rife/bld/extension/propertyfile/PropertyFileBuild.java index 1556910..5812f0e 100644 --- a/src/bld/java/rife/bld/extension/propertyfile/PropertyFileBuild.java +++ b/src/bld/java/rife/bld/extension/propertyfile/PropertyFileBuild.java @@ -1,9 +1,8 @@ package rife.bld.extension.propertyfile; -import rife.bld.BuildCommand; import rife.bld.Project; -import rife.bld.extension.PmdOperation; import rife.bld.publish.PublishDeveloper; +import rife.bld.publish.PublishInfo; import rife.bld.publish.PublishLicense; import rife.bld.publish.PublishScm; @@ -26,7 +25,7 @@ public class PropertyFileBuild extends Project { repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES); scope(compile) - .include(dependency("com.uwyn.rife2", "rife2", version(1, 5, 20))); + .include(dependency("com.uwyn.rife2", "rife2", version(1, 5, 19))); scope(test) .include(dependency("org.jsoup", "jsoup", version(1, 15, 4))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 9, 2))) @@ -34,27 +33,27 @@ public class PropertyFileBuild extends Project { .include(dependency("org.assertj:assertj-joda-time:2.2.0")); javadocOperation() - .javadocOptions() + .javadocOptions() .docLint(NO_MISSING) .link("https://rife2.github.io/rife2/"); publishOperation() - .repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2")) -// .repository(MAVEN_LOCAL) - .info() + .repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2")) +// .repository(MAVEN_LOCAL) + .info() .groupId("com.uwyn.rife2") .artifactId("bld-property-file") .description("bld Extension to Create or Modify Properties Files") .url("https://github.com/rife2/bld-property-file") .developer(new PublishDeveloper().id("ethauvin").name("Erik C. Thauvin").email("erik@thauvin.net") - .url("https://erik.thauvin.net/")) + .url("https://erik.thauvin.net/")) .developer(new PublishDeveloper().id("gbevin").name("Geert Bevin").email("gbevin@uwyn.com") - .url("https://github.com/gbevin")) + .url("https://github.com/gbevin")) .license(new PublishLicense().name("The Apache License, Version 2.0") - .url("http://www.apache.org/licenses/LICENSE-2.0.txt")) + .url("http://www.apache.org/licenses/LICENSE-2.0.txt")) .scm(new PublishScm().connection("scm:git:https://github.com/rife2/bld-property-file.git") - .developerConnection("scm:git:git@github.com:rife2/bld-property-file.git") - .url("https://github.com/rife2/bld-property-file")) + .developerConnection("scm:git:git@github.com:rife2/bld-property-file.git") + .url("https://github.com/rife2/bld-property-file")) .signKey(property("sign.key")) .signPassphrase(property("sign.passphrase")); } @@ -62,13 +61,4 @@ public class PropertyFileBuild extends Project { public static void main(String[] args) { new PropertyFileBuild().start(args); } - - @BuildCommand(summary = "Runs PMD analysis") - public void pmd() throws Exception { - new PmdOperation() - .fromProject(this) - .failOnViolation(true) - .ruleSets("config/pmd.xml") - .execute(); - } } diff --git a/src/main/java/rife/bld/extension/propertyfile/Calc.java b/src/main/java/rife/bld/extension/propertyfile/Calc.java index d6b2f70..9e90642 100644 --- a/src/main/java/rife/bld/extension/propertyfile/Calc.java +++ b/src/main/java/rife/bld/extension/propertyfile/Calc.java @@ -29,11 +29,6 @@ public final class Calc { public static final IntFunction ADD = Calc::add; public static final IntFunction SUB = Calc::sub; - - private Calc() { - // no-op - } - /** * Adds {@code 1} to the value. * diff --git a/src/main/java/rife/bld/extension/propertyfile/Entry.java b/src/main/java/rife/bld/extension/propertyfile/Entry.java index bd8087b..89a7e3e 100644 --- a/src/main/java/rife/bld/extension/propertyfile/Entry.java +++ b/src/main/java/rife/bld/extension/propertyfile/Entry.java @@ -30,6 +30,16 @@ public class Entry extends EntryBase { super(key); } + /** + * Sets the new {@link java.util.Properties property} value. + * + * @param s The new value + */ + public Entry set(Object s) { + setNewValue(s); + return this; + } + /** *

Sets the initial value to set the {@link java.util.Properties property} to, if not already defined.

* @@ -41,24 +51,6 @@ public class Entry extends EntryBase { return this; } - /** - * Sets the {@link Entry entry} up for deletion. - */ - public Entry delete() { - setDelete(true); - return this; - } - - /** - * Creates a new {@link Entry entry}. - * - * @param modify the modification function - */ - public Entry modify(BiFunction modify) { - setModify(modify); - return this; - } - /** * Creates a new {@link Entry entry}. * @@ -72,12 +64,20 @@ public class Entry extends EntryBase { } /** - * Sets the new {@link java.util.Properties property} value. + * Creates a new {@link Entry entry}. * - * @param s The new value + * @param modify the modification function */ - public Entry set(Object s) { - setNewValue(s); + public Entry modify(BiFunction modify) { + setModify(modify); + return this; + } + + /** + * Sets the {@link Entry entry} up for deletion. + */ + public Entry delete() { + setDelete(true); return this; } } diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryBase.java b/src/main/java/rife/bld/extension/propertyfile/EntryBase.java index 1cadf1c..ba9edc7 100644 --- a/src/main/java/rife/bld/extension/propertyfile/EntryBase.java +++ b/src/main/java/rife/bld/extension/propertyfile/EntryBase.java @@ -27,15 +27,15 @@ import java.util.function.IntFunction; * @since 1.0 */ public class EntryBase { - private IntFunction calc; - private Object defaultValue; - private boolean isDelete; private String key; - private BiFunction modify; - private String modifyValue = ""; + private Object defaultValue; private Object newValue; + private String modifyValue = ""; + private boolean isDelete; private String pattern = ""; private EntryDate.Units unit = EntryDate.Units.DAY; + private IntFunction calc; + private BiFunction modify; /** * Creates a new {@link EntryBase entry}. @@ -46,66 +46,6 @@ public class EntryBase { this.key = key; } - /** - * Returns the calculation function. - */ - protected IntFunction getCalc() { - return calc; - } - - /** - * Sets the calculation function. - */ - protected void setCalc(IntFunction calc) { - this.calc = calc; - } - - /** - * Returns the default value. - */ - protected Object getDefaultValue() { - return defaultValue; - } - - /** - * Sets the initial value to set the {@link java.util.Properties property} to, if not already defined. - * - * @param defaultValue the default value - */ - protected void setDefaultValue(Object defaultValue) { - this.defaultValue = defaultValue; - } - - /** - * Returns the key of the {@link java.util.Properties property}. - */ - protected String getKey() { - return key; - } - - /** - * Sets the key of the {@link java.util.Properties property}. - * - * @param key the {@link java.util.Properties property} key - */ - protected void setKey(String key) { - this.key = key; - } - - /** - * Returns the modify function. - */ - protected BiFunction getModify() { - return modify; - } - - /** - * Sets the modify function. - */ - protected void setModify(BiFunction modify) { - this.modify = modify; - } - /** * Returns the value to be used in the {@link #modify} function. */ @@ -123,19 +63,87 @@ public class EntryBase { } /** - * Returns the new value to set the {@link java.util.Properties property)} to. + * Returns the modify function. */ - public Object getNewValue() { - return newValue; + protected BiFunction getModify() { + return modify; } /** - * Sets a new value for {@link java.util.Properties property}. - * - * @param newValue the new value + * Sets the modify function. */ - public void setNewValue(Object newValue) { - this.newValue = newValue; + protected void setModify(BiFunction modify) { + this.modify = modify; + } + + /** + * Sets the modify function. + * + * @param value the value to perform a modification with + */ + protected void setModify(String value, BiFunction modify) { + this.modifyValue = value; + this.modify = modify; + } + + /** + * Returns {@code true} if the {@link java.util.Properties property} is to be deleted. + */ + protected boolean isDelete() { + return isDelete; + } + + /** + * Sets whether the {@link java.util.Properties property} should be deleted. + */ + protected void setDelete(boolean delete) { + isDelete = delete; + } + + /** + * Returns the calculation function. + */ + protected IntFunction getCalc() { + return calc; + } + + /** + * Sets the calculation function. + */ + protected void setCalc(IntFunction calc) { + this.calc = calc; + } + + /** + * Returns the key of the {@link java.util.Properties property}. + */ + protected String getKey() { + return key; + } + + /** + * Sets the key of the {@link java.util.Properties property}. + * + * @param key the {@link java.util.Properties property} key + */ + protected void setKey(String key) { + this.key = key; + } + + /** + * Returns the default value. + */ + protected Object getDefaultValue() { + return defaultValue; + } + + /** + * Sets the initial value to set the {@link java.util.Properties property} to, if not already defined. + * + * @param defaultValue the default value + */ + protected void setDefaultValue(Object defaultValue) { + this.defaultValue = defaultValue; } /** @@ -171,20 +179,6 @@ public class EntryBase { this.unit = unit; } - /** - * Returns {@code true} if the {@link java.util.Properties property} is to be deleted. - */ - protected boolean isDelete() { - return isDelete; - } - - /** - * Sets whether the {@link java.util.Properties property} should be deleted. - */ - protected void setDelete(boolean delete) { - isDelete = delete; - } - /** * Sets the key of the {@link java.util.Properties property}. * @@ -197,12 +191,18 @@ public class EntryBase { } /** - * Sets the modify function. - * - * @param value the value to perform a modification with + * Returns the new value to set the {@link java.util.Properties property)} to. */ - protected void setModify(String value, BiFunction modify) { - this.modifyValue = value; - this.modify = modify; + public Object getNewValue() { + return newValue; + } + + /** + * Sets a new value for {@link java.util.Properties property}. + * + * @param newValue the new value + */ + public void setNewValue(Object newValue) { + this.newValue = newValue; } } diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java index 51e6630..3522f47 100644 --- a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java +++ b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java @@ -37,43 +37,6 @@ public class EntryDate extends EntryBase { super(key); } - /** - * Creates a new {@link EntryDate entry}. - * - * @param calc the calculation function - */ - public EntryDate calc(IntFunction calc) { - setCalc(calc); - return this; - } - - /** - * Sets the {@link EntryDate entry} up for deletion. - */ - public EntryDate delete() { - setDelete(true); - return this; - } - - /** - * Sets the new {@link java.util.Properties property} value to now. - */ - public EntryDate now() { - setNewValue("now"); - return this; - } - - /** - * Sets the pattern for {@link EntryInt} and {@link EntryDate} to{@link java.text.DecimalFormat DecimalFormat} and - * {@link java.time.format.DateTimeFormatter DateTimeFormatter} respectively. - * - * @param pattern the pattern - */ - public EntryDate pattern(String pattern) { - setPattern(pattern); - return this; - } - /** * Sets the new {@link java.util.Properties property} value to an {@link Instant} * @@ -144,6 +107,35 @@ public class EntryDate extends EntryBase { return this; } + /** + * Sets the new {@link java.util.Properties property} value to now. + */ + public EntryDate now() { + setNewValue("now"); + return this; + } + + /** + * Creates a new {@link EntryDate entry}. + * + * @param calc the calculation function + */ + public EntryDate calc(IntFunction calc) { + setCalc(calc); + return this; + } + + /** + * Sets the pattern for {@link EntryInt} and {@link EntryDate} to{@link java.text.DecimalFormat DecimalFormat} and + * {@link java.time.format.DateTimeFormatter DateTimeFormatter} respectively. + * + * @param pattern the pattern + */ + public EntryDate pattern(String pattern) { + setPattern(pattern); + return this; + } + /** * Sets the {@link Units unit} value to apply to calculations for {@link EntryDate}. * @@ -154,6 +146,14 @@ public class EntryDate extends EntryBase { return this; } + /** + * Sets the {@link EntryDate entry} up for deletion. + */ + public EntryDate delete() { + setDelete(true); + return this; + } + /** * The units available for {@link EntryDate} calculations. * diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryInt.java b/src/main/java/rife/bld/extension/propertyfile/EntryInt.java index 9dd619b..f2001ef 100644 --- a/src/main/java/rife/bld/extension/propertyfile/EntryInt.java +++ b/src/main/java/rife/bld/extension/propertyfile/EntryInt.java @@ -35,12 +35,12 @@ public class EntryInt extends EntryBase { } /** - * Creates a new {@link EntryInt entry}. + * Sets the new {@link java.util.Properties property} value to an integer. * - * @param calc the calculation function. + * @param i The integer to set the value to */ - public EntryInt calc(IntFunction calc) { - setCalc(calc); + public EntryInt set(int i) { + setNewValue(i); return this; } @@ -55,6 +55,16 @@ public class EntryInt extends EntryBase { return this; } + /** + * Creates a new {@link EntryInt entry}. + * + * @param calc the calculation function. + */ + public EntryInt calc(IntFunction calc) { + setCalc(calc); + return this; + } + /** * Sets the {@link EntryInt entry} up for deletion. */ @@ -62,14 +72,4 @@ public class EntryInt extends EntryBase { setDelete(true); return this; } - - /** - * Sets the new {@link java.util.Properties property} value to an integer. - * - * @param i The integer to set the value to - */ - public EntryInt set(int i) { - setNewValue(i); - return this; - } } diff --git a/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java b/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java index 9364be2..77cc22b 100644 --- a/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java +++ b/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java @@ -16,7 +16,7 @@ package rife.bld.extension.propertyfile; -import rife.bld.BaseProject; +import rife.bld.Project; import rife.bld.operations.AbstractOperation; import java.io.File; @@ -32,20 +32,13 @@ import java.util.Properties; */ public class PropertyFileOperation extends AbstractOperation { private final List entries = new ArrayList<>(); + private final Project project; + private File file; private String comment = ""; private boolean failOnWarning; - private File file; - private BaseProject project; - /** - * Sets the comment to be inserted at the top of the {@link java.util.Properties} file. - * - * @param comment the header comment - */ - @SuppressWarnings("unused") - public PropertyFileOperation comment(String comment) { - this.comment = comment; - return this; + public PropertyFileOperation(Project project) { + this.project = project; } /** @@ -60,6 +53,50 @@ public class PropertyFileOperation extends AbstractOperation v - 2); - PropertyFileUtils.processDate(t, p, entryDate.now(), true); - assertThat(p.getProperty(entryDate.getKey())).as("processDate(now-2)").isEqualTo(String.valueOf(dayOfYear - 2)); - - entryDate.setCalc(SUB); - PropertyFileUtils.processDate(t, p, entryDate.set(new Date()), true); - assertThat(p.getProperty(entryDate.getKey())).as("processDate(date-1)").isEqualTo(String.valueOf(dayOfYear - 1)); - - entryDate.setCalc(v -> v - 2); - PropertyFileUtils.processDate(t, p, entryDate.set(Calendar.getInstance()), true); - assertThat(p.getProperty(entryDate.getKey())).as("processDate(cal-2)").isEqualTo(String.valueOf(dayOfYear - 2)); - - entryDate.setCalc(v -> v - 3); - PropertyFileUtils.processDate(t, p, entryDate.set(LocalDate.now()), - true); - assertThat(p.getProperty(entryDate.getKey())).as("processDate(LocalDate-3)").isEqualTo(String.valueOf(dayOfYear - 3)); + void testWarn() { + assertThatCode(() -> PropertyFileUtils.warn("command", "message", new IOException(t), true)) + .hasMessage(t).isInstanceOf(IOException.class); + assertThatCode(() -> PropertyFileUtils.warn("command", t, new Exception(t), false)) + .as("failOnWarning = false").doesNotThrowAnyException(); } @Test - @SuppressWarnings("PMD.SignatureDeclareThrowsException") - void parseIntSubTest() throws Exception { - var entryInt = newEntryInt(); - entryInt.calc(SUB); - entryInt.setPattern("0000"); - PropertyFileUtils.processInt(t, p, entryInt.defaultValue("0017"), true); - assertThat(p.getProperty(entryInt.getKey())).as("sub(0017)").isEqualTo("0016"); - - PropertyFileUtils.processInt(t, p, entryInt.set(16).calc(v -> v - 3), true); - assertThat(p.getProperty(entryInt.getKey())).as("sub(16)-3").isEqualTo("0013"); - } - - @Test - @SuppressWarnings("PMD.AvoidDuplicateLiterals") void parseStringAppend() { - var entry = newEntry(); - PropertyFileUtils.processString(p, entry.set(1)); PropertyFileUtils.processString(p, entry.modify("-foo", String::concat)); assertThat(p.getProperty(entry.getKey())).as(String.format("processString(%s, %s)", entry.getKey(), entry.getNewValue())).isEqualTo("1-foo"); } - @Test - void parseStringCap() { - var entry = newEntry(); - PropertyFileUtils.processString(p, entry.set(t).modify("", (v, s) -> v.toUpperCase(Localization.getLocale()))); - assertThat(p.getProperty(entry.getKey())).as("capitalize").isEqualTo(t.toUpperCase(Localization.getLocale())); - - } - - @Test - void parseStringCat() { - var entry = newEntry(); - entry.set(t).setModify("-foo", String::concat); - PropertyFileUtils.processString(p, entry); - assertThat(p.getProperty(entry.getKey())).as("replace").isEqualTo(t + "-foo"); - } - @Test void parseStringPrepend() { - var entry = newEntry(); - PropertyFileUtils.processString(p, entry.set(1)); PropertyFileUtils.processString(p, entry.modify("foo-", (v, s) -> s + v)); assertThat(p.getProperty(entry.getKey())).as(String.format("processString(%s, %s)", entry.getKey(), entry.getNewValue())) .isEqualTo("foo-1"); } + @Test + void parseStringCap() { + PropertyFileUtils.processString(p, entry.set(t).modify("", (v, s) -> v.toUpperCase(Localization.getLocale()))); + assertThat(p.getProperty(entry.getKey())).as("capitalize").isEqualTo(t.toUpperCase(Localization.getLocale())); + + } + @Test void parseStringReplace() { - var entry = newEntry(); entry.set(t).setModify("T", (v, s) -> v.replace("t", s)); PropertyFileUtils.processString(p, entry); assertThat(p.getProperty(entry.getKey())).as("replace(t -> T)").isEqualTo("TesT"); } + @Test + void parseStringCat() { + entry.set(t).setModify("-foo", String::concat); + PropertyFileUtils.processString(p, entry); + assertThat(p.getProperty(entry.getKey())).as("replace").isEqualTo(t + "-foo"); + } + @Test void parseStringSub() { - var entry = newEntry(); PropertyFileUtils.processString(p, entry.set(t).modify((v, s) -> v.substring(1))); assertThat(p.getProperty(entry.getKey())).as("substring(1)").isEqualTo(t.substring(1)); } @Test - @SuppressWarnings("PMD.SignatureDeclareThrowsException") - void parseTimeTest() throws Exception { - var entry = new EntryDate("time").pattern("m"); - var time = LocalTime.now(); - - entry.setCalc(ADD); - PropertyFileUtils.processDate(t, p, entry.set(time).unit(EntryDate.Units.MINUTE), true); - assertThat(p.getProperty(entry.getKey())).as("processDate(now+1)") - .isEqualTo(String.valueOf(time.plusMinutes(1).getMinute())); - - entry.setCalc(SUB); - PropertyFileUtils.processDate(t, p, entry.set(time).unit(EntryDate.Units.HOUR).pattern("H"), true); - assertThat(p.getProperty(entry.getKey())).as("processDate(now+1)") - .isEqualTo(String.valueOf(time.minusHours(1).getHour())); - } - - @Test - @SuppressWarnings("PMD.SignatureDeclareThrowsException") - void processDateAddTest() throws Exception { - var entryDate = newEntryDate(); - entryDate.setCalc(ADD); - PropertyFileUtils.processDate(t, p, entryDate.now(), true); - assertThat(p.getProperty(entryDate.getKey())).as("processDate(now+1)").isEqualTo(String.valueOf(dayOfYear + 1)); - - PropertyFileUtils.processDate(t, p, entryDate.now().calc(v -> v + 3), true); - assertThat(p.getProperty(entryDate.getKey())).as("processDate(now+3)").isEqualTo(String.valueOf(dayOfYear + 3)); - - entryDate.setCalc(ADD); - PropertyFileUtils.processDate(t, p, entryDate.set(ZonedDateTime.now()), true); - assertThat(p.getProperty(entryDate.getKey())).as("processDate(ZonedDateTime+1)") - .isEqualTo(String.valueOf(dayOfYear + 1)); - - PropertyFileUtils.processDate(t, p, entryDate.set(Instant.now()).calc(v -> v + 2), true); - assertThat(p.getProperty(entryDate.getKey())).as("processDate(Instant+2)").isEqualTo(String.valueOf(dayOfYear + 2)); - - entryDate.setCalc(v -> v + 3); - PropertyFileUtils.processDate(t, p, entryDate.set(LocalDateTime.now()), true); - assertThat(p.getProperty(entryDate.getKey())).as("processDate(LocalDteTime+2)").isEqualTo(String.valueOf(dayOfYear + 3)); - } - - @Test - @SuppressWarnings("PMD.SignatureDeclareThrowsException") void processIntAddTest() throws Exception { - var entryInt = newEntryInt(); entryInt.calc(ADD); entryInt.setDefaultValue("-1"); PropertyFileUtils.processInt(t, p, entryInt, true); @@ -218,22 +137,92 @@ class PropertyFileUtilsTest { } @Test - void processStringTest() { - var entry = newEntry(); - PropertyFileUtils.processString(p, entry); + void parseIntSubTest() throws Exception { + entryInt.calc(SUB); + entryInt.setPattern("0000"); + PropertyFileUtils.processInt(t, p, entryInt.defaultValue("0017"), true); + assertThat(p.getProperty(entryInt.getKey())).as("sub(0017)").isEqualTo("0016"); - assertThat(entry.getNewValue()).as(String.format("processString(%s, %s)", entry.getKey(), entry.getNewValue())) - .isEqualTo(p.getProperty(entry.getKey())); - - entry.setKey("version.minor"); - - PropertyFileUtils.processString(p, entry.set(0)); - assertThat(entry.getNewValue().toString()).as(String.format("processString(%s, %s)", entry.getKey(), entry.getNewValue())) - .isEqualTo(p.getProperty(entry.getKey())); + PropertyFileUtils.processInt(t, p, entryInt.set(16).calc(v -> v - 3), true); + assertThat(p.getProperty(entryInt.getKey())).as("sub(16)-3").isEqualTo("0013"); + } + + @Test + void processDateAddTest() throws Exception { + entryDate.setCalc(ADD); + PropertyFileUtils.processDate(t, p, entryDate.now(), true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(now+1)").isEqualTo(String.valueOf(dayOfYear + 1)); + + PropertyFileUtils.processDate(t, p, entryDate.now().calc(v -> v + 3), true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(now+3)").isEqualTo(String.valueOf(dayOfYear + 3)); + + entryDate.setCalc(ADD); + PropertyFileUtils.processDate(t, p, entryDate.set(ZonedDateTime.now()), true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(ZonedDateTime+1)") + .isEqualTo(String.valueOf(dayOfYear + 1)); + + PropertyFileUtils.processDate(t, p, entryDate.set(Instant.now()).calc(v -> v + 2), true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(Instant+2)").isEqualTo(String.valueOf(dayOfYear + 2)); + + entryDate.setCalc(v -> v + 3); + PropertyFileUtils.processDate(t, p, entryDate.set(LocalDateTime.now()), true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(LocalDteTime+2)").isEqualTo(String.valueOf(dayOfYear + 3)); + } + + @Test + void parseDateSub() throws Exception { + entryDate.setCalc(SUB); + PropertyFileUtils.processDate(t, p, entryDate.now(), true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(now-3)").isEqualTo(String.valueOf(dayOfYear - 1)); + + entryDate.setCalc(v -> v - 2); + PropertyFileUtils.processDate(t, p, entryDate.now(), true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(now-2)").isEqualTo(String.valueOf(dayOfYear - 2)); + + entryDate.setCalc(SUB); + PropertyFileUtils.processDate(t, p, entryDate.set(new Date()), true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(date-1)").isEqualTo(String.valueOf(dayOfYear - 1)); + + entryDate.setCalc(v -> v - 2); + PropertyFileUtils.processDate(t, p, entryDate.set(Calendar.getInstance()), true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(cal-2)").isEqualTo(String.valueOf(dayOfYear - 2)); + + entryDate.setCalc(v -> v - 3); + PropertyFileUtils.processDate(t, p, entryDate.set(LocalDate.now()), + true); + assertThat(p.getProperty(entryDate.getKey())).as("processDate(LocalDate-3)").isEqualTo(String.valueOf(dayOfYear - 3)); + } + + @Test + void parseTimeTest() throws Exception { + var entry = new EntryDate("time").pattern("m"); + var time = LocalTime.now(); + + entry.setCalc(ADD); + PropertyFileUtils.processDate(t, p, entry.set(time).unit(EntryDate.Units.MINUTE), true); + assertThat(p.getProperty(entry.getKey())).as("processDate(now+1)") + .isEqualTo(String.valueOf(time.plusMinutes(1).getMinute())); + + entry.setCalc(SUB); + PropertyFileUtils.processDate(t, p, entry.set(time).unit(EntryDate.Units.HOUR).pattern("H"), true); + assertThat(p.getProperty(entry.getKey())).as("processDate(now+1)") + .isEqualTo(String.valueOf(time.minusHours(1).getHour())); + } + + @Test + void testCurrentValue() { + var value = "value"; + var defaultValue = "default"; + var newValue = "new"; + + assertThat(PropertyFileUtils.currentValue(value, defaultValue, newValue)).as("all").isEqualTo(newValue); + assertThat(PropertyFileUtils.currentValue(value, null, null)).as("value").isEqualTo(value); + assertThat(PropertyFileUtils.currentValue(value, defaultValue, null)).as("value not default").isEqualTo(value); + assertThat(PropertyFileUtils.currentValue(null, defaultValue, null)).as("default").isEqualTo(defaultValue); + assertThat(PropertyFileUtils.currentValue(null, null, newValue)).as("new").isEqualTo(newValue); } @Test - @SuppressWarnings("PMD.SignatureDeclareThrowsException") void savePropertiesTest() throws Exception { var p = new Properties(); var test = "test"; @@ -251,25 +240,4 @@ class PropertyFileUtilsTest { tmp.deleteOnExit(); } - - @Test - void testCurrentValue() { - var value = "value"; - var defaultValue = "default"; - var newValue = "new"; - - assertThat(PropertyFileUtils.currentValue(value, defaultValue, newValue)).as("all").isEqualTo(newValue); - assertThat(PropertyFileUtils.currentValue(value, null, null)).as("value").isEqualTo(value); - assertThat(PropertyFileUtils.currentValue(value, defaultValue, null)).as("value not default").isEqualTo(value); - assertThat(PropertyFileUtils.currentValue(null, defaultValue, null)).as("default").isEqualTo(defaultValue); - assertThat(PropertyFileUtils.currentValue(null, null, newValue)).as("new").isEqualTo(newValue); - } - - @Test - void testWarn() { - assertThatCode(() -> PropertyFileUtils.warn("command", "message", new IOException(t), true)) - .hasMessage(t).isInstanceOf(IOException.class); - assertThatCode(() -> PropertyFileUtils.warn("command", t, new Exception(t), false)) - .as("failOnWarning = false").doesNotThrowAnyException(); - } } \ No newline at end of file