ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Holman, Chris" <Chris.Hol...@bskyb.com>
Subject RE: Checking if a Target Exists
Date Thu, 03 Nov 2011 16:38:08 GMT
If I understand the problem correctly, you could use a condition:

<condition property="targetExists">
	<typefound name="${targetName}"/>
</condition>

I've used this to check for a macrodef, not sure about targets?

Regards,
Chris Holman

-----Original Message-----
From: Vimil Saju [mailto:vimilsaju@yahoo.com] 
Sent: 03 November 2011 16:02
To: Steve Amerige; Ant Users List
Subject: Re: Checking if a Target Exists

Here is an example, I havent tested it though

<scriptdef name="hastarget" language="javascript">
         <attribute name="targetname" />
         <attribute name="property" />
         <![CDATA[
           var targetname = attributes.get("property");
   if(project.getTargets().containsKey(targetname)) {
project.setProperty(attributes.get("property"), "true");
   }           
         ]]>
</scriptdef>

the scriptdef can be then invoked as folows

<hastarget targetname="mytarget" property="targetExists"/>

the property 'targetExists' will be set to true if the target 'mytarget' is present in the
project. Otherwise it will not be set.


________________________________
From: Steve Amerige <Steve.Amerige@sas.com>
To: Ant Users List <user@ant.apache.org>; Vimil Saju <vimilsaju@yahoo.com>
Sent: Thursday, November 3, 2011 7:27 AM
Subject: Re: Checking if a Target Exists


Hi Vimil,

Thanks for the feedback.  Any specifics on just how to do what you
    mention (even if untested)?

Thanks again,
Steve Amerige
SAS Institute, Deployment Software Development

On 11/3/2011 9:55 AM, Vimil Saju wrote: 
I think you can use the scriptdef task to do this. You can write a script within the scriptdef
object to access the methods of the project object. The project object has methods to list
the targets defined under the project, which you can use to test if a given target exists.
Btw antcall does not launch a new jvm, it only reloads the build.xml. ________________________________
From: Steve Amerige <Steve.Amerige@sas.com> To: Ant Users List <user@ant.apache.org>
Sent: Thursday, November 3, 2011 4:52 AM
Subject: Checking if a Target Exists Hi all, I want to be able to check if a target exists
and hope you can help.  I'm looking for a generic solution that doesn't rely any knowledge
of the target name to be checked.  It is not possible to modify the target code.  And, I'd
like to avoid any solutions that cause the entire JVM to be loaded (e.g., as with antcall).
My environment is Ant 1.7 and allows for the use of Ant-Contrib and Groovy. Any ideas on how
to do this?  Even better, any solutions anyone have to share?! Thanks,
Steve Amerige
SAS Institute, Deployment Software Development 

Information in this email including any attachments may be privileged, confidential and is
intended exclusively for the addressee. The views expressed may not be official policy, but
the personal views of the originator. If you have received it in error, please notify the
sender by return e-mail and delete it from your system. You should not reproduce, distribute,
store, retransmit, use or disclose its contents to anyone. Please note we reserve the right
to monitor all e-mail communication through our internal and external networks. SKY and the
SKY marks are trade marks of British Sky Broadcasting Group plc and are used under licence.
British Sky Broadcasting Limited (Registration No. 2906991), Sky Interactive Limited (Registration
No. 3554332), Sky-In-Home Service Limited (Registration No. 2067075) and Sky Subscribers Services
Limited (Registration No. 2340150) are direct or indirect subsidiaries of British Sky Broadcasting
Group plc (Registration No. 2247735). All of the companies mentioned in this paragraph are
incorporated in England and Wales and share the same registered office at Grant Way, Isleworth,
Middlesex TW7 5QD.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message