ehatcher 02/02/23 12:42:14
Modified: src/main/org/apache/tools/ant/taskdefs Property.java
src/testcases/org/apache/tools/ant/taskdefs
PropertyTest.java
Log:
Added 'prefix' option to <property>. Designed to only work when loading a
property file or resource.
Revision Changes Path
1.44 +17 -0
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java
Index: Property.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- Property.java 26 Jan 2002 19:25:03 -0000 1.43
+++ Property.java 23 Feb 2002 20:42:14 -0000 1.44
@@ -86,6 +86,7 @@
protected Path classpath;
protected String env;
protected Reference ref;
+ protected String prefix;
protected boolean userProperty; // set read-only properties
@@ -124,6 +125,13 @@
public File getFile() {
return file;
}
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ if (!prefix.endsWith(".")) {
+ this.prefix += ".";
+ }
+ }
public void setRefid(Reference ref) {
this.ref = ref;
@@ -192,6 +200,10 @@
location);
}
}
+
+ if (file == null && resource == null && prefix != null) {
+ throw new BuildException("Prefix is only valid when loading from
a file or resource", location);
+ }
if ((name != null) && (value != null)) {
addProperty(name, value);
@@ -298,6 +310,11 @@
String value = props.getProperty(name);
String v = project.replaceProperties(value);
+
+ if (prefix != null) {
+ name = prefix + name;
+ }
+
addProperty(name, v);
}
}
1.6 +17 -0
jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
Index: PropertyTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PropertyTest.java 14 Nov 2001 12:25:30 -0000 1.5
+++ PropertyTest.java 23 Feb 2002 20:42:14 -0000 1.6
@@ -95,4 +95,21 @@
expectLog("test4", "http.url is http://localhost:999");
}
+ public void testPrefixSuccess() {
+ executeTarget("prefix.success");
+ assertEquals("80", project.getProperty("server1.http.port"));
+ }
+
+ public void testPrefixFailure() {
+ try {
+ executeTarget("prefix.fail");
+ }
+ catch (BuildException e) {
+ assertEquals("Prefix allowed on non-resource/file load - ", true,
+ e.getMessage().indexOf("Prefix is only valid") != -1);
+ return;
+ }
+ fail("Did not throw exception on invalid use of prefix");
+ }
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>