diff --git a/docs/manual/CoreTasks/property.html b/docs/manual/CoreTasks/property.html index 747f5d565..f9634b065 100644 --- a/docs/manual/CoreTasks/property.html +++ b/docs/manual/CoreTasks/property.html @@ -12,14 +12,17 @@
Sets a property (by name and value), or set of properties (from file or resource) in the project. Properties are case sensitive.
Properties are immutable: whoever sets a property first freezes it for the - rest of the build; they are most definately not variable. -There are five ways to set properties:
+ rest of the build; they are most definately not variable. +There are six ways to set properties:
file
or resource
. A "." is appended to the prefix if not specified.sets the property foo.dist
to the value "dist".
<property file="foo.properties"/>
reads a set of properties from a file called "foo.properties".
+<property url="http://www.mysite.com/bla/props/foo.properties"/>+
reads a set of properties from the address "http://www.mysite.com/bla/props/foo.properties".
<property resource="foo.properties"/>
reads a set of properties from a resource called "foo.properties".
Note that you can reference a global properties file for all of your Ant @@ -132,7 +141,7 @@ to be your home directory. Where the "user.home" property resolves to the file system depends on the operating system version and the JVM implementation. On Unix based systems, this will map to the user's home directory. On modern Windows variants, this will most likely resolve to the user's directory in the "Documents -and Settings" folder. Older windows variants such as Windows 98/ME are less +and Settings" folder. Older windows variants such as Windows 98/ME are less predictable, as are other operating system/JVM combinations.
@@ -142,8 +151,8 @@ predictable, as are other operating system/JVM combinations.
reads the system environment variables and stores them in properties, prefixed with "env". Note that this only works on select operating systems. -Two of the values are shown being echoed. -
+Two of the values are shown being echoed. +Copyright © 2000-2003 Apache Software Foundation. All rights
diff --git a/src/etc/testcases/taskdefs/property.xml b/src/etc/testcases/taskdefs/property.xml
index c46e21c73..75fbe6940 100644
--- a/src/etc/testcases/taskdefs/property.xml
+++ b/src/etc/testcases/taskdefs/property.xml
@@ -21,7 +21,13 @@
file
* or resource
.
@@ -345,16 +361,16 @@ public class Property extends Task {
getLocation());
}
} else {
- if (file == null && resource == null && env == null) {
- throw new BuildException("You must specify file, resource or "
+ if (url == null && file == null && resource == null && env == null) {
+ throw new BuildException("You must specify url, file, resource or "
+ "environment when not using the "
+ "name attribute", getLocation());
}
}
- if (file == null && resource == null && prefix != null) {
+ if (url == null && file == null && resource == null && prefix != null) {
throw new BuildException("Prefix is only valid when loading from "
- + "a file or resource", getLocation());
+ + "a url, file or resource", getLocation());
}
if ((name != null) && (value != null)) {
@@ -365,6 +381,10 @@ public class Property extends Task {
loadFile(file);
}
+ if (url != null) {
+ loadUrl(url);
+ }
+
if (resource != null) {
loadResource(resource);
}
@@ -388,6 +408,29 @@ public class Property extends Task {
}
}
+ /**
+ * load properties from a url
+ * @param url url to load from
+ */
+ protected void loadUrl(URL url) throws BuildException {
+ Properties props = new Properties();
+ log("Loading " + url, Project.MSG_VERBOSE);
+ try {
+ InputStream is = url.openStream();
+ try {
+ props.load(is);
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ addProperties(props);
+ } catch (IOException ex) {
+ throw new BuildException(ex, getLocation());
+ }
+ }
+
+
/**
* load properties from a file
* @param file file to load
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java b/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
index dda68fddf..937fb1c1e 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
@@ -60,25 +60,25 @@ import org.apache.tools.ant.BuildFileTest;
/**
* @author Conor MacNeill
*/
-public class PropertyTest extends BuildFileTest {
-
- public PropertyTest(String name) {
+public class PropertyTest extends BuildFileTest {
+
+ public PropertyTest(String name) {
super(name);
- }
-
- public void setUp() {
+ }
+
+ public void setUp() {
configureProject("src/etc/testcases/taskdefs/property.xml");
}
- public void test1() {
+ public void test1() {
// should get no output at all
expectOutputAndError("test1", "", "");
}
- public void test2() {
+ public void test2() {
expectLog("test2", "testprop1=aa, testprop3=xxyy, testprop4=aazz");
}
-
+
public void test3() {
try {
executeTarget("test3");
@@ -86,15 +86,19 @@ public class PropertyTest extends BuildFileTest {
catch (BuildException e) {
assertEquals("Circular definition not detected - ", true,
e.getMessage().indexOf("was circularly defined") != -1);
- return;
+ return;
}
- fail("Did not throw exception on circular exception");
+ fail("Did not throw exception on circular exception");
}
- public void test4() {
+ public void test4() {
expectLog("test4", "http.url is http://localhost:999");
}
-
+
+ public void test5() {
+ expectLog("test5", "http.url is http://localhost:999");
+ }
+
public void testPrefixSuccess() {
executeTarget("prefix.success");
assertEquals("80", project.getProperty("server1.http.port"));
@@ -107,9 +111,9 @@ public class PropertyTest extends BuildFileTest {
catch (BuildException e) {
assertEquals("Prefix allowed on non-resource/file load - ", true,
e.getMessage().indexOf("Prefix is only valid") != -1);
- return;
+ return;
}
fail("Did not throw exception on invalid use of prefix");
}
-
+
}