diff --git a/src/main/org/apache/tools/ant/types/PatternSet.java b/src/main/org/apache/tools/ant/types/PatternSet.java index d66fb0a05..603b5561f 100644 --- a/src/main/org/apache/tools/ant/types/PatternSet.java +++ b/src/main/org/apache/tools/ant/types/PatternSet.java @@ -26,6 +26,7 @@ import java.util.StringTokenizer; import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.PropertyHelper; import org.apache.tools.ant.util.FileUtils; /** @@ -44,12 +45,13 @@ public class PatternSet extends DataType implements Cloneable { /** * inner class to hold a name on list. "If" and "Unless" attributes * may be used to invalidate the entry based on the existence of a - * property (typically set thru the use of the Available task). + * property (typically set thru the use of the Available task) + * or value of an expression. */ public class NameEntry { private String name; - private String ifCond; - private String unlessCond; + private Object ifCond; + private Object unlessCond; /** * Sets the name pattern. @@ -62,28 +64,63 @@ public class PatternSet extends DataType implements Cloneable { /** * Sets the if attribute. This attribute and the "unless" - * attribute are used to validate the name, based in the - * existence of the property. + * attribute are used to validate the name, based on the + * existence of the property or the value of the evaluated + * property expression. * - * @param cond A property name. If this property is not - * present, the name is invalid. + * @param cond A property name or expression. If the + * expression evaluates to false or no property of + * its value is present, the name is invalid. + * @since Ant 1.8.0 */ - public void setIf(String cond) { + public void setIf(Object cond) { ifCond = cond; } + /** + * Sets the if attribute. This attribute and the "unless" + * attribute are used to validate the name, based on the + * existence of the property or the value of the evaluated + * property expression. + * + * @param cond A property name or expression. If the + * expression evaluates to false or no property of + * its value is present, the name is invalid. + */ + public void setIf(String cond) { + setIf((Object) cond); + } + /** * Sets the unless attribute. This attribute and the "if" - * attribute are used to validate the name, based in the - * existence of the property. + * attribute are used to validate the name, based on the + * existence of the property or the value of the evaluated + * property expression. * - * @param cond A property name. If this property is - * present, the name is invalid. + * @param cond A property name or expression. If the + * expression evaluates to true or a property of + * its value is present, the name is invalid. + * @param cond A property name or expression. + * @since Ant 1.8.0 */ - public void setUnless(String cond) { + public void setUnless(Object cond) { unlessCond = cond; } + /** + * Sets the unless attribute. This attribute and the "if" + * attribute are used to validate the name, based on the + * existence of the property or the value of the evaluated + * property expression. + * + * @param cond A property name or expression. If the + * expression evaluates to true or a property of + * its value is present, the name is invalid. + */ + public void setUnless(String cond) { + setUnless((Object) cond); + } + /** * @return the name attribute. */ @@ -105,13 +142,9 @@ public class PatternSet extends DataType implements Cloneable { } private boolean valid(Project p) { - if (ifCond != null && p.getProperty(ifCond) == null) { - return false; - } - if (unlessCond != null && p.getProperty(unlessCond) != null) { - return false; - } - return true; + PropertyHelper ph = PropertyHelper.getPropertyHelper(p); + return ph.testIfCondition(ifCond) + && ph.testUnlessCondition(unlessCond); } /** diff --git a/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java b/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java index 159616e7d..2e64cab11 100644 --- a/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java @@ -22,6 +22,7 @@ import java.util.Enumeration; import java.io.File; import org.apache.tools.ant.Project; +import org.apache.tools.ant.PropertyHelper; /** * This selector just holds one other selector and forwards all @@ -35,8 +36,8 @@ import org.apache.tools.ant.Project; */ public class SelectSelector extends BaseSelectorContainer { - private String ifProperty; - private String unlessProperty; + private Object ifCondition; + private Object unlessCondition; /** * Default constructor. @@ -51,13 +52,13 @@ public class SelectSelector extends BaseSelectorContainer { StringBuffer buf = new StringBuffer(); if (hasSelectors()) { buf.append("{select"); - if (ifProperty != null) { + if (ifCondition != null) { buf.append(" if: "); - buf.append(ifProperty); + buf.append(ifCondition); } - if (unlessProperty != null) { + if (unlessCondition != null) { buf.append(" unless: "); - buf.append(unlessProperty); + buf.append(unlessCondition); } buf.append(" "); buf.append(super.toString()); @@ -151,32 +152,51 @@ public class SelectSelector extends BaseSelectorContainer { * @return true if conditions are passed */ public boolean passesConditions() { - if (ifProperty != null - && getProject().getProperty(ifProperty) == null) { - return false; - } else if (unlessProperty != null - && getProject().getProperty(unlessProperty) != null) { - return false; - } - return true; + PropertyHelper ph = PropertyHelper.getPropertyHelper(getProject()); + return ph.testIfCondition(ifCondition) + && ph.testUnlessCondition(unlessCondition); } /** - * Sets the if attribute to a property which must exist for the + * Sets the if attribute to an expression which must evaluate to + * true or the name of an existing property for the * selector to select any files. - * @param ifProperty the property to check + * @param ifProperty the expression to check + * @since Ant 1.8.0 + */ + public void setIf(Object ifProperty) { + this.ifCondition = ifProperty; + } + + /** + * Sets the if attribute to an expression which must evaluate to + * true or the name of an existing property for the + * selector to select any files. + * @param ifProperty the expression to check */ public void setIf(String ifProperty) { - this.ifProperty = ifProperty; + setIf((Object) ifProperty); + } + + /** + * Sets the unless attribute to an expression which must evaluate to + * false or the name of a property which cannot exist for the + * selector to select any files. + * @param unlessProperty the expression to check + * @since Ant 1.8.0 + */ + public void setUnless(Object unlessProperty) { + this.unlessCondition = unlessProperty; } /** - * Sets the unless attribute to a property which cannot exist for the + * Sets the unless attribute to an expression which must evaluate to + * false or the name of a property which cannot exist for the * selector to select any files. - * @param unlessProperty the property to check + * @param unlessProperty the expression to check */ public void setUnless(String unlessProperty) { - this.unlessProperty = unlessProperty; + setUnless((Object) unlessProperty); } /** diff --git a/src/tests/antunit/types/patternset-test.xml b/src/tests/antunit/types/patternset-test.xml new file mode 100644 index 000000000..60690d498 --- /dev/null +++ b/src/tests/antunit/types/patternset-test.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/tests/antunit/types/selectors/select-test.xml b/src/tests/antunit/types/selectors/select-test.xml new file mode 100644 index 000000000..f5f5b99e1 --- /dev/null +++ b/src/tests/antunit/types/selectors/select-test.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +