> Over the next few weeks, I am going to try to commit a bunch of changes.
> I'm going to look at my personal archives for this mailing list, but quite
> frankly if you have something that you want added, the way to increase
your
> changes is to post it again. Now.
I wanted Ant to be able to deal with multiple "if"s in the <target> block,
so that I can do this:
<available property="jpeg.present"
classname="com.sun.image.codec.jpeg.JPEGCodec"/>
<available property="java2d.present"
classname="java.awt.image.BufferedImage"/>
<target name="prepare-jpeg" if="jpeg.present, java2d.present">
...
</target>
I think it works fine although I haven't given it a comprehensive test. It
did what I expected when I tested it for about 10 minutes. :-)
Regards,
Ross Burton
Index: ProjectHelper.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
,v
retrieving revision 1.11
diff -r1.11 ProjectHelper.java
175d174
< target.setCondition(targetCond);
187a187,196
> }
> }
>
> // Take care of conditions
>
> if (targetCond.length() > 0) {
> StringTokenizer tok =
> new StringTokenizer(targetCond, ",", false);
> while (tok.hasMoreTokens()) {
> target.addCondition(tok.nextToken().trim());
Index: Target.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Target.java,v
retrieving revision 1.3
diff -r1.3 Target.java
68c68
< private String condition = "";
---
> private Vector conditions = new Vector(2);
111,112c111,121
< public void setCondition(String property) {
< this.condition = (property == null) ? "" : property;
---
> public void setConditions(String conds) {
> if (conds.length() > 0) {
> StringTokenizer tok = new StringTokenizer(conds, ",", false);
> while (tok.hasMoreTokens()) {
> addCondition(tok.nextToken().trim());
> }
> }
> }
>
> public void addCondition(String condition) {
> conditions.addElement(condition);
116c125
< if (("".equals(this.condition)) ||
(project.getProperty(this.condition) != null)) {
---
> if ((this.conditions.size() == 0) || checkConditions()) {
123c132
< project.log("Skipped because property '" + this.condition + "'
not set.", this.name, Project.MSG_VERBOSE);
---
> project.log("Skipped because property '" + this.conditions + "
not set.", this.name, Project.MSG_VERBOSE);
124a134,150
> }
>
> private boolean checkConditions() {
> if (this.conditions.size() == 0) {
> // No conditions, so always build
> return true;
> } else {
> // We have a vector of conditions, iterate through them and check
> for (Enumeration e = this.conditions.elements();
e.hasMoreElements(); ) {
> String condition = (String)e.nextElement();
> if (project.getProperty(condition) == null) {
> // A condition has not been met, so cancel this task
> return false;
> }
> }
> return true;
> }