Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
650bb819cf |
9 changed files with 112 additions and 109 deletions
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<pattern value="rife.bld.extension.propertyFile.Entry" method="defaultValue" />
|
||||
|
@ -11,6 +12,10 @@
|
|||
<pattern value="rife.bld.extension.propertyfile.EntryDate" method="delete" />
|
||||
<pattern value="rife.bld.extension.propertyfile.EntryDate" />
|
||||
<pattern value="rife.bld.extension.propertyfile.EntryInt" method="delete" />
|
||||
<pattern value="rife.bld.extension.propertyfile.PropertyFileBuild" method="jacoco" />
|
||||
<pattern value="rife.bld.extension.propertyfile.PropertyFileBuild" method="pmd" />
|
||||
<pattern value="rife.bld.extension.propertyfile.PropertyFileOperation" method="fromProject" />
|
||||
<pattern value="rife.bld.extension.propertyfile.PropertyFileOperation" />
|
||||
</component>
|
||||
<component name="PDMPlugin">
|
||||
<option name="customRuleSets">
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[](https://opensource.org/licenses/Apache-2.0)
|
||||
[](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
|
||||
[](https://rife2.com/bld)
|
||||
[](https://rife2.com/bld)
|
||||
[](https://repo.rife2.com/#/releases/com/uwyn/rife2/bld-property-file)
|
||||
[](https://repo.rife2.com/#/snapshots/com/uwyn/rife2/bld-property-file)
|
||||
[](https://github.com/rife2/bld-property-file/actions/workflows/bld.yml)
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
<exclude name="ClassNamingConventions"/>
|
||||
<exclude name="ConfusingTernary"/>
|
||||
<exclude name="CommentDefaultAccessModifier"/>
|
||||
<exclude name="DefaultPackage"/>
|
||||
<exclude name="FieldNamingConventions"/>
|
||||
<exclude name="LocalVariableCouldBeFinal"/>
|
||||
<exclude name="LongVariable"/>
|
||||
|
|
|
@ -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,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||
bld.extension=com.uwyn.rife2:bld-property-file:0.9.2
|
||||
bld.repositories=RIFE2_SNAPSHOTS,RIFE2_RELEASES,MAVEN_CENTRAL
|
||||
bld.downloadExtensionSources=true
|
||||
bld.downloadLocation=
|
||||
bld.version=1.7.0
|
||||
bld.version=1.7.1
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
bld.downloadExtensionJavadoc=false
|
||||
bld.downloadExtensionSources=true
|
||||
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.1-SNAPSHOT
|
||||
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.0-SNAPSHOT
|
||||
bld.repositories=MAVEN_LOCAL,RIFE2_SNAPSHOTS,MAVEN_CENTRAL,RIFE2_RELEASES
|
||||
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.2
|
||||
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.0
|
||||
bld.repositories=RIFE2_SNAPSHOTS,RIFE2_RELEASES,MAVEN_CENTRAL
|
||||
bld.downloadLocation=
|
||||
bld.version=1.7.0
|
||||
bld.version=1.7.1
|
||||
|
|
|
@ -31,7 +31,7 @@ public class PropertyFileBuild extends Project {
|
|||
var rife2 = version(1, 7, 0);
|
||||
scope(compile)
|
||||
.include(dependency("com.uwyn.rife2", "rife2", rife2))
|
||||
.include(dependency("com.uwyn.rife2", "bld", rife2));
|
||||
.include(dependency("com.uwyn.rife2", "bld", version(1, 7, 1)));
|
||||
scope(test)
|
||||
.include(dependency("org.jsoup", "jsoup", version(1, 16, 1)))
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0)))
|
||||
|
@ -76,7 +76,7 @@ public class PropertyFileBuild extends Project {
|
|||
}
|
||||
|
||||
@BuildCommand(summary = "Runs PMD analysis")
|
||||
public void pmd() throws Exception {
|
||||
public void pmd() {
|
||||
new PmdOperation()
|
||||
.fromProject(this)
|
||||
.failOnViolation(true)
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.function.IntFunction;
|
|||
* @author <a href="https://github.com/gbevin">Geert Bevin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class EntryBase {
|
||||
private IntFunction<Integer> calc;
|
||||
private Object defaultValue;
|
||||
|
@ -53,13 +54,6 @@ public class EntryBase {
|
|||
return calc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the calculation function.
|
||||
*/
|
||||
protected void setCalc(IntFunction<Integer> calc) {
|
||||
this.calc = calc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default value.
|
||||
*/
|
||||
|
@ -67,15 +61,6 @@ public class EntryBase {
|
|||
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}.
|
||||
*/
|
||||
|
@ -83,15 +68,6 @@ public class EntryBase {
|
|||
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.
|
||||
*/
|
||||
|
@ -99,13 +75,6 @@ public class EntryBase {
|
|||
return modify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the modify function.
|
||||
*/
|
||||
protected void setModify(BiFunction<String, String, String> modify) {
|
||||
this.modify = modify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value to be used in the {@link #modify} function.
|
||||
*/
|
||||
|
@ -113,15 +82,6 @@ public class EntryBase {
|
|||
return modifyValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the modify value.
|
||||
*
|
||||
* @param value the modify value.
|
||||
*/
|
||||
protected void setModifyValue(String value) {
|
||||
this.modifyValue = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the new value to set the {@link java.util.Properties property)} to.
|
||||
*/
|
||||
|
@ -129,15 +89,6 @@ public class EntryBase {
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern.
|
||||
*/
|
||||
|
@ -145,16 +96,6 @@ public class EntryBase {
|
|||
return pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link java.text.DecimalFormat DecimalFormat} or {@link java.time.format.DateTimeFormatter DateTimeFormatter}
|
||||
* pattern to be used with {@link EntryDate} or {@link EntryInt} respectively.
|
||||
*
|
||||
* @param pattern the pattern
|
||||
*/
|
||||
protected void setPattern(String pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link EntryDate.Units unit}.
|
||||
*/
|
||||
|
@ -162,15 +103,6 @@ public class EntryBase {
|
|||
return unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link EntryDate.Units unit} value to apply to calculations.
|
||||
*
|
||||
* @param unit the {@link EntryDate.Units unit}
|
||||
*/
|
||||
protected void setUnit(EntryDate.Units unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the {@link java.util.Properties property} is to be deleted.
|
||||
*/
|
||||
|
@ -178,13 +110,6 @@ public class EntryBase {
|
|||
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}.
|
||||
*
|
||||
|
@ -196,6 +121,45 @@ public class EntryBase {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the calculation function.
|
||||
*/
|
||||
protected void setCalc(IntFunction<Integer> calc) {
|
||||
this.calc = calc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
*
|
||||
* @param key the {@link java.util.Properties property} key
|
||||
*/
|
||||
protected void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the modify function.
|
||||
*/
|
||||
protected void setModify(BiFunction<String, String, String> modify) {
|
||||
this.modify = modify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the modify function.
|
||||
*
|
||||
|
@ -205,4 +169,41 @@ public class EntryBase {
|
|||
this.modifyValue = value;
|
||||
this.modify = modify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the modify value.
|
||||
*
|
||||
* @param value the modify value.
|
||||
*/
|
||||
protected void setModifyValue(String value) {
|
||||
this.modifyValue = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new value for {@link java.util.Properties property}.
|
||||
*
|
||||
* @param newValue the new value
|
||||
*/
|
||||
public void setNewValue(Object newValue) {
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link java.text.DecimalFormat DecimalFormat} or {@link java.time.format.DateTimeFormatter DateTimeFormatter}
|
||||
* pattern to be used with {@link EntryDate} or {@link EntryInt} respectively.
|
||||
*
|
||||
* @param pattern the pattern
|
||||
*/
|
||||
protected void setPattern(String pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link EntryDate.Units unit} value to apply to calculations.
|
||||
*
|
||||
* @param unit the {@link EntryDate.Units unit}
|
||||
*/
|
||||
protected void setUnit(EntryDate.Units unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.text.DecimalFormat;
|
|||
import java.text.ParseException;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
@ -95,11 +94,11 @@ public final class PropertyFileUtils {
|
|||
* @param p the {@link Properties property}
|
||||
* @param entry the {@link Entry} containing the {@link Properties property} edits
|
||||
*/
|
||||
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
||||
@SuppressWarnings({"PMD.SignatureDeclareThrowsException", "PMD.ExceptionAsFlowControl"})
|
||||
public static boolean processDate(String command, Properties p, EntryDate entry, boolean failOnWarning)
|
||||
throws Exception {
|
||||
var success = true;
|
||||
var value = PropertyFileUtils.currentValue(null, entry.getDefaultValue(),
|
||||
var value = currentValue(null, entry.getDefaultValue(),
|
||||
entry.getNewValue());
|
||||
|
||||
var pattern = entry.getPattern();
|
||||
|
@ -159,19 +158,19 @@ public final class PropertyFileUtils {
|
|||
} else if (value instanceof ZonedDateTime) {
|
||||
if (offset != 0) {
|
||||
if (unit == EntryDate.Units.DAY) {
|
||||
value = ((ZonedDateTime) value).plus(offset, ChronoUnit.DAYS);
|
||||
value = ((ZonedDateTime) value).plusDays(offset);
|
||||
} else if (unit == EntryDate.Units.MONTH) {
|
||||
value = ((ZonedDateTime) value).plus(offset, ChronoUnit.MONTHS);
|
||||
value = ((ZonedDateTime) value).plusMonths(offset);
|
||||
} else if (unit == EntryDate.Units.WEEK) {
|
||||
value = ((ZonedDateTime) value).plus(offset, ChronoUnit.WEEKS);
|
||||
value = ((ZonedDateTime) value).plusWeeks(offset);
|
||||
} else if (unit == EntryDate.Units.YEAR) {
|
||||
value = ((ZonedDateTime) value).plus(offset, ChronoUnit.YEARS);
|
||||
value = ((ZonedDateTime) value).plusYears(offset);
|
||||
} else if (unit == EntryDate.Units.SECOND) {
|
||||
value = ((ZonedDateTime) value).plusSeconds(offset);
|
||||
} else if (unit == EntryDate.Units.MINUTE) {
|
||||
value = ((ZonedDateTime) value).plus(offset, ChronoUnit.MINUTES);
|
||||
value = ((ZonedDateTime) value).plusMinutes(offset);
|
||||
} else if (unit == EntryDate.Units.HOUR) {
|
||||
value = ((ZonedDateTime) value).plus(offset, ChronoUnit.HOURS);
|
||||
value = ((ZonedDateTime) value).plusHours(offset);
|
||||
}
|
||||
}
|
||||
parsedValue = dtf.format((ZonedDateTime) value);
|
||||
|
@ -204,7 +203,7 @@ public final class PropertyFileUtils {
|
|||
int intValue = 0;
|
||||
try {
|
||||
var fmt = new DecimalFormat(entry.getPattern());
|
||||
var value = PropertyFileUtils.currentValue(p.getProperty(entry.getKey()), entry.getDefaultValue(),
|
||||
var value = currentValue(p.getProperty(entry.getKey()), entry.getDefaultValue(),
|
||||
entry.getNewValue());
|
||||
|
||||
if (value != null) {
|
||||
|
@ -231,8 +230,7 @@ public final class PropertyFileUtils {
|
|||
* @param entry the {@link Entry} containing the {@link Properties property} edits
|
||||
*/
|
||||
public static boolean processString(Properties p, Entry entry) {
|
||||
var value = PropertyFileUtils.currentValue(p.getProperty(entry.getKey()), entry.getDefaultValue(),
|
||||
entry.getNewValue());
|
||||
var value = currentValue(p.getProperty(entry.getKey()), entry.getDefaultValue(), entry.getNewValue());
|
||||
|
||||
p.setProperty(entry.getKey(), String.valueOf(value));
|
||||
|
||||
|
|
|
@ -26,10 +26,10 @@ import java.util.Calendar;
|
|||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static rife.bld.extension.propertyfile.Calc.ADD;
|
||||
import static rife.bld.extension.propertyfile.Calc.SUB;
|
||||
import static org.assertj.core.api.Assertions.assertThat; // NOPMD
|
||||
import static org.assertj.core.api.Assertions.assertThatCode; // NOPMD
|
||||
import static rife.bld.extension.propertyfile.Calc.ADD; // NOPMD
|
||||
import static rife.bld.extension.propertyfile.Calc.SUB; // NOPMD
|
||||
|
||||
/**
|
||||
* PropertyFileUtilsTest class
|
||||
|
@ -42,16 +42,16 @@ class PropertyFileUtilsTest {
|
|||
final static Properties p = new Properties();
|
||||
final static String t = "test";
|
||||
|
||||
public EntryDate newEntryDate() {
|
||||
p.clear();
|
||||
return new EntryDate("adate").pattern("D");
|
||||
}
|
||||
|
||||
public Entry newEntry() {
|
||||
p.clear();
|
||||
return new Entry("version.major").set("1");
|
||||
}
|
||||
|
||||
public EntryDate newEntryDate() {
|
||||
p.clear();
|
||||
return new EntryDate("adate").pattern("D");
|
||||
}
|
||||
|
||||
public EntryInt newEntryInt() {
|
||||
p.clear();
|
||||
return new EntryInt("version.patch");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue