You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by jdepaul <jj...@us.ibm.com> on 2007/12/17 22:42:35 UTC

Calling targets and passing parms?!

Need to call an ANT target from a UNIX shell script and pass the parameter to
it - like a Build TAG name:  so from within the shell script, I'd like to
issue something like this:  ant -f mybuild.xml  Release_2007_12_01_001 - how
could I pass a parm as input parm to a script so ANT could do some variable
replacements for some of the files that get copied/filtered during the build
- what's the best way to do that?!

Thanks,
James

-- 
View this message in context: http://www.nabble.com/Calling-targets-and-passing-parms-%21-tp14374059p14374059.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


AW: Calling targets and passing parms?!

Posted by Ja...@rzf.fin-nrw.de.
> The ${label} parameter becomes set to "Release_2007_12_01_001" when
> the build script is executed. Even better, it cannot be reset via a
> <parameter> task. That means you could have a default value defined in
> your build file, and then have the command line value over ride it.


He meant <property> task instead of <parameter> ;)


> As I said before, you should set a default inside the build file, so
> if you don't provide a command line value, it will still have some
> sort of value.

If you dont know a good default and therefore rely on the "user input",
you could
do a 
   <fail unless="label">You must provide a 'label'</fail>
which causes the build to fail if you dont provide that property.


If you want to use "derived" values you could also provide a bunch of
property files
and load one of them using the given property. Again you should provide
defaults ...
   <property file="${label}.properties"/>
   <property file="default.properties"/>

Example:
   Release_2007_12_01_001.properties :
       version=2007.12
       release.manager=John Doe
   default.properties :
       name=${ant.project.name}
       version=${dstamp}
       release.manager=${user.name}
       company.name=ACME inc.
   build.xml
       ...
       <jar ...>
           <manifest>
               <attribute name="Built-By" value="${release.manager}"/>
               <attribute name="Implementation-Vendor"
value="${company.name}"/>
               <attribute name="Implementation-Title" value="${name}"/>
               <attribute name="Implementation-Version"
value="${version}"/> 



Jan

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


Re: Calling targets and passing parms?!

Posted by David Weintraub <qa...@gmail.com>.
Not sure if this is what you're looking for, but you can pass in
properties by using the -D flag:

ant -Dlabel=Release_2007_12_01_001 -f mybuild target

The ${label} parameter becomes set to "Release_2007_12_01_001" when
the build script is executed. Even better, it cannot be reset via a
<parameter> task. That means you could have a default value defined in
your build file, and then have the command line value over ride it.

To do a replace on a copy use the "filter" ability of the <copy> task:

 <copy todir="${releaseDir}">
    <fileset dir="${buildDir}"/>
    <filterset begintoken="@" endtoken="@">
        <filter token="label"  value="${label}"/>
    </filterset>
</copy>

That will replace all instances of "@label@" in the files with the
value of ${label}. I believe you can have multiple <filter> parameters
inside the <filterset>.

As I said before, you should set a default inside the build file, so
if you don't provide a command line value, it will still have some
sort of value.

On Dec 17, 2007 4:42 PM, jdepaul <jj...@us.ibm.com> wrote:
>
> Need to call an ANT target from a UNIX shell script and pass the parameter to
> it - like a Build TAG name:  so from within the shell script, I'd like to
> issue something like this:  ant -f mybuild.xml  Release_2007_12_01_001 - how
> could I pass a parm as input parm to a script so ANT could do some variable
> replacements for some of the files that get copied/filtered during the build
> - what's the best way to do that?!
>
> Thanks,
> James
>
> --
> View this message in context: http://www.nabble.com/Calling-targets-and-passing-parms-%21-tp14374059p14374059.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

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