You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by dkhanna123 <dk...@gmail.com> on 2009/07/23 18:46:00 UTC

failonerror for target and depends

I have a target defined as :

<target name="prompt" depends="-init1,-init2,-init3">

Now I want when ant call prompt target and if "init1" DOESNOT exist then it
should continue with init2 and init3.

I have used ant -k option but instead of continuing with init2 and init3 the
whole prompt target exits.

ANy suggestions
-- 
View this message in context: http://www.nabble.com/failonerror-for-target-and-depends-tp24629812p24629812.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: failonerror for target and depends

Posted by dkhanna123 <dk...@gmail.com>.
Its just that all my ant xml script are generated on the fly using xslt. Now
in some of the cases I don't even have target1 defined and that's where the
problem lies.

But looks like its not possible, so I'll have make some changes to my xslt
code itself.

Thanks



David Weintraub wrote:
> 
>> I understand how depends works but my question is..
>>
>> If I have two targets defined in depends for e.g  
>> depends="target1,target2",
>> and if some how target1 does not exist and instead of throwing error  
>> ant
>> should move ahead (after showing some warning) and execute target2.
> 
> 
> If you don't depend upon target1, then why are you putting it in a  
> depends parameter? The depends parameter says that this target can't  
> be executed unless the dependancy targets are first built.
> 
> Target1 and target2 both must exist. Otherwise, Ant can't build a  
> dependancy matrix.
> 
> You're also making assumption about execution order (Ant will try  
> target1, then target2.) Nothing in ant specifies whether one target is  
> executed before another. Ant figures out the order after it builds the  
> dependancy matrix.
> 
> In fact:
> 
> <target name="one" depends="two"/>
> <target name="two"/>
> <target name="three"
>      depends="one,two"/>
> 
> If I execute target "three", target "two" will be built before target  
> "one" even though I listed target "one" first in the "depends"  
> parameter.
> 
> I'm not sure what you're attempting, but if you need to test before  
> you execute, you can use the <condition> task, or you can try the  
> AntContrib's <try>/<catch> task:
> http://ant-contrib.sourceforge.net/tasks/tasks/index.html 
> .
> 
> You could put an <antcall> in the <try> block, and if it can't find  
> the target, go to the <catch> block where you'll simply echo that the  
> task can't be found. From there, your program will continue executing.
> 
> --
> David Weintraub
> David@Weintraub.name
> Sent from my iPhone while riding in my Ferrari. (Jealous?)
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/failonerror-for-target-and-depends-tp24629812p24638203.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: failonerror for target and depends

Posted by David Weintraub <qa...@gmail.com>.
> I understand how depends works but my question is..
>
> If I have two targets defined in depends for e.g  
> depends="target1,target2",
> and if some how target1 does not exist and instead of throwing error  
> ant
> should move ahead (after showing some warning) and execute target2.


If you don't depend upon target1, then why are you putting it in a  
depends parameter? The depends parameter says that this target can't  
be executed unless the dependancy targets are first built.

Target1 and target2 both must exist. Otherwise, Ant can't build a  
dependancy matrix.

You're also making assumption about execution order (Ant will try  
target1, then target2.) Nothing in ant specifies whether one target is  
executed before another. Ant figures out the order after it builds the  
dependancy matrix.

In fact:

<target name="one" depends="two"/>
<target name="two"/>
<target name="three"
     depends="one,two"/>

If I execute target "three", target "two" will be built before target  
"one" even though I listed target "one" first in the "depends"  
parameter.

I'm not sure what you're attempting, but if you need to test before  
you execute, you can use the <condition> task, or you can try the  
AntContrib's <try>/<catch> task: http://ant-contrib.sourceforge.net/tasks/tasks/index.html 
.

You could put an <antcall> in the <try> block, and if it can't find  
the target, go to the <catch> block where you'll simply echo that the  
task can't be found. From there, your program will continue executing.

--
David Weintraub
David@Weintraub.name
Sent from my iPhone while riding in my Ferrari. (Jealous?)

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


Re: failonerror for target and depends

Posted by dkhanna123 <dk...@gmail.com>.
Hi

I understand how depends works but my question is..

If I have two targets defined in depends for e.g depends="target1,target2",
and if some how target1 does not exist and instead of throwing error ant
should move ahead (after showing some warning) and execute target2.

THanks



