You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Priest, James (NIH/NIEHS) [C]" <Pr...@niehs.nih.gov> on 2007/02/23 14:13:29 UTC

Help with running different target based on user input?

I'm just getting started using Ant (from within Eclipse) to help deploy
my ColdFusion projects and Oracle sql scripts.

I've had great success so far but I have finally ran into a problem I
can't figure out.

I'm trying to run some Oracle scripts - but would like to prompt the
user while running them:

So I have:

<target name="script1">
	do something
</target>
<target name="script2">
	do something
</target>

<input  message="Populate people tables with test data? (run script3)"
validargs="y,n"  defaultvalue="n"/>

<target name="script3">
	do something
</target>

<input  message="Populate checklist tables with test data? (run
script4)" validargs="y,n"  defaultvalue="n"/>

<target name="script4">
	do something
</target>

I've dug through the ant tasks docs and the mailing list archives but
regardless of what I've tried - I can get it to work correctly.  

Does anyone have a good example of how something like this is done?

Thanks much!  
Jim

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


RE: Help with running different target based on user input?

Posted by "Priest, James (NIH/NIEHS) [C]" <Pr...@niehs.nih.gov>.
Glad you revised your entry - I was going to email you back that it
didn't work :)

Your second version was the ticket!!  I had something similar at one
point but I had my depends and if logic a bit mixed up...  This works
great! I need to go back and read the conditions docs again now that I
have a working example to compare. 

Thanks so much for the help!

Jim 

> -----Original Message-----
> From: RADEMAKERS Tanguy [mailto:Tanguy.RADEMAKERS@swift.com] 
> Sent: Friday, February 23, 2007 8:41 AM
> To: Ant Users List
> Subject: RE: Help with running different target based on user input?
> 
> after a more careful reading of your mail ;P
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <project name="" default="script3" basedir=".">
>     
>     <target name="ask_script3">
>     
>         <input  message="Populate people tables with test 
> data? (run script3)" 
>                 validargs="y,n"  
>                 defaultvalue="n" 
>                 addproperty="script3.run"/>
>         
>         <condition property="script3.run.required">
>             <equals arg1="y" arg2="${script3.run}"/>
>         </condition>
>     </target>
>     
>     <target name="script3" depends="ask_script3"
> if="script3.run.required">
>         <echo message="running script 3..."/>
>     </target> 
> 
> </project>
> 

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


RE: Help with running different target based on user input?

Posted by KD...@escholar.com.
Kevin Duffy
eScholar 
White Plains, NY
914-989-2983

RE: Help with running different target based on user input?

Posted by "Priest, James (NIH/NIEHS) [C]" <Pr...@niehs.nih.gov>.
Actually playing around with using depend - I think I can just eliminate
the user input entirely... :)

Now that I look at it - it seems redundant when you can just determine
what gets run by picking the appropriate target...

Thanks again!
Jim

> -----Original Message-----
> From: RADEMAKERS Tanguy [mailto:Tanguy.RADEMAKERS@swift.com] 

> My pleasure, and, yes, i am indeed on the CFE list (usually 
> posting things like "you can do that with ant!")

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


RE: Help with running different target based on user input?

Posted by RADEMAKERS Tanguy <Ta...@swift.com>.
>Thanks for all the help!!  Your name looks familiar - you are on the
>CFEclipse mailing list as well aren't you? :)

My pleasure, and, yes, i am indeed on the CFE list (usually posting
things like "you can do that with ant!")

/t

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


RE: Help with running different target based on user input?

Posted by "Priest, James (NIH/NIEHS) [C]" <Pr...@niehs.nih.gov>.
Thanks!! I figured out how in CFEclipse to run individual targets which
is more inline with your example - I'm going to rebuild my build file so
I can do as you suggested and have:

1) build-tables
2) build-table-with-reqdata (depend 1)
3) build-table-with-peopledata  (depend 1,2)
4) build-everything (depend 1,2,3)

