You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mario Madunic <ha...@imag.net> on 2007/09/11 19:40:09 UTC

newbie help: conditional exec

I have the following in my ant task to test for the existence of an xml file
after processing

<available file="CSV\csvArt.xml" property="artAvailable" />

What I want to do is run <exec> based on the above property value of true. I
can't seem to find a task to do this. Any help will be appreciated.


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


Re: newbie help: conditional exec

Posted by Peter Reilly <pe...@gmail.com>.
On 9/12/07, David Weintraub <qa...@gmail.com> wrote:
> Two steps:
>
> 1). After your test, do an <antcall> to call a new target
> 2). Us an "if" parameter in that target: For example:
>
> <available file="CVS\cvsArt.xml" property="artAvailable"/>
> <antcall target="artAvailable.target"/>
>
> <target name="artAvaliable.target if="artAvailable">
It is not good practice to use <antcall>.

The normal way is just to have the target in the dependence
list as normal, and use the if to stop it executing.
<project ..>
   ..
  <available file="CVS/cvsArt.xml" property="antAvailable"/>

  ..
  <target name="mytarget" if="artAvailable">
    .. do somthing with artAvail..
   </target>

Peter
> ...
>
> The other solution is to use the antContrib tasks which includes an <if> task:
>
> <if>
>    <available file="CVS/cvsArt.xml"/>
>    <then>
>         ...
>     </then>
> </if>
>
> I like a lot of the antContrib stuff, but you do have to make sure it
> is installed on all the machines that will use your build.xml file.
>
> On 9/11/07, Mario Madunic <ha...@imag.net> wrote:
> > I have the following in my ant task to test for the existence of an xml file
> > after processing
> >
> > <available file="CSV\csvArt.xml" property="artAvailable" />
> >
> > What I want to do is run <exec> based on the above property value of true. I
> > can't seem to find a task to do this. Any help will be appreciated.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>
>
> --
> --
> David Weintraub
> qazwart@gmail.com
>
> ---------------------------------------------------------------------
> 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


AW: newbie help: conditional exec

Posted by Knuplesch, Jürgen <Ju...@icongmbh.de>.
Try this

http://sourceforge.net/project/showfiles.php?group_id=36177 


-- 
Jürgen Knuplesch                    www.icongmbh.de
icon Systemhaus GmbH                Tel. +49 711 806098-275
Sophienstraße 40                    
D-70178 Stuttgart                   Fax. +49 711 806098-299

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121 
-----Ursprüngliche Nachricht-----
Von: Madunic, Marijan (RBI-US) [mailto:marijan.madunic@reedbusiness.com] 
Gesendet: Mittwoch, 12. September 2007 01:29
An: Ant Users List
Betreff: RE: newbie help: conditional exec

David,

Thank you. I'll give it a try later when I have a moment. Where can I download antContrib?

Marijan (Mario) Madunic

-----Original Message-----
From: David Weintraub [mailto:qazwart@gmail.com]
Sent: Tuesday, September 11, 2007 4:20 PM
To: Ant Users List
Subject: Re: newbie help: conditional exec

Two steps:

1). After your test, do an <antcall> to call a new target 2). Us an "if" parameter in that target: For example:

<available file="CVS\cvsArt.xml" property="artAvailable"/> <antcall target="artAvailable.target"/>

<target name="artAvaliable.target if="artAvailable"> ...

The other solution is to use the antContrib tasks which includes an <if>
task:

<if>
   <available file="CVS/cvsArt.xml"/>
   <then>
        ...
    </then>
</if>

I like a lot of the antContrib stuff, but you do have to make sure it is installed on all the machines that will use your build.xml file.

On 9/11/07, Mario Madunic <ha...@imag.net> wrote:
> I have the following in my ant task to test for the existence of an
xml file
> after processing
>
> <available file="CSV\csvArt.xml" property="artAvailable" />
>
> What I want to do is run <exec> based on the above property value of
true. I
> can't seem to find a task to do this. Any help will be appreciated.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional 
> commands, e-mail: user-help@ant.apache.org
>
>


--
--
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
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: newbie help: conditional exec

Posted by David Weintraub <qa...@gmail.com>.
Ant Contrib is a Source Forge project: <http://ant-contrib.sourceforge.net/>

The list of Ant Contrib tasks can be found here:
<http://ant-contrib.sourceforge.net/tasks/tasks/index.html>

Simply put the ant-contrib-version.jar inside the "lib" folder of your
Ant installation and add this line to your build.xml:

