ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Weintraub" <qazw...@gmail.com>
Subject Re: Need help in build.xml file...
Date Mon, 29 Dec 2008 18:20:56 GMT
First off. You shouldn't be doing antcalls. Especially in  order. Ant
has the ability to figure out how to build your software. All you have
to do is give it the  information it needs.

For example:
<project name="test" default="copy_jar" basename=".">
    <target name="clean">
    </target>

    <target name="prepare">
    </target>

    <target name="jar"
        depends="prepare">
    </target>

    <target name="copy_jar"
       depends="jar"
     </target>
</project>

In the above (fairly empty) Ant script, running "ant" will run target
"copy_jar". This is the default target.

When Ant looks to run "copy_jar", it will find a dependency on "jar".
This will find the dependency on "prepare". Thus, this ant script will
automatically run "prepare, jar, and "copy_jar" in that order. You
don't have to specify the order. Instead, you let Ant figure it out.

It's seems quite different from shell scripting or development, but
this is standard in build logic. You setup a dependency matrix, and
let your build tool decide the order. In a small script like this, it
really doesn't make much difference. But, when you start with larger
and larger projects, you'll save a lot of build time and heartache if
you let Ant figure out the build order.

Now, we could give the "prepare" target a dependency on executing the
"clean" target. Doing this means whenever I run "copy_jar", it will
automatically do a clean before anything else. However, you normally
don't want to do a clean because it breaks build avoidance. Imagine a
developer running the ant build, changing a file here or there, then
running the ant build again. If you use Ant's build avoidance
mechanism, you are only rebuilding what got changed, and that can save
you quite a bit of time. You probably want to hit that clean target
when you do a CM build, but don't force the developers to do a clean
with each build.

You can also use the <fail> task to cause an automatic error when you
execute a target. Fail can be set check for a condition too. You
notice that the "prepare" task includes the fail which will fail if
the directory ${carrotsharpdir} doesn't exist:

Here's a final outline of the build:

 <target name="prepare">
        <echo>Running prepare</echo>
        <fail message="No such directory as ${carrotsharpdir}">
            <condition>
                <not>
                    <available type="dir" file="${carrotsharpdir}"/>
                </not>
            </condition>
        </fail>
    </target>

    <target name="jar"
        depends="prepare">
        <echo>Running Jar</echo>
    </target>

    <target name="copy_jar"
        depends="jar">
        <echo>Running Deploy</echo>
    </target>

I hope this helps.

On Fri, Dec 26, 2008 at 7:21 PM, Anna Teittinen <ateittinen@i-a-i.com> wrote:
> Hello,
>
> I am relatively new to using ant.
> Can somebody help me with a problem I have in my build.xml file?
> Below is a snippet of code from my build.xml file.
> Below, "caratsharp.dir" refers to a directory.
> Basically, if that directory exists, then the clean, prepare, jar, and copy_jar targets
will get called; otherwise, an error msg should be printed and nothing more happens.
>
> When this build.xml is called when the "caratsharp.dir" directory exists, all the antcall
commands get done... great!
> However, when I run this script when the "caratsharp.dir" directory does not exist, the
error msg does not get printed.
>
> Does anyone have any insight to why the error msg ("${caratsharp.dir} does not exist")
does not get printed?
>
>
>  <target name="checkForCaratSharpDir">
>  <available property="present" file="${caratsharp.dir}" />
>  <available property="isaDir" file="${caratsharp.dir}" type="dir" />
>  <condition property="isaDir">
>  <and>
>  <isset property="present" />
>  <not>
>  <isset property="isaFile" />
>  </not>
>  </and>
>  </condition>
>  </target>
>  <target name="exists" depends="checkForCaratSharpDir" if="present">
>  <echo message="${caratsharp.dir} exists" />
>  <antcall target="clean" />
>  <antcall target="prepare" />
>  <antcall target="jar" />
>  <antcall target="copy_jar" />
>  </target>
>  <target name="printError" depends="checkForCaratSharpDir" if="isaFile">
>  <echo message="${caratsharp.dir} does not exist" />
>  </target>
>  <target name="all" depends="exists,printError" description="Cleans, compile then
builds the JAR file." />
>
>
>
> Thanks so much in advance for your help,
> --Anna
>
> __________________________________________________________________________
> This message and all attachments are PRIVATE, and contain information that
> is PROPRIETARY to Intelligent Automation, Inc. You are not authorized to
> transmit or otherwise disclose this message or any attachments to any
> third party whatsoever without the express written consent of Intelligent
> Automation, Inc. If you received this message in error or you are not
> willing to view this message or any attachments on a confidential basis,
> please immediately delete this email and any attachments and notify
> Intelligent Automation, Inc.
>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message