ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs DemuxOutputTask.java
Date Sun, 09 Feb 2003 07:59:54 GMT
conor       2003/02/08 23:59:53

  Modified:    src/main/org/apache/tools/ant Main.java Project.java
                        Task.java UnknownElement.java
               src/main/org/apache/tools/ant/taskdefs Ant.java
                        CallTarget.java Java.java Redirector.java
               src/main/org/apache/tools/ant/taskdefs/optional/junit
                        JUnitTask.java JUnitTestRunner.java
               src/testcases/org/apache/tools/ant/taskdefs
                        DemuxOutputTask.java
  Added:       src/main/org/apache/tools/ant DemuxInputStream.java
  Log:
  Input handling framework
  
  Non-forked Java tasks can now have their input redirected.
  
  Note that it would be possible to add a noninteractive flag to
  Ant preventing any input from System.in in any java classes
  druing a build. Would prevent locking up waiting for input
  
  Revision  Changes    Path
  1.78      +8 -7      jakarta-ant/src/main/org/apache/tools/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
  retrieving revision 1.77
  retrieving revision 1.78
  diff -u -w -u -r1.77 -r1.78
  --- Main.java	23 Jan 2003 16:33:24 -0000	1.77
  +++ Main.java	9 Feb 2003 07:59:52 -0000	1.78
  @@ -572,6 +572,8 @@
                   //System.setSecurityManager(new NoExitSecurityManager());
               }
               try {
  +                project.setDefaultInputStream(System.in);
  +                System.setIn(new DemuxInputStream(project));
                   System.setOut(new PrintStream(new DemuxOutputStream(project, false)));
                   System.setErr(new PrintStream(new DemuxOutputStream(project, true)));
   
  @@ -662,7 +664,7 @@
        * @exception BuildException if a specified InputHandler
        *                           implementation could not be loaded.
        */
  -    private void addInputHandler(Project project) {
  +    private void addInputHandler(Project project) throws BuildException {
           InputHandler handler = null;
           if (inputHandlerClassname == null) {
               handler = new DefaultInputHandler();
  @@ -675,8 +677,7 @@
                       + inputHandlerClassname
                       + " does not implement the InputHandler interface";
                   throw new BuildException(msg);
  -            }
  -            catch (Exception e) {
  +            } catch (Exception e) {
                   String msg = "Unable to instantiate specified input handler "
                       + "class " + inputHandlerClassname + " : "
                       + e.getClass().getName();
  
  
  
  1.128     +139 -57   jakarta-ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.127
  retrieving revision 1.128
  diff -u -w -u -r1.127 -r1.128
  --- Project.java	31 Jan 2003 07:57:41 -0000	1.127
  +++ Project.java	9 Feb 2003 07:59:52 -0000	1.128
  @@ -90,7 +90,6 @@
    */
   
   public class Project {
  -
       /** Message priority of "error". */
       public static final int MSG_ERR = 0;
       /** Message priority of "warning". */
  @@ -114,6 +113,13 @@
       private static final String VISITED = "VISITED";
   
       /**
  +     * The class name of the Ant class loader to use for 
  +     * JDK 1.2 and above
  +     */
  +    private static final String ANTCLASSLOADER_JDK12
  +        = "org.apache.tools.ant.loader.AntClassLoader2";
  +    
  +    /**
        * Version constant for Java 1.0
        *
        * @deprecated use org.apache.tools.ant.util.JavaEnvUtils instead
  @@ -205,14 +211,36 @@
       private InputHandler inputHandler = null;
   
       /**
  +     * The default input stream used to read any input
  +     */
  +    private InputStream defaultInputStream = null;
  +    
  +    /**
        * Sets the input handler
  +     * 
  +     * @param handler the InputHandler instance to use for gathering input.
        */
       public void setInputHandler(InputHandler handler) {
           inputHandler = handler;
       }
   
       /**
  +     * Set the default System input stream. Normally this stream is set to 
  +     * System.in. This inputStream is used when no task inptu redirection is
  +     * being performed.
  +     *
  +     * @param defaultInputStream the default input stream to use when input 
  +     *        is reuested.
  +     */
  +    public void setDefaultInputStream(InputStream defaultInputStream) {
  +        this.defaultInputStream = defaultInputStream;
  +    }
  +    
  +    /**
        * Retrieves the current input handler.
  +     *
  +     * @return the InputHandler instance currently in place for the project 
  +     *         instance.
        */
       public InputHandler getInputHandler() {
           return inputHandler;
  @@ -278,13 +306,18 @@
           setSystemProperties();
       }
   
  +    /**
  +     * Factory method to create a class loader for loading classes
  +     *
  +     * @return an appropriate classloader
  +     */
       private AntClassLoader createClassLoader() {
           AntClassLoader loader = null;
           if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
               try {
                   // 1.2+ - create advanced helper dynamically
                   Class loaderClass
  -                    = Class.forName("org.apache.tools.ant.loader.AntClassLoader2");
  +                    = Class.forName(ANTCLASSLOADER_JDK12);
                   loader = (AntClassLoader) loaderClass.newInstance();
               } catch (Exception e) {
                       log("Unable to create Class Loader: "
  @@ -300,6 +333,14 @@
           return loader;
       }
   
  +    /**
  +     * Factory method to create a class loader for loading classes from
  +     * a given path
  +     *
  +     * @param path the path from whcih clases are to be loaded.
  +     * 
  +     * @return an appropriate classloader
  +     */
       public AntClassLoader createClassLoader(Path path) {
           AntClassLoader loader = createClassLoader();
           loader.setClassPath(path);
  @@ -434,7 +475,8 @@
        * @since 1.5
        */
       public synchronized void setNewProperty(String name, String value) {
  -        PropertyHelper.getPropertyHelper(this).setNewProperty( null, name, value);
  +        PropertyHelper.getPropertyHelper(this).setNewProperty(null, name, 
  +                                                              value);
       }
   
       /**
  @@ -447,7 +489,8 @@
        * @see #setProperty(String,String)
        */
       public synchronized void setUserProperty(String name, String value) {
  -        PropertyHelper.getPropertyHelper(this).setUserProperty( null, name, value);
  +        PropertyHelper.getPropertyHelper(this).setUserProperty(null, name, 
  +                                                               value);
       }
   
       /**
  @@ -509,8 +552,7 @@
        *                           property name, e.g. <code>${xxx</code>
        */
       public String replaceProperties(String value)
  -        throws BuildException
  -    {
  +        throws BuildException {
           PropertyHelper ph=PropertyHelper.getPropertyHelper(this);
           return ph.replaceProperties(null, value, null);
       }
  @@ -1241,6 +1283,48 @@
       }
   
       /**
  +     * Read data from the default input stream. If no default has been 
  +     * specified, System.in is used. 
  +     *
  +     * @param buffer the buffer into which data is to be read.
  +     * @param offset the offset into the buffer at which data is stored.
  +     * @param length the amount of data to read
  +     *
  +     * @return the number of bytes read
  +     * 
  +     * @exception IOException if the data cannot be read
  +     */
  +    public int defaultInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        if (defaultInputStream != null) {
  +            return defaultInputStream.read(buffer, offset, length);
  +        } else {
  +            return System.in.read(buffer, offset, length);
  +        }
  +    }
  +    
  +    /**
  +     * Demux an input request to the correct task.
  +     *
  +     * @param buffer the buffer into which data is to be read.
  +     * @param offset the offset into the buffer at which data is stored.
  +     * @param length the amount of data to read
  +     *
  +     * @return the number of bytes read
  +     * 
  +     * @exception IOException if the data cannot be read
  +     */     
  +    public int demuxInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        Task task = (Task) threadTasks.get(Thread.currentThread());
  +        if (task == null) {
  +            return defaultInput(buffer, offset, length);
  +        } else {
  +            return task.handleInput(buffer, offset, length);
  +        }
  +    }
  +    
  +    /**
        * Demultiplexes flush operation so that each task receives the appropriate
        * messages. If the current thread is not currently executing a task,
        * the message is logged directly.
  @@ -1250,8 +1334,6 @@
        * @param line Message to handle. Should not be <code>null</code>.
        * @param isError Whether the text represents an error (<code>true</code>)
        *        or information (<code>false</code>).
  -     * @param terminated true if this line should be terminated with an 
  -     *        end-of-line marker
        */
       public void demuxFlush(String line, boolean isError) {
           Task task = (Task) threadTasks.get(Thread.currentThread());
  
  
  
  1.39      +20 -0     jakarta-ant/src/main/org/apache/tools/ant/Task.java
  
  Index: Task.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Task.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -w -u -r1.38 -r1.39
  --- Task.java	31 Jan 2003 07:57:41 -0000	1.38
  +++ Task.java	9 Feb 2003 07:59:52 -0000	1.39
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant;
   
   import java.util.Enumeration;
  +import java.io.IOException;
   
   /**
    * Base class for all tasks.
  @@ -313,6 +314,22 @@
       }
   
       /**
  +     * Handle an input request by this task
  +     *
  +     * @param buffer the buffer into which data is to be read.
  +     * @param offset the offset into the buffer at which data is stored.
  +     * @param length the amount of data to read
  +     *
  +     * @return the number of bytes read
  +     * 
  +     * @exception IOException if the data cannot be read
  +     */
  +    protected int handleInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        return getProject().defaultInput(buffer, offset, length);
  +    }
  +    
  +    /**
        * Handles an error line by logging it with the INFO priority.
        *
        * @param line The error line to log. Should not be <code>null</code>.
  @@ -396,6 +413,9 @@
   
       /**
        * Has this task been marked invalid?
  +     *
  +     * @return true if this task is no longer valid. A new task should be 
  +     * configured in this case.
        *
        * @since Ant 1.5
        */
  
  
  
  1.37      +31 -10    jakarta-ant/src/main/org/apache/tools/ant/UnknownElement.java
  
  Index: UnknownElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/UnknownElement.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -w -u -r1.36 -r1.37
  --- UnknownElement.java	31 Jan 2003 07:57:41 -0000	1.36
  +++ UnknownElement.java	9 Feb 2003 07:59:52 -0000	1.37
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant;
   
   import java.util.Vector;
  +import java.io.IOException;
   
   /**
    * Wrapper class that holds all the information necessary to create a task
  @@ -157,6 +158,26 @@
       }
   
       /**
  +     * Handle an input request by this element
  +     *
  +     * @param buffer the buffer into which data is to be read.
  +     * @param offset the offset into the buffer at which data is stored.
  +     * @param length the amount of data to read
  +     *
  +     * @return the number of bytes read
  +     * 
  +     * @exception IOException if the data cannot be read
  +     */
  +    protected int handleInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        if (realThing instanceof Task) {
  +            return ((Task) realThing).handleInput(buffer, offset, length);
  +        } else {
  +            return super.handleInput(buffer, offset, length);
  +        }
  +            
  +    }
  +    /**
        * Handles output sent to System.out by this task or its real task.
        *
        * @param line The line of output to log. Should not be <code>null</code>.
  @@ -241,8 +262,7 @@
        */
       protected void handleChildren(Object parent,
                                     RuntimeConfigurable parentWrapper)
  -        throws BuildException
  -    {
  +        throws BuildException {
           if (parent instanceof TaskAdapter) {
               parent = ((TaskAdapter) parent).getProxy();
           }
  @@ -277,7 +297,8 @@
                       // What ? Add data type ? createElement ?
                   }
               } else {
  -                realChild = ih.createElement(getProject(), parent, child.getTag());
  +                realChild 
  +                    = ih.createElement(getProject(), parent, child.getTag());
               }
   
               childWrapper.setProxy(realChild);
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/DemuxInputStream.java
  
  Index: DemuxInputStream.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant;
  
  import java.io.IOException;
  import java.io.InputStream;
  
  /**
   *
   * Passes input requests tot he project objetc for demuxing into 
   * individual tasks and threads.
   *
   * @since Ant 1.6
   * @author Conor MacNeill
   */
  public class DemuxInputStream extends InputStream {
  
      /**
       * The project to from which to get input.
       */
      private Project project;
      
      /**
       * Create a DemuxInputStream for the given project
       *
       * @param project the project instance
       */
      public DemuxInputStream(Project project) {
          this.project = project;
      }
  
      /**
       * @see InputStream.read()
       */
      public int read() throws IOException {
          byte[] buffer = new byte[1];
          project.demuxInput(buffer, 0, 1);
          return buffer[0];
      }
      
  
      /**
       * @see InputStream.read(byte[], int, int)
       */
      public int read(byte[] buffer, int offset, int length) throws IOException {
          return project.demuxInput(buffer, offset, length);
      }
  }
  
  
  
  1.73      +14 -1     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.72
  retrieving revision 1.73
  diff -u -w -u -r1.72 -r1.73
  --- Ant.java	31 Jan 2003 07:57:41 -0000	1.72
  +++ Ant.java	9 Feb 2003 07:59:53 -0000	1.73
  @@ -297,6 +297,18 @@
       }
   
       /**
  +     * @see Task#handleInput(byte[], int, int)
  +     */
  +    public int handleInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        if (newProject != null) {
  +            return newProject.demuxInput(buffer, offset, length);
  +        } else {
  +            return super.handleInput(buffer, offset, length);
  +        }
  +    }
  +    
  +    /**
        * Pass output sent to System.out to the new project.
        *
        * @since Ant 1.5.2
  @@ -443,7 +455,8 @@
        * requested.
        */
       private void addReferences() throws BuildException {
  -        Hashtable thisReferences = (Hashtable) getProject().getReferences().clone();
  +        Hashtable thisReferences 
  +            = (Hashtable) getProject().getReferences().clone();
           Hashtable newReferences = newProject.getReferences();
           Enumeration e;
           if (references.size() > 0) {
  
  
  
  1.29      +10 -0     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/CallTarget.java
  
  Index: CallTarget.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/CallTarget.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -w -u -r1.28 -r1.29
  --- CallTarget.java	31 Jan 2003 07:57:41 -0000	1.28
  +++ CallTarget.java	9 Feb 2003 07:59:53 -0000	1.29
  @@ -56,6 +56,7 @@
   
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Task;
  +import java.io.IOException;
   
   /**
    * Call another target in the same project.
  @@ -185,6 +186,15 @@
           }
       }
       
  +    public int handleInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        if (callee != null) {
  +            return callee.handleInput(buffer, offset, length);
  +        } else {
  +            return super.handleInput(buffer, offset, length);
  +        }
  +    }
  +
       /**
        * Pass output sent to System.out to the new project.
        *
  
  
  
  1.54      +9 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Java.java
  
  Index: Java.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Java.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -w -u -r1.53 -r1.54
  --- Java.java	8 Feb 2003 14:14:27 -0000	1.53
  +++ Java.java	9 Feb 2003 07:59:53 -0000	1.54
  @@ -416,6 +416,15 @@
           }
       }
       
  +    public int handleInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        if (redirector.getInputStream() != null) {
  +            return redirector.handleInput(buffer, offset, length);
  +        } else {
  +            return super.handleInput(buffer, offset, length);
  +        }
  +    }
  +
       /**
        * Pass output sent to System.out to specified output file.
        *
  
  
  
  1.2       +146 -6    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Redirector.java
  
  Index: Redirector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Redirector.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -u -r1.1 -r1.2
  --- Redirector.java	8 Feb 2003 14:14:27 -0000	1.1
  +++ Redirector.java	9 Feb 2003 07:59:53 -0000	1.2
  @@ -79,37 +79,92 @@
    * @since Ant 1.6
    */
   public class Redirector {
  +    /** 
  +     * The file receiveing standard output. Will also receive standard error
  +     * unless standard error is redirected or logError is true.
  +     */
       private File out;
  +    
  +    /**
  +     * The file to which standard error is being redirected 
  +     */
       private File error;
  +    
  +    /** 
  +     * The file from which standard input is being taken.
  +     */
       private File input;
   
  +    /** 
  +      * Indicates if standard error should be logged to Ant's log system
  +      * rather than the output. This has no effect if standard error is 
  +      * redirected to a file or property.
  +      */
       private boolean logError = false;
  +    
  +    /**
  +     * Buffer used to capture output for storage into a property
  +     */
       private ByteArrayOutputStream baos = null;
  +    
  +    /**
  +     * Buffer used to capture error output for storage into a property
  +     */
       private ByteArrayOutputStream errorBaos = null;
  +    
  +    /** The name of the property into which output is to be stored */
       private String outputProperty;
  +    
  +    /** The name of the property into which error output is to be stored */
       private String errorProperty;
  +    
  +    /** String from which input is taken */
       private String inputString;
  +    
  +    /** Flag which indicates if error and output files are to be appended. */
       private boolean append = false;
       
  +    /** The task for which this redirector is working */ 
       private Task managingTask;
   
  +    /** The stream for output data */
       private OutputStream outputStream = null;
  +    
  +    /** The stream for error output */
       private OutputStream errorStream = null;
  +    
  +    /** The stream for input */
       private InputStream inputStream = null; 
  +    
  +    /** Stream which are used for line oriented output */ 
       private PrintStream outPrintStream = null;
  +    
  +    /** Stream which is used for line oriented error output */
       private PrintStream errorPrintStream = null;
       
  +    /**
  +     * Create a redirector instance for the given task
  +     *
  +     * @param managingTask the task for which the redirector is to work
  +     */
       public Redirector(Task managingTask) {
           this.managingTask = managingTask;
       }
       
       /**
        * Set the input to use for the task
  +     *
  +     * @param input the file from which input is read.
        */
       public void setInput(File input) {
           this.input = input;
       }
   
  +    /**
  +     * Set the string to use as input
  +     *
  +     * @param inputString the string which is used as the input source
  +     */
       public void setInputString(String inputString) {
           this.inputString = inputString;
       }
  @@ -118,6 +173,8 @@
       /**
        * File the output of the process is redirected to. If error is not 
        * redirected, it too will appear in the output
  +     *
  +     * @param out the file to which output stream is written
        */
       public void setOutput(File out) {
           this.out = out;
  @@ -127,14 +184,18 @@
        * Controls whether error output of exec is logged. This is only useful
        * when output is being redirected and error output is desired in the
        * Ant log
  +     *
  +     * @param logError if true the standard error is sent to the Ant log system
  +     *        and not sent to output.
        */
       public void setLogError(boolean logError) {
           this.logError = logError;
       }
       
       /**
  -     * File the error stream of the process is redirected to.
  +     * Set the file to which standard error is to be redirected.
        *
  +     * @param error the file to which error is to be written
        */
       public void setError(File error) {
           this.error = error;
  @@ -143,6 +204,9 @@
       /**
        * Property name whose value should be set to the output of
        * the process.
  +     *
  +     * @param outputProperty the name of the property to be set with the 
  +     *        task's output.
        */
       public void setOutputProperty(String outputProperty) {
           this.outputProperty = outputProperty;
  @@ -152,6 +216,8 @@
        * Whether output should be appended to or overwrite an existing file.
        * Defaults to false.
        *
  +     * @param append if true output and error streams are appended to their
  +     *        respective files, if specified.
        */
       public void setAppend(boolean append) {
           this.append = append;
  @@ -161,11 +227,21 @@
        * Property name whose value should be set to the error of
        * the process.
        *
  +     * @param errorProperty the name of the property to be set 
  +     *        with the error output.
        */
       public void setErrorProperty(String errorProperty) {
           this.errorProperty = errorProperty;
       }
   
  +    /**
  +     * Set a property from a ByteArrayOutputStream
  +     *
  +     * @param baos contains the property value.
  +     * @param propertyName the property name.
  +     *
  +     * @exception IOException if the value cannot be read form the stream.
  +     */
       private void setPropertyFromBAOS(ByteArrayOutputStream baos, 
                                        String propertyName) throws IOException {
       
  @@ -183,6 +259,10 @@
       }
       
   
  +    /**
  +     * Create the input, error and output streams based on the 
  +     * configuration options.
  +     */
       public void createStreams() {        
           if (out == null && outputProperty == null) {
               outputStream = new LogOutputStream(managingTask, Project.MSG_INFO);
  @@ -265,6 +345,11 @@
       
       /**
        * Create the StreamHandler to use with our Execute instance.
  +     *
  +     * @return the execute stream handler to manage the input, output and
  +     * error streams.
  +     * 
  +     * @throws BuildException if the execute stream handler cannot be created.
        */
       public ExecuteStreamHandler createHandler() throws BuildException {
           createStreams();
  @@ -272,8 +357,9 @@
       }
      
       /**
  -     * Pass output sent to System.out to specified output file.
  +     * Pass output sent to System.out to specified output.
        *
  +     * @param line the data to be output
        */
       protected void handleOutput(String line) {
           if (outPrintStream == null) {
  @@ -283,8 +369,30 @@
       }
       
       /**
  -     * Pass output sent to System.out to specified output file.
  +     * Handle an input request
  +     *
  +     * @param buffer the buffer into which data is to be read.
  +     * @param offset the offset into the buffer at which data is stored.
  +     * @param length the amount of data to read
  +     *
  +     * @return the number of bytes read
  +     * 
  +     * @exception IOException if the data cannot be read
  +     */
  +    protected int handleInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        if (inputStream == null) {
  +            return managingTask.getProject().defaultInput(buffer, offset, 
  +                                                          length);
  +        } else {
  +            return inputStream.read(buffer, offset, length);
  +        }            
  +    }
  +    
  +    /**
  +     * Process data due to a flush operation.
        *
  +     * @param line the data being flushed.
        */
       protected void handleFlush(String line) {
           if (outPrintStream == null) {
  @@ -294,8 +402,9 @@
       }
       
       /**
  -     * Pass output sent to System.err to specified output file.
  +     * Process error output
        *
  +     * @param line the error output data.
        */
       protected void handleErrorOutput(String line) {
           if (errorPrintStream == null) {
  @@ -305,8 +414,9 @@
       }
       
       /**
  -     * Pass output sent to System.err to specified output file.
  +     * Handle a flush operation on the error stream
        *
  +     * @param line the error information being flushed.
        */
       protected void handleErrorFlush(String line) {
           if (errorPrintStream == null) {
  @@ -315,15 +425,45 @@
           errorPrintStream.print(line);
       }
   
  +    /**
  +     * Get the output stream for the redirector
  +     *
  +     * @return the redirector's output stream or null if no output 
  +     *         has been configured
  +     */
       public OutputStream getOutputStream() {
           return outputStream;
       }
       
  +    /**
  +     * Get the error stream for the redirector
  +     *
  +     * @return the redirector's error stream or null if no output 
  +     *         has been configured
  +     */
       public OutputStream getErrorStream() {
           return errorStream;
       }
   
  +    /**
  +     * Get the input stream for the redirector
  +     *
  +     * @return the redirector's input stream or null if no output 
  +     *         has been configured
  +     */
  +    public InputStream getInputStream() {
  +        return inputStream;
  +    }
       
  +    /**
  +     * Complete redirection. 
  +     *
  +     * This opertaion will close any streams and create any specified
  +     * property values.
  +     *
  +     * @throws IOException if the outptu properties cannot be read from their
  +     * output streams.
  +     */
       public void complete() throws IOException {
           System.out.flush();
           System.err.flush();
  
  
  
  1.56      +16 -1     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  
  Index: JUnitTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -w -u -r1.55 -r1.56
  --- JUnitTask.java	31 Jan 2003 07:57:41 -0000	1.55
  +++ JUnitTask.java	9 Feb 2003 07:59:53 -0000	1.56
  @@ -714,6 +714,21 @@
       }
   
       /**
  +     * @see Task#handleInput(byte[], int, int)
  +     * 
  +     * @since Ant 1.6
  +     */
  +    protected int handleInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        if (runner != null) {
  +            return runner.handleInput(buffer, offset, length);
  +        } else {
  +            return super.handleInput(buffer, offset, length);
  +        }
  +    }
  +    
  +    
  +    /**
        * Pass output sent to System.out to the TestRunner so it can
        * collect ot for the formatters.
        *
  
  
  
  1.30      +5 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
  
  Index: JUnitTestRunner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -w -u -r1.29 -r1.30
  --- JUnitTestRunner.java	31 Jan 2003 07:57:42 -0000	1.29
  +++ JUnitTestRunner.java	9 Feb 2003 07:59:53 -0000	1.30
  @@ -410,6 +410,11 @@
           }
       }
       
  +    protected int handleInput(byte[] buffer, int offset, int length) 
  +        throws IOException {
  +        return -1;
  +    }
  +    
       protected void handleErrorOutput(String line) {
           if (systemError != null) {
               systemError.println(line);
  
  
  
  1.4       +2 -1      jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/DemuxOutputTask.java
  
  Index: DemuxOutputTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/DemuxOutputTask.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- DemuxOutputTask.java	25 Feb 2002 04:33:25 -0000	1.3
  +++ DemuxOutputTask.java	9 Feb 2003 07:59:53 -0000	1.4
  @@ -56,9 +56,10 @@
   import org.apache.tools.ant.*;
   import org.apache.tools.ant.BuildFileTest;
   import java.util.Random;
  +
   /**
    * A simple task that prints to System.out and System.err and then catches
  - * the output which it then check. If the output does not match, an
  + * the output which it then checks. If the output does not match, an
    * exception is thrown
    *
    * @since 1.5
  
  
  

Mime
View raw message