Browse Source

Fix the increment/decrement operations so they work whether or not

a 'value' attr was specified. (And fix a tiny spacing nit :)
PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271420 13f79535-47bb-0310-9956-ffa450edef68
master
Diane Holt 23 years ago
parent
commit
47f04e469c
1 changed files with 23 additions and 3 deletions
  1. +23
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java

+ 23
- 3
src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java View File

@@ -430,7 +430,7 @@ public class PropertyFile extends Task
NOW_VALUE_.equals(m_default.toLowerCase()) &&
(m_operation == Operation.INCREMENT_OPER ||
m_operation == Operation.DECREMENT_OPER) ) {
oldValue = null;
oldValue = null;
}

if (oldValue != null) {
@@ -518,12 +518,14 @@ public class PropertyFile extends Task
{
int value = 0;
int newValue = 0;
int oldIntValue = 0;

DecimalFormat fmt = (m_pattern != null) ? new DecimalFormat(m_pattern)
: new DecimalFormat();

if (oldValue != null) {
try {
oldIntValue = fmt.parse(oldValue).intValue();
value = fmt.parse(oldValue).intValue();
}
catch (NumberFormatException nfe) { /* swollow */ }
@@ -548,10 +550,28 @@ public class PropertyFile extends Task
newValue = value;
}
else if (m_operation == Operation.INCREMENT_OPER) {
newValue = ++value;
if (this.m_value == "") {
// No value attr was given, so just increment "value"
// (which is the old value from the prop file, 0 by
// assignment above, if none) by 1.
newValue = ++value;
} else {
// A value attr was given, so add it to "value", which
// is the old value from the prop file (0, if none).
newValue = (oldIntValue + value) ;
}
}
else if (m_operation == Operation.DECREMENT_OPER) {
newValue = --value;
if (this.m_value == "") {
// No value attr was given, so just decrement "value"
// (which is the old value from the prop file, 0 by
// assignment above, if none) by 1.
newValue = --value;
} else {
// A value attr was given, so subtract from it "value",
// which is the old value from the prop file (0, if none).
newValue = (oldIntValue - value);
}
}
m_value = fmt.format(newValue);
}


Loading…
Cancel
Save