I really understand the reasons why properties are desired to be
immutable, however, sometimes it makes people upset, when they are forced
to use patterns which they do not like.  The proposed patch does not
change anything within the standard behaviour of properties, they are
immutable by default. But.. the user can override the default behaviour,
by new, introduced attribute 'final' (in analogy to final variables in
Java). If attribute final is "off", "false", "not", or "0", the property
will behave exactly like in ANT 1.0.8.

Thus:
<property name="cpath" value="${ext.dir}/OB.jar" final="off" />
<property name="cpath" value="${cpath}:${ext.dir}/jndi.jar" final="off" />
<property name="cpath" value="${cpath}:${ext.dir}/gnu-regexp.jar" final="off"/>
<property name="cpath" value="${cpath}:${ext.dir}/myutil.jar" final="off"/> 
<property name="cpath" value="${cpath}:${ext.dir}/myother.jar" final="off"/>

will work as in ANT 1.0.8, but if you add another line:

<property name="cpath" value="myallinone.jar" />

you will get:

$ ant
Buildfile: build.xml
 [property] Override ignored for cpath with myallinone.jar


The patch also changes ignoring overriding from being silent in normal ant
mode to being explicitly reported. I think not setting property because of
immutability should be reported to the user even if ant is invoked not in
verbose mode.  
The keyword 'final' is a little abused here, because it does not really
work as in Java, while it referes to the previously declared property not
to the current one.. any suggestions for better attribute name ;o)  ?
I think it should be left to the user, whether he wants to mess up with
his properties, or not...


best regards
Mariusz
Index: src/main/org/apache/tools/ant/taskdefs/Property.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
retrieving revision 1.9
diff -U5 -r1.9 Property.java
--- src/main/org/apache/tools/ant/taskdefs/Property.java        2000/07/21 
14:24:35     1.9
+++ src/main/org/apache/tools/ant/taskdefs/Property.java        2000/07/23 
03:54:09
@@ -72,27 +72,36 @@
     String value;
     String file;
     String resource;
 
     boolean userProperty=false; // set read-only properties
+    boolean overwrite = false;
 
     public void setName(String name) {
         this.name = name;
     }
 
     public String getName() {
-       return name;
+        return name;
     }
 
     public void setValue(String value) {
         this.value = value;
     }
 
     public String getValue() {
-       return value;
+        return value;
     }
 
+    public void setFinal(String value) {
+      if(value.toLowerCase().startsWith("off") ||
+         value.toLowerCase().startsWith("false") ||
+         value.toLowerCase().startsWith("not") ||
+         value.toLowerCase().startsWith("0"))
+        this.overwrite = true;
+    }
+
     public void setFile(String file) {
         this.file = file;
     }
 
     public String getFile() {
@@ -161,25 +170,25 @@
             addProperty(name, value);
         }
     }
 
     public void setUserProperty( boolean userP ) {
-       userProperty=userP;
+        userProperty=userP;
     }
 
     private void addProperty(String n, String v) {
         if( userProperty ) {
-            if (project.getUserProperty(n) == null) {
+            if (project.getUserProperty(n) == null || overwrite) {
                 project.setUserProperty(n, v);
             } else {
-                log("Override ignored for " + name, Project.MSG_VERBOSE);
+                log("Override ignored for " + name + " with " + v, 
Project.MSG_INFO);
             } 
         } else {
-            if (project.getProperty(n) == null) {
+            if (project.getProperty(n) == null || overwrite) {
                 project.setProperty(n, v);
             } else {
-                log("Override ignored for " + name, Project.MSG_VERBOSE);
+                log("Override ignored for " + name + " with "+v, 
Project.MSG_INFO);
             }
         }
     }
 
     private void resolveAllProperties(Hashtable props) {

Reply via email to