ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eugene Bekker" <ebek...@powervision.com>
Subject Re: Call for patches
Date Tue, 23 May 2000 13:53:12 GMT
I notice there are more and more requests to beef up the logic support for
tasks, like IFNOT and multiple IFs.  One thing to consider is to drop in an
existing logic parser, that would allow nested and more complicated boolean
statements, such as Mozilla's Rhino JavaScript engine.

On a project of mine we had a need for doing something similar (not for
Ant, but for an XML properties file).  Certain tags had an IF attribute
that was evaluated as boolean JavaScript code.  It allows us to put
arbitrarily complex boolean logic.

On top of that it also gave more script power within the properties file
such as computing values based on system properties, and parsing and
manipulating strings, etc...

Integrating Rhino into our XML parsing was extremely trivial and took about
10-15 lines of code.




Bill Barnhill wrote:
> 
> I am working on something similar, but from a different take. Instead
> of multiple if's, it is a task called availablelist which takes
> paramters classes, resources, and files, each of which are plural
> versions of the class, resource, and file parameters of the available
> task. Also it will handle all three parameters at once or in any
> combo. Not ready to submit this yet as it still has a bit to go.
> 
> ----- Original Message -----
> From: "Ross Burton" <rossyb@lineone.net>
> To: <ant-dev@jakarta.apache.org>
> Sent: Tuesday, May 23, 2000 7:50 AM
> Subject: Re: Call for patches
> 
> > > 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/ProjectHelpe
> r.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;
> > >  }
> >
> >
> >

-- 
Eugene Bekker
Chief Architect
PowerVision Corporation
http://www.powervision.com
tel://410/312.7243 cel://443/838.6330

Mime
View raw message