You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Anna Teittinen <at...@i-a-i.com> on 2008/12/27 01:21:27 UTC

Need help in build.xml file...

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


Re: Need help in build.xml file...

Posted by glenn opdycke-hansen <gl...@gmail.com>.
I would use the <mkdir> task to create the directory.  I would also consider
deleting the directory before the mkdir.
Is there a need for the multi-line <condition>?
Ant is not intended to be a scripting language.

On Fri, Dec 26, 2008 at 6:21 PM, Anna Teittinen <at...@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
>
>

Re: Need help in build.xml file...

Posted by glenn opdycke-hansen <gl...@gmail.com>.
I created an Ant script based on the code you provided.  The following
messages were returned:

exists:
Skipped because property 'present' not set.

printError:
Skipped because property 'isaFile' not set.

I did a quick rewrite of your code:

 <target name="checkForCaratSharpDir">
 <available property="csd.present" file="${caratsharp.dir}" type="dir"/>
 </target>

 <target name="exists" depends="checkForCaratSharpDir" if="csd.present">
 <echo message="${caratsharp.dir} exists" />
 <antcall target="clean-prepare-jar-copy_jar" />
 </target>

 <target name="printError" depends="checkForCaratSharpDir"
unless="csd.present">
 <echo message="${caratsharp.dir} does not exist" />
 </target>
 <target name="all" depends="exists,printError" description="Cleans, compile
then builds the JAR file." />

 <target  name="clean-prepare-jar-copy_jar" >
 <echo> depends="clean, prepare, jar, copy_jar" </echo>
 </target>

It now returns the following:

checkForCaratSharpDir:

exists:

printError:
     [echo] cs-src does not exist

all:




On Fri, Dec 26, 2008 at 6:21 PM, Anna Teittinen <at...@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
>
>

Re: Need help in build.xml file...

Posted by John Shott <sh...@stanford.edu>.
Anna:

I think that you aren't doing everything that you think you are doing in 
this snippet.  In particular, it appears as if nothing ever sets the 
isaFile property.  And, because your printError target depends on the 
isaFile property being set, you will never get your error message.

If I do a little guessing, I think that you <condition> task should be:

 <condition property="isaFile">
 <and>
  <isset property="present" /> 
 <not>
  <isset property="isaDir" /> 
  </not>
  </and>
  </condition>

Instead of:

>  <condition property="isaDir">
>  <and>
>   <isset property="present" /> 
>  <not>
>   <isset property="isaFile" /> 
>   </not>
>   </and>
>   </condition>
In other words, I think that you want to set the isaFile property if ${caratsharp.dir} exists but is NOT a directory, correct?

And, I think that you need to check for 3 things:

1. ${caratsharp.dir} doesn't exist at all ... that's an error.
2. ${carachsarp.dir} exists, but is not a directory (that is, it's a regular file) .... that's an error condition, too, isn't it?
3. ${caratsharp.dir} exists and is a directory .... this is what you want?

Here is, I think, a slightly modified version of your build.xml that, I think, does what you want .... maybe not in the most elegant way, but it is at least functional:

<target name="checkForCaratSharpDir">
  <available property="present" file="${caratsharp.dir}" />
  <available property="isaDir" file="${caratsharp.dir}" type="dir" />
  <condition property="isaFile">
    <and>
      <isset property="present" />
      <not>
        <isset property="isaDir" />
      </not>
    </and>
  </condition>
</target>

<target name="exists" depends="checkForCaratSharpDir" if="isaDir">
  <echo message="${caratsharp.dir} exists" /> 
  <antcall target="clean" /> 
  <antcall target="prepare" /> 
  <antcall target="jar" /> 
  <antcall target="copy_jar" /> 
</target>
<target name="printError" depends="checkForCaratSharpDir" unless="present">
  <echo message="${caratsharp.dir} does not exist" /> 
</target>
<target name="printFileError" depends="checkForCaratSharpDir" if="isaFile">
  <echo message="${caratsharp.dir} is a file instead of a directory" /> 
</target>
<target name="all" depends="exists,printError,printFileError"   description="Cleans, compile then builds the JAR file." /> 

At least that's the way it looks to me ....

Good luck,

John



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


Re: Need help in build.xml file...

Posted by David Weintraub <qa...@gmail.com>.
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 <at...@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