You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Eric Wood <EW...@llbean.com> on 2007/09/21 15:18:13 UTC

Best way to perform this type of conditonal test in ANT

I want to only call a target ( _pmd ) if the property "pmd.jar" is set. 

    <target name="perform-pmd" if="pmd.jar" >
        <runtarget target="_pmd" />
    </target>

    <target name="_pmd"
depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-java-pmd" />


The problem I have with the code above is that runtarget seems to run in
its own JVM so properties that are set in there that I need to reference
later are not available after it runs.  Also, if I add the "if" clause
to the _pmd target, the depends are processed first.

How do I best handle the conditional execution of a target without using
either antcall or runtarget?

Re: Best way to perform this type of conditonal test in ANT

Posted by David Kavanagh <dk...@gmail.com>.
Why not use <antcall> instead of <runtarget> ?

On 9/21/07, Eric Wood <EW...@llbean.com> wrote:
>
> I want to only call a target ( _pmd ) if the property "pmd.jar" is set.
>
>     <target name="perform-pmd" if="pmd.jar" >
>         <runtarget target="_pmd" />
>     </target>
>
>     <target name="_pmd"
> depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-java-pmd" />
>
>
> The problem I have with the code above is that runtarget seems to run in
> its own JVM so properties that are set in there that I need to reference
> later are not available after it runs.  Also, if I add the "if" clause
> to the _pmd target, the depends are processed first.
>
> How do I best handle the conditional execution of a target without using
> either antcall or runtarget?
>

RE: Best way to perform this type of conditonal test in ANT

Posted by "Anderson, Rob (Global Trade)" <Ro...@nike.com>.
Why have the wrapper target at all? Add the if condition to the "_pmd"
target itself.

 <target name="_pmd"
depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-java-pmd"
if="pmd.jar"/>

-Rob Anderson

> -----Original Message-----
> From: Eric Wood [mailto:EWood@llbean.com] 
> Sent: Friday, September 21, 2007 6:18 AM
> To: Ant Users List
> Subject: Best way to perform this type of conditonal test in ANT
> 
> I want to only call a target ( _pmd ) if the property 
> "pmd.jar" is set. 
> 
>     <target name="perform-pmd" if="pmd.jar" >
>         <runtarget target="_pmd" />
>     </target>
> 
>     <target name="_pmd"
> depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-ja
> va-pmd" />
> 
> 
> The problem I have with the code above is that runtarget 
> seems to run in
> its own JVM so properties that are set in there that I need 
> to reference
> later are not available after it runs.  Also, if I add the "if" clause
> to the _pmd target, the depends are processed first.
> 
> How do I best handle the conditional execution of a target 
> without using
> either antcall or runtarget?
> 


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


RE: Best way to perform this type of conditonal test in ANT

Posted by Eric Wood <EW...@llbean.com>.
I thought that was the way that runtarget worked so I think that you are
correct, there must be something else. I will check further to see.  I
will also look at the use of macros.  Sometimes it is hard for me to
think of things in the "ant" way.  I appreciate you help.

Eric 

-----Original Message-----
From: Peter Reilly [mailto:peter.kitt.reilly@gmail.com] 
Sent: Friday, September 21, 2007 9:49 AM
To: Ant Users List
Subject: Re: Best way to perform this type of conditonal test in ANT

The "ant" way is not to think in terms of calling targets, it is more
in-terms of invoking a target, and the target reads it's dependences.

In ant 1.6 the unit of reuse/encapsulation/block would be a macro.

I would use a macro instead of each of your pmd targets, and call them
directly from the pmd target.

...
However with <antcontrib> the runtarget does not set up a new ant
project context, so the properties set in them are visible afterwards,
so there must be something else wrong with your script.

For example:
<project default="abc" xmlns:ac="antlib:net.sf.antcontrib">
  <target name="abc">
    <ac:runtarget target="runme"/>
    <echo>${set_in_runme}</echo>
  </target>
  <target name="runme">
    <property name="set_in_runme" value="hello world"/>
  </target>
</project>

Buildfile: /work/reilly/learning/a/runtarget/build.xml

abc:

runme:
     [echo] hello world

BUILD SUCCESSFUL
Peter

