ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Munz" <mm...@apelon.com>
Subject WaitFor doesn't extend Task so it can't be used as a Task programmatically
Date Mon, 05 Aug 2002 21:06:01 GMT
Hello ant developers,

  Thanks for creating such an awesome tool!

  The following is the content of bug #11481, which I just submitted.  Any
hints / suggestions /ideas would be appreciated...

Hi.

  This is a design issue.  Lacking Architecture / Design documents, I'm not
sure whether this is a defect or a "feature", but either way, I needed a
workaround to use WaitFor that is not required for objects like Copy, and
this
is an inconsistency that should be addressed.

  I am writing a Task that uses Parallel, Sequence, and WaitFor.  The
following
code won't work.

  WaitFor wait;
  ...
  Sequential sequence = (Sequential) getProject().createTask("sequential");
  sequence.addTask(wait);

  It won't work because, although WaitFor has an interface compatible with
Task, it does not extend Task, but rather its superclass, ProjectComponent.

  workaround:

  I created a wrapper class that treats WaitFor like a Task.  It is included
below.

  solution:

  There are several possiblities.  I don't think that the workaround is a
robust solution.  Alternatives include making WaitFor a subclass of Task,
and
(I like this one) making Task (or something like it) an interface.  Such an
interface (let's call it ExecutableComponent) would have only one method:

  public void execute() throws BuildException;

  Just an idea -- I'm interested in hearing anyone else's ideas on the
matter.

---- WaitForTask.java ---------

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.WaitFor;

/**
 * The WaitFor Condition object is very much like a Task object.
 * This class adapts the WaitFor object to the Task API so that it can be
executed
 * as a Task.
 * @author Matt Munz
 */
public class WaitForTask extends Task
{
  protected WaitFor fDelegate;

  public WaitForTask(WaitFor newDelegate)
  {
    super();
    setDelegate(newDelegate);
  }

  public void execute() throws BuildException { delegate().execute(); }

  protected WaitFor delegate() { return fDelegate; }

  protected void setDelegate(WaitFor newDelegate) { fDelegate =
newDelegate; }
}

----------------------

- Matt Munz


--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message