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 | allows a per-user library location to be used if the main Ant install | ||||
| is locked down. | 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: | Fixed bugs: | ||||
| ----------- | ----------- | ||||
| * Filter readers were not handling line endings properly. Bugzilla | * 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 | * Don't multiply Class-Path attributes when updating jars. Bugzilla | ||||
| Report 21170. | Report 21170. | ||||
| * Do not overwrite the value (increment) attribute of PropertyFile nested Entry element. | |||||
| Bugzilla Report 21505. | |||||
| Other changes: | Other changes: | ||||
| -------------- | -------------- | ||||
| * Six new Clearcase tasks added. | * Six new Clearcase tasks added. | ||||
| @@ -69,6 +69,20 @@ | |||||
| </propertyfile> | </propertyfile> | ||||
| <property file="${test.propertyfile}"/> | <property file="${test.propertyfile}"/> | ||||
| </target> | </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> | </project> | ||||
| @@ -249,23 +249,7 @@ public class PropertyFile extends Task { | |||||
| BufferedOutputStream bos = null; | BufferedOutputStream bos = null; | ||||
| try { | try { | ||||
| bos = new BufferedOutputStream(new FileOutputStream(propertyfile)); | 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) { | } catch (IOException ioe) { | ||||
| throw new BuildException(ioe, getLocation()); | throw new BuildException(ioe, getLocation()); | ||||
| } finally { | } 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) { | private boolean checkParam(File param) { | ||||
| return !(param == null); | return !(param == null); | ||||
| } | } | ||||
| @@ -303,6 +279,7 @@ public class PropertyFile extends Task { | |||||
| private int operation = Operation.EQUALS_OPER; | private int operation = Operation.EQUALS_OPER; | ||||
| private String value = null; | private String value = null; | ||||
| private String defaultValue = null; | private String defaultValue = null; | ||||
| private String newValue = null; | |||||
| private String pattern = null; | private String pattern = null; | ||||
| private int field = Calendar.DATE; | private int field = Calendar.DATE; | ||||
| @@ -396,12 +373,12 @@ public class PropertyFile extends Task { | |||||
| npe.printStackTrace(); | npe.printStackTrace(); | ||||
| } | } | ||||
| if (value == null) { | |||||
| value = ""; | |||||
| if (newValue == null) { | |||||
| newValue = ""; | |||||
| } | } | ||||
| // Insert as a string by default | // 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); | 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) | DecimalFormat fmt = (pattern != null) ? new DecimalFormat(pattern) | ||||
| : new DecimalFormat(); | : new DecimalFormat(); | ||||
| try { | 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) { | } catch (NumberFormatException nfe) { | ||||
| // swallow | // swallow | ||||
| } catch (ParseException pe) { | } 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) { | } else if (operation == Operation.INCREMENT_OPER) { | ||||
| newValue = currentValue + value; | newValue = currentValue + value; | ||||
| } | } | ||||
| value = newValue; | |||||
| this.newValue = newValue; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
| @@ -85,6 +85,7 @@ public class PropertyFileTest extends BuildFileTest { | |||||
| initTestPropFile(); | initTestPropFile(); | ||||
| initBuildPropFile(); | initBuildPropFile(); | ||||
| configureProject(projectFilePath); | configureProject(projectFilePath); | ||||
| project.setProperty(valueDoesNotGetOverwrittenPropertyFileKey,valueDoesNotGetOverwrittenPropertyFile); | |||||
| } | } | ||||
| @@ -134,6 +135,12 @@ public class PropertyFileTest extends BuildFileTest { | |||||
| assertEquals("6",project.getProperty("int.without.value")); | 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 { | public void testDirect() throws Exception { | ||||
| PropertyFile pf = new PropertyFile(); | PropertyFile pf = new PropertyFile(); | ||||
| @@ -175,7 +182,7 @@ public class PropertyFileTest extends BuildFileTest { | |||||
| testProps.put("existing.prop", "37"); | testProps.put("existing.prop", "37"); | ||||
| FileOutputStream fos = new FileOutputStream(testPropsFilePath); | FileOutputStream fos = new FileOutputStream(testPropsFilePath); | ||||
| testProps.save(fos, "defaults"); | |||||
| testProps.store(fos, "defaults"); | |||||
| fos.close(); | fos.close(); | ||||
| } | } | ||||
| @@ -191,7 +198,7 @@ public class PropertyFileTest extends BuildFileTest { | |||||
| buildProps.put(DATE_KEY, NEW_DATE); | buildProps.put(DATE_KEY, NEW_DATE); | ||||
| FileOutputStream fos = new FileOutputStream(buildPropsFilePath); | FileOutputStream fos = new FileOutputStream(buildPropsFilePath); | ||||
| buildProps.save(fos, null); | |||||
| buildProps.store(fos, null); | |||||
| fos.close(); | fos.close(); | ||||
| } | } | ||||
| @@ -204,6 +211,10 @@ public class PropertyFileTest extends BuildFileTest { | |||||
| tempFile = new File(buildPropsFilePath); | tempFile = new File(buildPropsFilePath); | ||||
| tempFile.delete(); | tempFile.delete(); | ||||
| tempFile = null; | tempFile = null; | ||||
| tempFile = new File(valueDoesNotGetOverwrittenPropsFilePath); | |||||
| tempFile.delete(); | |||||
| tempFile = null; | |||||
| } | } | ||||
| @@ -214,7 +225,11 @@ public class PropertyFileTest extends BuildFileTest { | |||||
| testPropertyFile = "propertyfile.test.properties", | testPropertyFile = "propertyfile.test.properties", | ||||
| testPropertyFileKey = "test.propertyfile", | testPropertyFileKey = "test.propertyfile", | ||||
| testPropsFilePath = "src/etc/testcases/taskdefs/optional/" + testPropertyFile, | 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", | buildPropsFilePath = "src/etc/testcases/taskdefs/optional/propertyfile.build.properties", | ||||
| FNAME = "Bruce", | FNAME = "Bruce", | ||||