<taskdef resource="net/sf/antcontrib/antlib.xml"/>

On 9/11/07, Madunic, Marijan (RBI-US) <ma...@reedbusiness.com> wrote:
> David,
>
> Thank you. I'll give it a try later when I have a moment. Where can I
> download antContrib?
>
> Marijan (Mario) Madunic
>
> -----Original Message-----
> From: David Weintraub [mailto:qazwart@gmail.com]
> Sent: Tuesday, September 11, 2007 4:20 PM
> To: Ant Users List
> Subject: Re: newbie help: conditional exec
>
> Two steps:
>
> 1). After your test, do an <antcall> to call a new target
> 2). Us an "if" parameter in that target: For example:
>
> <available file="CVS\cvsArt.xml" property="artAvailable"/>
> <antcall target="artAvailable.target"/>
>
> <target name="artAvaliable.target if="artAvailable">
> ...
>
> The other solution is to use the antContrib tasks which includes an <if>
> task:
>
> <if>
>    <available file="CVS/cvsArt.xml"/>
>    <then>
>         ...
>     </then>
> </if>
>
> I like a lot of the antContrib stuff, but you do have to make sure it
> is installed on all the machines that will use your build.xml file.
>
> On 9/11/07, Mario Madunic <ha...@imag.net> wrote:
> > I have the following in my ant task to test for the existence of an
> xml file
> > after processing
> >
> > <available file="CSV\csvArt.xml" property="artAvailable" />
> >
> > What I want to do is run <exec> based on the above property value of
> true. I
> > can't seem to find a task to do this. Any help will be appreciated.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>
>
> --
> --
> David Weintraub
> qazwart@gmail.com
>
> ---------------------------------------------------------------------
> 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
>
>


-- 
--
David Weintraub
qazwart@gmail.com

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


RE: newbie help: conditional exec

Posted by "Madunic, Marijan (RBI-US)" <ma...@reedbusiness.com>.
David,

Thank you. I'll give it a try later when I have a moment. Where can I
download antContrib?

Marijan (Mario) Madunic

-----Original Message-----
From: David Weintraub [mailto:qazwart@gmail.com] 
Sent: Tuesday, September 11, 2007 4:20 PM
To: Ant Users List
Subject: Re: newbie help: conditional exec

Two steps:

1). After your test, do an <antcall> to call a new target
2). Us an "if" parameter in that target: For example:

<available file="CVS\cvsArt.xml" property="artAvailable"/>
<antcall target="artAvailable.target"/>

<target name="artAvaliable.target if="artAvailable">
...

The other solution is to use the antContrib tasks which includes an <if>
task:

<if>
   <available file="CVS/cvsArt.xml"/>
   <then>
        ...
    </then>
</if>

I like a lot of the antContrib stuff, but you do have to make sure it
is installed on all the machines that will use your build.xml file.

On 9/11/07, Mario Madunic <ha...@imag.net> wrote:
> I have the following in my ant task to test for the existence of an
xml file
> after processing
>
> <available file="CSV\csvArt.xml" property="artAvailable" />
>
> What I want to do is run <exec> based on the above property value of
true. I
> can't seem to find a task to do this. Any help will be appreciated.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
--
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
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: newbie help: conditional exec

Posted by David Weintraub <qa...@gmail.com>.
Two steps:

1). After your test, do an <antcall> to call a new target
2). Us an "if" parameter in that target: For example:

<available file="CVS\cvsArt.xml" property="artAvailable"/>
<antcall target="artAvailable.target"/>

<target name="artAvaliable.target if="artAvailable">
...

The other solution is to use the antContrib tasks which includes an <if> task:

<if>
   <available file="CVS/cvsArt.xml"/>
   <then>
        ...
    </then>
</if>

I like a lot of the antContrib stuff, but you do have to make sure it
is installed on all the machines that will use your build.xml file.

On 9/11/07, Mario Madunic <ha...@imag.net> wrote:
> I have the following in my ant task to test for the existence of an xml file
> after processing
>
> <available file="CSV\csvArt.xml" property="artAvailable" />
>
> What I want to do is run <exec> based on the above property value of true. I
> can't seem to find a task to do this. Any help will be appreciated.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
--
David Weintraub
qazwart@gmail.com

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


RE: newbie help: conditional exec

Posted by "Madunic, Marijan (RBI-US)" <ma...@reedbusiness.com>.
Thanks all for your suggestions and insightful replies. Since time at
work is not on my side I'll go with the antContrib and then rewrite
everything with the method that Bruce mentioned on the weekend. I think
it will take me a bit to get used the Way of Ant (tm).

