ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ross Burton" <ross.bur...@mail.com>
Subject Question and Patch
Date Wed, 19 Apr 2000 18:37:11 GMT
Hi,

First a quick question: why does Ant still use ProjectX for the XML parser,
even though it now belongs to the Apache group who has Xerces?

Anyway, 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" depends="init" if="jpeg.present,
java2d.present">
        <copydir src="${src.dir}" dest="${build.src}"
includes="**/components/image/JPEGEncoder*" filtering="on"/>
    </target>

So I patched it.  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;
>  }


Mime
View raw message