The reason for just warning them is backwards compatability. Submitted by: "Erik Hatcher" <erik@hatcher.net> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270054 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -301,6 +301,7 @@ public class Project { | |||||
| * <i>the immutability policy is not implemented at this level</i> | * <i>the immutability policy is not implemented at this level</i> | ||||
| * @param name name of property | * @param name name of property | ||||
| * @param value new value of the property | * @param value new value of the property | ||||
| * @deprecated use, set setNewProperty | |||||
| */ | */ | ||||
| public void setProperty(String name, String value) { | public void setProperty(String name, String value) { | ||||
| // command line properties take precedence | // command line properties take precedence | ||||
| @@ -308,6 +309,33 @@ public class Project { | |||||
| log("Override ignored for user property " + name, MSG_VERBOSE); | log("Override ignored for user property " + name, MSG_VERBOSE); | ||||
| return; | 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 + " -> " + | log("Setting project property: " + name + " -> " + | ||||
| value, MSG_DEBUG); | value, MSG_DEBUG); | ||||
| properties.put(name, value); | properties.put(name, value); | ||||
| @@ -193,7 +193,7 @@ public class Checksum extends MatchingTask implements Condition { | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| boolean value = validateAndExecute(); | boolean value = validateAndExecute(); | ||||
| if (verifyProperty != null) { | if (verifyProperty != null) { | ||||
| project.setProperty(verifyProperty, | |||||
| project.setNewProperty(verifyProperty, | |||||
| new Boolean(value).toString()); | new Boolean(value).toString()); | ||||
| } | } | ||||
| } | } | ||||
| @@ -104,7 +104,7 @@ public class ConditionTask extends ConditionBase { | |||||
| } | } | ||||
| Condition c = (Condition) getConditions().nextElement(); | Condition c = (Condition) getConditions().nextElement(); | ||||
| if (c.eval()) { | if (c.eval()) { | ||||
| getProject().setProperty(property, value); | |||||
| getProject().setNewProperty(property, value); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -196,7 +196,7 @@ public class ExecTask extends Task { | |||||
| String res=Integer.toString(result); | String res=Integer.toString(result); | ||||
| if(resultProperty!=null | if(resultProperty!=null | ||||
| && project.getProperty(resultProperty) == null) { | && project.getProperty(resultProperty) == null) { | ||||
| project.setProperty(resultProperty,res); | |||||
| project.setNewProperty(resultProperty,res); | |||||
| } | } | ||||
| } | } | ||||
| @@ -306,7 +306,7 @@ public class ExecTask extends Task { | |||||
| } | } | ||||
| val.append(line); | val.append(line); | ||||
| } | } | ||||
| project.setProperty(outputprop, val.toString()); | |||||
| project.setNewProperty(outputprop, val.toString()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -280,7 +280,7 @@ public class PathConvert extends Task { | |||||
| log( "Set property " + property + " = " + value, Project.MSG_VERBOSE ); | log( "Set property " + property + " = " + value, Project.MSG_VERBOSE ); | ||||
| getProject().setProperty( property, value ); | |||||
| getProject().setNewProperty( property, value ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -160,6 +160,9 @@ public class Property extends Task { | |||||
| createClasspath().setRefid(r); | createClasspath().setRefid(r); | ||||
| } | } | ||||
| /** | |||||
| * @deprecated | |||||
| */ | |||||
| public void setUserProperty(boolean userProperty) { | public void setUserProperty(boolean userProperty) { | ||||
| this.userProperty = userProperty; | this.userProperty = userProperty; | ||||
| } | } | ||||
| @@ -284,17 +287,14 @@ public class Property extends Task { | |||||
| protected void addProperty(String n, String v) { | protected void addProperty(String n, String v) { | ||||
| if( userProperty ) { | if( userProperty ) { | ||||
| log("DEPRECATED - Setting user properties through the Property task has been deprecated."); | |||||
| if (project.getUserProperty(n) == null) { | if (project.getUserProperty(n) == null) { | ||||
| project.setUserProperty(n, v); | project.setUserProperty(n, v); | ||||
| } else { | } else { | ||||
| log("Override ignored for " + n, Project.MSG_VERBOSE); | log("Override ignored for " + n, Project.MSG_VERBOSE); | ||||
| } | } | ||||
| } else { | } else { | ||||
| if (project.getProperty(n) == null) { | |||||
| project.setProperty(n, v); | |||||
| } else { | |||||
| log("Override ignored for " + n, Project.MSG_VERBOSE); | |||||
| } | |||||
| project.setNewProperty(n, v); | |||||
| } | } | ||||
| } | } | ||||
| @@ -80,19 +80,27 @@ import java.text.SimpleDateFormat; | |||||
| public class Tstamp extends Task { | public class Tstamp extends Task { | ||||
| private Vector customFormats = new Vector(); | 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 { | public void execute() throws BuildException { | ||||
| try { | try { | ||||
| Date d = new Date(); | Date d = new Date(); | ||||
| SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd"); | SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd"); | ||||
| project.setProperty("DSTAMP", dstamp.format(d)); | |||||
| project.setNewProperty(prefix + "DSTAMP", dstamp.format(d)); | |||||
| SimpleDateFormat tstamp = new SimpleDateFormat ("HHmm"); | 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); | 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(); | Enumeration i = customFormats.elements(); | ||||
| while(i.hasMoreElements()) { | while(i.hasMoreElements()) { | ||||
| @@ -107,7 +115,7 @@ public class Tstamp extends Task { | |||||
| public CustomFormat createFormat() | public CustomFormat createFormat() | ||||
| { | { | ||||
| CustomFormat cts = new CustomFormat(); | |||||
| CustomFormat cts = new CustomFormat(prefix); | |||||
| customFormats.addElement(cts); | customFormats.addElement(cts); | ||||
| return cts; | return cts; | ||||
| } | } | ||||
| @@ -122,14 +130,16 @@ public class Tstamp extends Task { | |||||
| private String variant; | private String variant; | ||||
| private int offset = 0; | private int offset = 0; | ||||
| private int field = Calendar.DATE; | private int field = Calendar.DATE; | ||||
| private String prefix=""; | |||||
| public CustomFormat() | |||||
| public CustomFormat(String prefix) | |||||
| { | { | ||||
| this.prefix = prefix; | |||||
| } | } | ||||
| public void setProperty(String propertyName) | public void setProperty(String propertyName) | ||||
| { | { | ||||
| this.propertyName = propertyName; | |||||
| this.propertyName = prefix + propertyName; | |||||
| } | } | ||||
| public void setPattern(String pattern) | public void setPattern(String pattern) | ||||
| @@ -227,7 +237,7 @@ public class Tstamp extends Task { | |||||
| if (timeZone != null){ | if (timeZone != null){ | ||||
| sdf.setTimeZone(timeZone); | sdf.setTimeZone(timeZone); | ||||
| } | } | ||||
| project.setProperty(propertyName, sdf.format(date)); | |||||
| project.setNewProperty(propertyName, sdf.format(date)); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||