Browse Source

import failed to import file specified as absolute path imported from an URI/jar - PR 50953

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1554392 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 11 years ago
parent
commit
c7741302fd
3 changed files with 37 additions and 0 deletions
  1. +4
    -0
      WHATSNEW
  2. +9
    -0
      src/main/org/apache/tools/ant/taskdefs/ImportTask.java
  3. +24
    -0
      src/tests/antunit/taskdefs/import-url-test.xml

+ 4
- 0
WHATSNEW View File

@@ -8,6 +8,10 @@ Changes that could break older environments:
Fixed bugs: Fixed bugs:
----------- -----------


* <import>/<include> failed when the importing file was loaded from an
URI or a jar and it imported a file from the local file system via
an absolute path.
Bugzilla Report 50953


Other changes: Other changes:
-------------- --------------


+ 9
- 0
src/main/org/apache/tools/ant/taskdefs/ImportTask.java View File

@@ -248,6 +248,10 @@ public class ImportTask extends Task {
// *not* the current directory (same as entity includes). // *not* the current directory (same as entity includes).


if (file != null) { if (file != null) {
if (isExistingAbsoluteFile(file)) {
return new FileResource(new File(file));
}

File buildFile = File buildFile =
new File(getLocation().getFileName()).getAbsoluteFile(); new File(getLocation().getFileName()).getAbsoluteFile();
if (buildFile.exists()) { if (buildFile.exists()) {
@@ -271,6 +275,11 @@ public class ImportTask extends Task {
return null; return null;
} }


private boolean isExistingAbsoluteFile(String name) {
File f = new File(name);
return f.isAbsolute() && f.exists();
}

/** /**
* Whether the task is in include (as opposed to import) mode. * Whether the task is in include (as opposed to import) mode.
* *


+ 24
- 0
src/tests/antunit/taskdefs/import-url-test.xml View File

@@ -18,6 +18,7 @@
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> <project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
<import file="../antunit-base.xml" /> <import file="../antunit-base.xml" />


<mkdir dir="${output}"/>
<mkdir dir="${input}/a/b"/> <mkdir dir="${input}/a/b"/>
<mkdir dir="${input}/a/c"/> <mkdir dir="${input}/a/c"/>
<echo file="${input}/a/b/outer.xml"><![CDATA[ <echo file="${input}/a/b/outer.xml"><![CDATA[
@@ -39,6 +40,18 @@
</project>]]></echo> </project>]]></echo>
<echo file="${input}/a/c/test.properties"><![CDATA[ <echo file="${input}/a/c/test.properties"><![CDATA[
foo=bar foo=bar
]]></echo>
<echo file="${input}/a/b/external-import.xml"><![CDATA[
<project name="external-import">
<import file="${output}/imported.xml"/>
</project>
]]></echo>
<echo file="${output}/imported.xml"><![CDATA[
<project name="imported">
<target name="bar">
<echo>In imported</echo>
</target>
</project>
]]></echo> ]]></echo>
<jar destfile="${test.jar}"> <jar destfile="${test.jar}">
<fileset dir="${input}"/> <fileset dir="${input}"/>
@@ -55,6 +68,11 @@ foo=bar
<classpath location="${test.jar}"/> <classpath location="${test.jar}"/>
</javaresource> </javaresource>
</import> </import>
<import>
<javaresource name="a/b/external-import.xml">
<classpath location="${test.jar}"/>
</javaresource>
</import>


<target name="testImportOfNestedFile" depends="foo"> <target name="testImportOfNestedFile" depends="foo">
<au:assertLogContains text="In inner"/> <au:assertLogContains text="In inner"/>
@@ -62,6 +80,11 @@ foo=bar
<au:assertLogContains text="foo is bar"/> <au:assertLogContains text="foo is bar"/>
</target> </target>


<target name="testImportOfNestedFileWithAbsolutePath" depends="bar"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50953">
<au:assertLogContains text="In imported"/>
</target>

<target name="tearDown"> <target name="tearDown">
<taskdef name="close" <taskdef name="close"
classname="org.apache.tools.ant.taskdefs.CloseResources"/> classname="org.apache.tools.ant.taskdefs.CloseResources"/>
@@ -73,5 +96,6 @@ foo=bar
<delete file="${test.jar}" quiet="true" deleteonexit="true"/> <delete file="${test.jar}" quiet="true" deleteonexit="true"/>
<!-- Calling antunit-base.tearDown sometimes causes ISEs in <import> in Ant-Build-Matrix: --> <!-- Calling antunit-base.tearDown sometimes causes ISEs in <import> in Ant-Build-Matrix: -->
<delete dir="${input}"/> <delete dir="${input}"/>
<delete dir="${output}"/>
</target> </target>
</project> </project>

Loading…
Cancel
Save