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/common/org/apache/ant/common/service ExecService.java
Date Tue, 09 Apr 2002 11:42:40 GMT
conor       02/04/09 04:42:40

  Modified:    proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution
                        CoreExecService.java Frame.java
               proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system
                        Ant.java AntBase.java AntCall.java
               proposal/mutant/src/java/common/org/apache/ant/common/service
                        ExecService.java
  Added:       proposal/mutant/src/java/common/org/apache/ant/common/event
                        BuildListenerAdapter.java
  Log:
  Output management
  
  Revision  Changes    Path
  1.8       +166 -107  jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreExecService.java
  
  Index: CoreExecService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/CoreExecService.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -u -r1.7 -r1.8
  --- CoreExecService.java	7 Apr 2002 14:38:06 -0000	1.7
  +++ CoreExecService.java	9 Apr 2002 11:42:40 -0000	1.8
  @@ -54,6 +54,7 @@
   package org.apache.ant.antcore.execution;
   import java.io.File;
   import java.net.MalformedURLException;
  +import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
   import org.apache.ant.antcore.modelparser.XMLProjectParser;
  @@ -73,9 +74,14 @@
    * @created 8 February 2002
    */
   public class CoreExecService implements ExecService {
  +
       /** The Frame this service instance is working for */
       private Frame frame;
   
  +    /** A map of subbuild keys to the frame of the subbuild. */
  +    private Map subBuilds = new HashMap();
  +
  +
       /**
        * Constructor
        *
  @@ -85,65 +91,17 @@
           this.frame = frame;
       }
   
  -    /**
  -     * Run a sub-build.
  -     *
  -     * @param antFile the file containing the XML description of the model
  -     * @param targets A list of targets to be run
  -     * @param properties the initiali properties to be used in the build
  -     * @exception ExecutionException if the subbuild cannot be run
  -     */
  -    public void runBuild(File antFile, Map properties, List targets)
  -         throws ExecutionException {
  -        try {
  -            // Parse the build file into a project
  -            XMLProjectParser parser = new XMLProjectParser();
  -            Project project
  -                 = parser.parseBuildFile(InitUtils.getFileURL(antFile));
  -            runBuild(project, properties, targets);
  -        } catch (MalformedURLException e) {
  -            throw new ExecutionException(e);
  -        } catch (XMLParseException e) {
  -            throw new ExecutionException(e);
  -        }
  -    }
  -
  -    /**
  -     * Run a sub-build.
  -     *
  -     * @param model the project model to be used for the build
  -     * @param targets A list of targets to be run
  -     * @param properties the initiali properties to be used in the build
  -     * @exception ExecutionException if the subbuild cannot be run
  -     */
  -    public void runBuild(Project model, Map properties, List targets)
  -         throws ExecutionException {
  -        Frame newFrame = frame.createFrame(model);
  -        newFrame.setInitialProperties(properties);
  -        newFrame.runBuild(targets);
  -    }
  -
  -    /**
  -     * Run a sub-build using the current frame's project model
  -     *
  -     * @param targets A list of targets to be run
  -     * @param properties the initiali properties to be used in the build
  -     * @exception ExecutionException if the subbuild cannot be run
  -     */
  -    public void callTarget(Map properties, List targets)
  -         throws ExecutionException {
  -        runBuild(frame.getProject(), properties, targets);
  -    }
   
       /**
  -     * Execute a task. The task should have already been initialised by
  -     * the core. This is checked
  +     * Execute a task. The task should have already been initialised by the
  +     * core. This is checked
        *
        * @param task the task to be executed
        * @exception ExecutionException if there is an execution problem
        */
       public void executeTask(Task task) throws ExecutionException {
           AntContext context = task.getAntContext();
  +
           if (!(context instanceof ExecutionContext)) {
               throw new ExecutionException("The Task was not configured with an"
                    + " appropriate context");
  @@ -151,16 +109,20 @@
           ExecutionContext execContext = (ExecutionContext) context;
           
           frame.getEventSupport().fireTaskStarted(task);
  +
           Throwable failureCause = null;
  +
           try {
               ClassLoader currentLoader 
                   = LoaderUtils.setContextLoader(execContext.getClassLoader());
  +
               task.execute();
               LoaderUtils.setContextLoader(currentLoader);
           } catch (Throwable e) {
               ExecutionException ee =
                   new ExecutionException(e.getClass().getName() + ": "
                    + e.getMessage(), e);
  +
               failureCause = ee;
               throw ee;
           } finally {
  @@ -168,6 +130,17 @@
           }
       }
   
  +
  +    /**
  +     * Get the base directory for this execution of this frame
  +     *
  +     * @return the base directory
  +     */
  +    public File getBaseDir() {
  +        return frame.getBaseDir();
  +    }
  +
  +
       /**
        * get the name of the project associated with this execution.
        *
  @@ -177,13 +150,99 @@
           return frame.getProjectName();
       }
   
  +
  +    /**
  +     * Handle subbuild output.
  +     *
  +     * @param subbuildKey the core's key for managing the subbuild.
  +     * @param line the content produce by the current thread.
  +     * @param isErr true if this content is from the thread's error stream.
  +     */
  +    public void handleBuildOutput(Object subbuildKey, String line,
  +                                  boolean isErr) throws ExecutionException {
  +        getSubbuildFrame(subbuildKey).threadOutput(line, isErr);                      
               
  +    }
  +
  +
  +    private Frame getSubbuildFrame(Object key) throws ExecutionException {
  +        Frame subFrame = (Frame) subBuilds.get(key);
  +
  +        if (subFrame == null) {
  +            throw new ExecutionException("Could not find execution frame "
  +                 + "for subbuild");
  +        }
  +        return subFrame;
  +    }
  +    
       /**
  -     * Get the base directory for this execution of this frame
  +     * Run a build which have been previously setup
        *
  -     * @return the base directory
  +     * @param targets A list of targets to be run
  +     * @param key Description of the Parameter
  +     * @exception ExecutionException if the build cannot be run
        */
  -    public File getBaseDir() {
  -        return frame.getBaseDir();
  +    public void runBuild(Object key, List targets) throws ExecutionException {
  +        getSubbuildFrame(key).runBuild(targets);
  +        subBuilds.remove(key);
  +    }
  +
  +
  +    /**
  +     * Setup a sub-build.
  +     *
  +     * @param antFile the file containing the XML description of the model
  +     * @param properties the initiali properties to be used in the build
  +     * @return Description of the Return Value
  +     * @exception ExecutionException if the subbuild cannot be run
  +     */
  +    public Object setupBuild(File antFile, Map properties)
  +         throws ExecutionException {
  +        try {
  +            // Parse the build file into a project
  +            XMLProjectParser parser = new XMLProjectParser();
  +            Project project
  +                 = parser.parseBuildFile(InitUtils.getFileURL(antFile));
  +
  +            return setupBuild(project, properties);
  +        } catch (MalformedURLException e) {
  +            throw new ExecutionException(e);
  +        } catch (XMLParseException e) {
  +            throw new ExecutionException(e);
  +        }
  +    }
  +
  +
  +    /**
  +     * Setup a sub-build.
  +     *
  +     * @param model the project model to be used for the build
  +     * @param properties the initiali properties to be used in the build
  +     * @return Description of the Return Value
  +     * @exception ExecutionException if the subbuild cannot be run
  +     */
  +    public Object setupBuild(Project model, Map properties)
  +         throws ExecutionException {
  +        Frame newFrame = frame.createFrame(model);
  +
  +        newFrame.setInitialProperties(properties);
  +
  +        Object key = new Object();
  +
  +        subBuilds.put(key, newFrame);
  +        return key;
  +    }
  +
  +
  +    /**
  +     * Setup a sub-build using the current frame's project model
  +     *
  +     * @param properties the initiali properties to be used in the build
  +     * @return Description of the Return Value
  +     * @exception ExecutionException if the subbuild cannot be run
  +     */
  +    public Object setupBuild(Map properties)
  +         throws ExecutionException {
  +        return setupBuild(frame.getProject(), properties);
       }
   }
   
  
  
  
  1.15      +84 -93    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.14
  retrieving revision 1.15
  diff -u -w -u -r1.14 -r1.15
  --- Frame.java	8 Apr 2002 16:01:24 -0000	1.14
  +++ Frame.java	9 Apr 2002 11:42:40 -0000	1.15
  @@ -151,10 +151,9 @@
       /**
        * Create an Execution Frame for the given project
        *
  -     * @param standardLibs            The libraries of tasks and types
  -     *      available to this frame
  -     * @param config                  the user config to use for this
  -     *      execution of Ant
  +     * @param standardLibs The libraries of tasks and types available to this
  +     *      frame
  +     * @param config the user config to use for this execution of Ant
        * @param initConfig              Ant's initialisation config
        * @exception ExecutionException  if a component of the library cannot be
        *      imported
  @@ -171,10 +170,8 @@
        * 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
  +     * @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 {
  @@ -253,8 +250,8 @@
       /**
        * Set the initial properties to be used when the frame starts execution
        *
  -     * @param properties              a Map of named properties which may in
  -     *      fact be any object
  +     * @param properties a Map of named properties which may in fact be any
  +     *      object
        * @exception ExecutionException  if the properties cannot be set
        */
       protected void setInitialProperties(Map properties)
  @@ -291,10 +288,9 @@
       /**
        * Get a definition from a referenced frame
        *
  -     * @param definitionName          the name of the definition relative to
  -     *      this frame
  -     * @return                        the appropriate import info object from
  -     *      the referenced frame's imports
  +     * @param definitionName the name of the definition relative to this frame
  +     * @return the appropriate import info object from the referenced frame's
  +     *      imports
        * @exception ExecutionException  if the referenced definition cannot be
        *      found
        */
  @@ -381,8 +377,7 @@
        *
        * @param serviceInterfaceClass   the service interface for which an
        *      implementation is require
  -     * @return                        the core's implementation of the service
  -     *      interface
  +     * @return the core's implementation of the service interface
        * @exception ExecutionException  if the core does not provide an
        *      implementatin of the requested interface
        */
  @@ -423,8 +418,8 @@
        * Get a referenced frame by its reference name
        *
        * @param referenceName  the name under which the frame was imported.
  -     * @return               the Frame asscociated with the given reference
  -     *      name or null if there is no such project.
  +     * @return the Frame asscociated with the given reference name or null if
  +     *      there is no such project.
        */
       protected Frame getReferencedFrame(String referenceName) {
           return (Frame) referencedFrames.get(referenceName);
  @@ -460,10 +455,9 @@
       /**
        * Get a value from this frame or any imported frame
        *
  -     * @param name                    the name of the data value - may contain
  -     *      reference delimiters
  -     * @return                        the data value fetched from the
  -     *      appropriate frame
  +     * @param name the name of the data value - may contain reference
  +     *      delimiters
  +     * @return the data value fetched from the appropriate frame
        * @exception ExecutionException  if the value is not defined
        */
       protected Object getDataValue(String name) throws ExecutionException {
  @@ -484,8 +478,8 @@
       /**
        * Indicate if a data value has been set
        *
  -     * @param name                    the name of the data value - may contain
  -     *      reference delimiters
  +     * @param name the name of the data value - may contain reference
  +     *      delimiters
        * @return                        true if the value exists
        * @exception ExecutionException  if the containing frame for the value
        *      does not exist
  @@ -510,8 +504,8 @@
        * where the name is relative to this frame
        *
        * @param elementName  The name of the element
  -     * @return             the execution frame for the project that contains
  -     *      the given target
  +     * @return the execution frame for the project that contains the given
  +     *      target
        */
       protected Frame getContainingFrame(String elementName) {
           int index = elementName.lastIndexOf(Project.REF_DELIMITER);
  @@ -541,8 +535,8 @@
       /**
        * Add a collection of properties to this frame
        *
  -     * @param properties              the collection of property values,
  -     *      indexed by their names
  +     * @param properties the collection of property values, indexed by their
  +     *      names
        * @exception ExecutionException  if the frame cannot be created.
        */
       protected void addProperties(Map properties) throws ExecutionException {
  @@ -558,8 +552,7 @@
       /**
        * Create a new frame for a given project
        *
  -     * @param project                 the project model the frame will deal
  -     *      with
  +     * @param project the project model the frame will deal with
        * @return                        an Frame ready to build the project
        * @exception ExecutionException  if the frame cannot be created.
        */
  @@ -622,8 +615,7 @@
       /**
        * Run the given list of targets
        *
  -     * @param targets                 a list of target names which are to be
  -     *      evaluated
  +     * @param targets a list of target names which are to be evaluated
        * @exception ExecutionException  if there is a problem in the build
        */
       protected void runBuild(List targets) throws ExecutionException {
  @@ -653,10 +645,9 @@
       /**
        * Execute the tasks of a target in this frame with the given name
        *
  -     * @param targetName              the name of the target whose tasks will
  -     *      be evaluated
  -     * @exception ExecutionException  if there is a problem executing the
  -     *      tasks of the target
  +     * @param targetName the name of the target whose tasks will be evaluated
  +     * @exception ExecutionException if there is a problem executing the tasks
  +     *      of the target
        */
       protected void executeTarget(String targetName) throws ExecutionException {
           // to execute a target we must determine its dependencies and
  @@ -727,8 +718,8 @@
        * Execute the given target's tasks. The target must be local to this
        * frame's project
        *
  -     * @param targetName              the name of the target within this frame
  -     *      that is to be executed.
  +     * @param targetName the name of the target within this frame that is to
  +     *      be executed.
        * @exception ExecutionException  if there is a problem executing tasks
        */
       protected void executeTargetTasks(String targetName)
  
  
  
  1.7       +4 -9      jakarta-ant/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/Ant.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -u -r1.6 -r1.7
  --- Ant.java	7 Apr 2002 14:38:07 -0000	1.6
  +++ Ant.java	9 Apr 2002 11:42:40 -0000	1.7
  @@ -105,11 +105,8 @@
        * @exception ExecutionException if the build can't be run
        */
       public void execute() throws ExecutionException {
  -        System.out.println("Starting Ant Task");
           if (baseDir == null) {
  -            ExecService execService
  -                = (ExecService) getCoreService(ExecService.class);
  -            baseDir = execService.getBaseDir();
  +            baseDir = getExecService().getBaseDir();
           }
           
           File antFile = null;
  @@ -125,11 +122,9 @@
           
           setProperty(MagicProperties.BASEDIR, baseDir.getAbsolutePath());
           
  -        ExecService execService
  -             = (ExecService) getCoreService(ExecService.class);
  -
  -        execService.runBuild(antFile, getProperties(), getTargets());
  -        System.out.println("Ending Ant Task");
  +        Object key = getExecService().setupBuild(antFile, getProperties());
  +        setSubBuildKey(key);
  +        getExecService().runBuild(key, getTargets());
       }
   }
   
  
  
  
  1.5       +221 -136  jakarta-ant/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/AntBase.java
  
  Index: AntBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/AntBase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -u -r1.4 -r1.5
  --- AntBase.java	7 Apr 2002 14:38:07 -0000	1.4
  +++ AntBase.java	9 Apr 2002 11:42:40 -0000	1.5
  @@ -60,6 +60,7 @@
   import org.apache.ant.common.antlib.AbstractTask;
   import org.apache.ant.common.antlib.AntContext;
   import org.apache.ant.common.service.DataService;
  +import org.apache.ant.common.service.ExecService;
   import org.apache.ant.common.util.ExecutionException;
   
   /**
  @@ -85,46 +86,49 @@
   
   
           /**
  -         * Sets the name of the Property
  +         * Gets the name of the Property
            *
  -         * @param name the new name value
  +         * @return the name value
            */
  -        public void setName(String name) {
  -            this.name = name;
  +        public String getName() {
  +            return name;
           }
   
  +
           /**
  -         * Sets the value of the Property
  +         * Gets the value of the Property
            *
  -         * @param value the new value value
  +         * @return the value value
            */
  -        public void setValue(String value) {
  -            this.value = value;
  +        public String getValue() {
  +            return value;
           }
   
  +
           /**
  -         * Gets the name of the Property
  +         * Sets the name of the Property
            *
  -         * @return the name value
  +         * @param name the new name value
            */
  -        public String getName() {
  -            return name;
  +        public void setName(String name) {
  +            this.name = name;
           }
   
  +
           /**
  -         * Gets the value of the Property
  +         * Sets the value of the Property
            *
  -         * @return the value value
  +         * @param value the new value value
            */
  -        public String getValue() {
  -            return value;
  +        public void setValue(String value) {
  +            this.value = value;
           }
   
  +
           /**
            * Validate this data type instance
            *
  -         * @exception ExecutionException if either attribute has not been
  -         *      set
  +         * @exception ExecutionException if either attribute has not been set
            */
           public void validateComponent() throws ExecutionException {
               if (name == null) {
  @@ -138,6 +142,7 @@
           }
       }
   
  +
       /**
        * A simple class to store information about references being passed
        *
  @@ -150,42 +155,47 @@
           /** The id to be used in the sub-build for this reference */
           private String toId;
   
  +
           /**
  -         * Sets the refId of the Reference
  +         * Gets the refId of the Reference
            *
  -         * @param refId the new refId value
  +         * @return the refId value
            */
  -        public void setRefId(String refId) {
  -            this.refId = refId;
  +        public String getRefId() {
  +            return refId;
           }
   
  +
           /**
  -         * Sets the toId of the Reference
  +         * Gets the toId of the Reference
            *
  -         * @param toId the new toId value
  +         * @return the toId value
            */
  -        public void setToId(String toId) {
  -            this.toId = toId;
  +        public String getToId() {
  +            return toId;
           }
   
  +
           /**
  -         * Gets the refId of the Reference
  +         * Sets the refId of the Reference
            *
  -         * @return the refId value
  +         * @param refId the new refId value
            */
  -        public String getRefId() {
  -            return refId;
  +        public void setRefId(String refId) {
  +            this.refId = refId;
           }
   
  +
           /**
  -         * Gets the toId of the Reference
  +         * Sets the toId of the Reference
            *
  -         * @return the toId value
  +         * @param toId the new toId value
            */
  -        public String getToId() {
  -            return toId;
  +        public void setToId(String toId) {
  +            this.toId = toId;
           }
   
  +
           /**
            * Validate this data type instance
            *
  @@ -200,68 +210,36 @@
           }
       }
   
  -    /** The name of the target to be evaluated in the sub-build */
  -    private String targetName;
  +
  +    /** The core's data service for manipulating the properties */
  +    private DataService dataService;
  +
  +    /** The core's ExecutionService for running builds and external programs */
  +    private ExecService execService;
   
       /**
  -     * flag which indicates if all current properties should be passed to
  -     * the subbuild
  +     * flag which indicates if all current properties should be passed to the
  +     * subbuild
        */
       private boolean inheritAll = true;
   
       /**
  -     * flag which indicates if all current references should be passed to
  -     * the subbuild
  +     * flag which indicates if all current references should be passed to the
  +     * subbuild
        */
       private boolean inheritRefs = false;
   
       /** The properties which will be passed to the sub-build */
       private Map properties = new HashMap();
   
  -    /** The core's data service for manipulating the properties */
  -    private DataService dataService;
  -
       /**
  -     * Sets the target to be executed in the subbuild
  -     *
  -     * @param targetName the name of the target to build
  +     * The key to the subbuild with which the Ant task can manage the subbuild
        */
  -    public void setTarget(String targetName) {
  -        this.targetName = targetName;
  -    }
  +    private Object subbuildKey;
   
  -    /**
  -     * Indicate if all properties should be passed
  -     *
  -     * @param inheritAll true if all properties should be passed
  -     */
  -    public void setInheritAll(boolean inheritAll) {
  -        this.inheritAll = inheritAll;
  -    }
  +    /** The name of the target to be evaluated in the sub-build */
  +    private String targetName;
   
  -    /**
  -     * Indicate if all references are to be passed to the subbuild
  -     *
  -     * @param inheritRefs true if the sub-build should be given all the
  -     *      current references
  -     */
  -    public void setInheritRefs(boolean inheritRefs) {
  -        this.inheritRefs = inheritRefs;
  -    }
  -
  -    /**
  -     * Initialise this task
  -     *
  -     * @param context core's context
  -     * @param componentType the component type of this component (i.e its
  -     *      defined name in the build file)
  -     * @exception ExecutionException if we can't access the data service
  -     */
  -    public void init(AntContext context, String componentType)
  -         throws ExecutionException {
  -        super.init(context, componentType);
  -        dataService = (DataService) getCoreService(DataService.class);
  -    }
   
       /**
        * Add a property to be passed to the subbuild
  @@ -272,6 +250,7 @@
           properties.put(property.getName(), property.getValue());
       }
   
  +
       /**
        * Add a reference to be passed
        *
  @@ -281,11 +260,13 @@
        */
       public void addReference(Reference reference) throws ExecutionException {
           String refId = reference.getRefId();
  +
           if (!dataService.isDataValueSet(refId)) {
               throw new ExecutionException("RefId \"" + refId + "\" is not set");
           }
           Object value = dataService.getDataValue(refId);
           String toId = reference.getToId();
  +
           if (toId == null) {
               toId = refId;
           }
  @@ -293,16 +274,35 @@
           properties.put(toId, value);
       }
   
  +
       /**
  -     * Set a property for the subbuild
  +     * Get the core's execution service
        *
  -     * @param propertyName the property name
  -     * @param propertyValue the value of the property
  +     * @return the core's execution service.
        */
  -    protected void setProperty(String propertyName, Object propertyValue) {
  -        properties.put(propertyName, propertyValue);
  +    protected ExecService getExecService() {
  +        return execService;
  +    }
  +
  +
  +    /**
  +     * Get the properties to be used with the sub-build
  +     *
  +     * @return the properties the sub-build will start with
  +     */
  +    protected Map getProperties() {
  +        if (!inheritAll) {
  +            return properties;
  +        }
  +
  +        // need to combine existing properties with new ones
  +        Map subBuildProperties = dataService.getAllProperties();
  +
  +        subBuildProperties.putAll(properties);
  +        return subBuildProperties;
       }
   
  +
       /**
        * Get the list of targets to be executed
        *
  @@ -310,27 +310,112 @@
        */
       protected List getTargets() {
           List targets = new ArrayList();
  +
           if (targetName != null) {
               targets.add(targetName);
           }
           return targets;
       }
   
  +
       /**
  -     * Get the properties to be used with the sub-build
  +     * 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.
        *
  -     * @return the properties the sub-build will start with
  +     * @param line The line of error info produce by the task
        */
  -    protected Map getProperties() {
  -        if (!inheritAll) {
  -            return properties;
  +    public void handleSystemErr(String line) {
  +        if (subbuildKey == null) {
  +            super.handleSystemErr(line);
  +        } else {
  +        }
           }
   
  -        // need to combine existing properties with new ones
  -        Map subBuildProperties = dataService.getAllProperties();
  -        subBuildProperties.putAll(properties);
  -        return subBuildProperties;
  +
  +    /**
  +     * 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) {
  +        if (subbuildKey == null) {
  +            super.handleSystemOut(line);
  +        } else {
       }
  +    }
  +
   
  +    /**
  +     * Initialise this task
  +     *
  +     * @param context core's context
  +     * @param componentType the component type of this component (i.e its
  +     *      defined name in the build file)
  +     * @exception ExecutionException if we can't access the data service
  +     */
  +    public void init(AntContext context, String componentType)
  +         throws ExecutionException {
  +        super.init(context, componentType);
  +        dataService = (DataService) getCoreService(DataService.class);
  +        execService = (ExecService) getCoreService(ExecService.class);
  +
  +    }
  +
  +
  +    /**
  +     * Indicate if all properties should be passed
  +     *
  +     * @param inheritAll true if all properties should be passed
  +     */
  +    public void setInheritAll(boolean inheritAll) {
  +        this.inheritAll = inheritAll;
  +    }
  +
  +
  +    /**
  +     * Indicate if all references are to be passed to the subbuild
  +     *
  +     * @param inheritRefs true if the sub-build should be given all the
  +     *      current references
  +     */
  +    public void setInheritRefs(boolean inheritRefs) {
  +        this.inheritRefs = inheritRefs;
  +    }
  +
  +
  +    /**
  +     * Set a property for the subbuild
  +     *
  +     * @param propertyName the property name
  +     * @param propertyValue the value of the property
  +     */
  +    protected void setProperty(String propertyName, Object propertyValue) {
  +        properties.put(propertyName, propertyValue);
  +    }
  +
  +
  +    /**
  +     * Set the key of the subbuild
  +     *
  +     * @param key the key returned by the Ant core for managing the subbuild
  +     */
  +    protected void setSubBuildKey(Object key) {
  +        this.subbuildKey = key;
  +    }
  +
  +
  +    /**
  +     * Sets the target to be executed in the subbuild
  +     *
  +     * @param targetName the name of the target to build
  +     */
  +    public void setTarget(String targetName) {
  +        this.targetName = targetName;
  +    }
   }
   
  
  
  
  1.6       +4 -4      jakarta-ant/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/AntCall.java
  
  Index: AntCall.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/AntCall.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -u -r1.5 -r1.6
  --- AntCall.java	7 Apr 2002 14:38:07 -0000	1.5
  +++ AntCall.java	9 Apr 2002 11:42:40 -0000	1.6
  @@ -69,12 +69,12 @@
        * @exception ExecutionException if the build fails
        */
       public void execute() throws ExecutionException {
  -        ExecService execService
  -             = (ExecService) getCoreService(ExecService.class);
           setProperty(MagicProperties.BASEDIR, 
  -            execService.getBaseDir().getAbsolutePath());
  +            getExecService().getBaseDir().getAbsolutePath());
   
  -        execService.callTarget(getProperties(), getTargets());
  +        Object key = getExecService().setupBuild(getProperties());
  +        setSubBuildKey(key);
  +        getExecService().runBuild(key, getTargets());
       }
   
       /**
  
  
  
  1.1                  jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildListenerAdapter.java
  
  Index: BuildListenerAdapter.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.ant.common.event;
  
  /**
   * Abstract adapter for build listeners which don't want to implement all of
   * the BuildListener methods
   *
   * @author    Conor MacNeill
   * @created   9 April 2002
   */
  public abstract class BuildListenerAdapter implements BuildListener {
      /**
       * Fired before any targets are started.
       *
       * @param event  the build event for this notification
       */
      public void buildStarted(BuildEvent event) {
      }
  
  
      /**
       * Fired after the last target has finished. This event will still be
       * thrown if an error occured during the build.
       *
       * @param event  the build event for this notification
       */
      public void buildFinished(BuildEvent event) {
      }
  
  
  
      /**
       * Fired when a target is started.
       *
       * @param event  the build event for this notification
       */
      public void targetStarted(BuildEvent event) {
      }
  
  
  
      /**
       * Fired when a target has finished. This event will still be thrown if an
       * error occured during the build.
       *
       * @param event  the build event for this notification
       */
      public void targetFinished(BuildEvent event) {
      }
  
  
  
      /**
       * Fired when a task is started.
       *
       * @param event  the build event for this notification
       */
      public void taskStarted(BuildEvent event) {
      }
  
  
  
      /**
       * Fired when a task has finished. This event will still be throw if an
       * error occured during the build.
       *
       * @param event  the build event for this notification
       */
      public void taskFinished(BuildEvent event) {
      }
  
  
  
      /**
       * Fired whenever a message is logged.
       *
       * @param event  the build event for this notification
       */
      public void messageLogged(BuildEvent event) {
      }
  
  }
  
  
  
  
  1.6       +31 -12    jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/service/ExecService.java
  
  Index: ExecService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/service/ExecService.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -u -r1.5 -r1.6
  --- ExecService.java	3 Apr 2002 06:15:41 -0000	1.5
  +++ ExecService.java	9 Apr 2002 11:42:40 -0000	1.6
  @@ -67,38 +67,47 @@
    */
   public interface ExecService {
       /**
  -     * Run a sub-build.
  +     * Setup a sub-build.
        *
        * @param antFile the file containing the XML description of the model
  -     * @param targets A list of targets to be run
        * @param properties the initiali properties to be used in the build
  -     * @exception ExecutionException if the subbuild cannot be run
  +     * @exception ExecutionException if the subbuild cannot be setup
  +     * @return a key to the build allowing it to be executed and managed
        */
  -    void runBuild(File antFile, Map properties, List targets)
  +    Object setupBuild(File antFile, Map properties)
            throws ExecutionException;
   
       /**
  -     * Run a sub-build.
  +     * Setup a sub-build.
        *
        * @param model the project model to be used for the build
  -     * @param targets A list of targets to be run
        * @param properties the initiali properties to be used in the build
  -     * @exception ExecutionException if the subbuild cannot be run
  +     * @exception ExecutionException if the subbuild cannot be setup
  +     * @return a key to the build allowing it to be executed and managed
        */
  -    void runBuild(Project model, Map properties, List targets)
  +    Object setupBuild(Project model, Map properties)
            throws ExecutionException;
   
       /**
  -     * Run a sub-build using the current frame's project model
  +     * Setup a sub-build using the current frame's project model
        *
  -     * @param targets A list of targets to be run
        * @param properties the initiali properties to be used in the build
  -     * @exception ExecutionException if the subbuild cannot be run
  +     * @exception ExecutionException if the subbuild cannot be setup
        */
  -    void callTarget(Map properties, List targets)
  +    Object setupBuild(Map properties)
            throws ExecutionException;
   
       /**
  +     * Run a build which have been previously setup
  +     *
  +     * @param buildKey the buildKey returned previously when the build was
  +     *        setup
  +     * @param targets A list of targets to be run
  +     * @exception ExecutionException if the build cannot be run
  +     */
  +   void runBuild(Object buildKey, List targets) throws ExecutionException;
  +         
  +    /**
        * execute a task. The task should have already been initialised by
        * the core
        *
  @@ -120,5 +129,15 @@
        * @return the base directory for this execution of Ant
        */
       File getBaseDir();
  +    
  +    /**
  +     * Handle subbuild output.
  +     *
  +     * @param subbuildKey the core's key for managing the subbuild.
  +     * @param line the content produce by the current thread.
  +     * @param isErr true if this content is from the thread's error stream.
  +     */
  +    void handleBuildOutput(Object subbuildKey, String line, boolean isErr) 
  +        throws ExecutionException;
   }
   
  
  
  

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