From 09cdfea6b8e92ade904fee1bac9cacf0d168b5e1 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 22 Jun 2024 23:39:49 -0700 Subject: [PATCH 1/5] Bumped PMD extension to version 1.1.0 --- examples/lib/bld/bld-wrapper.jar | Bin 27319 -> 27319 bytes examples/lib/bld/bld-wrapper.properties | 4 ++-- lib/bld/bld-wrapper.jar | Bin 27319 -> 27319 bytes lib/bld/bld-wrapper.properties | 6 +++--- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/lib/bld/bld-wrapper.jar b/examples/lib/bld/bld-wrapper.jar index dd5ee65380652cff3f560906ac29f48c6ca46804..d0dd498906eca1e5fe8afe066c9be8fce538a773 100644 GIT binary patch delta 131 zcmdmfm2vx3M&1B#W)=|!4h{~6kiHWWdFz;g)W$v~V-UT0vvD^QnBi!~t_Nm#r<`X5 wGi1{Y!BUe0GweYElP705gXx Date: Sun, 23 Jun 2024 10:43:25 -0700 Subject: [PATCH 2/5] Added build command values --- examples/README.md | 14 ++++++++++++++ .../java/com/example/PropertyFileExampleBuild.java | 10 +++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/README.md b/examples/README.md index ede07c3..13b19da 100644 --- a/examples/README.md +++ b/examples/README.md @@ -3,3 +3,17 @@ ```console ./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 +``` \ 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 8b8ffca..c004cc1 100644 --- a/examples/src/bld/java/com/example/PropertyFileExampleBuild.java +++ b/examples/src/bld/java/com/example/PropertyFileExampleBuild.java @@ -50,7 +50,7 @@ public class PropertyFileExampleBuild extends Project { new PropertyFileExampleBuild().start(args); } - @BuildCommand(summary = "Updates major version") + @BuildCommand(value = "update-major", summary = "Updates major version") public void updateMajor() throws Exception { new PropertyFileOperation() .fromProject(this) @@ -66,7 +66,7 @@ public class PropertyFileExampleBuild extends Project { .execute(); } - @BuildCommand(summary = "Updates minor version") + @BuildCommand(value = "update-minor", summary = "Updates minor version") public void updateMinor() throws Exception { new PropertyFileOperation() .fromProject(this) @@ -82,7 +82,7 @@ public class PropertyFileExampleBuild extends Project { .execute(); } - @BuildCommand(summary = "Updates patch version") + @BuildCommand(value = "update-patch", summary = "Updates patch version") public void updatePatch() throws Exception { new PropertyFileOperation() .fromProject(this) @@ -98,7 +98,7 @@ public class PropertyFileExampleBuild extends Project { .execute(); } - @BuildCommand(summary = "Updates the release") + @BuildCommand(value = "update-release", summary = "Updates the release") public void updateRelease() throws Exception { new PropertyFileOperation() .fromProject(this) @@ -110,7 +110,7 @@ public class PropertyFileExampleBuild extends Project { .execute(); } - @BuildCommand(summary = "Delete version properties") + @BuildCommand(value = "delete-version", summary = "Delete version properties") public void deleteVersion() throws Exception { new PropertyFileOperation() .fromProject(this) From 3db6ca026d8131b22233dc10b49ba23285c5d275 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 23 Jun 2024 10:46:17 -0700 Subject: [PATCH 3/5] Removed argument from safeDelete() --- .../bld/extension/propertyfile/Entry.java | 2 +- .../bld/extension/propertyfile/EntryBase.java | 70 +++++++++---------- .../bld/extension/propertyfile/EntryDate.java | 2 +- .../bld/extension/propertyfile/EntryInt.java | 2 +- 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/main/java/rife/bld/extension/propertyfile/Entry.java b/src/main/java/rife/bld/extension/propertyfile/Entry.java index 816ce21..379255c 100644 --- a/src/main/java/rife/bld/extension/propertyfile/Entry.java +++ b/src/main/java/rife/bld/extension/propertyfile/Entry.java @@ -53,7 +53,7 @@ public class Entry extends EntryBase { * @return the entry */ public Entry delete() { - setDelete(true); + setDelete(); 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 b381b0f..b724ed3 100644 --- a/src/main/java/rife/bld/extension/propertyfile/EntryBase.java +++ b/src/main/java/rife/bld/extension/propertyfile/EntryBase.java @@ -28,15 +28,15 @@ import java.util.function.IntFunction; */ @SuppressWarnings("PMD.DataClass") public class EntryBase { - private IntFunction calc; - private Object defaultValue; - private boolean isDelete; - private String key; - private BiFunction modify; - private String modifyValue = ""; - private Object newValue; - private String pattern = ""; - private EntryDate.Units unit = EntryDate.Units.DAY; + private IntFunction calc_; + private Object defaultValue_; + private boolean isDelete_; + private String key_; + private String modifyValue_ = ""; + private BiFunction modify_; + private Object newValue_; + private String pattern_ = ""; + private EntryDate.Units unit_ = EntryDate.Units.DAY; /** * Creates a new {@link EntryBase entry}. @@ -44,7 +44,7 @@ public class EntryBase { * @param key the required property key */ public EntryBase(String key) { - this.key = key; + key_ = key; } /** @@ -53,7 +53,7 @@ public class EntryBase { * @return the calc function */ protected IntFunction getCalc() { - return calc; + return calc_; } /** @@ -62,7 +62,7 @@ public class EntryBase { * @return the default value */ protected Object getDefaultValue() { - return defaultValue; + return defaultValue_; } /** @@ -71,7 +71,7 @@ public class EntryBase { * @return the key */ protected String getKey() { - return key; + return key_; } /** @@ -80,16 +80,16 @@ public class EntryBase { * @return the modify function */ protected BiFunction 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 */ protected String getModifyValue() { - return modifyValue; + return modifyValue_; } /** @@ -98,7 +98,7 @@ public class EntryBase { * @return the new value */ public Object getNewValue() { - return newValue; + return newValue_; } /** @@ -107,7 +107,7 @@ public class EntryBase { * @return the pattern */ protected String getPattern() { - return pattern; + return pattern_; } /** @@ -116,7 +116,7 @@ public class EntryBase { * @return the unit */ protected EntryDate.Units getUnit() { - return unit; + return unit_; } /** @@ -125,7 +125,7 @@ public class EntryBase { * @return {@code true} or {@code false} */ protected boolean isDelete() { - return isDelete; + return isDelete_; } /** @@ -136,7 +136,7 @@ public class EntryBase { */ @SuppressWarnings("unused") public EntryBase key(String key) { - setKey(key); + key_ = key; return this; } @@ -146,7 +146,7 @@ public class EntryBase { * @param calc the calc function */ protected void setCalc(IntFunction calc) { - this.calc = calc; + calc_ = calc; } /** @@ -155,16 +155,14 @@ public class EntryBase { * @param defaultValue the default value */ protected void setDefaultValue(Object defaultValue) { - this.defaultValue = defaultValue; + defaultValue_ = defaultValue; } /** - * Sets whether the {@link java.util.Properties property} should be deleted. - * - * @param delete {@code true} or {@code false} + * Sets the {@link java.util.Properties property} to be deleted. */ - protected void setDelete(boolean delete) { - isDelete = delete; + protected void setDelete() { + isDelete_ = true; } /** @@ -173,7 +171,7 @@ public class EntryBase { * @param key the {@link java.util.Properties property} key */ protected void setKey(String key) { - this.key = key; + key_ = key; } /** @@ -182,7 +180,7 @@ public class EntryBase { * @param modify the modify function */ protected void setModify(BiFunction modify) { - this.modify = modify; + modify_ = modify; } /** @@ -192,8 +190,8 @@ public class EntryBase { * @param modify the modify function */ protected void setModify(String value, BiFunction modify) { - this.modifyValue = value; - this.modify = modify; + modifyValue_ = value; + modify_ = modify; } /** @@ -202,7 +200,7 @@ public class EntryBase { * @param value the modify value. */ protected void setModifyValue(String value) { - this.modifyValue = value; + modifyValue_ = value; } /** @@ -211,7 +209,7 @@ public class EntryBase { * @param newValue the new value */ public void setNewValue(Object newValue) { - this.newValue = newValue; + newValue_ = newValue; } /** @@ -221,7 +219,7 @@ public class EntryBase { * @param pattern the 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} */ protected void setUnit(EntryDate.Units unit) { - this.unit = unit; + unit_ = unit; } } diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java index 4d7fba3..a25b0e1 100644 --- a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java +++ b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java @@ -54,7 +54,7 @@ public class EntryDate extends EntryBase { * @return this instance */ public EntryDate delete() { - setDelete(true); + setDelete(); return this; } diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryInt.java b/src/main/java/rife/bld/extension/propertyfile/EntryInt.java index 753d3e7..54226f4 100644 --- a/src/main/java/rife/bld/extension/propertyfile/EntryInt.java +++ b/src/main/java/rife/bld/extension/propertyfile/EntryInt.java @@ -63,7 +63,7 @@ public class EntryInt extends EntryBase { * @return this instance */ public EntryInt delete() { - setDelete(true); + setDelete(); return this; } From bd27eac071ce06f9a820d70c32a965754f6a961f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 23 Jun 2024 10:47:18 -0700 Subject: [PATCH 4/5] Minor code cleanup --- .../propertyfile/PropertyFileOperation.java | 40 +++++++++---------- .../propertyfile/PropertyFileUtils.java | 8 ++-- .../propertyfile/PropertyFileUtilsTest.java | 6 --- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java b/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java index e01cb11..0ecf5d7 100644 --- a/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java +++ b/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java @@ -31,11 +31,11 @@ import java.util.Properties; * @since 1.0 */ public class PropertyFileOperation extends AbstractOperation { - private final List entries = new ArrayList<>(); - private String comment = ""; - private boolean failOnWarning; - private File file; - private BaseProject project; + private final List entries_ = new ArrayList<>(); + 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. @@ -43,9 +43,8 @@ public class PropertyFileOperation extends AbstractOperation Date: Sun, 23 Jun 2024 10:47:49 -0700 Subject: [PATCH 5/5] Added tests for operation --- .../PropertyFileOperationTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/test/java/rife/bld/extension/propertyfile/PropertyFileOperationTest.java diff --git a/src/test/java/rife/bld/extension/propertyfile/PropertyFileOperationTest.java b/src/test/java/rife/bld/extension/propertyfile/PropertyFileOperationTest.java new file mode 100644 index 0000000..22dc242 --- /dev/null +++ b/src/test/java/rife/bld/extension/propertyfile/PropertyFileOperationTest.java @@ -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"); + } +}