diff --git a/docs/manual/CoreTasks/import.html b/docs/manual/CoreTasks/import.html
index d2c18b1ab..9f4e28c20 100644
--- a/docs/manual/CoreTasks/import.html
+++ b/docs/manual/CoreTasks/import.html
@@ -150,9 +150,9 @@ project).
To create a relative resource you'd use something like:
- <url id="imported.basedir" url="${ant.file.imported}/."/>
<loadproperties>
- <url url="${toString:imported.basedir}/imported.properties"/>
+ <url baseUrl="${ant.file.imported}"
+ relativePath="imported.properties"/>
</loadproperties>
diff --git a/docs/manual/CoreTasks/include.html b/docs/manual/CoreTasks/include.html
index b89967977..24d2f361b 100644
--- a/docs/manual/CoreTasks/include.html
+++ b/docs/manual/CoreTasks/include.html
@@ -153,9 +153,9 @@ project).
To create a relative resource you'd use something like:
- <url id="included.basedir" url="${ant.file.included}/."/>
<loadproperties>
- <url url="${toString:included.basedir}/included.properties"/>
+ <url baseUrl="${ant.file.included}"
+ relativePath="included.properties"/>
</loadproperties>
diff --git a/docs/manual/CoreTypes/resources.html b/docs/manual/CoreTypes/resources.html
index f84fa3f63..37c9345a7 100644
--- a/docs/manual/CoreTypes/resources.html
+++ b/docs/manual/CoreTypes/resources.html
@@ -254,6 +254,16 @@ element.
file |
The file to expose as a file: url |
+
+ baseUrl |
+ The base URL which must be combined with relativePath |
+
+
+ relativePath |
+ Relative path that defines the url combined with
+ baseUrl |
+ If using baseUrl |
+
diff --git a/src/main/org/apache/tools/ant/helper/AntXMLContext.java b/src/main/org/apache/tools/ant/helper/AntXMLContext.java
index 36f7b0844..496303922 100644
--- a/src/main/org/apache/tools/ant/helper/AntXMLContext.java
+++ b/src/main/org/apache/tools/ant/helper/AntXMLContext.java
@@ -124,12 +124,16 @@ public class AntXMLContext {
*/
public void setBuildFile(File buildFile) {
this.buildFile = buildFile;
- this.buildFileParent = new File(buildFile.getParent());
- implicitTarget.setLocation(new Location(buildFile.getAbsolutePath()));
- try {
- setBuildFile(FileUtils.getFileUtils().getFileURL(buildFile));
- } catch (MalformedURLException ex) {
- throw new BuildException(ex);
+ if (buildFile != null) {
+ this.buildFileParent = new File(buildFile.getParent());
+ implicitTarget.setLocation(new Location(buildFile.getAbsolutePath()));
+ try {
+ setBuildFile(FileUtils.getFileUtils().getFileURL(buildFile));
+ } catch (MalformedURLException ex) {
+ throw new BuildException(ex);
+ }
+ } else {
+ this.buildFileParent = null;
}
}
diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
index d5d1adef6..6daff3b14 100644
--- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
+++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
@@ -219,6 +219,7 @@ public class ProjectHelper2 extends ProjectHelper {
buildFileName = buildFile.toString();
} else if (url != null) {
try {
+ context.setBuildFile((File) null);
context.setBuildFile(url);
} catch (java.net.MalformedURLException ex) {
throw new BuildException(ex);
diff --git a/src/main/org/apache/tools/ant/types/resources/URLResource.java b/src/main/org/apache/tools/ant/types/resources/URLResource.java
index fc4c05d20..e391be6f1 100644
--- a/src/main/org/apache/tools/ant/types/resources/URLResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/URLResource.java
@@ -46,6 +46,8 @@ public class URLResource extends Resource implements URLProvider {
private URL url;
private URLConnection conn;
+ private URL baseURL;
+ private String relPath;
/**
* Default constructor.
@@ -107,6 +109,34 @@ public class URLResource extends Resource implements URLProvider {
}
}
+ /**
+ * Base URL which combined with the relativePath attribute defines
+ * the URL.
+ * @since Ant 1.8.0
+ */
+ public synchronized void setBaseURL(URL base) {
+ checkAttributesAllowed();
+ if (url != null) {
+ throw new BuildException("can't define URL and baseURL attribute");
+ }
+ baseURL = base;
+ }
+
+ /**
+ * Relative path which combined with the baseURL attribute defines
+ * the URL.
+ * @since Ant 1.8.0
+ */
+ public synchronized void setRelativePath(String r) {
+ checkAttributesAllowed();
+ if (url != null) {
+ throw new BuildException("can't define URL and relativePath"
+ + " attribute");
+ }
+ relPath = r;
+ }
+
+
/**
* Get the URL used by this URLResource.
* @return a URL object.
@@ -115,6 +145,19 @@ public class URLResource extends Resource implements URLProvider {
if (isReference()) {
return ((URLResource) getCheckedRef()).getURL();
}
+ if (url == null) {
+ if (baseURL != null) {
+ if (relPath == null) {
+ throw new BuildException("must provide relativePath"
+ + " attribute when using baseURL.");
+ }
+ try {
+ url = new URL(baseURL, relPath);
+ } catch (MalformedURLException e) {
+ throw new BuildException(e);
+ }
+ }
+ }
return url;
}
@@ -124,7 +167,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized void setRefid(Reference r) {
//not using the accessor in this case to avoid side effects
- if (url != null) {
+ if (url != null || baseURL != null || relPath != null) {
throw tooManyAttributes();
}
super.setRefid(r);
diff --git a/src/tests/antunit/taskdefs/import-url-test.xml b/src/tests/antunit/taskdefs/import-url-test.xml
index 71e7a304e..f194bff62 100644
--- a/src/tests/antunit/taskdefs/import-url-test.xml
+++ b/src/tests/antunit/taskdefs/import-url-test.xml
@@ -21,16 +21,25 @@
+
]]>
+
In inner
+ ant.file.inner is ${ant.file.inner}
+ type is ${ant.file.type.inner}
+
+
+
+ foo is ${foo}
]]>
+
@@ -45,5 +54,7 @@
+
+