Bug 55097 - Files imported twice if resolved via different resource types
Summary: Files imported twice if resolved via different resource types
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.9.1
Hardware: All All
: P2 minor (vote)
Target Milestone: 1.9.4
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-13 01:50 UTC by Adrian Sutton
Modified: 2013-12-31 11:05 UTC (History)
0 users



Attachments
Simple demonstration of problem (837 bytes, application/zip)
2013-06-13 01:50 UTC, Adrian Sutton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Sutton 2013-06-13 01:50:53 UTC
Created attachment 30429 [details]
Simple demonstration of problem

If you import the same file via two different resource types (url and javaresource in my case) it can be resolved to exactly the same URL but still be imported twice.

Attached is a complete demonstration of this problem.  In brief, if we have a file imported.xml which fails if it is imported twice, then:

<?xml version="1.0"?>
<project name="multi-import">

  <dirname file="${ant.file}" property="path"/>
  <import>
    <url url="file:${path}/imported.xml"/>
    <javaresource classpath="." name="imported.xml"/>
  </import>
</project>

will fail. This is despite the fact that ant -debug clearly shows the file is resolved to the same underlying URL:

Importing file file:/home/suttona/bugs/ant-multi-import/imported.xml from /home/suttona/bugs/ant-multi-import/build.xml
Overriding previous definition of reference to ant.projectHelper
Adding reference: ant.projectHelper
parsing buildfile file:/home/suttona/bugs/ant-multi-import/imported.xml with URI = file:/home/suttona/bugs/ant-multi-import/imported.xml
...
Importing file imported.xml from /home/suttona/bugs/ant-multi-import/build.xml
ResourceStream for imported.xml loaded from ant loader
Overriding previous definition of reference to ant.projectHelper
Adding reference: ant.projectHelper
Resource imported.xml loaded from ant loader
parsing buildfile file:/home/suttona/bugs/ant-multi-import/imported.xml with URI = file:/home/suttona/bugs/ant-multi-import/imported.xml


The simplified example is clearly a stupid thing to do, but we ran across this issue in a much more reasonable use case. For the background see http://www.symphonious.net/2013/06/12/importing-an-ant-buildfile-multiple-times/

The work around is just to use URLs consistently - they are quite capable of pointing to files on remote servers local file systems or within zip/jar files which is all we need.

Issue exists at least as far back as 1.8.4.
Comment 1 Stefan Bodewig 2013-12-31 11:05:33 UTC
fixed with svn revision 1554400