@@ -129,6 +129,13 @@ public class EchoProperties extends Task {
private String format = "text";
private String prefix;
/**
* @since Ant 1.7
*/
private String regex;
/**
* Sets the input file.
*
@@ -163,19 +170,20 @@ public class EchoProperties extends Task {
/**
* If the prefix is set, then only properties which start with this
* prefix string will be recorded. If this is never set, or it is set
* to an empty string or <tt>null</tt>, then all properties will be
* recorded. <P>
* prefix string will be recorded. If regex is not set and if this
* is never set, or it is set to an empty string or <tt>null</tt>,
* then all properties will be recorded. <P>
*
* For example, if the property is set as:
* For example, if the attribute is set as:
* <PRE><echoproperties prefix="ant." /></PRE>
* then the property "ant.home" will be recorded, but "ant-example"
* will not.
*
*@param prefix The new prefix value
* @param prefix The new prefix value
*/
public void setPrefix(String prefix) {
if (prefix != null && prefix.length() != 0) {
this.prefix = prefix;
PropertySet ps = new PropertySet();
ps.setProject(getProject());
ps.appendPrefix(prefix);
@@ -183,6 +191,31 @@ public class EchoProperties extends Task {
}
}
/**
* If the regex is set, then only properties whose names match it
* will be recorded. If prefix is not set and if this is never set,
* or it is set to an empty string or <tt>null</tt>, then all
* properties will be recorded.<P>
*
* For example, if the attribute is set as:
* <PRE><echoproperties prefix=".*ant.*" /></PRE>
* then the properties "ant.home" and "user.variant" will be recorded,
* but "ant-example" will not.
*
* @param regex The new regex value
*
* @since Ant 1.7
*/
public void setRegex(String regex) {
if (regex != null && regex.length() != 0) {
this.regex = regex;
PropertySet ps = new PropertySet();
ps.setProject(getProject());
ps.appendRegex(regex);
addPropertyset(ps);
}
}
/**
* A set of properties to write.
* @param ps the property set to write
@@ -209,6 +242,7 @@ public class EchoProperties extends Task {
/**
* @see EnumeratedAttribute#getValues()
* @return accepted values
*/
public String[] getValues() {
return formats;
@@ -221,6 +255,10 @@ public class EchoProperties extends Task {
*@exception BuildException trouble, probably file IO
*/
public void execute() throws BuildException {
if (prefix != null && regex != null) {
throw new BuildException("Please specify either prefix"
+ " or regex, but not both", getLocation());
}
//copy the properties file
Hashtable allProps = new Hashtable();