Return-Path: X-Original-To: apmail-ant-user-archive@www.apache.org Delivered-To: apmail-ant-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3E57A10AA9 for ; Fri, 27 Sep 2013 00:25:50 +0000 (UTC) Received: (qmail 99654 invoked by uid 500); 27 Sep 2013 00:25:49 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 99602 invoked by uid 500); 27 Sep 2013 00:25:49 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 99594 invoked by uid 99); 27 Sep 2013 00:25:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Sep 2013 00:25:49 +0000 X-ASF-Spam-Status: No, hits=3.2 required=5.0 tests=FREEMAIL_REPLY,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mgainty@hotmail.com designates 65.55.111.164 as permitted sender) Received: from [65.55.111.164] (HELO blu0-omc4-s25.blu0.hotmail.com) (65.55.111.164) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Sep 2013 00:25:44 +0000 Received: from BLU172-W46 ([65.55.111.136]) by blu0-omc4-s25.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 26 Sep 2013 17:25:23 -0700 X-TMN: [514O9g8Rr/hoxnXIc665PkOqJlpVPzO7] X-Originating-Email: [mgainty@hotmail.com] Message-ID: Content-Type: multipart/alternative; boundary="_562bf488-3977-4e64-8209-e00324f38a73_" From: Martin Gainty To: Ant Users List Subject: RE: "scoping" for macro definitions? Date: Thu, 26 Sep 2013 20:25:22 -0400 Importance: Normal In-Reply-To: <1380235404.55576.YahooMailNeo@web162604.mail.bf1.yahoo.com> References: ,<1380235404.55576.YahooMailNeo@web162604.mail.bf1.yahoo.com> MIME-Version: 1.0 X-OriginalArrivalTime: 27 Sep 2013 00:25:23.0800 (UTC) FILETIME=[0E8C2D80:01CEBB18] X-Virus-Checked: Checked by ClamAV on apache.org --_562bf488-3977-4e64-8209-e00324f38a73_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable that was my initial answer .. but then I considered the collision of the gl= obal ant namespace (that macrodef plays in) with a customised non-ant names= pace is implicitly declared within Ants global namespace=20 The default namespace used by Ant is "antlib:org.apache.tools.ant".=20 thus=20 embedding any other elements with non-ant namespaces inside Ant global name= space is verboten=20 (that is up until the end tag is encountered) =20 Parser> I am parsing macrodef with antlib:org.apache.tools.ant namespace=20 Operator>Here is new Element with New Namespace embedded inside Macrodef Parser:No you cannot I am still parsing the elements and attributes of antl= ib:org.apache.tools.ant.namespace =20 Since Ant namespace is globally available we can reference Ant namespace ty= pes inside customised namespaces=20 consider: >From Ant 1.6.2=2C elements nested inside a namespaced element may also be i= n Ant's default namespace. This means that the following is now allowed:=20 ... NOT allowed ... IMHO DefineAttribute static class (embedded in Macrodef) is the solution wh= y 1)DefineAttribute stays within the Macrodef and stays within global ant nam= espace (antlib:org.apache.tools.ant) boundaries 2)DefineAttribute accomodates assignment of unique values for each instanta= tion of the MacroDef =20 Here is the code /** 481: * A nested define element for the MacroDef task. 482: * 483: * It provides an attribute with a guaranteed unique value 484: * on every instantiation of the macro. This allows to use 485: * this uniquely named attribute in property names used 486: * internally by the macro=2C thus creating unique property 487: * names and side-stepping Ant's property immutability rules. 488: *

489: * Of course=2C this work around as the side effect of littering 490: * the global Ant property namespace=2C so is far for ideal=2C but 491: * will have to make do awaiting a better fix... 492: * 493: * @since ant 1.7 494: */ 495:... public static class DefineAttribute extends Attribute { 496: 497: private static long count =3D 0=3B 498: private String prefix =3D ""=3B 499: 500: /** 501: * Sets a prefix for the generated name. 502: * 503: * @param prefixValue the prefix to use. 504: */ 505:... public void setPrefix(String prefixValue) { 506: prefix =3D prefixValue=3B 507: } 508: 509: /** 510: * Sets the default value. 511: * 512: * This is not allowed for the define nested element. 513: * 514: * @param defaultValue not used 515: * @throws BuildException=2C always 516: */ 517:... public void setDefault(String defaultValue) { 518: throw new BuildException( 519: "Illegal attribute \"default\" for define element")=3B 520: } 521: 522: /** 523: * Gets the default value for this attibute. 524: *=20 525: * @return the generated unique name=2C of the form 526: * "prefix#this classname#<=3BaCounter>=3B". 527: */ 528:... public String getDefault() { 529:... synchronized (DefineAttribute.class) { 530: // Make sure counter is managed globally 531: return prefix + "#" + getClass().getName() + "#" + (++= count)=3B 532: } 533: } 534: 535: } // END static class DefineAttribute http://www.javadocexamples.com/java_source/org/apache/tools/ant/taskdefs/Ma= croDef.java.html =20 -Martin =20 > Date: Thu=2C 26 Sep 2013 15:43:24 -0700 > From: vimilsaju@yahoo.com > Subject: Re: "scoping" for macro definitions? > To: user@ant.apache.org >=20 > I am not sure if this feature is available in ant 1.7 but can't you use n= amespaces to scope the macrodefs like follows >=20 > > >=20 > Now all the macrodefs in buildCommon.xml has to be accessed as follows >=20 > =20 > Any macrodef you define in your build.xml can be accessed without using t= he namespace syntax. >=20 >=20 > ________________________________ > From: Cyril Sagan > To: Ant Users List =20 > Sent: Thursday=2C September 26=2C 2013 3:15 PM > Subject: "scoping" for macro definitions? >=20 >=20 > Is there a way to override a macro defined from a library I cannot > control=2C my goal is to provide a local implementation=2C but not have t= o > change all the callers. >=20 > I'm stuck on Ant 1.7.0=2C and cannot update. >=20 > How could I "fake out" a scoping mechanism to accomplish something like: > or >=20 > I tried using to "override" the macro=2C but I can't figure > out how to invoke the original macro of the same name. I could > redefine the macro from the library in my local ant script=2C but I > don't want to open a possibility that my local implementation could > get out of sync with the one from the provided library. >=20 > Another way to express what I need is the macro equivalent of target > overriding=2C which is accomplished with the code snip below=2C but I nee= d > it for ! >=20 > common.xml: > > > > > >=20 > build.xml: > > > /> >=20 > > >=20 >=20 > But what if its a macro (or scriptdef)? In principle here's what I was > hoping could > work=2C but it doesn't=2C so that's why I'm asking: >=20 > common.xml: > > > > > > > > > >=20 > build.xml: > > > > > >=20 > > > > > > > > >=20 > > >=20 > Any ideas would be much appreciated. Thanks. >=20 > --Cyril = --_562bf488-3977-4e64-8209-e00324f38a73_--