ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Checksum.java ConditionTask.java ExecTask.java PathConvert.java Property.java Tstamp.java
Date Fri, 30 Nov 2001 17:35:07 GMT
donaldp     01/11/30 09:35:07

  Modified:    src/main/org/apache/tools/ant Project.java
               src/main/org/apache/tools/ant/taskdefs Checksum.java
                        ConditionTask.java ExecTask.java PathConvert.java
                        Property.java Tstamp.java
  Log:
  This patch forces property setting to follow the same rules as the rest of ant in most tasks.
The few tasks where we have not forced immutability will instead get 3 line ugly warnings
telling them that they should upgrade or not use the same property name etc.
  
  The reason for just warning them is backwards compatability.
  
  Submitted by: "Erik Hatcher" <erik@hatcher.net>
  
  Revision  Changes    Path
  1.81      +28 -0     jakarta-ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- Project.java	2001/11/27 08:25:08	1.80
  +++ Project.java	2001/11/30 17:35:06	1.81
  @@ -301,11 +301,39 @@
        * <i>the immutability policy is not implemented at this level</i> 
        * @param name name of property
        * @param value new value of the property
  +     * @deprecated use, set setNewProperty
        */
       public void setProperty(String name, String value) {
           // command line properties take precedence
           if (null != userProperties.get(name)) {
               log("Override ignored for user property " + name, MSG_VERBOSE);
  +            return;
  +        }
  +
  +        if (null != properties.get(name)) {
  +            log("DEPRECATED - Project.setProperty('" + name + "','" + value + "') used
" + 
  +                "to overide an immutable property. Task writer should use Project.setNewProperty()
" +
  +                "instead and the build writer should not reuse the same property name for
" + 
  +                "different values.");
  +        }
  +
  +        log("Setting project property: " + name + " -> " +
  +             value, MSG_DEBUG);
  +        properties.put(name, value);
  +    }
  +
  +    /**
  +     * set a property. Any existing property of the same name 
  +     * is overwritten, unless it is a user property. 
  +     * <i>the immutability policy <b>is</b> enforced at this level</i>

  +     * @param name name of property
  +     * @param value new value of the property
  +     * @since 1.5
  +     */
  +    public void setNewProperty(String name, String value) {
  +        // command line properties take precedence
  +        if (null != properties.get(name)) {
  +            log("Override ignored for property " + name, MSG_VERBOSE);
               return;
           }
           log("Setting project property: " + name + " -> " +
  
  
  
  1.5       +1 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Checksum.java
  
  Index: Checksum.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Checksum.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Checksum.java	2001/11/22 09:37:34	1.4
  +++ Checksum.java	2001/11/30 17:35:06	1.5
  @@ -193,7 +193,7 @@
       public void execute() throws BuildException {
           boolean value = validateAndExecute();
           if (verifyProperty != null) {
  -            project.setProperty(verifyProperty,
  +            project.setNewProperty(verifyProperty,
                                   new Boolean(value).toString());
           }
       }
  
  
  
  1.3       +2 -2      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
  
  Index: ConditionTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConditionTask.java	2001/11/28 01:15:29	1.2
  +++ ConditionTask.java	2001/11/30 17:35:06	1.3
  @@ -69,7 +69,7 @@
    * ConditionBase.</p>
    *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class ConditionTask extends ConditionBase {
   
  @@ -104,7 +104,7 @@
           }
           Condition c = (Condition) getConditions().nextElement();
           if (c.eval()) {
  -            getProject().setProperty(property, value);
  +            getProject().setNewProperty(property, value);
           }
       }
   }
  
  
  
  1.21      +2 -2      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java
  
  Index: ExecTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ExecTask.java	2001/11/27 23:45:49	1.20
  +++ ExecTask.java	2001/11/30 17:35:06	1.21
  @@ -196,7 +196,7 @@
           String res=Integer.toString(result);
           if(resultProperty!=null
              && project.getProperty(resultProperty) == null) {
  -                project.setProperty(resultProperty,res);
  +                project.setNewProperty(resultProperty,res);
           }
       }
       
  @@ -306,7 +306,7 @@
                   }
                   val.append(line);
               }
  -            project.setProperty(outputprop, val.toString());
  +            project.setNewProperty(outputprop, val.toString());
           }
       }
   
  
  
  
  1.5       +1 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java
  
  Index: PathConvert.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PathConvert.java	2001/10/28 21:26:29	1.4
  +++ PathConvert.java	2001/11/30 17:35:06	1.5
  @@ -280,7 +280,7 @@
   
           log( "Set property " + property + " = " + value, Project.MSG_VERBOSE );
   
  -        getProject().setProperty( property, value );
  +        getProject().setNewProperty( property, value );
       }
   
       /**
  
  
  
  1.35      +5 -5      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java
  
  Index: Property.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- Property.java	2001/11/22 08:41:49	1.34
  +++ Property.java	2001/11/30 17:35:06	1.35
  @@ -160,6 +160,9 @@
           createClasspath().setRefid(r);
       }
   
  +    /**
  +    * @deprecated
  +    */
       public void setUserProperty(boolean userProperty) {
           this.userProperty = userProperty;
       }
  @@ -284,17 +287,14 @@
   
       protected void addProperty(String n, String v) {
           if( userProperty ) {
  +            log("DEPRECATED - Setting user properties through the Property task has been
deprecated.");
               if (project.getUserProperty(n) == null) {
                   project.setUserProperty(n, v);
               } else {
                   log("Override ignored for " + n, Project.MSG_VERBOSE);
               } 
           } else {
  -            if (project.getProperty(n) == null) {
  -                project.setProperty(n, v);
  -            } else {
  -                log("Override ignored for " + n, Project.MSG_VERBOSE);
  -            }
  +            project.setNewProperty(n, v);
           }
       }
   
  
  
  
  1.15      +17 -7     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Tstamp.java	2001/11/25 16:01:57	1.14
  +++ Tstamp.java	2001/11/30 17:35:06	1.15
  @@ -80,19 +80,27 @@
   public class Tstamp extends Task {
   
       private Vector customFormats = new Vector();
  +    private String prefix = "";
  +    
  +    public void setPrefix(String prefix) {
  +        this.prefix = prefix;
  +        if (!this.prefix.endsWith(".")) {
  +            this.prefix += ".";
  +        }
  +    }
   
       public void execute() throws BuildException {
           try {
               Date d = new Date();
   
               SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd");
  -            project.setProperty("DSTAMP", dstamp.format(d));
  +            project.setNewProperty(prefix + "DSTAMP", dstamp.format(d));
   
               SimpleDateFormat tstamp = new SimpleDateFormat ("HHmm");
  -            project.setProperty("TSTAMP", tstamp.format(d));
  +            project.setNewProperty(prefix + "TSTAMP", tstamp.format(d));
   
               SimpleDateFormat today  = new SimpleDateFormat ("MMMM d yyyy", Locale.US);
  -            project.setProperty("TODAY", today.format(d));
  +            project.setNewProperty(prefix + "TODAY", today.format(d));
   
               Enumeration i = customFormats.elements();
               while(i.hasMoreElements()) {
  @@ -107,7 +115,7 @@
   
       public CustomFormat createFormat()
       {
  -        CustomFormat cts = new CustomFormat();
  +        CustomFormat cts = new CustomFormat(prefix);
           customFormats.addElement(cts);
           return cts;
       }
  @@ -122,14 +130,16 @@
           private String variant;
           private int offset = 0;
           private int field = Calendar.DATE;
  +        private String prefix="";
           
  -        public CustomFormat()
  +        public CustomFormat(String prefix)
           {
  +            this.prefix = prefix;
           }
           
           public void setProperty(String propertyName)
           {
  -            this.propertyName = propertyName;
  +            this.propertyName = prefix + propertyName;
           }
           
           public void setPattern(String pattern)
  @@ -227,7 +237,7 @@
               if (timeZone != null){
                   sdf.setTimeZone(timeZone);
               }
  -            project.setProperty(propertyName, sdf.format(date));
  +            project.setNewProperty(propertyName, sdf.format(date));
           }
       }
   }
  
  
  

--
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