Well, here it is, the patch I worked myself into by bringing up the immutability issues.
I would love to add <available> to this patch - just say the word! :)
The warning messages probably aren't as big and bold as Peter had requested,
so feel free to modify them to your liking.
Not that much code changed, and my test cases should exercise things
reasonably.
I think I've taken care of all the tasks that we mentioned - and because
setProperty was modified to issue a warning when a property override occurs,
the tasks that still call setProperty (like <junit>) will get that message
when overriding a property (but not otherwise).
I'll go back and check all the e-mails on this topic tomorrow to make sure
all the bases have been covered. The one loose end is that getProperties
and getUserProperties return back the actual Hashtable object - so to close
that hole we need to make it return a copy instead. Anyone object to that
copy being made and returned?
Thanks,
Erik
cvs -q diff -u src/main/org/apache/tools/ant/taskdefs/Checksum.java
src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
src/main/org/apache/tools/ant/taskdefs/ExecTask.java
src/main/org/apache/tools/ant/taskdefs/PathConvert.java
src/main/org/apache/tools/ant/Project.java
src/main/org/apache/tools/ant/taskdefs/Property.java
src/main/org/apache/tools/ant/taskdefs/Tstamp.java
Index: src/main/org/apache/tools/ant/taskdefs/Checksum.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Checksum.java,v
retrieving revision 1.4
diff -u -r1.4 Checksum.java
--- src/main/org/apache/tools/ant/taskdefs/Checksum.java 2001/11/22
09:37:34 1.4
+++ src/main/org/apache/tools/ant/taskdefs/Checksum.java 2001/11/29
02:40:34
@@ -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());
}
}
Index: src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java,v
retrieving revision 1.2
diff -u -r1.2 ConditionTask.java
--- src/main/org/apache/tools/ant/taskdefs/ConditionTask.java 2001/11/28
01:15:29 1.2
+++ src/main/org/apache/tools/ant/taskdefs/ConditionTask.java 2001/11/29
02:40:34
@@ -104,7 +104,7 @@
}
Condition c = (Condition) getConditions().nextElement();
if (c.eval()) {
- getProject().setProperty(property, value);
+ getProject().setNewProperty(property, value);
}
}
}
Index: src/main/org/apache/tools/ant/taskdefs/ExecTask.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java,v
retrieving revision 1.20
diff -u -r1.20 ExecTask.java
--- src/main/org/apache/tools/ant/taskdefs/ExecTask.java 2001/11/27
23:45:49 1.20
+++ src/main/org/apache/tools/ant/taskdefs/ExecTask.java 2001/11/29
02:40:34
@@ -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());
}
}
Index: src/main/org/apache/tools/ant/taskdefs/PathConvert.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java,v
retrieving revision 1.4
diff -u -r1.4 PathConvert.java
--- src/main/org/apache/tools/ant/taskdefs/PathConvert.java 2001/10/28
21:26:29 1.4
+++ src/main/org/apache/tools/ant/taskdefs/PathConvert.java 2001/11/29
02:40:35
@@ -280,7 +280,7 @@
log( "Set property " + property + " = " + value, Project.MSG_VERBOSE );
- getProject().setProperty( property, value );
+ getProject().setNewProperty( property, value );
}
/**
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.34
diff -u -r1.34 Property.java
--- src/main/org/apache/tools/ant/taskdefs/Property.java 2001/11/22
08:41:49 1.34
+++ src/main/org/apache/tools/ant/taskdefs/Property.java 2001/11/29
02:40:36
@@ -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);
}
}
Index: src/main/org/apache/tools/ant/taskdefs/Tstamp.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java,v
retrieving revision 1.14
diff -u -r1.14 Tstamp.java
--- src/main/org/apache/tools/ant/taskdefs/Tstamp.java 2001/11/25 16:01:57
1.14
+++ src/main/org/apache/tools/ant/taskdefs/Tstamp.java 2001/11/29 02:40:36
@@ -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));
}
}
}
Index: src/main/org/apache/tools/ant/Project.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.80
diff -u -r1.80 Project.java
--- src/main/org/apache/tools/ant/Project.java 2001/11/27 08:25:08 1.80
+++ src/main/org/apache/tools/ant/Project.java 2001/11/29 02:40:39
@@ -301,11 +301,36 @@
* <i>the immutability policy is not implemented at this level</i>
* @param name name of property
* @param value new value of the property
+ * @deprecated, 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 - The setProperty method is deprecated. Use
setNewProperty instead.");
+ }
+
+ 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 + " -> " +
<?xml version="1.0"?>
<project name="available-test" basedir="." default="test1">
<target name="test1">
<property name="test" value="original"/>
<available file="immutable.xml" property="test" value="override"/>
</target>
<target name="test2">
<tstamp/>
<tstamp prefix="start"/>
</target>
<target name="test3">
<property name="DSTAMP" value="original"/>
<tstamp/>
</target>
<target name="test4">
<property name="test" value="original"/>
<condition property="test" value="override">
<equals arg1="1" arg2="1"/>
</condition>
</target>
<target name="test5">
<property name="test" value="original"/>
<checksum file="immutable.xml" verifyProperty="test"/>
</target>
<target name="test6">
<property name="test1" value="original"/>
<property name="test2" value="original"/>
<!-- How to make this cross-platform? -->
<exec executable="cmd.exe" os="Windows 2000" outputproperty="test1" resultProperty="test2">
<arg line="/c dir"/>
</exec>
</target>
<target name="test7">
<property name="test" value="original"/>
<pathconvert targetos="unix" property="test" >
<path>
<pathelement location="/lib/weblogicaux.jar" />
<pathelement location="/classes" />
<pathelement location="/mssqlserver4/classes" />
<pathelement location="c:\winnt\System32" />
</path>
</pathconvert>
</target>
</project>
ImmutableTest.java
Description: java/
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
