From 2495b9a97e4a392c6dc05ca3464b6a4a889f9f71 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Sun, 20 May 2018 17:45:43 +0200
Subject: [PATCH] add basedir attribute to
https://bz.apache.org/bugzilla/show_bug.cgi?id=62379
---
WHATSNEW | 5 +++++
manual/Types/resources.html | 9 ++++++++
.../ant/types/resources/ResourceList.java | 22 +++++++++++++++++++
src/tests/antunit/taskdefs/copy-test.xml | 18 +++++++++++++++
4 files changed, 54 insertions(+)
diff --git a/WHATSNEW b/WHATSNEW
index 8834fadcc..66e7399a0 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -43,6 +43,11 @@ Other changes:
availableProcessors, freeMemory, maxMemory and totalMemory methods
of the Java Runtime class.
+ * has a new basedir attribute that can be used to
+ resolve relative names and provides a root for the FileResources
+ generated.
+ Bugzilla Report 62379
+
Changes from Ant 1.9.10 TO Ant 1.9.11
=====================================
diff --git a/manual/Types/resources.html b/manual/Types/resources.html
index 8ba77aa12..5bdc2314f 100644
--- a/manual/Types/resources.html
+++ b/manual/Types/resources.html
@@ -1334,6 +1334,15 @@ collection. Since Ant 1.9.5.
The encoding of the nested resources |
No, default is platform default |
+
+ basedir |
+ Base directory that is used to resolve
+ relative file names against. Is also used to provide a base
+ directory to the FileResources created by this resource
+ collection. Since Ant 1.9.12
+ |
+ No |
+
diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceList.java b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
index b24277dda..79cbbb5cb 100644
--- a/src/main/org/apache/tools/ant/types/resources/ResourceList.java
+++ b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
@@ -19,6 +19,7 @@ package org.apache.tools.ant.types.resources;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -49,6 +50,7 @@ public class ResourceList extends DataType implements ResourceCollection {
private final Union cachedResources = new Union();
private volatile boolean cached = false;
private String encoding = null;
+ private File baseDir;
public ResourceList() {
cachedResources.setCache(true);
@@ -99,6 +101,21 @@ public class ResourceList extends DataType implements ResourceCollection {
this.encoding = encoding;
}
+ /**
+ * Basedir to use for file resources read from nested resources -
+ * this allows the resources contained inside this collection to
+ * be considered relative to a certain base directory.
+ *
+ * @param basedir the basedir
+ * @since Ant 1.9.12
+ */
+ public final void setBasedir(File baseDir) {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ this.baseDir = baseDir;
+ }
+
/**
* Makes this instance in effect a reference to another ResourceList
* instance.
@@ -250,6 +267,11 @@ public class ResourceList extends DataType implements ResourceCollection {
// resource
}
}
+ if (baseDir != null) {
+ FileResource fr = new FileResource(baseDir, expandedLine);
+ fr.setProject(getProject());
+ return fr;
+ }
return new FileResource(getProject(), expandedLine);
}
}
diff --git a/src/tests/antunit/taskdefs/copy-test.xml b/src/tests/antunit/taskdefs/copy-test.xml
index 5bca72480..1fd4b59f1 100644
--- a/src/tests/antunit/taskdefs/copy-test.xml
+++ b/src/tests/antunit/taskdefs/copy-test.xml
@@ -484,4 +484,22 @@ public class NullByteStreamResource extends Resource {
+
+
+
+
+
+
+ Testfile
+
+
+
+
+
+
+
+
+
+