Marijan (Mario) Madunic

-----Original Message-----
From: Bruce Atherton [mailto:bruce@callenish.com] 
Sent: Wednesday, September 12, 2007 9:23 AM
To: Ant Users List
Subject: Re: newbie help: conditional exec

Better to adopt the Way of Ant (tm) rather than fighting against it. 
Think of your problem this way, and restructure your build file to
match:

What you want to do is to put your article information into your 
database if there are any articles available.
Before you can do that, you need to make sure there is a separate 
articles file for any articles present in the raw XML.
Before you can do that, you need to make sure your raw XML files are 
filtered to remove junk.
Before you can do that, you need to make sure your raw XML files are 
uncompressed.

So what you really want is something like (adjust to fit your real
problem):

<project default="upload-to-db" >

  <target name="upload-to-db" depends="generate-article-file" 
if="article-file-present">
    ...
  </target>

  <target name="generate-article-file" depends="filter-junk">
    ...
    <available property="article-file-present" />
  </target>

  <target name="filter-junk" depends="uncompress-raw-xml">
    ...
  </target>

  <target name="uncompress-raw-xml">
    <unzip />
  </target>
</project>

This may seem counterintuitive since the property appears to be declared

after the "upload-to-db" target's "depends" attribute is analyzed, but 
in fact nothing is determined about whether the "upload-to-db" target 
will execute until all of its dependencies have been executed.

Mario Madunic wrote:
> Sorry I didn't give enough info.
>
> Since I'm a relative newbie to ant I create a pipeline task not
relying on any
> other target. So in the example below my workflow looks like the
following:
>
> unzip archive of xml files
> filter xml files
> parse xml files (will create CSV\csvArt.xml if there are any
type="articles")
> <exec> bcp csv to SQLServer
>
> So what I wanted to insert in my flow was
> <available file="CSV\csvArt.xml" property="artAvailable" />
> after the parse xml files
> then test the value of artAvailable and if true <exec> bcp into
SQLServer
>
> Is this possible? or a pointer to an example or tutorial.
>
> Marijan (Mario) Madunic
>
>
> Quoting "Anderson, Rob (Global Trade)" <Ro...@nike.com>:
>
>   
>> Use the if attribute of <target>...
>>
>> <target name="exec-something" if="artAvailable">
>>  <exec ...
>> </target>
>>
>> Be aware that this does not test the value of the artAvailable
property,
>> only whether or not it exists. See the manual for more info.
>>
>> http://ant.apache.org/manual/using.html#targets
>>
>>
>> -Rob Anderson
>>
>>     
>>> -----Original Message-----
>>> From: Mario Madunic [mailto:hajduk@imag.net] 
>>> Sent: Tuesday, September 11, 2007 10:40 AM
>>> To: user@ant.apache.org
>>> Subject: newbie help: conditional exec
>>>
>>> I have the following in my ant task to test for the existence 
>>> of an xml file after processing
>>>
>>> <available file="CSV\csvArt.xml" property="artAvailable" />
>>>
>>> What I want to do is run <exec> based on the above property 
>>> value of true. I can't seem to find a task to do this. Any 
>>> help will be appreciated.
>>>
>>>
>>>
---------------------------------------------------------------------
>>> 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


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


Re: newbie help: conditional exec

Posted by Bruce Atherton <br...@callenish.com>.
Better to adopt the Way of Ant (tm) rather than fighting against it. 
Think of your problem this way, and restructure your build file to match:

What you want to do is to put your article information into your 
database if there are any articles available.
Before you can do that, you need to make sure there is a separate 
articles file for any articles present in the raw XML.
Before you can do that, you need to make sure your raw XML files are 
filtered to remove junk.
Before you can do that, you need to make sure your raw XML files are 
uncompressed.

So what you really want is something like (adjust to fit your real problem):

<project default="upload-to-db" >

  <target name="upload-to-db" depends="generate-article-file" 
if="article-file-present">
    ...
  </target>

  <target name="generate-article-file" depends="filter-junk">
    ...
    <available property="article-file-present" />
  </target>

  <target name="filter-junk" depends="uncompress-raw-xml">
    ...
  </target>

  <target name="uncompress-raw-xml">
    <unzip />
  </target>
</project>

This may seem counterintuitive since the property appears to be declared 
after the "upload-to-db" target's "depends" attribute is analyzed, but 
in fact nothing is determined about whether the "upload-to-db" target 
will execute until all of its dependencies have been executed.

