dganesh2002
dganesh2002

Reputation: 2210

ant copy task hanging when the source file is missing

In one of our build script, we have following simple copy task added ->

<copy todir="${targetdir}" 
    file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"/>

This copy task started hanging when the glassfish jar name got changed (version upgrade which are not in our control) at the source location. I was expecting it to error out causing the build failure in that case. Actually at first I was not able to figure out at what particular step build was hanging. Then when I added "-debug" to the ant command and I realized its successfully completing a step prior to this copy task and still there was no trace of copy command that is hung. When I updated the new jar name, it worked fine and build was successful which proved that the copy task is hanging because of filename got changed. To make it easy to debug next time, I added an echo statement like below just prior to that copy task ->

<echo message="Copying glassfish jar to ${targetdir}.."/>

But I am still confused as to why it didn't give error with build failure? I am using Apache Ant version 1.7.1. Could this be a bug? How else I can avoid this situation in future with just the copy task (without using * in the jar name)? TIA

Upvotes: 2

Views: 871

Answers (2)

Dante WWWW
Dante WWWW

Reputation: 2739

To force the build to quit, an alternative way

<available file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar" 
           property="glassfish.jaxb.xjc.jar.present"/>

<fail message="you message" unless="glassfish.jaxb.xjc.jar.present"/>

just a few lines less :)

If you want to dig into it, try this:

write a simple build file, which contains only one target with copy, and put it to the same place of your main build file.

<target name="test-copy">
    <!-- here use an old (wrong) file name -->
    <copy todir="${targetdir}" 
          file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"/>
</target>

run it, check if it fails or hangs.

If this simple build file works, it's very possible that something else in your main build file is causing the bug.

Upvotes: 1

David W.
David W.

Reputation: 107040

That worked for me. Well, didn't work for me. I got the error message. I am using Ant 1.8 and Ant 1.9.2. I didn't try it with Ant 1.7, but I doubt it's a bug.

Try to use the -v parameter in Ant:

 $ ant -v target

And be prepared for a longwinded output. This will give you information what's going on with Ant, and may explain why it's freezing. There's a few things you could do: Use a fileset to specify the file.

<copy todir="${targetdir}">
    <fileset dir="${sourcedir}/modules">
        <include name="glassfish*.jar"/>  <!-- Will catch any glassfish.jar -->
    </fileset>
</copy> 

Of course, if the file doesn't exist, you won't get an error or even a warning. However, a <fail/> before will detect the issue:

<fail message="missing file ${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar">
    <condition>
        <not>
            <available 
                file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"
                type="file"/>
        </not>
    </condition>
 </fail>

Upvotes: 1

Related Questions