Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 47363 invoked from network); 4 Dec 2001 02:14:20 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 4 Dec 2001 02:14:20 -0000 Received: (qmail 13641 invoked by uid 97); 4 Dec 2001 02:14:24 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 13625 invoked by uid 97); 4 Dec 2001 02:14:23 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 13612 invoked from network); 4 Dec 2001 02:14:23 -0000 Message-ID: <012201c17c69$5e896f00$6401a8c0@darden.virginia.edu> From: "Erik Hatcher" To: "ant-dev" Subject: [PATCH] Immutability Patch 2 Date: Mon, 3 Dec 2001 21:14:12 -0500 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_011F_01C17C3F.748DF9D0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_011F_01C17C3F.748DF9D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Yup, its me again! :) The issue that Peter brought up with ant/antcall is being addressed in this patch. Property was modified to allow setting user properties without warning, but that mode cannot be enabled from a statement (I removed the setUserProperty method as it was undocumented and probably only used by ant/antcall under the covers). Project had several calls to setProperty in it, which in theory could generate a deprecated warning. I added an internal method to allow setting "basedir" and a couple of other places to set a property silently if it wasn't a user property (setPropertyInternal, its protected, although private would have been ok with me too). I modified getProperties and getUserProperties to return copies of the collections to prevent modifications of properties that way. I updated WHATSNEW (maybe the back door shouldn't be mentioned there - maybe we should just close that open door :). This should be yet another step forward in the battle against property mutability. Let me know if there are any problems with this patch or if I've missed something. Thanks, Erik ------=_NextPart_000_011F_01C17C3F.748DF9D0 Content-Type: text/plain; name="immutabality2_patch.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="immutabality2_patch.txt" Index: src/main/org/apache/tools/ant/taskdefs/Ant.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.ja= va,v retrieving revision 1.33 diff -u -r1.33 Ant.java --- src/main/org/apache/tools/ant/taskdefs/Ant.java 2001/11/22 08:40:03 = 1.33 +++ src/main/org/apache/tools/ant/taskdefs/Ant.java 2001/12/04 01:45:07 @@ -330,8 +330,9 @@ if (newProject =3D=3D null) { reinit(); } - Property p=3D(Property)newProject.createTask("property"); - p.setUserProperty(true); + Property p =3D new Property(true); + p.setProject(newProject); + p.setTaskName("property"); properties.addElement( p ); return p; } Index: src/main/org/apache/tools/ant/taskdefs/Property.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Proper= ty.java,v retrieving revision 1.36 diff -u -r1.36 Property.java --- src/main/org/apache/tools/ant/taskdefs/Property.java 2001/12/01 = 03:34:35 1.36 +++ src/main/org/apache/tools/ant/taskdefs/Property.java 2001/12/04 = 01:45:08 @@ -88,7 +88,16 @@ protected Reference ref =3D null; =20 protected boolean userProperty=3Dfalse; // set read-only properties - + =20 + public Property() { + super(); + } + =20 + public Property(boolean userProperty) { + this(); + this.userProperty =3D userProperty; + } + =20 public void setName(String name) { this.name =3D name; } @@ -160,11 +169,8 @@ createClasspath().setRefid(r); } =20 - /** - * @deprecated - */ - public void setUserProperty(boolean userProperty) { - this.userProperty =3D userProperty; + public boolean isUserProperty() { + return userProperty; } =20 public String toString() { @@ -287,12 +293,11 @@ =20 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) =3D=3D null) { project.setUserProperty(n, v); } else { log("Override ignored for " + n, Project.MSG_VERBOSE); - }=20 + } } else { project.setNewProperty(n, v); } Index: src/main/org/apache/tools/ant/Project.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v retrieving revision 1.82 diff -u -r1.82 Project.java --- src/main/org/apache/tools/ant/Project.java 2001/12/01 03:31:40 1.82 +++ src/main/org/apache/tools/ant/Project.java 2001/12/04 01:45:11 @@ -159,7 +159,7 @@ public Project() { fileUtils =3D FileUtils.newFileUtils(); } - + =20 /** * Initialise the project. * @@ -353,6 +353,18 @@ userProperties.put(name, value); properties.put(name, value); } + =20 + /** + * Allows Project and subclasses to set a property unless its + * already defined as a user property. There are a few cases=20 + * internally to Project that need to do this currently. + */ + protected void setPropertyInternal(String name, String value) { + if (null !=3D userProperties.get(name)) { + return; + } + properties.put(name, value); + } =20 /** * query a property. @@ -377,19 +389,37 @@ } =20 /** - * get the property hashtable + * get a copy of the property hashtable * @return the hashtable containing all properties, user included */ public Hashtable getProperties() { - return properties; + Hashtable propertiesCopy =3D new Hashtable(); + =20 + Enumeration e =3D properties.keys(); + while (e.hasMoreElements()) { + Object name =3D e.nextElement(); + Object value =3D properties.get(name); + propertiesCopy.put(name, value); + } + =20 + return propertiesCopy; } =20 /** - * get the user property hashtable + * get a copy of the user property hashtable * @return the hashtable user properties only */ public Hashtable getUserProperties() { - return userProperties; + Hashtable propertiesCopy =3D new Hashtable(); + =20 + Enumeration e =3D userProperties.keys(); + while (e.hasMoreElements()) { + Object name =3D e.nextElement(); + Object value =3D properties.get(name); + propertiesCopy.put(name, value); + } + =20 + return propertiesCopy; } =20 /** @@ -486,7 +516,7 @@ if (!baseDir.isDirectory())=20 throw new BuildException("Basedir " + = baseDir.getAbsolutePath() + " is not a directory"); this.baseDir =3D baseDir; - setProperty( "basedir", this.baseDir.getPath()); + setPropertyInternal( "basedir", this.baseDir.getPath()); String msg =3D "Project base dir set to: " + this.baseDir; log(msg, MSG_VERBOSE); } @@ -521,7 +551,7 @@ * @throws BuildException if this Java version is not supported */ public void setJavaVersionProperty() throws BuildException { - setProperty("ant.java.version", javaVersion); + setPropertyInternal("ant.java.version", javaVersion); =20 // sanity check if (javaVersion =3D=3D JAVA_1_0) { @@ -543,7 +573,7 @@ while (e.hasMoreElements()) { Object name =3D e.nextElement(); String value =3D systemP.get(name).toString(); - this.setProperty(name.toString(), value); + this.setPropertyInternal(name.toString(), value); } } =20 Index: WHATSNEW =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/cvspublic/jakarta-ant/WHATSNEW,v retrieving revision 1.183 diff -u -r1.183 WHATSNEW --- WHATSNEW 2001/11/30 21:09:03 1.183 +++ WHATSNEW 2001/12/04 01:45:13 @@ -17,7 +17,9 @@ instead. =20 * Some loopholes in the immutability rule have been closed. It is no = longer - possible to overwrite a property using tasks like or = . =20 + possible to overwrite a property using tasks like , = , + , , or . 's hole remains, = although + a deprecation warning has been added if a property is overriden using = it. =20 Fixed bugs: ----------- ------=_NextPart_000_011F_01C17C3F.748DF9D0 Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: For additional commands, e-mail: ------=_NextPart_000_011F_01C17C3F.748DF9D0--