David Weintraub wrote:
> 
> When you state that a target "A"is dependent upon target "B", target "B"
> MUST run and execute before target "A" can execute.
> 
> Ant isn't a programming language. It is a dependency matrix. You specify
> which targets are dependent upon other targets, and Maven will sort out
> the
> build order for you. Are your "depends" other targets, or are you treating
> them as command line parameters?
> 
> Here's how depends work:
> 
> *<project>
>    <target name="clean"/>
>    <target name="getsource"/>
>    <target name="compile" depends="getsource"/>
>    <target name="test depends="compile"/>
>    <target name="package" depends="compile"/>
>    <target name="deploy" depends="package"/>
> </project*
> 
> In this shell of a build script, if I do
> 
> *$ ant package*
> 
> Ant will look at target "package", and determine that it depends upon
> target
> "compile". Target "compile" depends upon target "getsource", so Ant will
> run
> targets "getsource", "compile", and "package" in that order.
> 
> Note that target "clean" and target "test" don't get executed because
> they're not in the dependency matrix that Ant built. Also notice that all
> targets mentioned in the "depends" parameter must exist, and that a
> failure
> in any previously executed target will cause the build to fail.
> 
> If you are trying to build a "subroutine", you should look at the
> <macroDef>
> task. You can define a macro that can have optional and required
> parameters:
> 
> *<target name="foo">*
> *   <bar init2="fubar" init3="barfoo"/>*
> *</target>*
> 
> *<macrodef name="bar">*
> *   <attribute name="init1" default="NOT-SET"/>*
> *   <attribute name="init2/>*
> *   <attribute name="init3 default="SOME VALUE"/>*
> *   <sequential>*
> *      <echo>Called macro "bar" with parameters @{init1}, @{init2}, and
> @{init3}</echo>*
> *   </sequential>*
> *</macrodef>*
> 
> In the above, target "foo" calles the macro you defined, "bar". Because
> there is no default value, you must include "init2" when calling bar.
> However, you don't need "init1" or "init3" because they have default
> values.
> 
> Is this more what you're looking for?
> 
> On Thu, Jul 23, 2009 at 12:46 PM, dkhanna123 <dk...@gmail.com> wrote:
> 
>>
>> I have a target defined as :
>>
>> <target name="prompt" depends="-init1,-init2,-init3">
>>
>> Now I want when ant call prompt target and if "init1" DOESNOT exist then
>> it
>> should continue with init2 and init3.
>>
>> I have used ant -k option but instead of continuing with init2 and init3
>> the
>> whole prompt target exits.
>>
>> ANy suggestions
>> --
>> View this message in context:
>> http://www.nabble.com/failonerror-for-target-and-depends-tp24629812p24629812.html
>> Sent from the Ant - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
> 
> 
> -- 
> David Weintraub
> qazwart@gmail.com
> 
> 

-- 
View this message in context: http://www.nabble.com/failonerror-for-target-and-depends-tp24629812p24635303.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: failonerror for target and depends

Posted by David Weintraub <qa...@gmail.com>.
When you state that a target "A"is dependent upon target "B", target "B"
MUST run and execute before target "A" can execute.

Ant isn't a programming language. It is a dependency matrix. You specify
which targets are dependent upon other targets, and Maven will sort out the
build order for you. Are your "depends" other targets, or are you treating
them as command line parameters?

Here's how depends work:

*<project>
   <target name="clean"/>
   <target name="getsource"/>
   <target name="compile" depends="getsource"/>
   <target name="test depends="compile"/>
   <target name="package" depends="compile"/>
   <target name="deploy" depends="package"/>
</project*

In this shell of a build script, if I do

*$ ant package*

Ant will look at target "package", and determine that it depends upon target
"compile". Target "compile" depends upon target "getsource", so Ant will run
targets "getsource", "compile", and "package" in that order.

Note that target "clean" and target "test" don't get executed because
they're not in the dependency matrix that Ant built. Also notice that all
targets mentioned in the "depends" parameter must exist, and that a failure
in any previously executed target will cause the build to fail.

If you are trying to build a "subroutine", you should look at the <macroDef>
task. You can define a macro that can have optional and required parameters:

*<target name="foo">*
*   <bar init2="fubar" init3="barfoo"/>*
*</target>*

*<macrodef name="bar">*
*   <attribute name="init1" default="NOT-SET"/>*
*   <attribute name="init2/>*
*   <attribute name="init3 default="SOME VALUE"/>*
*   <sequential>*
*      <echo>Called macro "bar" with parameters @{init1}, @{init2}, and
@{init3}</echo>*
*   </sequential>*
*</macrodef>*

In the above, target "foo" calles the macro you defined, "bar". Because
there is no default value, you must include "init2" when calling bar.
However, you don't need "init1" or "init3" because they have default values.

Is this more what you're looking for?

On Thu, Jul 23, 2009 at 12:46 PM, dkhanna123 <dk...@gmail.com> wrote:

>
> I have a target defined as :
>
> <target name="prompt" depends="-init1,-init2,-init3">
>
> Now I want when ant call prompt target and if "init1" DOESNOT exist then it
> should continue with init2 and init3.
>
> I have used ant -k option but instead of continuing with init2 and init3
> the
> whole prompt target exits.
>
> ANy suggestions
> --
> View this message in context:
> http://www.nabble.com/failonerror-for-target-and-depends-tp24629812p24629812.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
David Weintraub
qazwart@gmail.com