Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 31047 invoked from network); 13 Jan 2005 13:53:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 13 Jan 2005 13:53:22 -0000 Received: (qmail 32162 invoked by uid 500); 13 Jan 2005 13:53:21 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 32106 invoked by uid 500); 13 Jan 2005 13:53:21 -0000 Mailing-List: contact dev-help@ant.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 dev@ant.apache.org Received: (qmail 32092 invoked by uid 500); 13 Jan 2005 13:53:20 -0000 Received: (qmail 32088 invoked by uid 99); 13 Jan 2005 13:53:20 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 13 Jan 2005 05:53:20 -0800 Received: (qmail 31018 invoked by uid 1539); 13 Jan 2005 13:53:19 -0000 Date: 13 Jan 2005 13:53:19 -0000 Message-ID: <20050113135319.31016.qmail@minotaur.apache.org> From: peterreilly@apache.org To: ant-cvs@apache.org Subject: cvs commit: ant/src/main/org/apache/tools/ant/taskdefs MacroDef.java MacroInstance.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N peterreilly 2005/01/13 05:53:19 Modified: src/main/org/apache/tools/ant/taskdefs MacroDef.java MacroInstance.java Log: Add in Jose's nested element for manual and testcases to follow... Revision Changes Path 1.27 +75 -5 ant/src/main/org/apache/tools/ant/taskdefs/MacroDef.java Index: MacroDef.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/MacroDef.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- MacroDef.java 27 May 2004 14:38:46 -0000 1.26 +++ MacroDef.java 13 Jan 2005 13:53:19 -0000 1.27 @@ -226,21 +226,51 @@ } if (attribute.getName().equals(textName)) { throw new BuildException( - "the attribute name \"" + attribute.getName() + "the name \"" + attribute.getName() + "\" has already been used by the text element"); } for (int i = 0; i < attributes.size(); ++i) { - if (((Attribute) attributes.get(i)).getName().equals( - attribute.getName())) { + Attribute att = (Attribute) attributes.get(i); + if (att.getName().equals(attribute.getName())) { throw new BuildException( - "the attribute " + attribute.getName() - + " has already been specified"); + "the name \"" + attribute.getName() + + "\" has already been used in " + + (att instanceof DefineAttribute ? "a define element" + : "another attribute element")); } } attributes.add(attribute); } /** + * Add a define element. + * + * @param def a define nested element. + */ + public void addConfiguredDefine(DefineAttribute def) { + if (def.getName() == null) { + throw new BuildException( + "the define nested element needed a \"name\" attribute"); + } + if (def.getName().equals(textName)) { + throw new BuildException( + "the name \"" + def.getName() + + "\" has already been used by the text element"); + } + for (int i = 0; i < attributes.size(); ++i) { + Attribute att = (Attribute) attributes.get(i); + if (att.getName().equals(def.getName())) { + throw new BuildException( + "the name \"" + def.getName() + + "\" has already been used in " + + (att instanceof DefineAttribute ? "another define element" + : "an attribute element")); + } + } + attributes.add(def); + } + + /** * Add an element element. * * @param element an element nested element. @@ -388,6 +418,46 @@ */ public int hashCode() { return objectHashCode(defaultValue) + objectHashCode(name); + } + } + + /** + * A nested define element for the MacroDef task. + * It provides an attribute with a guatanteed unique value on every instantiation of the macro. + * @since ant 1.7 + */ + public static class DefineAttribute extends Attribute { + private static long count = 0; + private String prefix = ""; + + /** + * Set a prefix for the generated name + * @param prefixValue the prefix to use. + */ + public void setPrefix(String prefixValue) { + prefix = prefixValue; + } + + /** + * Set the default value. + * This is not allowed for the define nested element. + * @param defaultValue not used + */ + public void setDefault(String defaultValue) { + throw new BuildException( + "Illegal attribute \"default\" for define element"); + } + + /** + * Get the default value for this attibute. + * This returns the name "prefix#this classname#. + * @return the generated name + */ + public String getDefault() { + synchronized (DefineAttribute.class) { + // Make sure counter is managed globally + return prefix + "#" + DefineAttribute.class.getName() + "#" + (++count); + } } } 1.30 +3 -0 ant/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java Index: MacroInstance.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- MacroInstance.java 12 Nov 2004 15:14:59 -0000 1.29 +++ MacroInstance.java 13 Jan 2005 13:53:19 -0000 1.30 @@ -335,6 +335,9 @@ if (value == null) { value = attribute.getDefault(); value = macroSubs(value, localProperties); + } else if (attribute instanceof MacroDef.DefineAttribute) { + // Do not process given value, will fail as unknown attribute + continue; } if (value == null) { throw new BuildException( --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org