antoine     2003/07/11 14:25:35

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional
                        PropertyFile.java
               src/testcases/org/apache/tools/ant/taskdefs/optional
                        PropertyFileTest.java
               src/etc/testcases/taskdefs/optional propertyfile.xml
  Log:
  resolves bug : propertyfile does *2 instead of +1
  actually due to field value of PropertyFile.Entry class overwritten
  after execution with the result (contains the increment before execution)
  PR: 21505
  
  Revision  Changes    Path
  1.456     +8 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.455
  retrieving revision 1.456
  diff -u -r1.455 -r1.456
  --- WHATSNEW  10 Jul 2003 13:23:47 -0000      1.455
  +++ WHATSNEW  11 Jul 2003 21:25:35 -0000      1.456
  @@ -49,6 +49,10 @@
     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
  @@ -194,6 +198,10 @@
   
   * 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:
   --------------
  
  
  
  1.29      +14 -32    
ant/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
  
  Index: PropertyFile.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- PropertyFile.java 16 Feb 2003 13:57:42 -0000      1.28
  +++ PropertyFile.java 11 Jul 2003 21:25:35 -0000      1.29
  @@ -249,23 +249,7 @@
           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 @@
           }
       }
   
  -    /**
  -    * 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 @@
           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 @@
                   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 @@
                   currentValue.add(field, offset);
               }
   
  -            value = fmt.format(currentValue.getTime());
  +            newValue = fmt.format(currentValue.getTime());
           }
   
   
  @@ -466,7 +443,12 @@
               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 @@
                   }
               }
   
  -            value = fmt.format(newValue);
  +            this.newValue = fmt.format(newValue);
           }
           
           /**
  @@ -518,7 +500,7 @@
               } else if (operation == Operation.INCREMENT_OPER) {
                   newValue = currentValue + value;
               }
  -            value = newValue;
  +            this.newValue = newValue;
           }
           
           /**
  
  
  
  1.8       +19 -4     
ant/src/testcases/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
  
  Index: PropertyFileTest.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PropertyFileTest.java     10 Feb 2003 14:14:51 -0000      1.7
  +++ PropertyFileTest.java     11 Jul 2003 21:25:35 -0000      1.8
  @@ -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 @@
           initTestPropFile();
           initBuildPropFile();
           configureProject(projectFilePath);
  +        
project.setProperty(valueDoesNotGetOverwrittenPropertyFileKey,valueDoesNotGetOverwrittenPropertyFile);
       }
   
   
  @@ -134,6 +135,12 @@
           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 @@
           testProps.put("existing.prop", "37");
         
           FileOutputStream fos = new FileOutputStream(testPropsFilePath);
  -        testProps.save(fos, "defaults");
  +        testProps.store(fos, "defaults");
           fos.close();
       }
   
  @@ -191,7 +198,7 @@
           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 @@
           tempFile = new File(buildPropsFilePath);
           tempFile.delete();
           tempFile = null;
  +
  +        tempFile = new File(valueDoesNotGetOverwrittenPropsFilePath);
  +        tempFile.delete();
  +        tempFile = null;
       }
      
   
  @@ -214,7 +225,11 @@
           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",
  
  
  
  1.4       +14 -0     ant/src/etc/testcases/taskdefs/optional/propertyfile.xml
  
  Index: propertyfile.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/optional/propertyfile.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- propertyfile.xml  1 Jun 2002 12:26:37 -0000       1.3
  +++ propertyfile.xml  11 Jul 2003 21:25:35 -0000      1.4
  @@ -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>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to