And get rid of the AntCall...

Thanks for all the help!!  Your name looks familiar - you are on the
CFEclipse mailing list as well aren't you? :)

Jim

> -----Original Message-----
> From: RADEMAKERS Tanguy [mailto:Tanguy.RADEMAKERS@swift.com] 
> Sent: Friday, February 23, 2007 11:34 AM
> To: Ant Users List
> Subject: RE: Help with running different target based on user input?
> 
> Hey James, 
> 
> Just a last disclaimer/whatnot: it's worth mentioning that 
> <antcall> is not meant to be used as a poor man's "goto" - 
> it's more about allowing you to reuse an existing target, 
> optionally with different properties.
> Ant scripts can get pretty hairy even when you do everything 
> "by the book" (because build processes in the real world can 
> get pretty hairy).
> Do yourself a favor and swim with ant's flow on this one, or 
> you *will* run into problems one day down the road... and 
> i'll feel terrible for having pointed you down the path to 
> wrack and ruin ;)
> 
> That's it, mother mode off!
> 
> /t
> 
> >-----Original Message-----
> >From: Priest, James (NIH/NIEHS) [C] [mailto:PriestJ@niehs.nih.gov]
> >Sent: Friday, February 23, 2007 4:37 PM
> >To: Ant Users List
> >Subject: RE: Help with running different target based on user input?
> >
> >Okay - gotcha.   For what I need now it's OK but I see where you are
> >going...
> >
> >I'll copy my current code and rework it using 'depend' and 
> see if I can 
> >make it work...  I can see how that would be very flexible!
> >
> >Thanks!
> >Jim
> 
> ---------------------------------------------------------------------
> 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: Help with running different target based on user input?

Posted by RADEMAKERS Tanguy <Ta...@swift.com>.
Hey James, 

Just a last disclaimer/whatnot: it's worth mentioning that <antcall> is
not meant to be used as a poor man's "goto" - it's more about allowing
you to reuse an existing target, optionally with different properties.
Ant scripts can get pretty hairy even when you do everything "by the
book" (because build processes in the real world can get pretty hairy).
Do yourself a favor and swim with ant's flow on this one, or you *will*
run into problems one day down the road... and i'll feel terrible for
having pointed you down the path to wrack and ruin ;)

That's it, mother mode off!

/t

>-----Original Message-----
>From: Priest, James (NIH/NIEHS) [C] [mailto:PriestJ@niehs.nih.gov] 
>Sent: Friday, February 23, 2007 4:37 PM
>To: Ant Users List
>Subject: RE: Help with running different target based on user input?
>
>Okay - gotcha.   For what I need now it's OK but I see where you are
>going...
>
>I'll copy my current code and rework it using 'depend' and see if I can
>make it work...  I can see how that would be very flexible!
>
>Thanks!
>Jim

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


RE: Help with running different target based on user input?

Posted by "Priest, James (NIH/NIEHS) [C]" <Pr...@niehs.nih.gov>.
Okay - gotcha.   For what I need now it's OK but I see where you are
going...

I'll copy my current code and rework it using 'depend' and see if I can
make it work...  I can see how that would be very flexible!

Thanks!
Jim 

> -----Original Message-----
> From: RADEMAKERS Tanguy [mailto:Tanguy.RADEMAKERS@swift.com] 
> 
> do you think you'll ever want to run script 3 *without* 
> running script 4? 'Coz if you do, antcall is not the way to 
> go - just make the script 4 target depend on the script 3 
> target. That way, if you want to run just script 3, you just 
> call "ant script3", otherwise you call "ant script4", which 
> will run script 3 as well... that's more the "ant way" to do 
> things. Same logic applies for running script 1 and script 2 
> - if they always need to run then put them both in the same 
> target (call it dbinit or setup or whatever) and then make 
> script 3 dependent on that. Then you
> can:
> 
> "ant dbinit" -> runs script 1 and script 2 "ant script3" -> 
> runs script 1 and script 2 and script 3 "ant script4" -> runs 
> script 1 and script 2 and script 3 and script 4
>

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


