Bug 45960 - replace task failed to delete file
Summary: replace task failed to delete file
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.7.1
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 1.8.0
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-07 00:22 UTC by Support niveau 3 Agora
Modified: 2008-12-03 03:19 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Support niveau 3 Agora 2008-10-07 00:22:20 UTC
I use an ant script to build an EAR file.

This script runs fine since years on Unix systems.
On Windows, an exception happens with the following message :

D:\DevWebSDI02\NE00P\UEDIE\bin\Z55C02.xml:325: IOException in D:\DevWebSDI02\wlo\DWRDZ82TEI\EAR\online\Agora\z55cnxtest\WEB-INF\web.xml - java.io.IOException:Failed to delete D:\DevWebSDI02\wlo\DWRDZ82TEI\EAR\online\Agora\z55cnxtest\WEB-INF\web.xml while trying to rename D:\DevWebSDI02\wlo\DWRDZ82TEI\EAR\online\Agora\z55cnxtest\WEB-INF\rep371926229.tmp


The line 325 and followings are :
<replace file="${ear.dir}${file.separator}$..." propertyfile="${scriptsdir}$...">
  <replacefilter token="@@@@ROLE_USER@@@@" property="ROLE_USER_${templ}" />
  <replacefilter token="@@@@AUTH_METHOD@@@@" property="AUTH_METHOD_${templ}" />
</replace>

The ant version used is Eclipse's one org.apache.ant_1.7.0.v200706080842
The same problem happens with Ant 1.7.1.

My workaround is to call System.gc() when entering in the replace method of the file FileUtils.java

But it has an effect on speed execution.

I had also found some posts about this problem and Stefan Bodewig was talking about relations between JVM and Windows file systems but unfortunately, I cannot retrieve these posts.
Comment 1 Stefan Bodewig 2008-10-09 04:43:22 UTC
I've looked through my archives of the last two years but don't find the post you talked about, it may have been older than that.

Anyway.

Ant has just closed the file (because it had to read it) and it may very well be that the JVM hasn't released the file handle to the operating system yet (and your call to GC made it release the handle).  We have had similar cases in <delete> where we explicitly insert a System.gc() on Windows and retry after sleeping for a 10 millis if a call to delete() fails - we could introduce the same in replace as well.

Comment 2 Stefan Bodewig 2008-10-09 05:23:30 UTC
should work better with svn trunk revision 703151.
Comment 3 Support niveau 3 Agora 2008-10-10 03:00:07 UTC
I'll test as soon as possible.
Thanks
Comment 4 Support niveau 3 Agora 2008-12-02 04:48:27 UTC
correction seems good but I can't access to Apache SVN repositories from my company.
Comment 5 Stefan Bodewig 2008-12-03 01:32:45 UTC
you can download a snapshot of Ant's trunk from http://svn.apache.org/snapshots/ant/
Comment 6 Support niveau 3 Agora 2008-12-03 03:19:39 UTC
I've just made a test.
The bug is fixed.