Submitted by: Vincent Bergbauer <vincent_bergbauer@yahoo.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268042 13f79535-47bb-0310-9956-ffa450edef68master
@@ -3186,9 +3186,10 @@ resource) in the project.</p> | |||||
property cannot be set, and will be ignored. This means that properties set | property cannot be set, and will be ignored. This means that properties set | ||||
outside the current project always override the properties of the current | outside the current project always override the properties of the current | ||||
project.</p> | project.</p> | ||||
<p>There are three ways to set properties:</p> | |||||
<p>There are four ways to set properties:</p> | |||||
<ul> | <ul> | ||||
<li>By supplying both the <i>name</i> and <i>value</i> attribute.</li> | <li>By supplying both the <i>name</i> and <i>value</i> attribute.</li> | ||||
<li>By supplying both the <i>name</i> and <i>refid</i> attribute.</li> | |||||
<li>By setting the <i>file</i> attribute with the filename of the property | <li>By setting the <i>file</i> attribute with the filename of the property | ||||
file to load. This property file has the format as defined by the file used | file to load. This property file has the format as defined by the file used | ||||
in the class java.util.Properties.</li> | in the class java.util.Properties.</li> | ||||
@@ -3217,7 +3218,13 @@ This also holds for properties loaded from a property file.</p> | |||||
<tr> | <tr> | ||||
<td valign="top">value</td> | <td valign="top">value</td> | ||||
<td valign="top">the value of the property.</td> | <td valign="top">the value of the property.</td> | ||||
<td valign="middle" align="center" rowspan="3">Yes</td> | |||||
<td valign="middle" align="center" rowspan="4">Yes</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">refid</td> | |||||
<td valign="top"><a href="#references">Reference</a> to an object | |||||
defined elsewhere. Only yields reasonable results for references | |||||
to <a href="#path">PATH like structures</a> or properties.</td> | |||||
</tr> | </tr> | ||||
<tr> | <tr> | ||||
<td valign="top">resource</td> | <td valign="top">resource</td> | ||||
@@ -55,6 +55,7 @@ | |||||
package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
import org.apache.tools.ant.*; | import org.apache.tools.ant.*; | ||||
import org.apache.tools.ant.types.Reference; | |||||
import java.io.*; | import java.io.*; | ||||
import java.util.*; | import java.util.*; | ||||
@@ -72,6 +73,7 @@ public class Property extends Task { | |||||
String value; | String value; | ||||
File file; | File file; | ||||
String resource; | String resource; | ||||
private Reference ref = null; | |||||
boolean userProperty=false; // set read-only properties | boolean userProperty=false; // set read-only properties | ||||
@@ -99,6 +101,14 @@ public class Property extends Task { | |||||
return file; | return file; | ||||
} | } | ||||
public void setRefid(Reference ref) { | |||||
this.ref = ref; | |||||
} | |||||
public Reference getRefid() { | |||||
return ref; | |||||
} | |||||
public void setResource(String resource) { | public void setResource(String resource) { | ||||
this.resource = resource; | this.resource = resource; | ||||
} | } | ||||
@@ -107,6 +117,10 @@ public class Property extends Task { | |||||
return resource; | return resource; | ||||
} | } | ||||
public String toString() { | |||||
return value == null ? "" : value; | |||||
} | |||||
public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
try { | try { | ||||
if ((name != null) && (value != null)) { | if ((name != null) && (value != null)) { | ||||
@@ -117,6 +131,13 @@ public class Property extends Task { | |||||
if (resource != null) loadResource(resource); | if (resource != null) loadResource(resource); | ||||
if ((name != null) && (ref != null)) { | |||||
Object obj = ref.getReferencedObject(getProject()); | |||||
if (obj != null) { | |||||
addProperty(name, obj.toString()); | |||||
} | |||||
} | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
throw new BuildException(e, location); | throw new BuildException(e, location); | ||||
} | } | ||||