actually due to field value of PropertyFile.Entry class overwritten after execution with the result (contains the increment before execution) PR: 21505 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274810 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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. | |||
| @@ -69,6 +69,20 @@ | |||
| </propertyfile> | |||
| <property file="${test.propertyfile}"/> | |||
| </target> | |||
| <target name="createfile"> | |||
| <echo file="${overwrite.test.propertyfile}"> | |||
| foo=3 | |||
| </echo> | |||
| </target> | |||
| <target name="bugDemo1" depends="createfile,bugDemoInit"/> | |||
| <target name="bugDemo2" depends="bugDemoInit"> | |||
| <property file="${overwrite.test.propertyfile}"/> | |||
| </target> | |||
| <target name="bugDemoInit"> | |||
| <propertyfile file="${overwrite.test.propertyfile}"> | |||
| <entry key="foo" default="0" value="1" operation="+" type="int"/> | |||
| </propertyfile> | |||
| </target> | |||
| </project> | |||
| @@ -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; | |||
| } | |||
| /** | |||
| @@ -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", | |||