RE: Help with running different target based on user input?

Posted by RADEMAKERS Tanguy <Ta...@swift.com>.
do you think you'll ever want to run script 3 *without* running script
4? 'Coz if you do, antcall is not the way to go - just make the script 4
target depend on the script 3 target. That way, if you want to run just
script 3, you just call "ant script3", otherwise you call "ant script4",
which will run script 3 as well... that's more the "ant way" to do
things. Same logic applies for running script 1 and script 2 - if they
always need to run then put them both in the same target (call it dbinit
or setup or whatever) and then make script 3 dependent on that. Then you
can:

"ant dbinit" -> runs script 1 and script 2
"ant script3" -> runs script 1 and script 2 and script 3
"ant script4" -> runs script 1 and script 2 and script 3 and script 4

/t

>-----Original Message-----
>From: Priest, James (NIH/NIEHS) [C] [mailto:PriestJ@niehs.nih.gov] 
>Sent: Friday, February 23, 2007 4:15 PM
>To: Ant Users List
>Subject: RE: Help with running different target based on user input?
>
>> -----Original Message-----
>> From: RADEMAKERS Tanguy [mailto:Tanguy.RADEMAKERS@swift.com] 
>
>> Ant is not a scripting language... assuming that "run script 
>> four" is a target in your build file, you could call it from 
>> within another target using the <antcall> task. You should 
>> also look into the AntContrib third party tasks, since they 
>> have an "if" task.
>> 
>> Maybe if you gave us some more info on what you're trying to achieve?
>
>Basically I have a series of sql scripts that I want to run...
>
>Script1 and Script2 need to always run.
>
>Script2 and Script3 are optional but there are some table 
>dependencies -
>so for example if I don't run Script3, I can't run Script 4 without
>throwing an error.
>
>I added an AntCall within Script3 to call Script4 and it seems to
>work!!!
>
>Thanks again for the pointers!
>
>Jim
>
>
>---------------------------------------------------------------------
>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: Help with running different target based on user input?

Posted by "Priest, James (NIH/NIEHS) [C]" <Pr...@niehs.nih.gov>.
> -----Original Message-----
> From: RADEMAKERS Tanguy [mailto:Tanguy.RADEMAKERS@swift.com] 

> Ant is not a scripting language... assuming that "run script 
> four" is a target in your build file, you could call it from 
> within another target using the <antcall> task. You should 
> also look into the AntContrib third party tasks, since they 
> have an "if" task.
> 
> Maybe if you gave us some more info on what you're trying to achieve?

Basically I have a series of sql scripts that I want to run...

Script1 and Script2 need to always run.

Script2 and Script3 are optional but there are some table dependencies -
so for example if I don't run Script3, I can't run Script 4 without
throwing an error.

I added an AntCall within Script3 to call Script4 and it seems to
work!!!

Thanks again for the pointers!

Jim


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


RE: Help with running different target based on user input?

Posted by RADEMAKERS Tanguy <Ta...@swift.com>.
i'm not too sure i understand what you mean by "chain dependencies
together". In ant, a target can depend on more than one other targets
(just pass a comma separated list) and ant handles generating the graph
of dependent targets for you (so if target c depends on target b which
depends on target a... etc). All of this is explained on the target page
in the section "Using Ant" of the manual.

>If they run Script 3 they should be prompted if they want to run script
>4 - otherwise the build should just stop.

Ant is not a scripting language... assuming that "run script four" is a
target in your build file, you could call it from within another target
using the <antcall> task. You should also look into the AntContrib third
party tasks, since they have an "if" task.

Maybe if you gave us some more info on what you're trying to achieve?

/t




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


RE: Help with running different target based on user input?

Posted by "Priest, James (NIH/NIEHS) [C]" <Pr...@niehs.nih.gov>.
One last question :)