Mario Madunic wrote:
> Sorry I didn't give enough info.
>
> Since I'm a relative newbie to ant I create a pipeline task not relying on any
> other target. So in the example below my workflow looks like the following:
>
> unzip archive of xml files
> filter xml files
> parse xml files (will create CSV\csvArt.xml if there are any type="articles")
> <exec> bcp csv to SQLServer
>
> So what I wanted to insert in my flow was
> <available file="CSV\csvArt.xml" property="artAvailable" />
> after the parse xml files
> then test the value of artAvailable and if true <exec> bcp into SQLServer
>
> Is this possible? or a pointer to an example or tutorial.
>
> Marijan (Mario) Madunic
>
>
> Quoting "Anderson, Rob (Global Trade)" <Ro...@nike.com>:
>
>   
>> Use the if attribute of <target>...
>>
>> <target name="exec-something" if="artAvailable">
>>  <exec ...
>> </target>
>>
>> Be aware that this does not test the value of the artAvailable property,
>> only whether or not it exists. See the manual for more info.
>>
>> http://ant.apache.org/manual/using.html#targets
>>
>>
>> -Rob Anderson
>>
>>     
>>> -----Original Message-----
>>> From: Mario Madunic [mailto:hajduk@imag.net] 
>>> Sent: Tuesday, September 11, 2007 10:40 AM
>>> To: user@ant.apache.org
>>> Subject: newbie help: conditional exec
>>>
>>> I have the following in my ant task to test for the existence 
>>> of an xml file after processing
>>>
>>> <available file="CSV\csvArt.xml" property="artAvailable" />
>>>
>>> What I want to do is run <exec> based on the above property 
>>> value of true. I can't seem to find a task to do this. Any 
>>> help will be appreciated.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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: newbie help: conditional exec

Posted by Mario Madunic <ha...@imag.net>.
Sorry I didn't give enough info.

Since I'm a relative newbie to ant I create a pipeline task not relying on any
other target. So in the example below my workflow looks like the following:

unzip archive of xml files
filter xml files
parse xml files (will create CSV\csvArt.xml if there are any type="articles")
<exec> bcp csv to SQLServer

So what I wanted to insert in my flow was
<available file="CSV\csvArt.xml" property="artAvailable" />
after the parse xml files
then test the value of artAvailable and if true <exec> bcp into SQLServer

Is this possible? or a pointer to an example or tutorial.

Marijan (Mario) Madunic


Quoting "Anderson, Rob (Global Trade)" <Ro...@nike.com>:

> Use the if attribute of <target>...
> 
> <target name="exec-something" if="artAvailable">
>  <exec ...
> </target>
> 
> Be aware that this does not test the value of the artAvailable property,
> only whether or not it exists. See the manual for more info.
> 
> http://ant.apache.org/manual/using.html#targets
> 
> 
> -Rob Anderson
> 
> > -----Original Message-----
> > From: Mario Madunic [mailto:hajduk@imag.net] 
> > Sent: Tuesday, September 11, 2007 10:40 AM
> > To: user@ant.apache.org
> > Subject: newbie help: conditional exec
> > 
> > I have the following in my ant task to test for the existence 
> > of an xml file after processing
> > 
> > <available file="CSV\csvArt.xml" property="artAvailable" />
> > 
> > What I want to do is run <exec> based on the above property 
> > value of true. I can't seem to find a task to do this. Any 
> > help will be appreciated.
> > 
> > 
> > ---------------------------------------------------------------------
> > 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: newbie help: conditional exec

Posted by "Anderson, Rob (Global Trade)" <Ro...@nike.com>.
Use the if attribute of <target>...

<target name="exec-something" if="artAvailable">
 <exec ...
</target>

Be aware that this does not test the value of the artAvailable property,
only whether or not it exists. See the manual for more info.

http://ant.apache.org/manual/using.html#targets


-Rob Anderson

> -----Original Message-----
> From: Mario Madunic [mailto:hajduk@imag.net] 
> Sent: Tuesday, September 11, 2007 10:40 AM
> To: user@ant.apache.org
> Subject: newbie help: conditional exec
> 
> I have the following in my ant task to test for the existence 
> of an xml file after processing
> 
> <available file="CSV\csvArt.xml" property="artAvailable" />
> 
> What I want to do is run <exec> based on the above property 
> value of true. I can't seem to find a task to do this. Any 
> help will be appreciated.
> 
> 
> ---------------------------------------------------------------------
> 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