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/proposal/mutant/src/java/start/org/apache/tools/ant Main.java
Date Mon, 25 Feb 2002 13:28:58 GMT
conor       02/02/25 05:28:58

  Modified:    proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution
                        BuildEventSupport.java ComponentManager.java
                        ExecutionManager.java Frame.java
               proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser
                        ProjectHandler.java
               proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant
                        Task.java
               proposal/mutant/src/java/cli/org/apache/ant/cli
                        Commandline.java
               proposal/mutant/src/java/common/org/apache/ant/common/antlib
                        AbstractTask.java AntLibFactory.java
                        StandardLibFactory.java Task.java
               proposal/mutant/src/java/common/org/apache/ant/common/model
                        Project.java
  Added:       proposal/mutant/src/java/common/org/apache/ant/common/util
                        DemuxOutputReceiver.java DemuxOutputStream.java
               proposal/mutant/src/java/start/org/apache/tools/ant
                        Main.java
  Log:
  IMplement DemuxOutputStreams to capture System.out and System.err usage
  
  Revision  Changes    Path
  1.5       +42 -5     jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/BuildEventSupport.java
  
  Index: BuildEventSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/BuildEventSupport.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -u -r1.4 -r1.5
  --- BuildEventSupport.java	20 Feb 2002 13:43:14 -0000	1.4
  +++ BuildEventSupport.java	25 Feb 2002 13:28:57 -0000	1.5
  @@ -54,12 +54,15 @@
   package org.apache.ant.antcore.execution;
   import java.util.ArrayList;
   import java.util.Iterator;
  -
  +import java.util.Map;
  +import java.util.HashMap;
   import java.util.List;
  -import org.apache.ant.common.model.ModelElement;
  -import org.apache.ant.common.event.BuildListener;
  -import org.apache.ant.common.event.BuildEvent;
   import org.apache.ant.common.antlib.Task;
  +import org.apache.ant.common.event.BuildEvent;
  +import org.apache.ant.common.event.BuildListener;
  +import org.apache.ant.common.model.ModelElement;
  +import org.apache.ant.common.util.DemuxOutputReceiver;
  +import org.apache.ant.common.event.MessageLevel;
   
   /**
    * BuildEventSupport is used by classes which which to send build events to
  @@ -68,13 +71,16 @@
    * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
    * @created 15 January 2002
    */
  -public class BuildEventSupport {
  +public class BuildEventSupport implements DemuxOutputReceiver {
       /**
        * The listeners attached to the object which contains this support
        * object
        */
       private List listeners = new ArrayList();
   
  +    /** Records the latest task to be executed on a thread (Thread to Task). */
  +    private Map threadTasks = new HashMap();
  +
       /**
        * Gets the listeners of the BuildEventSupport
        *
  @@ -166,6 +172,9 @@
        * @param task the task with which the event is associated
        */
       public void fireTaskStarted(Task task) {
  +        synchronized (this) {
  +            threadTasks.put(Thread.currentThread(), task);
  +        }
           BuildEvent event = new BuildEvent(task, BuildEvent.TASK_STARTED);
           for (Iterator i = listeners.iterator(); i.hasNext(); ) {
               BuildListener listener = (BuildListener)i.next();
  @@ -181,6 +190,11 @@
        */
       public void fireTaskFinished(Task task,
                                    Throwable cause) {
  +        System.out.flush();
  +        System.err.flush();
  +        synchronized (this) {
  +            threadTasks.remove(Thread.currentThread());
  +        }
           BuildEvent event = new BuildEvent(task, BuildEvent.TASK_FINISHED,
               cause);
           for (Iterator i = listeners.iterator(); i.hasNext(); ) {
  @@ -202,6 +216,29 @@
           for (Iterator i = listeners.iterator(); i.hasNext(); ) {
               BuildListener listener = (BuildListener)i.next();
               listener.messageLogged(event);
  +        }
  +    }
  +
  +    /**
  +     * Demultiplexes output so that each task receives the appropriate
  +     * messages. If the current thread is not currently executing a task,
  +     * the message is logged directly.
  +     *
  +     * @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>).
  +     */
  +    public void threadOutput(String line, boolean isError) {
  +        Task task = (Task)threadTasks.get(Thread.currentThread());
  +        if (task == null) {
  +            fireMessageLogged(this, line, 
  +                isError ? MessageLevel.MSG_ERR : MessageLevel.MSG_INFO);
  +        } else {
  +            if (isError) {
  +                task.handleSystemErr(line);
  +            } else {
  +                task.handleSystemOut(line);
  +            }
           }
       }
   }
  
  
  
  1.7       +5 -0      jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java
  
  Index: ComponentManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -u -r1.6 -r1.7
  --- ComponentManager.java	20 Feb 2002 13:43:14 -0000	1.6
  +++ ComponentManager.java	25 Feb 2002 13:28:57 -0000	1.7
  @@ -422,7 +422,12 @@
            throws ExecutionException {
   
           ImportInfo definition = getDefinition(componentName);
  +        if (definition == null) {
  +            throw new ExecutionException("There is no definition of the <"
  +                + componentName + "> component");
  +        }
           String className = definition.getClassName();
  +            
           ComponentLibrary componentLibrary
                = definition.getComponentLibrary();
           String localName = definition.getLocalName();
  
  
  
  1.10      +14 -1     jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java
  
  Index: ExecutionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -w -u -r1.9 -r1.10
  --- ExecutionManager.java	19 Feb 2002 02:12:21 -0000	1.9
  +++ ExecutionManager.java	25 Feb 2002 13:28:57 -0000	1.10
  @@ -64,6 +64,7 @@
   import org.apache.ant.common.model.Project;
   import org.apache.ant.common.util.AntException;
   import org.apache.ant.common.util.ExecutionException;
  +import org.apache.ant.common.util.DemuxOutputReceiver;
   import org.apache.ant.init.InitConfig;
   
   /**
  @@ -75,7 +76,7 @@
    * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
    * @created 12 January 2002
    */
  -public class ExecutionManager {
  +public class ExecutionManager implements DemuxOutputReceiver {
       /** The AntLibraries built from Ant's Populated Task Libraries. */
       private Map antLibraries = new HashMap();
   
  @@ -210,6 +211,18 @@
           if (mainFrame != null) {
               mainFrame.removeBuildListener(listener);
           }
  +    }
  +
  +    /**
  +     * Handle the content from a single thread. This method will be called
  +     * by the thread producing the content. The content is broken up into
  +     * separate lines
  +     *
  +     * @param line the content produce by the current thread.
  +     * @param isErr true if this content is from the thread's error stream.
  +     */
  +    public void threadOutput(String line, boolean isErr) {
  +        eventSupport.threadOutput(line, isErr);
       }
   
   }
  
  
  
  1.7       +31 -21    jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java
  
  Index: Frame.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -u -r1.6 -r1.7
  --- Frame.java	20 Feb 2002 13:43:14 -0000	1.6
  +++ Frame.java	25 Feb 2002 13:28:57 -0000	1.7
  @@ -74,6 +74,7 @@
   import org.apache.ant.common.service.MagicProperties;
   import org.apache.ant.common.util.AntException;
   import org.apache.ant.common.util.ConfigException;
  +import org.apache.ant.common.util.DemuxOutputReceiver;
   import org.apache.ant.common.util.ExecutionException;
   import org.apache.ant.common.util.FileUtils;
   import org.apache.ant.init.InitConfig;
  @@ -86,7 +87,7 @@
    * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
    * @created 14 January 2002
    */
  -public class Frame {
  +public class Frame implements DemuxOutputReceiver {
       /** the base dir of the project */
       private File baseDir;
   
  @@ -143,9 +144,7 @@
        */
       private ComponentManager componentManager;
   
  -    /**
  -     * The core's execution Service
  -     */
  +    /** The core's execution Service  */
       private CoreExecService execService;
       
       /**
  @@ -166,6 +165,18 @@
       }
   
       /**
  +     * Replace ${} style constructions in the given value with the string
  +     * value of the corresponding data values in the frame
  +     *
  +     * @param value the string to be scanned for property references.
  +     * @return the string with all property references replaced
  +     * @exception ExecutionException if any of the properties do not exist
  +     */
  +    public String replacePropertyRefs(String value) throws ExecutionException {
  +        return dataService.replacePropertyRefs(value);
  +    }
  +
  +    /**
        * Sets the Project of the Frame
        *
        * @param project The new Project value
  @@ -190,18 +201,6 @@
       }
   
       /**
  -     * Replace ${} style constructions in the given value with the string
  -     * value of the corresponding data values in the frame
  -     *
  -     * @param value the string to be scanned for property references.
  -     * @return the string with all property references replaced
  -     * @exception ExecutionException if any of the properties do not exist
  -     */
  -    public String replacePropertyRefs(String value) throws ExecutionException {
  -        return dataService.replacePropertyRefs(value);
  -    }
  -    
  -    /**
        * Set a value in this frame or any of its imported frames.
        *
        * @param name the name of the value
  @@ -603,7 +602,6 @@
           } catch (ConfigException e) {
               throw new ExecutionException(e);
           }
  -
       }
   
       /**
  @@ -710,6 +708,18 @@
       }
   
       /**
  +     * Handle the content from a single thread. This method will be called
  +     * by the thread producing the content. The content is broken up into
  +     * separate lines
  +     *
  +     * @param line the content produce by the current thread.
  +     * @param isErr true if this content is from the thread's error stream.
  +     */
  +    public void threadOutput(String line, boolean isErr) {
  +        eventSupport.threadOutput(line, isErr);
  +    }
  +
  +    /**
        * Determine the base directory for each frame in the frame hierarchy
        *
        * @exception ExecutionException if the base directories cannot be
  
  
  
  1.3       +18 -5     jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/ProjectHandler.java
  
  Index: ProjectHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/ProjectHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -u -r1.2 -r1.3
  --- ProjectHandler.java	18 Feb 2002 12:36:04 -0000	1.2
  +++ ProjectHandler.java	25 Feb 2002 13:28:57 -0000	1.3
  @@ -76,6 +76,15 @@
       /** The default attribute name */
       public static final String DEFAULT_ATTR = "default";
   
  +    /** The name of the element used to define references */
  +    public static final String REF_ELEMENT = "ant:ref";
  +    
  +    /** The name of the element used to define references */
  +    public static final String INCLUDE_ELEMENT = "ant:include";
  +    
  +    /** The name of the element used to define references */
  +    public static final String TARGET_ELEMENT = "target";
  +
       /** The project being parsed. */
       private Project project;
   
  @@ -149,7 +158,7 @@
                                Attributes attributes)
            throws SAXParseException {
                
  -        if (qualifiedName.equals("ref")) {
  +        if (qualifiedName.equals(REF_ELEMENT)) {
               RefHandler refHandler = new RefHandler();
               refHandler.start(getParseContext(), getXMLReader(), this,
                   getLocator(), attributes, getElementSource(),
  @@ -160,12 +169,12 @@
               } catch (ModelException e) {
                   throw new SAXParseException(e.getMessage(), getLocator(), e);
               }
  -        } else if (qualifiedName.equals("include")) {
  +        } else if (qualifiedName.equals(INCLUDE_ELEMENT)) {
               IncludeHandler includeHandler = new IncludeHandler(project);
               includeHandler.start(getParseContext(), getXMLReader(),
                   this, getLocator(), attributes, getElementSource(),
                   qualifiedName);
  -        } else if (qualifiedName.equals("target")) {
  +        } else if (qualifiedName.equals(TARGET_ELEMENT)) {
               TargetHandler targetHandler = new TargetHandler();
               targetHandler.start(getParseContext(), getXMLReader(),
                   this, getLocator(), attributes,
  @@ -175,13 +184,17 @@
               } catch (ModelException e) {
                   throw new SAXParseException(e.getMessage(), getLocator(), e);
               }
  -        } else {
  +        } else if (localName != null) {
               // everything else is a task
               BuildElementHandler buildElementHandler = new BuildElementHandler();
               buildElementHandler.start(getParseContext(), getXMLReader(),
                   this, getLocator(), attributes, getElementSource(),
                   qualifiedName);
               project.addTask(buildElementHandler.getBuildElement());
  +        } else {
  +          // ignore namespaced elements
  +          throw new SAXParseException("Only the \"ant\" namespace is "
  +            + "currently recognized (" + qualifiedName + ")", getLocator());
           }
       }
   
  
  
  
  1.6       +25 -0     jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Task.java
  
  Index: Task.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Task.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -u -r1.5 -r1.6
  --- Task.java	20 Feb 2002 13:43:15 -0000	1.5
  +++ Task.java	25 Feb 2002 13:28:57 -0000	1.6
  @@ -165,6 +165,31 @@
       }
   
       /**
  +     * Handle Output produced by the task. When a task prints to System.out
  +     * the container may catch this and redirect the content back to the
  +     * task by invoking this method. This method must NOT call System.out,
  +     * directly or indirectly.
  +     *
  +     * @param line The line of content produce by the task
  +     */
  +    public void handleSystemOut(String line) {
  +        handleOutput(line);
  +    }
  +
  +    /**
  +     * Handle error information produced by the task. When a task prints to
  +     * System.err the container may catch this and redirect the content back
  +     * to the task by invoking this method. This method must NOT call
  +     * System.err, directly or indirectly.
  +     *
  +     * @param line The line of error info produce by the task
  +     */
  +    public void handleSystemErr(String line) {
  +        // default behaviout is to log at WARN level
  +        handleErrorOutput(line);
  +    }
  +
  +    /**
        * Handle output captured for this task
        *
        * @param line the captured output
  
  
  
  1.11      +8 -0      jakarta-ant/proposal/mutant/src/java/cli/org/apache/ant/cli/Commandline.java
  
  Index: Commandline.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/cli/org/apache/ant/cli/Commandline.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -w -u -r1.10 -r1.11
  --- Commandline.java	19 Feb 2002 02:12:21 -0000	1.10
  +++ Commandline.java	25 Feb 2002 13:28:57 -0000	1.11
  @@ -57,6 +57,7 @@
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.PrintStream;
  +import java.io.OutputStream;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.ArrayList;
  @@ -75,6 +76,7 @@
   import org.apache.ant.common.event.MessageLevel;
   import org.apache.ant.common.model.Project;
   import org.apache.ant.common.util.ConfigException;
  +import org.apache.ant.common.util.DemuxOutputStream;
   import org.apache.ant.init.InitConfig;
   import org.apache.ant.init.InitUtils;
   
  @@ -298,6 +300,12 @@
   
               // create the execution manager to execute the build
               executionManager = new ExecutionManager(initConfig, config);
  +            OutputStream demuxOut
  +                = new DemuxOutputStream(executionManager, false);
  +            OutputStream demuxErr
  +                = new DemuxOutputStream(executionManager, true);
  +            System.setOut(new PrintStream(demuxOut));
  +            System.setErr(new PrintStream(demuxErr));
               addBuildListeners(executionManager);
           } catch (Throwable e) {
               if (logger != null) {
  
  
  
  1.4       +26 -0     jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractTask.java
  
  Index: AbstractTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractTask.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- AbstractTask.java	20 Feb 2002 13:43:15 -0000	1.3
  +++ AbstractTask.java	25 Feb 2002 13:28:57 -0000	1.4
  @@ -52,6 +52,7 @@
    * <http://www.apache.org/>.
    */
   package org.apache.ant.common.antlib;
  +import org.apache.ant.common.event.MessageLevel;
   
   /**
    * Abstract implementation of the Task interface
  @@ -81,5 +82,30 @@
           return taskName;
       }
   
  +    /**
  +     * Handle Output produced by the task. When a task prints to System.out
  +     * the container may catch this and redirect the content back to the
  +     * task by invoking this method. This method must NOT call System.out,
  +     * directly or indirectly.
  +     *
  +     * @param line The line of content produce by the task
  +     */
  +    public void handleSystemOut(String line) {
  +        // default behaviout is to log at INFO level
  +        log(line, MessageLevel.MSG_INFO);
  +    }
  +
  +    /**
  +     * Handle error information produced by the task. When a task prints to
  +     * System.err the container may catch this and redirect the content back
  +     * to the task by invoking this method. This method must NOT call
  +     * System.err, directly or indirectly.
  +     *
  +     * @param line The line of error info produce by the task
  +     */
  +    public void handleSystemErr(String line) {
  +        // default behaviout is to log at WARN level
  +        log(line, MessageLevel.MSG_WARN);
  +    }
   }
   
  
  
  
  1.5       +118 -118  jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntLibFactory.java
  
  Index: AntLibFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntLibFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -u -r1.4 -r1.5
  
  
  
  1.5       +135 -135  jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/StandardLibFactory.java
  
  Index: StandardLibFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/StandardLibFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -u -r1.4 -r1.5
  
  
  
  1.3       +20 -0     jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/Task.java
  
  Index: Task.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/Task.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -u -r1.2 -r1.3
  --- Task.java	20 Feb 2002 13:43:15 -0000	1.2
  +++ Task.java	25 Feb 2002 13:28:58 -0000	1.3
  @@ -81,5 +81,25 @@
        * @return the taskName value
        */
       String getTaskName();
  +
  +    /**
  +     * Handle Output produced by the task. When a task prints to System.out
  +     * the container may catch this and redirect the content back to the
  +     * task by invoking this method. This method must NOT call System.out,
  +     * directly or indirectly.
  +     *
  +     * @param line The line of content produce by the task
  +     */
  +    void handleSystemOut(String line);
  +
  +    /**
  +     * Handle error information produced by the task. When a task prints to
  +     * System.err the container may catch this and redirect the content back
  +     * to the task by invoking this method. This method must NOT call
  +     * System.err, directly or indirectly.
  +     *
  +     * @param line The line of error info produce by the task
  +     */
  +    void handleSystemErr(String line);
   }
   
  
  
  
  1.3       +25 -14    jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/model/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/model/Project.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -u -r1.2 -r1.3
  --- Project.java	18 Feb 2002 12:36:05 -0000	1.2
  +++ Project.java	25 Feb 2002 13:28:58 -0000	1.3
  @@ -253,9 +253,16 @@
        *
        * @param fullTargetName The name of the target relative to this project
        * @return the Target object with the given name
  +     * @exception ModelException if the given target does not exist in this
  +     *      project
        */
  -    public Target getRefTarget(String fullTargetName) {
  +    public Target getRefTarget(String fullTargetName) throws ModelException {
           Project containingProject = getRefProject(fullTargetName);
  +        if (containingProject == null) {
  +            throw new ModelException("The target name \"" + fullTargetName
  +                 + "\" does not exist in this project");
  +        }
  +
           if (containingProject == this) {
               return getTarget(fullTargetName);
           }
  @@ -504,6 +511,7 @@
           if (flattenedList.contains(fullTargetName)) {
               return;
           }
  +        try {
           String fullProjectName = getFullProjectName(fullTargetName);
           Target target = getRefTarget(fullTargetName);
           if (target == null) {
  @@ -517,6 +525,9 @@
                    : fullProjectName + REF_DELIMITER + localDependencyName;
               flattenDependency(flattenedList, fullDependencyName);
               flattenedList.add(fullDependencyName);
  +            }
  +        } catch (ModelException e) {
  +            throw new ConfigException(e);
           }
       }
   }
  
  
  
  1.1                  jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/util/DemuxOutputReceiver.java
  
  Index: DemuxOutputReceiver.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 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.ant.common.util;
  
  /**
   * A Demux output receiver receives buffered content which has been
   * demultiplexed from the output potentially generated by multiple threads
   *
   * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
   * @created 22 February 2002
   */
  public interface DemuxOutputReceiver {
      /**
       * Handle the content from a single thread. This method will be called
       * by the thread producing the content. The content is broken up into
       * separate lines
       *
       * @param line the content produce by the current thread.
       * @param isErr true if this content is from the thread's error stream.
       */
      void threadOutput(String line, boolean isErr);
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/util/DemuxOutputStream.java
  
  Index: DemuxOutputStream.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 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.ant.common.util;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  
  import java.io.OutputStream;
  import java.util.Hashtable;
  
  /**
   * Buffers content written per thread and forwards the buffers onto the
   * given receiver
   *
   * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
   * @created 22 February 2002
   */
  public class DemuxOutputStream extends OutputStream {
  
      /**
       * A data class to store information about a buffer. Such informatio is
       * stored on a per-thread basis.
       *
       * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
       * @created 22 February 2002
       */
      private static class BufferInfo {
          /** The per-thread output stream  */
          private ByteArrayOutputStream buffer;
  
          /**
           * Whether the next line-terminator should be skipped in terms of
           * processing the buffer or not. Used to avoid \r\n invoking
           * processBuffer twice.
           */
          private boolean skip = false;
      }
  
      /** Maximum buffer size */
      private static final int MAX_SIZE = 1024;
      /** Mapping from thread to buffer (Thread to BufferInfo) */
      private Hashtable buffers = new Hashtable();
  
      /** The object which receives the output  */
      private DemuxOutputReceiver receiver;
  
      /** Whether or not this stream represents an error stream  */
      private boolean isErrorStream;
  
      /**
       * Creates a new instance of this class.
       *
       * @param isErrorStream true if this is the error string, otherwise a
       *      normal output stream. This is passed to the project so it knows
       *      which stream it is receiving.
       * @param receiver The receiver to which demux'd content is sent.
       */
      public DemuxOutputStream(DemuxOutputReceiver receiver,
          boolean isErrorStream) {
          this.receiver = receiver;
          this.isErrorStream = isErrorStream;
      }
  
      /**
       * Writes the data to the buffer and flushes the buffer if a line
       * separator is detected or if the buffer has reached its maximum size.
       *
       * @param cc data to log (byte).
       * @exception IOException if the data cannot be written to the stream
       */
      public void write(int cc) throws IOException {
          final byte c = (byte)cc;
  
          BufferInfo bufferInfo = getBufferInfo();
          if ((c == '\n') || (c == '\r')) {
              if (!bufferInfo.skip) {
                  processBuffer(bufferInfo.buffer);
              }
          } else {
              bufferInfo.buffer.write(cc);
              if (bufferInfo.buffer.size() > MAX_SIZE) {
                  processBuffer(bufferInfo.buffer);
              }
          }
          bufferInfo.skip = (c == '\r');
      }
  
      /**
       * Equivalent to calling {@link #flush flush} on the stream.
       *
       * @exception IOException if there is a problem closing the stream.
       */
      public void close() throws IOException {
          flush();
      }
  
      /**
       * Writes all remaining data in the buffer associated with the current
       * thread to the project.
       *
       * @exception IOException if there is a problem flushing the stream.
       */
      public void flush() throws IOException {
          BufferInfo bufferInfo = getBufferInfo();
          if (bufferInfo.buffer.size() > 0) {
              processBuffer(bufferInfo.buffer);
          }
      }
  
  
      /**
       * Converts the buffer to a string and sends it to {@link
       * Project#demuxOutput(String,boolean) Project.demuxOutput}.
       *
       * @param buffer the ByteArrayOutputStream used to collect the output
       *      until a line separator is seen.
       */
      protected void processBuffer(ByteArrayOutputStream buffer) {
          String output = buffer.toString();
          receiver.threadOutput(output, isErrorStream);
          resetBufferInfo();
      }
  
      /**
       * Returns the buffer associated with the current thread.
       *
       * @return a ByteArrayOutputStream for the current thread to write data
       *      to
       */
      private BufferInfo getBufferInfo() {
          Thread current = Thread.currentThread();
          BufferInfo bufferInfo = (BufferInfo)buffers.get(current);
          if (bufferInfo == null) {
              bufferInfo = new BufferInfo();
              bufferInfo.buffer = new ByteArrayOutputStream();
              bufferInfo.skip = false;
              buffers.put(current, bufferInfo);
          }
          return bufferInfo;
      }
  
      /** Resets the buffer for the current thread.  */
      private void resetBufferInfo() {
          Thread current = Thread.currentThread();
          buffers.remove(current);
      }
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/mutant/src/java/start/org/apache/tools/ant/Main.java
  
  Index: Main.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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;
  
  /**
   * Old Ant1 entry point
   *
   * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
   */
  public class Main {
     /**
       * Entry point for starting command line Ant
       *
       * @param args commandline arguments
       */
      public static void main(String[] args) {
          org.apache.ant.start.Main.main(args);
      }
  }
  
  
  
  

--
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