Is there a way to chain the dependencies together?  So I'll run Script 1
and 2...

Then prompt for them to run Script 3...

If they run Script 3 they should be prompted if they want to run script
4 - otherwise the build should just stop.

Thanks,
Jim

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


RE: Help with running different target based on user input?

Posted by RADEMAKERS Tanguy <Ta...@swift.com>.
after a more careful reading of your mail ;P

<?xml version="1.0" encoding="UTF-8"?>
<project name="" default="script3" basedir=".">
    
    <target name="ask_script3">
    
        <input  message="Populate people tables with test data? (run
script3)" 
                validargs="y,n"  
                defaultvalue="n" 
                addproperty="script3.run"/>
        
        <condition property="script3.run.required">
            <equals arg1="y" arg2="${script3.run}"/>
        </condition>
    </target>
    
    <target name="script3" depends="ask_script3"
if="script3.run.required">
        <echo message="running script 3..."/>
    </target> 

</project>

-----

D:\scrap\ant>ant
Buildfile: build.xml

ask_script3:
    [input] Populate people tables with test data? (run script3)(y,n)
n

script3:

BUILD SUCCESSFUL
Total time: 2 seconds

D:\scrap\ant>ant
Buildfile: build.xml

ask_script3:
    [input] Populate people tables with test data? (run script3)(y,n)
y

script3:
     [echo] running script 3...

BUILD SUCCESSFUL
Total time: 1 second
D:\scrap\ant>


/t

>-----Original Message-----
>From: RADEMAKERS Tanguy 
>Sent: Friday, February 23, 2007 2:25 PM
>To: 'Ant Users List'
>Subject: RE: Help with running different target based on user input?
>
>Hello James,
>
>You should put the input tasks within the target blocks that 
>"consume" the inputted info:
>
>
><target name="script3">
>
>	<input  message="Populate people tables with test data? 
>(run script3)" 
>		  validargs="y,n"  
>		  defaultvalue="n" 
>		  addproperty="foo"/>
>	<do something arg="${foo}/>
>
></target>
>
>check out the ant manual page for the input task for some examples.
>
>/t 
>

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


RE: Help with running different target based on user input?

Posted by RADEMAKERS Tanguy <Ta...@swift.com>.
Hello James,

You should put the input tasks within the target blocks that "consume"
the inputted info:


<target name="script3">

	<input  message="Populate people tables with test data? (run
script3)" 
		  validargs="y,n"  
		  defaultvalue="n" 
		  addproperty="foo"/>
	<do something arg="${foo}/>

</target>

check out the ant manual page for the input task for some examples.

/t 

>-----Original Message-----
>From: Priest, James (NIH/NIEHS) [C] [mailto:PriestJ@niehs.nih.gov] 
>Sent: Friday, February 23, 2007 2:13 PM
>To: user@ant.apache.org
>Subject: Help with running different target based on user input?
>
>I'm just getting started using Ant (from within Eclipse) to help deploy
>my ColdFusion projects and Oracle sql scripts.
>
>I've had great success so far but I have finally ran into a problem I
>can't figure out.
>
>I'm trying to run some Oracle scripts - but would like to prompt the
>user while running them:
>
>So I have:
>
><target name="script1">
>	do something
></target>
><target name="script2">
>	do something
></target>
>
><input  message="Populate people tables with test data? (run script3)"
>validargs="y,n"  defaultvalue="n"/>
>
><target name="script3">
>	do something
></target>
>
><input  message="Populate checklist tables with test data? (run
>script4)" validargs="y,n"  defaultvalue="n"/>
>
><target name="script4">
>	do something
></target>
>
>I've dug through the ant tasks docs and the mailing list archives but
>regardless of what I've tried - I can get it to work correctly.  
>
>Does anyone have a good example of how something like this is done?
>
>Thanks much!  
>Jim
>
>---------------------------------------------------------------------
>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