ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs TStampTest.java
Date Wed, 25 Sep 2002 15:12:56 GMT
bodewig     2002/09/25 08:12:55

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs Tstamp.java
               src/testcases/org/apache/tools/ant/taskdefs TStampTest.java
  Log:
  <tstamp>'s prefix attribute didn't apply to nested <format>s.
  
  The code tries to use the prefix but fails because setPrefix() gets
  called after createFormat().
  
  PR: 12829
  Submitted by:   gjfdh at yahoo.com
  
  Revision  Changes    Path
  1.289     +2 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.288
  retrieving revision 1.289
  diff -u -r1.288 -r1.289
  --- WHATSNEW	23 Sep 2002 16:01:43 -0000	1.288
  +++ WHATSNEW	25 Sep 2002 15:12:55 -0000	1.289
  @@ -32,6 +32,8 @@
   * <replaceregexp> could append a newline character at the end of the
     file.
   
  +* <tstamp>'s prefix attribute failed to apply to nested <format> elements.
  +
   Other changes:
   --------------
   
  
  
  
  1.33      +16 -11    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
  
  Index: Tstamp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Tstamp.java	25 Jul 2002 15:21:05 -0000	1.32
  +++ Tstamp.java	25 Sep 2002 15:12:55 -0000	1.33
  @@ -115,14 +115,14 @@
               }
   
               SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd");
  -            getProject().setNewProperty(prefix + "DSTAMP", dstamp.format(d));
  +            setProperty("DSTAMP", dstamp.format(d));
   
               SimpleDateFormat tstamp = new SimpleDateFormat ("HHmm");
  -            getProject().setNewProperty(prefix + "TSTAMP", tstamp.format(d));
  +            setProperty("TSTAMP", tstamp.format(d));
   
               SimpleDateFormat today
                   = new SimpleDateFormat ("MMMM d yyyy", Locale.US);
  -            getProject().setNewProperty(prefix + "TODAY", today.format(d));
  +            setProperty("TODAY", today.format(d));
   
           } catch (Exception e) {
               throw new BuildException(e);
  @@ -134,12 +134,20 @@
        * @return a ready to fill-in format
        */
       public CustomFormat createFormat() {
  -        CustomFormat cts = new CustomFormat(prefix);
  +        CustomFormat cts = new CustomFormat();
           customFormats.addElement(cts);
           return cts;
       }
   
       /**
  +     * helper that encapsulates prefix logic and property setting
  +     * policy (i.e. we use setNewProperty instead of setProperty).
  +     */
  +    private void setProperty(String name, String value) {
  +        getProject().setNewProperty(prefix + name, value);
  +    }
  +
  +    /**
        * This nested element that allows a property to be set
        * to the current date and time in a given format.
        * The date/time patterns are as defined in the
  @@ -157,14 +165,11 @@
           private String variant;
           private int offset = 0;
           private int field = Calendar.DATE;
  -        private String prefix = "";
   
           /**
  -         * Create a format with the current prefix
  -         * @param prefix
  +         * Create a format
            */
  -        public CustomFormat(String prefix) {
  -            this.prefix = prefix;
  +        public CustomFormat() {
           }
   
           /**
  @@ -172,7 +177,7 @@
            * @param propertyName
            */
           public void setProperty(String propertyName) {
  -            this.propertyName = prefix + propertyName;
  +            this.propertyName = propertyName;
           }
   
           /**
  @@ -306,7 +311,7 @@
               if (timeZone != null){
                   sdf.setTimeZone(timeZone);
               }
  -            project.setNewProperty(propertyName, sdf.format(date));
  +            Tstamp.this.setProperty(propertyName, sdf.format(date));
           }
       }
   
  
  
  
  1.3       +13 -0     jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TStampTest.java
  
  Index: TStampTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TStampTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TStampTest.java	22 Jun 2002 23:38:37 -0000	1.2
  +++ TStampTest.java	25 Sep 2002 15:12:55 -0000	1.3
  @@ -121,6 +121,7 @@
           assertEquals(expected, today);
   
       }
  +
       /**
        * verifies that custom props have priority over the
        * originals
  @@ -130,6 +131,18 @@
           tstamp.setPrefix("prefix");
           tstamp.execute();
           String prop= project.getProperty("prefix.DSTAMP");
  +        assertNotNull(prop);
  +    }
  +
  +    public void testFormatPrefix() throws Exception {
  +	Tstamp.CustomFormat format = tstamp.createFormat();
  +        format.setProperty("format");
  +        format.setPattern("HH:mm:ss z");
  +        format.setTimezone("GMT");
  +
  +        tstamp.setPrefix("prefix");
  +        tstamp.execute();
  +        String prop= project.getProperty("prefix.format");
           assertNotNull(prop);
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message