On 9/21/07, Eric Wood <EW...@llbean.com> wrote:
> Thanks,
>
> I have created a bunch of targets for PMD that I would like to keep, 
> so the question is how do I call these targets from the "pmd" target 
> while still keeping the conditional clause?
>
> I found that if I use antcall (or runtarget like in the code below), 
> then properties that are set that I want to reference later are 
> unavailable.  How do I " ... do pmd stuff" by invoking other targets?
>
> Eric
>
> -----Original Message-----
> From: Peter Reilly [mailto:peter.kitt.reilly@gmail.com]
> Sent: Friday, September 21, 2007 9:27 AM
> To: Ant Users List
> Subject: Re: Best way to perform this type of conditonal test in ANT
>
> Opp, I hit send by accident, (gmail does not have the same key 
> shortcuts as emacs).
> <project>
>    <target name="init">
>        <available file="lib/pmd.jar" property="pmd.jar"/>
>    <target>
>    <target name="pmd" depends="init" if="pmd.jar">
>      ... do pmd stuff
>    <target>
> </project>
>
>
>
> On 9/21/07, Peter Reilly <pe...@gmail.com> wrote:
> > <project>
> >    <target name="init">
> >       <available file="lib/pmd.jar" property="pmd.jar"/>
> >    <target>
> >
> >
> >
> > On 9/21/07, Eric Wood <EW...@llbean.com> wrote:
> > > I want to only call a target ( _pmd ) if the property "pmd.jar" is
> set.
> > >
> > >     <target name="perform-pmd" if="pmd.jar" >
> > >         <runtarget target="_pmd" />
> > >     </target>
> > >
> > >     <target name="_pmd"
> > > depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-java-p
> > > md
> > > " />
> > >
> > >
> > > The problem I have with the code above is that runtarget seems to 
> > > run in its own JVM so properties that are set in there that I need

> > > to reference later are not available after it runs.  Also, if I 
> > > add the "if" clause to the _pmd target, the depends are processed
first.
> > >
> > > How do I best handle the conditional execution of a target without

> > > using either antcall or runtarget?
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional

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

> commands, e-mail: user-help@ant.apache.org
>
>

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


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


Re: Best way to perform this type of conditonal test in ANT

Posted by Peter Reilly <pe...@gmail.com>.
The "ant" way is not to think in terms of calling targets,
it is more in-terms of invoking a target, and the
target reads it's dependences.

In ant 1.6 the unit of reuse/encapsulation/block would be a macro.

I would use a macro instead of each of your pmd targets, and
call them directly from the pmd target.

...
However with <antcontrib> the runtarget does not
set up a new ant project context, so the properties
set in them are visible afterwards, so there
must be something else wrong with your script.

For example:
<project default="abc" xmlns:ac="antlib:net.sf.antcontrib">
  <target name="abc">
    <ac:runtarget target="runme"/>
    <echo>${set_in_runme}</echo>
  </target>
  <target name="runme">
    <property name="set_in_runme" value="hello world"/>
  </target>
</project>

Buildfile: /work/reilly/learning/a/runtarget/build.xml

abc:

runme:
     [echo] hello world

BUILD SUCCESSFUL
Peter

On 9/21/07, Eric Wood <EW...@llbean.com> wrote:
> Thanks,
>
> I have created a bunch of targets for PMD that I would like to keep, so
> the question is how do I call these targets from the "pmd" target while
> still keeping the conditional clause?
>
> I found that if I use antcall (or runtarget like in the code below),
> then properties that are set that I want to reference later are
> unavailable.  How do I " ... do pmd stuff" by invoking other targets?
>
> Eric
>
> -----Original Message-----
> From: Peter Reilly [mailto:peter.kitt.reilly@gmail.com]
> Sent: Friday, September 21, 2007 9:27 AM
> To: Ant Users List
> Subject: Re: Best way to perform this type of conditonal test in ANT
>
> Opp, I hit send by accident, (gmail does not have the same key shortcuts
> as emacs).
> <project>
>    <target name="init">
>        <available file="lib/pmd.jar" property="pmd.jar"/>
>    <target>
>    <target name="pmd" depends="init" if="pmd.jar">
>      ... do pmd stuff
>    <target>
> </project>
>
>
>
> On 9/21/07, Peter Reilly <pe...@gmail.com> wrote:
> > <project>
> >    <target name="init">
> >       <available file="lib/pmd.jar" property="pmd.jar"/>
> >    <target>
> >
> >
> >
> > On 9/21/07, Eric Wood <EW...@llbean.com> wrote:
> > > I want to only call a target ( _pmd ) if the property "pmd.jar" is
> set.
> > >
> > >     <target name="perform-pmd" if="pmd.jar" >
> > >         <runtarget target="_pmd" />
> > >     </target>
> > >
> > >     <target name="_pmd"
> > > depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-java-pmd
> > > " />
> > >
> > >
> > > The problem I have with the code above is that runtarget seems to
> > > run in its own JVM so properties that are set in there that I need
> > > to reference later are not available after it runs.  Also, if I add
> > > the "if" clause to the _pmd target, the depends are processed first.
> > >
> > > How do I best handle the conditional execution of a target without
> > > using either antcall or runtarget?
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
> commands, e-mail: user-help@ant.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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


RE: Best way to perform this type of conditonal test in ANT

Posted by Eric Wood <EW...@llbean.com>.
Thanks, 

I have created a bunch of targets for PMD that I would like to keep, so
the question is how do I call these targets from the "pmd" target while
still keeping the conditional clause?

I found that if I use antcall (or runtarget like in the code below),
then properties that are set that I want to reference later are
unavailable.  How do I " ... do pmd stuff" by invoking other targets? 

Eric

