diff --git a/docs/manual/CoreTasks/property.html b/docs/manual/CoreTasks/property.html
index b37f27a32..70841a6b3 100644
--- a/docs/manual/CoreTasks/property.html
+++ b/docs/manual/CoreTasks/property.html
@@ -33,7 +33,7 @@ resource) in the project. Properties are case sensitive.
rest of the build; they are most definitely not variables.
There are seven ways to set properties:
- - By supplying both the name and value attribute.
+ - By supplying both the name and one of value or location attribute.
- By supplying the name and nested text.
- By supplying both the name and refid attribute.
- By setting the file attribute with the filename of the property
@@ -154,6 +154,16 @@ SYSTEM).
A "." is appended to the prefix if not specified.
No |
+
+ relative |
+ If set to true the relative path to basedir is set. |
+ No (default=false) |
+
+
+ basedir |
+ The basedir to calculate the relative path from. |
+ No (default=${basedir}) |
+
Parameters specified as nested elements
@@ -211,6 +221,17 @@ environment variable STAGE some or all values could be overwritten, e.g
name for the test server). Finally all these values could be overwritten by personal settings with
a file per user.
+
+ <property name="foo" location="my/file.txt" relative="true" basedir=".."/>
+
+Stores the relative path in foo: projectbasedir/my/file.txt
+
+
+ <property name="foo" location="my/file.txt" relative="true" basedir="cvs"/>
+
+Stores the relative path in foo: ../my/file.txt
+
+
Property Files
As stated, this task will load in a properties file stored in the file
diff --git a/src/main/org/apache/tools/ant/taskdefs/Property.java b/src/main/org/apache/tools/ant/taskdefs/Property.java
index 4892aa5a8..1b2bd4e6b 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Property.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Property.java
@@ -92,6 +92,8 @@ public class Property extends Task {
private Project fallback;
private Object untypedValue;
private boolean valueAttributeUsed = false;
+ private boolean relative = false;
+ private File basedir;
protected boolean userProperty; // set read-only properties
// CheckStyle:VisibilityModifier ON
@@ -124,6 +126,24 @@ public class Property extends Task {
this.fallback = fallback;
}
+ /**
+ * Sets 'relative' attribute.
+ * @param relative new value
+ * @since Ant 1.8.0
+ */
+ public void setRelative(boolean relative) {
+ this.relative = relative;
+ }
+
+ /**
+ * Sets 'basedir' attribute.
+ * @param basedir new value
+ * @since Ant 1.8.0
+ */
+ public void setBasedir(File basedir) {
+ this.basedir = basedir;
+ }
+
/**
* The name of the property to set.
* @param name property name
@@ -151,7 +171,11 @@ public class Property extends Task {
* @ant.attribute group="name"
*/
public void setLocation(File location) {
- setValue(location.getAbsolutePath());
+ if (relative) {
+ internalSetValue(location);
+ } else {
+ setValue(location.getAbsolutePath());
+ }
}
/* the following method is first in source so IH will pick it up first:
@@ -433,7 +457,19 @@ public class Property extends Task {
}
if (name != null && untypedValue != null) {
- addProperty(name, untypedValue);
+ if (relative) {
+ try {
+ File from = untypedValue instanceof File ? (File)untypedValue : new File(untypedValue.toString());
+ File to = basedir != null ? basedir : getProject().getBaseDir();
+ String relPath = FileUtils.getFileUtils().getRelativePath(to, from);
+ relPath = relPath.replace('/', File.separatorChar);
+ addProperty(name, relPath);
+ } catch (Exception e) {
+ throw new BuildException(e, getLocation());
+ }
+ } else {
+ addProperty(name, untypedValue);
+ }
}
if (file != null) {
@@ -466,7 +502,7 @@ public class Property extends Task {
}
}
}
-
+
/**
* load properties from a url
* @param url url to load from
diff --git a/src/tests/antunit/taskdefs/property-test.xml b/src/tests/antunit/taskdefs/property-test.xml
index 761285b68..3a3e10a60 100644
--- a/src/tests/antunit/taskdefs/property-test.xml
+++ b/src/tests/antunit/taskdefs/property-test.xml
@@ -47,4 +47,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+