ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan George <al...@hereuare.com>
Subject [PATCH]Re: if and unless attributes for all Tasks
Date Tue, 15 May 2001 20:36:27 GMT
Roger Vaughn wrote:

> --- Daniel Barclay <Daniel.Barclay@digitalfocus.com>
> wrote:
> > You don't think one might want to configure how a
> > target is executed
> > by parameterizing tasks with boolean values
> > similarly to how we
> > parameterize tasks with string values?
>
> An if/unless uber-task would eliminate the need for
> this, but since Ant doesn't (yet?) support nested
> tasks, could be difficult to implement.
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/

I'm not sure what you mean above, but the below patch implements an
if/unless for everything that 'isa' Task.

-alan

Index: jakarta-ant/src/main/org/apache/tools/ant/Target.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Target.java,v
retrieving revision 1.17
diff -r1.17 Target.java
150,166c150,176
<                 try {
<                     project.fireTaskStarted(task);
<                     task.maybeConfigure();
<                     task.execute();
<                     project.fireTaskFinished(task, null);
<                 }
<                 catch(RuntimeException exc) {
<                     if (exc instanceof BuildException) {
<                         BuildException be = (BuildException) exc;
<                         if (be.getLocation() ==
Location.UNKNOWN_LOCATION) {
<                             be.setLocation(task.getLocation());
<                         }
<                     }
<                     project.fireTaskFinished(task, exc);
<                     throw exc;
<                 }
<             }
---
>   try {
>       project.fireTaskStarted(task);
>       task.maybeConfigure();
>
>       if (task.testIfCondition() && task.testUnlessCondition()) {
>    task.execute();
>       } else if (!task.testIfCondition()) {
>    project.log(this, "Task skipped because property '" + task.getIf()
+ "' not set.",
>         Project.MSG_VERBOSE);
>       } else {
>    project.log(this, "Task skipped because property '" +
task.getUnless() + "' set.",
>         Project.MSG_VERBOSE);
>       }
>
>       project.fireTaskFinished(task, null);
>   }
>   catch(RuntimeException exc) {
>       if (exc instanceof BuildException) {
>    BuildException be = (BuildException) exc;
>    if (be.getLocation() == Location.UNKNOWN_LOCATION) {
>        be.setLocation(task.getLocation());
>    }
>       }
>       project.fireTaskFinished(task, exc);
>       throw exc;
>   }
>      }
168c178
<             project.log(this, "Skipped because property '" +
this.ifCondition + "' not set.",
---
>             project.log(this, "Target skipped because property '" +
this.ifCondition + "' not set.",
171c181
<             project.log(this, "Skipped because property '" +
this.unlessCondition + "' set.",
---
>             project.log(this, "Target skipped because property '" +
this.unlessCondition + "' set.",
Index: jakarta-ant/src/main/org/apache/tools/ant/Task.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Task.java,v
retrieving revision 1.17
diff -r1.17 Task.java
71a72,73
>     protected String ifCondition = "";
>     protected String unlessCondition = "";
169a172,187
>     public void setIf( String property ) {
>  ifCondition=(property == null) ? "" : property;
>     }
>
>     public String getIf() {
>         return ifCondition;
>     }
>
>     public void setUnless( String property ) {
>  unlessCondition=(property == null) ? "" : property;
>     }
>
>     public String getUnless() {
>         return unlessCondition;
>     }
>
222a241,251
>
>     public boolean testIfCondition() {
>         return "".equals(ifCondition)
>             || project.getProperty(ifCondition) != null;
>     }
>
>     public boolean testUnlessCondition() {
>         return "".equals(unlessCondition)
>             || project.getProperty(unlessCondition) == null;
>     }
>



Mime
View raw message