-----Original Message-----
From: Peter Reilly [mailto:peter.kitt.reilly@gmail.com] 
Sent: Friday, September 21, 2007 9:27 AM
To: Ant Users List
Subject: Re: Best way to perform this type of conditonal test in ANT

Opp, I hit send by accident, (gmail does not have the same key shortcuts
as emacs).
<project>
   <target name="init">
       <available file="lib/pmd.jar" property="pmd.jar"/>
   <target>
   <target name="pmd" depends="init" if="pmd.jar">
     ... do pmd stuff
   <target>
</project>



On 9/21/07, Peter Reilly <pe...@gmail.com> wrote:
> <project>
>    <target name="init">
>       <available file="lib/pmd.jar" property="pmd.jar"/>
>    <target>
>
>
>
> On 9/21/07, Eric Wood <EW...@llbean.com> wrote:
> > I want to only call a target ( _pmd ) if the property "pmd.jar" is
set.
> >
> >     <target name="perform-pmd" if="pmd.jar" >
> >         <runtarget target="_pmd" />
> >     </target>
> >
> >     <target name="_pmd"
> > depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-java-pmd
> > " />
> >
> >
> > The problem I have with the code above is that runtarget seems to 
> > run in its own JVM so properties that are set in there that I need 
> > to reference later are not available after it runs.  Also, if I add 
> > the "if" clause to the _pmd target, the depends are processed first.
> >
> > How do I best handle the conditional execution of a target without 
> > using either antcall or runtarget?
> >
>

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


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


Re: Best way to perform this type of conditonal test in ANT

Posted by Peter Reilly <pe...@gmail.com>.
Opp, I hit send by accident, (gmail does not have
the same key shortcuts as emacs).
<project>
   <target name="init">
       <available file="lib/pmd.jar" property="pmd.jar"/>
   <target>
   <target name="pmd" depends="init" if="pmd.jar">
     ... do pmd stuff
   <target>
</project>



On 9/21/07, Peter Reilly <pe...@gmail.com> wrote:
> <project>
>    <target name="init">
>       <available file="lib/pmd.jar" property="pmd.jar"/>
>    <target>
>
>
>
> On 9/21/07, Eric Wood <EW...@llbean.com> wrote:
> > I want to only call a target ( _pmd ) if the property "pmd.jar" is set.
> >
> >     <target name="perform-pmd" if="pmd.jar" >
> >         <runtarget target="_pmd" />
> >     </target>
> >
> >     <target name="_pmd"
> > depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-java-pmd" />
> >
> >
> > The problem I have with the code above is that runtarget seems to run in
> > its own JVM so properties that are set in there that I need to reference
> > later are not available after it runs.  Also, if I add the "if" clause
> > to the _pmd target, the depends are processed first.
> >
> > How do I best handle the conditional execution of a target without using
> > either antcall or runtarget?
> >
>

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


Re: Best way to perform this type of conditonal test in ANT

Posted by Peter Reilly <pe...@gmail.com>.
<project>
   <target name="init">
      <available file="lib/pmd.jar" property="pmd.jar"/>
   <target>



On 9/21/07, Eric Wood <EW...@llbean.com> wrote:
> I want to only call a target ( _pmd ) if the property "pmd.jar" is set.
>
>     <target name="perform-pmd" if="pmd.jar" >
>         <runtarget target="_pmd" />
>     </target>
>
>     <target name="_pmd"
> depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-java-pmd" />
>
>
> The problem I have with the code above is that runtarget seems to run in
> its own JVM so properties that are set in there that I need to reference
> later are not available after it runs.  Also, if I add the "if" clause
> to the _pmd target, the depends are processed first.
>
> How do I best handle the conditional execution of a target without using
> either antcall or runtarget?
>

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


RE: Best way to perform this type of conditonal test in ANT

Posted by Martin Gainty <mg...@hotmail.com>.
Hi Eric
If you look athttp://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
 
you can use java jar with fork=false (if you dont want to spawn a new JVM)
Does this help?Martin Gainty______________________________________________Disclaimer and confidentiality noteEverything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission.> Subject: Best way to perform this type of conditonal test in ANT> Date: Fri, 21 Sep 2007 09:18:13 -0400> From: EWood@llbean.com> To: user@ant.apache.org> > I want to only call a target ( _pmd ) if the property "pmd.jar" is set. > > <target name="perform-pmd" if="pmd.jar" >> <runtarget target="_pmd" />> </target>> > <target name="_pmd"> depends="pmd-init,find-pmd-java-files,modified-java-pmd,new-java-pmd" />> > > The problem I have with the code above is that runtarget seems to run in> its own JVM so properties that are set in there that I need to reference> later are not available after it runs. Also, if I add the "if" clause> to the _pmd target, the depends are processed first.> > How do I best handle the conditional execution of a target without using> either antcall or runtarget?
_________________________________________________________________
More photos; more messages; more whatever – Get MORE with Windows Live™ Hotmail®. NOW with 5GB storage.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_5G_0907