ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 11481] New: - WaitFor doesn't extend Task so it can't be used as a Task programmatically
Date Mon, 05 Aug 2002 20:42:57 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11481>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11481

WaitFor doesn't extend Task so it can't be used as a Task programmatically

           Summary: WaitFor doesn't extend Task so it can't be used as a
                    Task programmatically
           Product: Ant
           Version: 1.5
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Core tasks
        AssignedTo: ant-dev@jakarta.apache.org
        ReportedBy: mmunz@apelon.com


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