diff --git a/WHATSNEW b/WHATSNEW
index 68fdeee67..21869a87c 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -49,6 +49,10 @@ Changes that could break older environments:
allows a per-user library location to be used if the main Ant install
is locked down.
+* The Entry nested element of PropertyFile will not any more have its value
+ attribute (actually increment) overwritten with the new value of the entry
+ after execution.
+
Fixed bugs:
-----------
* Filter readers were not handling line endings properly. Bugzilla
@@ -195,6 +199,10 @@ Fixed bugs:
* Don't multiply Class-Path attributes when updating jars. Bugzilla
Report 21170.
+* Do not overwrite the value (increment) attribute of PropertyFile nested Entry element.
+ Bugzilla Report 21505.
+
+
Other changes:
--------------
* Six new Clearcase tasks added.
diff --git a/src/etc/testcases/taskdefs/optional/propertyfile.xml b/src/etc/testcases/taskdefs/optional/propertyfile.xml
index c55478642..cac075a5f 100644
--- a/src/etc/testcases/taskdefs/optional/propertyfile.xml
+++ b/src/etc/testcases/taskdefs/optional/propertyfile.xml
@@ -69,6 +69,20 @@
+
+
+ foo=3
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
index bba095b19..33c8b434f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
@@ -249,23 +249,7 @@ public class PropertyFile extends Task {
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(propertyfile));
-
- // Properties.store is not available in JDK 1.1
- Method m =
- Properties.class.getMethod("store",
- new Class[] {
- OutputStream.class,
- String.class});
- m.invoke(properties, new Object[] {bos, comment});
-
- } catch (NoSuchMethodException nsme) {
- properties.save(bos, comment);
- } catch (InvocationTargetException ite) {
- Throwable t = ite.getTargetException();
- throw new BuildException(t, getLocation());
- } catch (IllegalAccessException iae) {
- // impossible
- throw new BuildException(iae, getLocation());
+ properties.store(bos, comment);
} catch (IOException ioe) {
throw new BuildException(ioe, getLocation());
} finally {
@@ -277,14 +261,6 @@ public class PropertyFile extends Task {
}
}
- /**
- * Returns whether the given parameter has been defined.
- * @todo IDEA is saying this method is never used - remove?
- */
- private boolean checkParam(String param) {
- return !((param == null) || (param.equals("null")));
- }
-
private boolean checkParam(File param) {
return !(param == null);
}
@@ -303,6 +279,7 @@ public class PropertyFile extends Task {
private int operation = Operation.EQUALS_OPER;
private String value = null;
private String defaultValue = null;
+ private String newValue = null;
private String pattern = null;
private int field = Calendar.DATE;
@@ -396,12 +373,12 @@ public class PropertyFile extends Task {
npe.printStackTrace();
}
- if (value == null) {
- value = "";
+ if (newValue == null) {
+ newValue = "";
}
// Insert as a string by default
- props.put(key, value);
+ props.put(key, newValue);
}
/**
@@ -447,7 +424,7 @@ public class PropertyFile extends Task {
currentValue.add(field, offset);
}
- value = fmt.format(currentValue.getTime());
+ newValue = fmt.format(currentValue.getTime());
}
@@ -466,7 +443,12 @@ public class PropertyFile extends Task {
DecimalFormat fmt = (pattern != null) ? new DecimalFormat(pattern)
: new DecimalFormat();
try {
- currentValue = fmt.parse(getCurrentValue(oldValue)).intValue();
+ String curval = getCurrentValue(oldValue);
+ if (curval != null) {
+ currentValue = fmt.parse(curval).intValue();
+ } else {
+ currentValue = 0;
+ }
} catch (NumberFormatException nfe) {
// swallow
} catch (ParseException pe) {
@@ -494,7 +476,7 @@ public class PropertyFile extends Task {
}
}
- value = fmt.format(newValue);
+ this.newValue = fmt.format(newValue);
}
/**
@@ -518,7 +500,7 @@ public class PropertyFile extends Task {
} else if (operation == Operation.INCREMENT_OPER) {
newValue = currentValue + value;
}
- value = newValue;
+ this.newValue = newValue;
}
/**
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
index 6bb3d8aba..0b099dcf1 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -85,6 +85,7 @@ public class PropertyFileTest extends BuildFileTest {
initTestPropFile();
initBuildPropFile();
configureProject(projectFilePath);
+ project.setProperty(valueDoesNotGetOverwrittenPropertyFileKey,valueDoesNotGetOverwrittenPropertyFile);
}
@@ -134,6 +135,12 @@ public class PropertyFileTest extends BuildFileTest {
assertEquals("6",project.getProperty("int.without.value"));
}
+ public void testValueDoesNotGetOverwritten() {
+ // this test shows that the bug report 21505 is fixed
+ executeTarget("bugDemo1");
+ executeTarget("bugDemo2");
+ assertEquals("5", project.getProperty("foo"));
+ }
/*
public void testDirect() throws Exception {
PropertyFile pf = new PropertyFile();
@@ -175,7 +182,7 @@ public class PropertyFileTest extends BuildFileTest {
testProps.put("existing.prop", "37");
FileOutputStream fos = new FileOutputStream(testPropsFilePath);
- testProps.save(fos, "defaults");
+ testProps.store(fos, "defaults");
fos.close();
}
@@ -191,7 +198,7 @@ public class PropertyFileTest extends BuildFileTest {
buildProps.put(DATE_KEY, NEW_DATE);
FileOutputStream fos = new FileOutputStream(buildPropsFilePath);
- buildProps.save(fos, null);
+ buildProps.store(fos, null);
fos.close();
}
@@ -204,6 +211,10 @@ public class PropertyFileTest extends BuildFileTest {
tempFile = new File(buildPropsFilePath);
tempFile.delete();
tempFile = null;
+
+ tempFile = new File(valueDoesNotGetOverwrittenPropsFilePath);
+ tempFile.delete();
+ tempFile = null;
}
@@ -214,7 +225,11 @@ public class PropertyFileTest extends BuildFileTest {
testPropertyFile = "propertyfile.test.properties",
testPropertyFileKey = "test.propertyfile",
testPropsFilePath = "src/etc/testcases/taskdefs/optional/" + testPropertyFile,
-
+
+ valueDoesNotGetOverwrittenPropertyFile = "overwrite.test.properties",
+ valueDoesNotGetOverwrittenPropertyFileKey = "overwrite.test.propertyfile",
+ valueDoesNotGetOverwrittenPropsFilePath = "src/etc/testcases/taskdefs/optional/" + valueDoesNotGetOverwrittenPropertyFile,
+
buildPropsFilePath = "src/etc/testcases/taskdefs/optional/propertyfile.build.properties",
FNAME = "Bruce",