You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@apache.org on 2001/05/01 09:50:16 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant ProjectHelper.java

conor       01/05/01 00:50:16

  Modified:    .        build.xml
               proposal/antfarm/core/org/apache/tools/ant Target.java
                        TaskData.java Workspace.java
               proposal/antfarm/xml/org/apache/tools/ant/xml
                        ProjectHandler.java
               src/main/org/apache/tools/ant ProjectHelper.java
  Log:
  Repair install target and correct mionor typo
  
  Revision  Changes    Path
  1.147     +1 -1      jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.146
  retrieving revision 1.147
  diff -u -r1.146 -r1.147
  --- build.xml	2001/04/03 11:26:26	1.146
  +++ build.xml	2001/05/01 07:50:12	1.147
  @@ -521,7 +521,7 @@
          ===================================================================
     -->
     <target name="install" if="ant.install">
  -    <antcall target="dist">
  +    <antcall target="internal_dist">
         <param name="dist.dir" value="${ant.install}" />
       </antcall>
     </target>
  
  
  
  1.2       +71 -71    jakarta-ant/proposal/antfarm/core/org/apache/tools/ant/Target.java
  
  Index: Target.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/antfarm/core/org/apache/tools/ant/Target.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Target.java	2000/12/16 00:23:45	1.1
  +++ Target.java	2001/05/01 07:50:13	1.2
  @@ -1,72 +1,72 @@
  -/* Copyright (c) 2000 The Apache Software Foundation */
  -
  -package org.apache.tools.ant;
  -
  -import java.util.*;
  -
  -/**
  - *  Represents a set of actions to be executed, which may or may
  - *  not depend on other sets of actions.
  - *
  - *  @author <a href="mailto:mpfoemme@thoughtworks.com">Matthew Foemmel</a>
  - */
  -public class Target {
  -    private Project project;
  -    private String name;
  -    private String location;
  -    private List tasks;
  -    private List depends;
  -
  -    /**
  -     *  Called by the Project class to create new targets.
  -     */
  -    Target(Project project, String name) {
  -        this.project = project;
  -        this.name = name;
  -        this.location = null;
  -        this.tasks = new ArrayList();
  -        this.depends = new ArrayList();
  -    }
  -
  -    public Project getProject() {
  -        return project;
  -    }
  -
  -    public String getName() {
  -        return name;
  -    }
  -
  -    public String getLocation() {
  -        return location;
  -    }
  -
  -    public void setLocation(String location) {
  -        this.location = location;
  -    }
  -
  -    public List getTasks() {
  -        return tasks;
  -    }
  -
  -    public void addDepend(String depend) {
  -        // If no project was specified, use this target's project
  -        if (depend.indexOf(Workspace.SCOPE_SEPARATOR) == -1) {
  -            depend = getProject().getName() + Workspace.SCOPE_SEPARATOR + depend;
  -        }
  -        depends.add(depend);
  -    }
  -
  -    public List getDepends() {
  -        return depends;
  -    }
  -
  -    /**
  -     *  Creates a task proxy for this target. The proxy will
  -     *  be converted into an actual task object at build time.
  -     */
  -    public TaskProxy createTaskProxy(String name) {
  -        TaskProxy proxy = new TaskProxy(this, name);
  -        tasks.add(proxy);
  -        return proxy;
  -    }
  +/* Copyright (c) 2000 The Apache Software Foundation */
  +
  +package org.apache.tools.ant;
  +
  +import java.util.*;
  +
  +/**
  + *  Represents a set of actions to be executed, which may or may
  + *  not depend on other sets of actions.
  + *
  + *  @author <a href="mailto:mpfoemme@thoughtworks.com">Matthew Foemmel</a>
  + */
  +public class Target {
  +    private Project project;
  +    private String name;
  +    private String location;
  +    private List tasks;
  +    private List depends;
  +
  +    /**
  +     *  Called by the Project class to create new targets.
  +     */
  +    Target(Project project, String name) {
  +        this.project = project;
  +        this.name = name;
  +        this.location = null;
  +        this.tasks = new ArrayList();
  +        this.depends = new ArrayList();
  +    }
  +
  +    public Project getProject() {
  +        return project;
  +    }
  +
  +    public String getName() {
  +        return name;
  +    }
  +
  +    public String getLocation() {
  +        return location;
  +    }
  +
  +    public void setLocation(String location) {
  +        this.location = location;
  +    }
  +
  +    public List getTasks() {
  +        return tasks;
  +    }
  +
  +    public void addDepend(String depend) {
  +        // If no project was specified, use this target's project
  +        if (depend.indexOf(Workspace.SCOPE_SEPARATOR) == -1) {
  +            depend = getProject().getName() + Workspace.SCOPE_SEPARATOR + depend;
  +        }
  +        depends.add(depend);
  +    }
  +
  +    public List getDepends() {
  +        return depends;
  +    }
  +
  +    /**
  +     *  Creates a task proxy for this target. The proxy will
  +     *  be converted into an actual task object at build time.
  +     */
  +    public TaskProxy createTaskProxy(String name) {
  +        TaskProxy proxy = new TaskProxy(this, name);
  +        tasks.add(proxy);
  +        return proxy;
  +    }
   }
  
  
  
  1.2       +239 -239  jakarta-ant/proposal/antfarm/core/org/apache/tools/ant/TaskData.java
  
  Index: TaskData.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/antfarm/core/org/apache/tools/ant/TaskData.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TaskData.java	2000/12/16 00:23:45	1.1
  +++ TaskData.java	2001/05/01 07:50:13	1.2
  @@ -1,240 +1,240 @@
  -/* Copyright (c) 2000 The Apache Software Foundation */
  -
  -package org.apache.tools.ant;
  -
  -import java.beans.*;
  -import java.lang.reflect.*;
  -import java.util.*;
  -
  -/**
  - *  This class stores info about a bean's properties so that
  - *  the actual bean can be instantiated at a later time. This data
  - *  is used to store info about a task, since the actual
  - *  task class might not be loaded until after parsing is completed.
  - *
  - *  @see TaskProxy
  - *
  - *  @author <a href="mailto:mpfoemme@thoughtworks.com">Matthew Foemmel</a>
  - */
  -public class TaskData {
  -    private TaskProxy proxy;
  -    private String location;
  -    private String text;
  -    private Map properties;
  -
  -    /**
  -     *  Constructs a new TaskData under the specified task.
  -     */
  -    public TaskData(TaskProxy proxy) {
  -        this.proxy = proxy;
  -        this.location = null;
  -        this.properties = new HashMap();
  -    }
  -
  -    /**
  -     *  Returns the task proxy that this data is associated with.
  -     */
  -    public TaskProxy getTaskProxy() {
  -        return proxy;
  -    }
  -
  -    /**
  -     *  Returns the location in the build fiole where this data was defined.
  -     */
  -    public String getLocation() {
  -        return location;
  -    }
  -
  -    /**
  -     *  Returns the location in the build fiole where this data was defined.
  -     */
  -    public void setLocation(String location) {
  -        this.location = location;
  -    }
  -
  -    /**
  -     *  Sets the text for this bean data, for cases where the bean is a simple
  -     *  type like String or int.
  -     */
  -    public void setText(String text) {
  -        this.text = text;
  -    }
  -
  -
  -    /**
  -     *  Sets the value of a property on the bean. Multiple properties can be
  -     *  added with the same name only if the property on the bean is an array.
  -     */
  -    public TaskData addProperty(String name) {
  -        TaskData data = new TaskData(proxy);
  -        getProperties(name).add(data);
  -        return data;
  -    }
  -
  -    /**
  -     *  Returns the list of property values for the specified name.
  -     */
  -    private List getProperties(String name) {
  -        List result = (List) properties.get(name);
  -        if (result == null) {
  -            result = new ArrayList();
  -            properties.put(name, result);
  -        }
  -        return result;
  -    }
  -
  -    /**
  -     *  Creates a new bean instance and initializes its properties.
  -     */
  -    public Object createBean(Class type) throws BuildException {
  -        Object bean = null;
  -
  -        // See if an editor exists for this type
  -        PropertyEditor editor = PropertyEditorManager.findEditor(type);
  -
  -        if (editor == null) {
  -            // We don't know how to handle text for types without editors
  -            if (text != null) {
  -                throw new BuildException("Unexpected text \"" + text + "\"", location);
  -            }
  -
  -            try {
  -                bean = type.newInstance();
  -            }
  -            catch(InstantiationException exc) {
  -                throw new AntException("Unable to instantiate " + type.getName(), exc);
  -            }
  -            catch(IllegalAccessException exc) {
  -                throw new AntException("Unable to access constructor for " + type.getName(), exc);
  -            }
  -        }
  -        else {
  -            try {
  -                // Let the editor parse the text
  -                editor.setAsText(parseVariables(text));
  -            }
  -            catch(NumberFormatException exc) {
  -                throw new BuildException("\"" + text + "\" is not a valid number", location);
  -            }
  -
  -            bean = editor.getValue();
  -        }
  -
  -        // Update the fields on the bean
  -        updateProperties(bean);
  -
  -        return bean;
  -    }
  -
  -    /**
  -     *  Sets all of the property values on the bean.
  -     */
  -    private void updateProperties(Object bean) throws BuildException {
  -
  -        // Call setProperty for each property that's been defined
  -        Iterator itr = properties.entrySet().iterator();
  -        while (itr.hasNext()) {
  -            Map.Entry entry = (Map.Entry) itr.next();
  -            String name = (String) entry.getKey();
  -            List values = (List) entry.getValue();
  -            setProperty(bean, name, values);
  -        }
  -    }
  -
  -    /**
  -     *  Finds the PropertyDescriptor for the specifed property and sets it.
  -     */
  -    private void setProperty(Object bean, String name, List value) throws BuildException {
  -        PropertyDescriptor[] descriptors = getPropertyDescriptors(bean.getClass());
  -
  -        // Search for the property with the matching name
  -        for (int i = 0; i < descriptors.length; i++) {
  -            if (descriptors[i].getName().equals(name)) {
  -                setProperty(bean, descriptors[i], value);
  -                return;
  -            }
  -        }
  -
  -        throw new BuildException("Unexpected attribute \"" + name + "\"", location);
  -    }
  -
  -    /**
  -     *  Sets a single property on a bean.
  -     */
  -    private static void setProperty(Object obj, PropertyDescriptor descriptor, List values) throws BuildException {
  -        Object value = null;
  -
  -        Class type = descriptor.getPropertyType();
  -
  -        if (type.isArray()) {
  -            value = createBeans(type.getComponentType(), values);
  -        }
  -        else if (values.size() == 1) {
  -            TaskData data = (TaskData) values.get(0);
  -            value = data.createBean(type);
  -
  -        }
  -
  -        try {
  -            descriptor.getWriteMethod().invoke(obj, new Object[] { value });
  -        }
  -        catch(IllegalAccessException exc) {
  -            throw new AntException("Unable to access write method for \"" + descriptor.getName() + "\"", exc);
  -        }
  -        catch(InvocationTargetException exc) {
  -            throw new AntException("Unable to set property \"" + descriptor.getName() + "\"", exc.getTargetException());
  -        }
  -    }
  -
  -    /**
  -     *  Creates a number of beans with the same type using the list of TaskData's
  -     */
  -    private static Object[] createBeans(Class type, List values) throws BuildException {
  -        Object[] beans = (Object[]) Array.newInstance(type, values.size());
  -        int i = 0;
  -        Iterator itr = values.iterator();
  -        while (itr.hasNext()) {
  -            TaskData data = (TaskData) itr.next();
  -            beans[i++] = data.createBean(type);
  -        }
  -        return beans;
  -    }
  -
  -    /**
  -     *  Uses the Introspector class to lookup the property descriptors for the class.
  -     */
  -    private static PropertyDescriptor[] getPropertyDescriptors(Class type) {
  -        try {
  -            return Introspector.getBeanInfo(type, Object.class).getPropertyDescriptors();
  -        }
  -        catch(IntrospectionException exc) {
  -            throw new AntException("Unable to get bean info for " + type.getName());
  -        }
  -    }
  -
  -    /**
  -     *  Replaces any variables in the input string with their values.
  -     */
  -    private String parseVariables(String input) throws BuildException {
  -        StringBuffer output = new StringBuffer();
  -
  -        int start = 0;
  -        int end = 0;
  -        while ((start = input.indexOf('{', end)) != -1) {
  -            output.append(input.substring(end,start));
  -            end = input.indexOf('}', start);
  -            if (end != -1) {
  -                String name = input.substring(++start, end++);
  -                String value = proxy.getTarget().getProject().getVariable(name);
  -                if (value == null) {
  -                    throw new BuildException("The variable \"" + name + "\" has not been defined");
  -                }
  -                output.append(value);
  -            }
  -        }
  -
  -        output.append(input.substring(end));
  -
  -        return output.toString();
  -    }
  +/* Copyright (c) 2000 The Apache Software Foundation */
  +
  +package org.apache.tools.ant;
  +
  +import java.beans.*;
  +import java.lang.reflect.*;
  +import java.util.*;
  +
  +/**
  + *  This class stores info about a bean's properties so that
  + *  the actual bean can be instantiated at a later time. This data
  + *  is used to store info about a task, since the actual
  + *  task class might not be loaded until after parsing is completed.
  + *
  + *  @see TaskProxy
  + *
  + *  @author <a href="mailto:mpfoemme@thoughtworks.com">Matthew Foemmel</a>
  + */
  +public class TaskData {
  +    private TaskProxy proxy;
  +    private String location;
  +    private String text;
  +    private Map properties;
  +
  +    /**
  +     *  Constructs a new TaskData under the specified task.
  +     */
  +    public TaskData(TaskProxy proxy) {
  +        this.proxy = proxy;
  +        this.location = null;
  +        this.properties = new HashMap();
  +    }
  +
  +    /**
  +     *  Returns the task proxy that this data is associated with.
  +     */
  +    public TaskProxy getTaskProxy() {
  +        return proxy;
  +    }
  +
  +    /**
  +     *  Returns the location in the build fiole where this data was defined.
  +     */
  +    public String getLocation() {
  +        return location;
  +    }
  +
  +    /**
  +     *  Returns the location in the build fiole where this data was defined.
  +     */
  +    public void setLocation(String location) {
  +        this.location = location;
  +    }
  +
  +    /**
  +     *  Sets the text for this bean data, for cases where the bean is a simple
  +     *  type like String or int.
  +     */
  +    public void setText(String text) {
  +        this.text = text;
  +    }
  +
  +
  +    /**
  +     *  Sets the value of a property on the bean. Multiple properties can be
  +     *  added with the same name only if the property on the bean is an array.
  +     */
  +    public TaskData addProperty(String name) {
  +        TaskData data = new TaskData(proxy);
  +        getProperties(name).add(data);
  +        return data;
  +    }
  +
  +    /**
  +     *  Returns the list of property values for the specified name.
  +     */
  +    private List getProperties(String name) {
  +        List result = (List) properties.get(name);
  +        if (result == null) {
  +            result = new ArrayList();
  +            properties.put(name, result);
  +        }
  +        return result;
  +    }
  +
  +    /**
  +     *  Creates a new bean instance and initializes its properties.
  +     */
  +    public Object createBean(Class type) throws BuildException {
  +        Object bean = null;
  +
  +        // See if an editor exists for this type
  +        PropertyEditor editor = PropertyEditorManager.findEditor(type);
  +
  +        if (editor == null) {
  +            // We don't know how to handle text for types without editors
  +            if (text != null) {
  +                throw new BuildException("Unexpected text \"" + text + "\"", location);
  +            }
  +
  +            try {
  +                bean = type.newInstance();
  +            }
  +            catch(InstantiationException exc) {
  +                throw new AntException("Unable to instantiate " + type.getName(), exc);
  +            }
  +            catch(IllegalAccessException exc) {
  +                throw new AntException("Unable to access constructor for " + type.getName(), exc);
  +            }
  +        }
  +        else {
  +            try {
  +                // Let the editor parse the text
  +                editor.setAsText(parseVariables(text));
  +            }
  +            catch(NumberFormatException exc) {
  +                throw new BuildException("\"" + text + "\" is not a valid number", location);
  +            }
  +
  +            bean = editor.getValue();
  +        }
  +
  +        // Update the fields on the bean
  +        updateProperties(bean);
  +
  +        return bean;
  +    }
  +
  +    /**
  +     *  Sets all of the property values on the bean.
  +     */
  +    private void updateProperties(Object bean) throws BuildException {
  +
  +        // Call setProperty for each property that's been defined
  +        Iterator itr = properties.entrySet().iterator();
  +        while (itr.hasNext()) {
  +            Map.Entry entry = (Map.Entry) itr.next();
  +            String name = (String) entry.getKey();
  +            List values = (List) entry.getValue();
  +            setProperty(bean, name, values);
  +        }
  +    }
  +
  +    /**
  +     *  Finds the PropertyDescriptor for the specifed property and sets it.
  +     */
  +    private void setProperty(Object bean, String name, List value) throws BuildException {
  +        PropertyDescriptor[] descriptors = getPropertyDescriptors(bean.getClass());
  +
  +        // Search for the property with the matching name
  +        for (int i = 0; i < descriptors.length; i++) {
  +            if (descriptors[i].getName().equals(name)) {
  +                setProperty(bean, descriptors[i], value);
  +                return;
  +            }
  +        }
  +
  +        throw new BuildException("Unexpected attribute \"" + name + "\"", location);
  +    }
  +
  +    /**
  +     *  Sets a single property on a bean.
  +     */
  +    private static void setProperty(Object obj, PropertyDescriptor descriptor, List values) throws BuildException {
  +        Object value = null;
  +
  +        Class type = descriptor.getPropertyType();
  +
  +        if (type.isArray()) {
  +            value = createBeans(type.getComponentType(), values);
  +        }
  +        else if (values.size() == 1) {
  +            TaskData data = (TaskData) values.get(0);
  +            value = data.createBean(type);
  +
  +        }
  +
  +        try {
  +            descriptor.getWriteMethod().invoke(obj, new Object[] { value });
  +        }
  +        catch(IllegalAccessException exc) {
  +            throw new AntException("Unable to access write method for \"" + descriptor.getName() + "\"", exc);
  +        }
  +        catch(InvocationTargetException exc) {
  +            throw new AntException("Unable to set property \"" + descriptor.getName() + "\"", exc.getTargetException());
  +        }
  +    }
  +
  +    /**
  +     *  Creates a number of beans with the same type using the list of TaskData's
  +     */
  +    private static Object[] createBeans(Class type, List values) throws BuildException {
  +        Object[] beans = (Object[]) Array.newInstance(type, values.size());
  +        int i = 0;
  +        Iterator itr = values.iterator();
  +        while (itr.hasNext()) {
  +            TaskData data = (TaskData) itr.next();
  +            beans[i++] = data.createBean(type);
  +        }
  +        return beans;
  +    }
  +
  +    /**
  +     *  Uses the Introspector class to lookup the property descriptors for the class.
  +     */
  +    private static PropertyDescriptor[] getPropertyDescriptors(Class type) {
  +        try {
  +            return Introspector.getBeanInfo(type, Object.class).getPropertyDescriptors();
  +        }
  +        catch(IntrospectionException exc) {
  +            throw new AntException("Unable to get bean info for " + type.getName());
  +        }
  +    }
  +
  +    /**
  +     *  Replaces any variables in the input string with their values.
  +     */
  +    private String parseVariables(String input) throws BuildException {
  +        StringBuffer output = new StringBuffer();
  +
  +        int start = 0;
  +        int end = 0;
  +        while ((start = input.indexOf('{', end)) != -1) {
  +            output.append(input.substring(end,start));
  +            end = input.indexOf('}', start);
  +            if (end != -1) {
  +                String name = input.substring(++start, end++);
  +                String value = proxy.getTarget().getProject().getVariable(name);
  +                if (value == null) {
  +                    throw new BuildException("The variable \"" + name + "\" has not been defined");
  +                }
  +                output.append(value);
  +            }
  +        }
  +
  +        output.append(input.substring(end));
  +
  +        return output.toString();
  +    }
   }
  
  
  
  1.2       +448 -448  jakarta-ant/proposal/antfarm/core/org/apache/tools/ant/Workspace.java
  
  Index: Workspace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/antfarm/core/org/apache/tools/ant/Workspace.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Workspace.java	2000/12/16 00:23:45	1.1
  +++ Workspace.java	2001/05/01 07:50:14	1.2
  @@ -1,449 +1,449 @@
  -/* Copyright (c) 2000 The Apache Software Foundation */
  -
  -package org.apache.tools.ant;
  -
  -import java.util.*;
  -
  -/**
  - *  The main class in the Ant class hierarchy. A workspace contains
  - *  multiple projects, which in turn contain multiple targets, which
  - *  in turn contain multiple task proxies. The workspace also handles
  - *  the sorting and execution of targets during a build.
  - *
  - *  @author <a href="mailto:mpfoemme@thoughtworks.com">Matthew Foemmel</a>
  - */
  -public class Workspace {
  -    public static final char SCOPE_SEPARATOR = ':';
  -
  -    private Importer importer;
  -    private Map projects;
  -    private Map tasks;
  -    private List listeners;
  -
  -    private Task currentTask = null;
  -
  -    /**
  -     *  Constructs new Ant workspace with no projects. The only
  -     *  task that will be registered is the "load" task.
  -     *
  -     *  The importer is used to handle the actual reading of build files.
  -     *  In theory, different importers could be used to read project info from
  -     *  DOM trees, serialized objects, databases, etc.
  -     */
  -    public Workspace(Importer importer) {
  -        this.importer = importer;
  -        this.projects = new HashMap();
  -        this.tasks = new HashMap();
  -        this.listeners = new ArrayList();
  -
  -        registerTask("load", Load.class);
  -    }
  -
  -    /**
  -     *  Assigns a task class to a name.
  -     */
  -    public void registerTask(String name, Class type) {
  -        tasks.put(name, type);
  -    }
  -
  -    /**
  -     *  Returns the class for a task with the specified name.
  -     */
  -    public Class getTaskClass(String name) throws BuildException {
  -        Class type = (Class) tasks.get(name);
  -        if (type == null) {
  -            throw new BuildException("No task named \"" + name + "\" has been loaded");
  -        }
  -        return type;
  -    }
  -
  -    /**
  -     *  Creates a project with the specified name. The project initially
  -     *  contains no targets.
  -     */
  -    public Project createProject(String name) {
  -        Project project = new Project(this, name);
  -        projects.put(name, project);
  -        return project;
  -    }
  -
  -    /**
  -     *  Returns the project with the specified name, or throws
  -     *  an exception if no project exists with that name.
  -     */
  -    public Project getProject(String name) throws BuildException {
  -        Project project = (Project) projects.get(name);
  -        if (project == null) {
  -            throw new BuildException("Project \"" + name + "\" not found");
  -        }
  -        return project;
  -    }
  -
  -    /**
  -     *  Builds all of the targets in the list. Target names must
  -     *  be of the form projectname:targetname.
  -     */
  -    public boolean build(List fullNames) throws BuildException {
  -
  -        // This lets the tasks intercept System.exit() calls
  -        SecurityManager sm = System.getSecurityManager();
  -        System.setSecurityManager(new AntSecurityManager());
  -
  -        fireBuildStarted();
  -
  -        try {
  -            // Parse the project files...
  -            importTargets(fullNames);
  -
  -            // ...figure out the build order...
  -            List toDoList = sortTargets(fullNames);
  -
  -            // ...and build the targets
  -            Iterator itr = toDoList.iterator();
  -            while (itr.hasNext()) {
  -                Target target = (Target) itr.next();
  -                buildTarget(target);
  -            }
  -            fireBuildFinished(null);
  -            return true;
  -        }
  -        catch(BuildException exc) {
  -            fireBuildFinished(exc);
  -            return false;
  -        }
  -        finally {
  -            System.setSecurityManager(sm);
  -        }
  -    }
  -
  -    /**
  -     *  Adds a listener to the workspace.
  -     */
  -    public void addBuildListener(BuildListener listener) {
  -        listeners.add(listener);
  -    }
  -
  -    /**
  -     *  Removes a listener to the workspace.
  -     */
  -    public void removeBuildListener(BuildListener listener) {
  -        listeners.remove(listener);
  -    }
  -
  -    /**
  -     *  Fires a messageLogged event with DEBUG priority
  -     */
  -    public void debug(String message) {
  -        fireMessageLogged(message, BuildEvent.DEBUG);
  -    }
  -
  -    /**
  -     *  Fires a messageLogged event with INFO priority
  -     */
  -    public void info(String message) {
  -        fireMessageLogged(message, BuildEvent.INFO);
  -    }
  -
  -    /**
  -     *  Fires a messageLogged event with WARN priority
  -     */
  -    public void warn(String message) {
  -        fireMessageLogged(message, BuildEvent.WARN);
  -    }
  -
  -    /**
  -     *  Fires a messageLogged event with ERROR priority
  -     */
  -    public void error(String message) {
  -        fireMessageLogged(message, BuildEvent.ERROR);
  -    }
  -
  -    /**
  -     *  Imports into the workspace all of the projects required to
  -     *  build a set of targets.
  -     */
  -    private void importTargets(List fullNames) throws BuildException {
  -        Iterator itr = fullNames.iterator();
  -        while (itr.hasNext()) {
  -            String fullName = (String) itr.next();
  -            String projectName = getProjectName(fullName);
  -            importProject(projectName);
  -        }
  -    }
  -
  -    /**
  -     *  Imports the project into the workspace, as well as any others
  -     *  that the project depends on.
  -     */
  -    public Project importProject(String projectName) throws BuildException {
  -        Project project = (Project) projects.get(projectName);
  -
  -        // Don't parse a project file more than once
  -        if (project == null) {
  -
  -            // Parse the project file
  -            project = createProject(projectName);
  -
  -            fireImportStarted(project);
  -            try {
  -                importer.importProject(project);
  -                fireImportFinished(project, null);
  -            }
  -            catch(BuildException exc) {
  -                fireImportFinished(project, exc);
  -                throw exc;
  -            }
  -
  -            // Parse any imported projects as well
  -            Iterator itr = project.getImports().iterator();
  -            while (itr.hasNext()) {
  -                Import imp = (Import) itr.next();
  -                importProject(imp.getName());
  -            }
  -        }
  -
  -        return project;
  -    }
  -
  -
  -
  -    /**
  -     *  Builds a specific target. This assumes that the targets it depends
  -     *  on have already been built.
  -     */
  -    private void buildTarget(Target target) throws BuildException {
  -        fireTargetStarted(target);
  -
  -        try {
  -            List tasks = target.getTasks();
  -            Iterator itr = tasks.iterator();
  -            while (itr.hasNext()) {
  -                TaskProxy proxy = (TaskProxy) itr.next();
  -                executeTask(target, proxy);
  -            }
  -
  -            fireTargetFinished(target, null);
  -        }
  -        catch(BuildException exc) {
  -            fireTargetFinished(target, null);
  -            throw exc;
  -        }
  -    }
  -
  -    /**
  -     *  Instantiates the task from the proxy and executes.
  -     */
  -    private void executeTask(Target target, TaskProxy proxy) throws BuildException {
  -        Task task = proxy.createTask();
  -        task.setWorkspace(this);
  -        task.setProject(target.getProject());
  -        task.setTarget(target);
  -
  -        fireTaskStarted(task);
  -        currentTask = task;
  -        try {
  -            task.execute();
  -
  -            fireTaskFinished(task, null);
  -        }
  -        catch(BuildException exc) {
  -            exc.setLocation(proxy.getLocation());
  -            fireTaskFinished(task, exc);
  -            throw exc;
  -        }
  -        finally {
  -            currentTask = null;
  -        }
  -    }
  -
  -    /**
  -     *  Does a topological sort on a list of target names. Returns
  -     *  a list of Target objects in the order to be executed.
  -     */
  -    private List sortTargets(List fullNames) throws BuildException {
  -        List results = new ArrayList();
  -        sortTargets(results, new Stack(), fullNames);
  -        return results;
  -    }
  -
  -    private void sortTargets(List results, Stack visited, List fullNames) throws BuildException {
  -        Iterator itr = fullNames.iterator();
  -        while (itr.hasNext()) {
  -            String fullName = (String) itr.next();
  -
  -            // Check for cycles
  -            if (visited.contains(fullName)) {
  -                throwCyclicDependency(visited, fullName);
  -            }
  -
  -            // Check if we're already added this target to the list
  -            Target target = getTarget(fullName);
  -            if (results.contains(target)) {
  -                continue;
  -            }
  -
  -            visited.push(fullName);
  -            sortTargets(results, visited, target.getDepends());
  -            results.add(target);
  -            visited.pop();
  -        }
  -    }
  -
  -    /**
  -     *  Creates and throws an exception indicating a cyclic dependency.
  -     */
  -    private void throwCyclicDependency(Stack visited, String fullName) throws BuildException {
  -        StringBuffer msg = new StringBuffer("Cyclic dependency: ");
  -        for (int i = 0; i < visited.size(); i++) {
  -            msg.append((String)visited.get(i));
  -            msg.append(" -> ");
  -        }
  -        msg.append(fullName);
  -        throw new BuildException(msg.toString());
  -    }
  -
  -    /**
  -     *  Parses the full target name into is project and target components,
  -     *  then locates the Target object.
  -     */
  -    private Target getTarget(String fullName) throws BuildException {
  -        String projectName = getProjectName(fullName);
  -        String targetName = getTargetName(fullName);
  -
  -        Project project = (Project) projects.get(projectName);
  -        if (project == null) {
  -            throw new BuildException("Project \"" + projectName + "\" not found");
  -        }
  -
  -        Target target = project.getTarget(targetName);
  -        if (target == null) {
  -            throw new BuildException("Target \"" + fullName + "\" not found");
  -        }
  -
  -        return target;
  -    }
  -
  -    /**
  -     *  Returns the project portion of a full target name.
  -     */
  -    public static String getProjectName(String fullName) throws BuildException {
  -        int pos = fullName.indexOf(SCOPE_SEPARATOR);
  -        if (pos == -1 || pos == 0) {
  -            throw new BuildException("\"" + fullName + "\" is not a valid target name");
  -        }
  -
  -        return fullName.substring(0, pos);
  -    }
  -
  -    /**
  -     *  Returns the target portion of a full target name.
  -     */
  -    public static String getTargetName(String fullName) throws BuildException {
  -        int pos = fullName.indexOf(SCOPE_SEPARATOR);
  -        if (pos == -1 || pos == 0) {
  -            throw new BuildException("\"" + fullName + "\" is not a valid target name");
  -        }
  -
  -        return fullName.substring(pos + 1);
  -    }
  -
  -    private void fireMessageLogged(String message, int priority) {
  -        BuildEvent event;
  -        if (currentTask == null) {
  -            event = new BuildEvent(this);
  -        }
  -        else {
  -            event = new BuildEvent(currentTask);
  -        }
  -        event.setMessage(message, priority);
  -
  -        Iterator itr = listeners.iterator();
  -        while (itr.hasNext()) {
  -            BuildListener listener = (BuildListener) itr.next();
  -            listener.messageLogged(event);
  -        }
  -    }
  -
  -    private void fireBuildStarted() {
  -        Iterator itr = listeners.iterator();
  -        while (itr.hasNext()) {
  -            BuildListener listener = (BuildListener) itr.next();
  -            BuildEvent event = new BuildEvent(this);
  -            listener.buildStarted(event);
  -        }
  -    }
  -
  -    private void fireBuildFinished(BuildException exc) {
  -        BuildEvent event = new BuildEvent(this);
  -        event.setException(exc);
  -
  -        Iterator itr = listeners.iterator();
  -        while (itr.hasNext()) {
  -            BuildListener listener = (BuildListener) itr.next();
  -            listener.buildFinished(event);
  -        }
  -    }
  -
  -    private void fireImportStarted(Project project) {
  -        BuildEvent event = new BuildEvent(project);
  -
  -        Iterator itr = listeners.iterator();
  -        while (itr.hasNext()) {
  -            BuildListener listener = (BuildListener) itr.next();
  -            listener.importStarted(event);
  -        }
  -    }
  -
  -    private void fireImportFinished(Project project, BuildException exc) {
  -        BuildEvent event = new BuildEvent(project);
  -        event.setException(exc);
  -
  -        Iterator itr = listeners.iterator();
  -        while (itr.hasNext()) {
  -            BuildListener listener = (BuildListener) itr.next();
  -            listener.importFinished(event);
  -        }
  -    }
  -
  -    private void fireTargetStarted(Target target) {
  -        BuildEvent event = new BuildEvent(target);
  -
  -        Iterator itr = listeners.iterator();
  -        while (itr.hasNext()) {
  -            BuildListener listener = (BuildListener) itr.next();
  -            listener.targetStarted(event);
  -        }
  -    }
  -
  -    private void fireTargetFinished(Target target, BuildException exc) {
  -        BuildEvent event = new BuildEvent(target);
  -        event.setException(exc);
  -
  -        Iterator itr = listeners.iterator();
  -        while (itr.hasNext()) {
  -            BuildListener listener = (BuildListener) itr.next();
  -            listener.targetFinished(event);
  -        }
  -    }
  -
  -    private void fireTaskStarted(Task task) {
  -        BuildEvent event = new BuildEvent(task);
  -
  -        Iterator itr = listeners.iterator();
  -        while (itr.hasNext()) {
  -            BuildListener listener = (BuildListener) itr.next();
  -            listener.taskStarted(event);
  -        }
  -    }
  -
  -    private void fireTaskFinished(Task task, BuildException exc) {
  -        BuildEvent event = new BuildEvent(task);
  -        event.setException(exc);
  -
  -        Iterator itr = listeners.iterator();
  -        while (itr.hasNext()) {
  -            BuildListener listener = (BuildListener) itr.next();
  -            listener.taskFinished(event);
  -        }
  -    }
  +/* Copyright (c) 2000 The Apache Software Foundation */
  +
  +package org.apache.tools.ant;
  +
  +import java.util.*;
  +
  +/**
  + *  The main class in the Ant class hierarchy. A workspace contains
  + *  multiple projects, which in turn contain multiple targets, which
  + *  in turn contain multiple task proxies. The workspace also handles
  + *  the sorting and execution of targets during a build.
  + *
  + *  @author <a href="mailto:mpfoemme@thoughtworks.com">Matthew Foemmel</a>
  + */
  +public class Workspace {
  +    public static final char SCOPE_SEPARATOR = ':';
  +
  +    private Importer importer;
  +    private Map projects;
  +    private Map tasks;
  +    private List listeners;
  +
  +    private Task currentTask = null;
  +
  +    /**
  +     *  Constructs new Ant workspace with no projects. The only
  +     *  task that will be registered is the "load" task.
  +     *
  +     *  The importer is used to handle the actual reading of build files.
  +     *  In theory, different importers could be used to read project info from
  +     *  DOM trees, serialized objects, databases, etc.
  +     */
  +    public Workspace(Importer importer) {
  +        this.importer = importer;
  +        this.projects = new HashMap();
  +        this.tasks = new HashMap();
  +        this.listeners = new ArrayList();
  +
  +        registerTask("load", Load.class);
  +    }
  +
  +    /**
  +     *  Assigns a task class to a name.
  +     */
  +    public void registerTask(String name, Class type) {
  +        tasks.put(name, type);
  +    }
  +
  +    /**
  +     *  Returns the class for a task with the specified name.
  +     */
  +    public Class getTaskClass(String name) throws BuildException {
  +        Class type = (Class) tasks.get(name);
  +        if (type == null) {
  +            throw new BuildException("No task named \"" + name + "\" has been loaded");
  +        }
  +        return type;
  +    }
  +
  +    /**
  +     *  Creates a project with the specified name. The project initially
  +     *  contains no targets.
  +     */
  +    public Project createProject(String name) {
  +        Project project = new Project(this, name);
  +        projects.put(name, project);
  +        return project;
  +    }
  +
  +    /**
  +     *  Returns the project with the specified name, or throws
  +     *  an exception if no project exists with that name.
  +     */
  +    public Project getProject(String name) throws BuildException {
  +        Project project = (Project) projects.get(name);
  +        if (project == null) {
  +            throw new BuildException("Project \"" + name + "\" not found");
  +        }
  +        return project;
  +    }
  +
  +    /**
  +     *  Builds all of the targets in the list. Target names must
  +     *  be of the form projectname:targetname.
  +     */
  +    public boolean build(List fullNames) throws BuildException {
  +
  +        // This lets the tasks intercept System.exit() calls
  +        SecurityManager sm = System.getSecurityManager();
  +        System.setSecurityManager(new AntSecurityManager());
  +
  +        fireBuildStarted();
  +
  +        try {
  +            // Parse the project files...
  +            importTargets(fullNames);
  +
  +            // ...figure out the build order...
  +            List toDoList = sortTargets(fullNames);
  +
  +            // ...and build the targets
  +            Iterator itr = toDoList.iterator();
  +            while (itr.hasNext()) {
  +                Target target = (Target) itr.next();
  +                buildTarget(target);
  +            }
  +            fireBuildFinished(null);
  +            return true;
  +        }
  +        catch(BuildException exc) {
  +            fireBuildFinished(exc);
  +            return false;
  +        }
  +        finally {
  +            System.setSecurityManager(sm);
  +        }
  +    }
  +
  +    /**
  +     *  Adds a listener to the workspace.
  +     */
  +    public void addBuildListener(BuildListener listener) {
  +        listeners.add(listener);
  +    }
  +
  +    /**
  +     *  Removes a listener to the workspace.
  +     */
  +    public void removeBuildListener(BuildListener listener) {
  +        listeners.remove(listener);
  +    }
  +
  +    /**
  +     *  Fires a messageLogged event with DEBUG priority
  +     */
  +    public void debug(String message) {
  +        fireMessageLogged(message, BuildEvent.DEBUG);
  +    }
  +
  +    /**
  +     *  Fires a messageLogged event with INFO priority
  +     */
  +    public void info(String message) {
  +        fireMessageLogged(message, BuildEvent.INFO);
  +    }
  +
  +    /**
  +     *  Fires a messageLogged event with WARN priority
  +     */
  +    public void warn(String message) {
  +        fireMessageLogged(message, BuildEvent.WARN);
  +    }
  +
  +    /**
  +     *  Fires a messageLogged event with ERROR priority
  +     */
  +    public void error(String message) {
  +        fireMessageLogged(message, BuildEvent.ERROR);
  +    }
  +
  +    /**
  +     *  Imports into the workspace all of the projects required to
  +     *  build a set of targets.
  +     */
  +    private void importTargets(List fullNames) throws BuildException {
  +        Iterator itr = fullNames.iterator();
  +        while (itr.hasNext()) {
  +            String fullName = (String) itr.next();
  +            String projectName = getProjectName(fullName);
  +            importProject(projectName);
  +        }
  +    }
  +
  +    /**
  +     *  Imports the project into the workspace, as well as any others
  +     *  that the project depends on.
  +     */
  +    public Project importProject(String projectName) throws BuildException {
  +        Project project = (Project) projects.get(projectName);
  +
  +        // Don't parse a project file more than once
  +        if (project == null) {
  +
  +            // Parse the project file
  +            project = createProject(projectName);
  +
  +            fireImportStarted(project);
  +            try {
  +                importer.importProject(project);
  +                fireImportFinished(project, null);
  +            }
  +            catch(BuildException exc) {
  +                fireImportFinished(project, exc);
  +                throw exc;
  +            }
  +
  +            // Parse any imported projects as well
  +            Iterator itr = project.getImports().iterator();
  +            while (itr.hasNext()) {
  +                Import imp = (Import) itr.next();
  +                importProject(imp.getName());
  +            }
  +        }
  +
  +        return project;
  +    }
  +
  +
  +
  +    /**
  +     *  Builds a specific target. This assumes that the targets it depends
  +     *  on have already been built.
  +     */
  +    private void buildTarget(Target target) throws BuildException {
  +        fireTargetStarted(target);
  +
  +        try {
  +            List tasks = target.getTasks();
  +            Iterator itr = tasks.iterator();
  +            while (itr.hasNext()) {
  +                TaskProxy proxy = (TaskProxy) itr.next();
  +                executeTask(target, proxy);
  +            }
  +
  +            fireTargetFinished(target, null);
  +        }
  +        catch(BuildException exc) {
  +            fireTargetFinished(target, null);
  +            throw exc;
  +        }
  +    }
  +
  +    /**
  +     *  Instantiates the task from the proxy and executes.
  +     */
  +    private void executeTask(Target target, TaskProxy proxy) throws BuildException {
  +        Task task = proxy.createTask();
  +        task.setWorkspace(this);
  +        task.setProject(target.getProject());
  +        task.setTarget(target);
  +
  +        fireTaskStarted(task);
  +        currentTask = task;
  +        try {
  +            task.execute();
  +
  +            fireTaskFinished(task, null);
  +        }
  +        catch(BuildException exc) {
  +            exc.setLocation(proxy.getLocation());
  +            fireTaskFinished(task, exc);
  +            throw exc;
  +        }
  +        finally {
  +            currentTask = null;
  +        }
  +    }
  +
  +    /**
  +     *  Does a topological sort on a list of target names. Returns
  +     *  a list of Target objects in the order to be executed.
  +     */
  +    private List sortTargets(List fullNames) throws BuildException {
  +        List results = new ArrayList();
  +        sortTargets(results, new Stack(), fullNames);
  +        return results;
  +    }
  +
  +    private void sortTargets(List results, Stack visited, List fullNames) throws BuildException {
  +        Iterator itr = fullNames.iterator();
  +        while (itr.hasNext()) {
  +            String fullName = (String) itr.next();
  +
  +            // Check for cycles
  +            if (visited.contains(fullName)) {
  +                throwCyclicDependency(visited, fullName);
  +            }
  +
  +            // Check if we're already added this target to the list
  +            Target target = getTarget(fullName);
  +            if (results.contains(target)) {
  +                continue;
  +            }
  +
  +            visited.push(fullName);
  +            sortTargets(results, visited, target.getDepends());
  +            results.add(target);
  +            visited.pop();
  +        }
  +    }
  +
  +    /**
  +     *  Creates and throws an exception indicating a cyclic dependency.
  +     */
  +    private void throwCyclicDependency(Stack visited, String fullName) throws BuildException {
  +        StringBuffer msg = new StringBuffer("Cyclic dependency: ");
  +        for (int i = 0; i < visited.size(); i++) {
  +            msg.append((String)visited.get(i));
  +            msg.append(" -> ");
  +        }
  +        msg.append(fullName);
  +        throw new BuildException(msg.toString());
  +    }
  +
  +    /**
  +     *  Parses the full target name into is project and target components,
  +     *  then locates the Target object.
  +     */
  +    private Target getTarget(String fullName) throws BuildException {
  +        String projectName = getProjectName(fullName);
  +        String targetName = getTargetName(fullName);
  +
  +        Project project = (Project) projects.get(projectName);
  +        if (project == null) {
  +            throw new BuildException("Project \"" + projectName + "\" not found");
  +        }
  +
  +        Target target = project.getTarget(targetName);
  +        if (target == null) {
  +            throw new BuildException("Target \"" + fullName + "\" not found");
  +        }
  +
  +        return target;
  +    }
  +
  +    /**
  +     *  Returns the project portion of a full target name.
  +     */
  +    public static String getProjectName(String fullName) throws BuildException {
  +        int pos = fullName.indexOf(SCOPE_SEPARATOR);
  +        if (pos == -1 || pos == 0) {
  +            throw new BuildException("\"" + fullName + "\" is not a valid target name");
  +        }
  +
  +        return fullName.substring(0, pos);
  +    }
  +
  +    /**
  +     *  Returns the target portion of a full target name.
  +     */
  +    public static String getTargetName(String fullName) throws BuildException {
  +        int pos = fullName.indexOf(SCOPE_SEPARATOR);
  +        if (pos == -1 || pos == 0) {
  +            throw new BuildException("\"" + fullName + "\" is not a valid target name");
  +        }
  +
  +        return fullName.substring(pos + 1);
  +    }
  +
  +    private void fireMessageLogged(String message, int priority) {
  +        BuildEvent event;
  +        if (currentTask == null) {
  +            event = new BuildEvent(this);
  +        }
  +        else {
  +            event = new BuildEvent(currentTask);
  +        }
  +        event.setMessage(message, priority);
  +
  +        Iterator itr = listeners.iterator();
  +        while (itr.hasNext()) {
  +            BuildListener listener = (BuildListener) itr.next();
  +            listener.messageLogged(event);
  +        }
  +    }
  +
  +    private void fireBuildStarted() {
  +        Iterator itr = listeners.iterator();
  +        while (itr.hasNext()) {
  +            BuildListener listener = (BuildListener) itr.next();
  +            BuildEvent event = new BuildEvent(this);
  +            listener.buildStarted(event);
  +        }
  +    }
  +
  +    private void fireBuildFinished(BuildException exc) {
  +        BuildEvent event = new BuildEvent(this);
  +        event.setException(exc);
  +
  +        Iterator itr = listeners.iterator();
  +        while (itr.hasNext()) {
  +            BuildListener listener = (BuildListener) itr.next();
  +            listener.buildFinished(event);
  +        }
  +    }
  +
  +    private void fireImportStarted(Project project) {
  +        BuildEvent event = new BuildEvent(project);
  +
  +        Iterator itr = listeners.iterator();
  +        while (itr.hasNext()) {
  +            BuildListener listener = (BuildListener) itr.next();
  +            listener.importStarted(event);
  +        }
  +    }
  +
  +    private void fireImportFinished(Project project, BuildException exc) {
  +        BuildEvent event = new BuildEvent(project);
  +        event.setException(exc);
  +
  +        Iterator itr = listeners.iterator();
  +        while (itr.hasNext()) {
  +            BuildListener listener = (BuildListener) itr.next();
  +            listener.importFinished(event);
  +        }
  +    }
  +
  +    private void fireTargetStarted(Target target) {
  +        BuildEvent event = new BuildEvent(target);
  +
  +        Iterator itr = listeners.iterator();
  +        while (itr.hasNext()) {
  +            BuildListener listener = (BuildListener) itr.next();
  +            listener.targetStarted(event);
  +        }
  +    }
  +
  +    private void fireTargetFinished(Target target, BuildException exc) {
  +        BuildEvent event = new BuildEvent(target);
  +        event.setException(exc);
  +
  +        Iterator itr = listeners.iterator();
  +        while (itr.hasNext()) {
  +            BuildListener listener = (BuildListener) itr.next();
  +            listener.targetFinished(event);
  +        }
  +    }
  +
  +    private void fireTaskStarted(Task task) {
  +        BuildEvent event = new BuildEvent(task);
  +
  +        Iterator itr = listeners.iterator();
  +        while (itr.hasNext()) {
  +            BuildListener listener = (BuildListener) itr.next();
  +            listener.taskStarted(event);
  +        }
  +    }
  +
  +    private void fireTaskFinished(Task task, BuildException exc) {
  +        BuildEvent event = new BuildEvent(task);
  +        event.setException(exc);
  +
  +        Iterator itr = listeners.iterator();
  +        while (itr.hasNext()) {
  +            BuildListener listener = (BuildListener) itr.next();
  +            listener.taskFinished(event);
  +        }
  +    }
   }
  
  
  
  1.2       +288 -288  jakarta-ant/proposal/antfarm/xml/org/apache/tools/ant/xml/ProjectHandler.java
  
  Index: ProjectHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/antfarm/xml/org/apache/tools/ant/xml/ProjectHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProjectHandler.java	2000/12/16 00:23:48	1.1
  +++ ProjectHandler.java	2001/05/01 07:50:15	1.2
  @@ -1,289 +1,289 @@
  -/* Copyright (c) 2000 The Apache Software Foundation */
  -
  -package org.apache.tools.ant.xml;
  -
  -import java.io.*;
  -import java.util.*;
  -import javax.xml.parsers.*;
  -import org.apache.tools.ant.*;
  -import org.xml.sax.*;
  -import org.xml.sax.ext.*;
  -import org.xml.sax.helpers.*;
  -
  -/**
  - *  This class populates a Project object via SAX events.
  - */
  -public class ProjectHandler extends DefaultHandler /* implements LexicalHandler */ {
  -    private Workspace workspace;
  -    private Project project;
  -    private Locator locator;
  -
  -    /**
  -     *  The top of this stack represents the "current" event handler.
  -     */
  -    private Stack handlers;
  -
  -    /**
  -     * Constructs a SAX handler for the specified project.
  -     */
  -    public ProjectHandler(Project project) {
  -        this.project = project;
  -        this.workspace = project.getWorkspace();
  -        this.handlers = new Stack();
  -        this.handlers.push(new RootHandler());
  -    }
  -
  -    public Project getProject() {
  -        return project;
  -    }
  -
  -    public void setDocumentLocator(Locator locator) {
  -        this.locator = locator;
  -    }
  -
  -    protected String getLocation() {
  -        return locator.getPublicId() + ":" + locator.getLineNumber();
  -    }
  -
  -    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  -        // Delegate to the current handler
  -        ((ContentHandler)handlers.peek()).startElement(namespaceURI, localName, qName, atts);
  -    }
  -
  -    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  -        // Delegate to the current handler
  -        ((ContentHandler)handlers.peek()).endElement(namespaceURI, localName, qName);
  -    }
  -
  -    public void characters(char[] ch, int start, int length) {
  -        //XXX need to implement text content
  -    }
  -
  -    public void processingInstruction(String target, String data) {
  -        System.out.println("@" + target + "@" + data + "@");
  -    }
  -
  -    /*
  -    public void comment(char[] ch, int start, int length) {)
  -    public void endCDATA() {}
  -    public void endDTD() {}
  -    public void endEntity(java.lang.String name) {}
  -    public void startCDATA() {}
  -    public void startDTD(String name, String publicId, String systemId) {}
  -    public void startEntity(java.lang.String name)  {}
  -    */
  -
  -    /**
  -     * This class handles any top level SAX events.
  -     */
  -    private class RootHandler extends DefaultHandler {
  -        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  -            if (isAntNamespace(namespaceURI) && localName.equals("project")) {
  -                handlers.push(new ProjectElemHandler(qName, atts));
  -            }
  -            else {
  -                throw new SAXParseException("Unexpected element \"" + qName + "\"", locator);
  -            }
  -        }
  -
  -        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  -            handlers.pop();
  -        }
  -    }
  -
  -    /**
  -     *  This class handles events that occur with a "project" element.
  -     */
  -    private class ProjectElemHandler extends DefaultHandler {
  -        public ProjectElemHandler(String qName, Attributes atts) throws SAXException {
  -            String projectName = null;
  -
  -            for (int i = 0; i < atts.getLength(); i++) {
  -                if (!isAntNamespace(atts.getURI(i))) {
  -                    continue;
  -                }
  -
  -                String name = atts.getQName(i);
  -                String value = atts.getValue(i);
  -                if (name.equals("name")) {
  -                    projectName = value;
  -                }
  -                else {
  -                    throw new SAXParseException("Unexpected attribute \"" + name + "\"", locator);
  -                }
  -            }
  -
  -            if (projectName == null) {
  -                throw new SAXParseException("Missing attribute \"name\"", locator);
  -            }
  -
  -            if (!projectName.equals(project.getName())) {
  -                throw new SAXParseException("A project named \"" + projectName + "\" must be located in a file called \"" + projectName + ".ant\"", locator);
  -            }
  -        }
  -
  -        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  -            if (isAntNamespace(namespaceURI) && localName.equals("target")) {
  -                handlers.push(new TargetElemHandler(project, qName, atts));
  -            }
  -            else if (isAntNamespace(namespaceURI) && localName.equals("import")) {
  -                handlers.push(new ImportElemHandler(project, qName, atts));
  -            }
  -            else {
  -                throw new SAXParseException("Unexpected element \"" + qName + "\"", locator);
  -            }
  -        }
  -
  -        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  -            handlers.pop();
  -        }
  -    }
  -
  -    /**
  -     *  This class handles events that occur with a "target" element.
  -     */
  -    private class TargetElemHandler extends DefaultHandler {
  -        private Target target;
  -
  -        public TargetElemHandler(Project project, String qName, Attributes atts) throws SAXException {
  -            String targetName = null;
  -            String dependencies = "";
  -
  -            for (int i = 0; i < atts.getLength(); i++) {
  -                if (!isAntNamespace(atts.getURI(i))) {
  -                    continue;
  -                }
  -
  -                String name = atts.getQName(i);
  -                String value = atts.getValue(i);
  -                if (name.equals("name")) {
  -                    targetName = value;
  -                }
  -                else if (name.equals("depends")) {
  -                    dependencies = value;
  -                }
  -                else {
  -                    throw new SAXParseException("Unexpected attribute \"" + name + "\"", locator);
  -                }
  -            }
  -
  -            if (targetName == null) {
  -                throw new SAXParseException("Missing attribute \"name\"", locator);
  -            }
  -
  -            try {
  -                target = project.createTarget(targetName);
  -                target.setLocation(getLocation());
  -                parseDepends(dependencies);
  -            }
  -            catch(BuildException exc) {
  -                throw new SAXException(exc);
  -            }
  -        }
  -
  -        /**
  -         *  Parses the list of space-separated project names.
  -         */
  -        private void parseDepends(String depends) {
  -            StringTokenizer tokenizer = new StringTokenizer(depends);
  -            while (tokenizer.hasMoreTokens()) {
  -                String targetName = tokenizer.nextToken();
  -                target.addDepend(targetName);
  -            }
  -        }
  -
  -        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  -            if (!isAntNamespace(namespaceURI)) {
  -                throw new SAXParseException("Unexpected attribute \"" + qName + "\"", locator);
  -            }
  -
  -            TaskProxy proxy = target.createTaskProxy(qName);
  -            proxy.setLocation(getLocation());
  -            handlers.push(new TaskElemHandler(proxy.getData(), qName, atts));
  -        }
  -
  -        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  -            handlers.pop();
  -        }
  -    }
  -
  -    /**
  -     *  This class handles events that occur with a "import" element.
  -     */
  -    private class ImportElemHandler extends DefaultHandler {
  -        public ImportElemHandler(Project project, String qName, Attributes atts) throws SAXException {
  -            String importName = null;
  -
  -            for (int i = 0; i < atts.getLength(); i++) {
  -                if (!isAntNamespace(atts.getURI(i))) {
  -                    continue;
  -                }
  -
  -                String name = atts.getQName(i);
  -                String value = atts.getValue(i);
  -                if (name.equals("name")) {
  -                    importName = value;
  -                }
  -                else {
  -                    throw new SAXParseException("Unexpected attribute \"" + name + "\"", locator);
  -                }
  -            }
  -
  -            if (importName == null) {
  -                throw new SAXParseException("Missing attribute \"name\"",  locator);
  -            }
  -
  -            Import imp = project.createImport(importName);
  -            imp.setLocation(getLocation());
  -        }
  -
  -        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  -            throw new SAXParseException("Unexpected element \"" + qName + "\"", locator);
  -        }
  -
  -        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  -            handlers.pop();
  -        }
  -    }
  -
  -    /**
  -     *  This class handles events that occur with a task element.
  -     */
  -    private class TaskElemHandler extends DefaultHandler {
  -        private TaskData data;
  -
  -        public TaskElemHandler(TaskData data, String qName, Attributes atts) throws SAXException {
  -            this.data = data;
  -
  -            for (int i = 0; i < atts.getLength(); i++) {
  -                if (!isAntNamespace(atts.getURI(i))) {
  -                    continue;
  -                }
  -
  -                String name = atts.getQName(i);
  -                String value = atts.getValue(i);
  -                TaskData child = data.addProperty(name);
  -                child.setLocation(getLocation());
  -                child.setText(value);
  -            }
  -        }
  -
  -        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  -            if (!isAntNamespace(namespaceURI)) {
  -                throw new SAXParseException("Unexpected element \"" + qName + "\"", locator);
  -            }
  -
  -            TaskData child = data.addProperty(qName);
  -            child.setLocation(getLocation());
  -            handlers.push(new TaskElemHandler(child, qName, atts));
  -        }
  -
  -        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  -            handlers.pop();
  -        }
  -    }
  -
  -    private static boolean isAntNamespace(String uri) {
  -        return uri == null ? false : uri.equals("");
  -    }
  +/* Copyright (c) 2000 The Apache Software Foundation */
  +
  +package org.apache.tools.ant.xml;
  +
  +import java.io.*;
  +import java.util.*;
  +import javax.xml.parsers.*;
  +import org.apache.tools.ant.*;
  +import org.xml.sax.*;
  +import org.xml.sax.ext.*;
  +import org.xml.sax.helpers.*;
  +
  +/**
  + *  This class populates a Project object via SAX events.
  + */
  +public class ProjectHandler extends DefaultHandler /* implements LexicalHandler */ {
  +    private Workspace workspace;
  +    private Project project;
  +    private Locator locator;
  +
  +    /**
  +     *  The top of this stack represents the "current" event handler.
  +     */
  +    private Stack handlers;
  +
  +    /**
  +     * Constructs a SAX handler for the specified project.
  +     */
  +    public ProjectHandler(Project project) {
  +        this.project = project;
  +        this.workspace = project.getWorkspace();
  +        this.handlers = new Stack();
  +        this.handlers.push(new RootHandler());
  +    }
  +
  +    public Project getProject() {
  +        return project;
  +    }
  +
  +    public void setDocumentLocator(Locator locator) {
  +        this.locator = locator;
  +    }
  +
  +    protected String getLocation() {
  +        return locator.getPublicId() + ":" + locator.getLineNumber();
  +    }
  +
  +    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  +        // Delegate to the current handler
  +        ((ContentHandler)handlers.peek()).startElement(namespaceURI, localName, qName, atts);
  +    }
  +
  +    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  +        // Delegate to the current handler
  +        ((ContentHandler)handlers.peek()).endElement(namespaceURI, localName, qName);
  +    }
  +
  +    public void characters(char[] ch, int start, int length) {
  +        //XXX need to implement text content
  +    }
  +
  +    public void processingInstruction(String target, String data) {
  +        System.out.println("@" + target + "@" + data + "@");
  +    }
  +
  +    /*
  +    public void comment(char[] ch, int start, int length) {)
  +    public void endCDATA() {}
  +    public void endDTD() {}
  +    public void endEntity(java.lang.String name) {}
  +    public void startCDATA() {}
  +    public void startDTD(String name, String publicId, String systemId) {}
  +    public void startEntity(java.lang.String name)  {}
  +    */
  +
  +    /**
  +     * This class handles any top level SAX events.
  +     */
  +    private class RootHandler extends DefaultHandler {
  +        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  +            if (isAntNamespace(namespaceURI) && localName.equals("project")) {
  +                handlers.push(new ProjectElemHandler(qName, atts));
  +            }
  +            else {
  +                throw new SAXParseException("Unexpected element \"" + qName + "\"", locator);
  +            }
  +        }
  +
  +        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  +            handlers.pop();
  +        }
  +    }
  +
  +    /**
  +     *  This class handles events that occur with a "project" element.
  +     */
  +    private class ProjectElemHandler extends DefaultHandler {
  +        public ProjectElemHandler(String qName, Attributes atts) throws SAXException {
  +            String projectName = null;
  +
  +            for (int i = 0; i < atts.getLength(); i++) {
  +                if (!isAntNamespace(atts.getURI(i))) {
  +                    continue;
  +                }
  +
  +                String name = atts.getQName(i);
  +                String value = atts.getValue(i);
  +                if (name.equals("name")) {
  +                    projectName = value;
  +                }
  +                else {
  +                    throw new SAXParseException("Unexpected attribute \"" + name + "\"", locator);
  +                }
  +            }
  +
  +            if (projectName == null) {
  +                throw new SAXParseException("Missing attribute \"name\"", locator);
  +            }
  +
  +            if (!projectName.equals(project.getName())) {
  +                throw new SAXParseException("A project named \"" + projectName + "\" must be located in a file called \"" + projectName + ".ant\"", locator);
  +            }
  +        }
  +
  +        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  +            if (isAntNamespace(namespaceURI) && localName.equals("target")) {
  +                handlers.push(new TargetElemHandler(project, qName, atts));
  +            }
  +            else if (isAntNamespace(namespaceURI) && localName.equals("import")) {
  +                handlers.push(new ImportElemHandler(project, qName, atts));
  +            }
  +            else {
  +                throw new SAXParseException("Unexpected element \"" + qName + "\"", locator);
  +            }
  +        }
  +
  +        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  +            handlers.pop();
  +        }
  +    }
  +
  +    /**
  +     *  This class handles events that occur with a "target" element.
  +     */
  +    private class TargetElemHandler extends DefaultHandler {
  +        private Target target;
  +
  +        public TargetElemHandler(Project project, String qName, Attributes atts) throws SAXException {
  +            String targetName = null;
  +            String dependencies = "";
  +
  +            for (int i = 0; i < atts.getLength(); i++) {
  +                if (!isAntNamespace(atts.getURI(i))) {
  +                    continue;
  +                }
  +
  +                String name = atts.getQName(i);
  +                String value = atts.getValue(i);
  +                if (name.equals("name")) {
  +                    targetName = value;
  +                }
  +                else if (name.equals("depends")) {
  +                    dependencies = value;
  +                }
  +                else {
  +                    throw new SAXParseException("Unexpected attribute \"" + name + "\"", locator);
  +                }
  +            }
  +
  +            if (targetName == null) {
  +                throw new SAXParseException("Missing attribute \"name\"", locator);
  +            }
  +
  +            try {
  +                target = project.createTarget(targetName);
  +                target.setLocation(getLocation());
  +                parseDepends(dependencies);
  +            }
  +            catch(BuildException exc) {
  +                throw new SAXException(exc);
  +            }
  +        }
  +
  +        /**
  +         *  Parses the list of space-separated project names.
  +         */
  +        private void parseDepends(String depends) {
  +            StringTokenizer tokenizer = new StringTokenizer(depends);
  +            while (tokenizer.hasMoreTokens()) {
  +                String targetName = tokenizer.nextToken();
  +                target.addDepend(targetName);
  +            }
  +        }
  +
  +        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  +            if (!isAntNamespace(namespaceURI)) {
  +                throw new SAXParseException("Unexpected attribute \"" + qName + "\"", locator);
  +            }
  +
  +            TaskProxy proxy = target.createTaskProxy(qName);
  +            proxy.setLocation(getLocation());
  +            handlers.push(new TaskElemHandler(proxy.getData(), qName, atts));
  +        }
  +
  +        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  +            handlers.pop();
  +        }
  +    }
  +
  +    /**
  +     *  This class handles events that occur with a "import" element.
  +     */
  +    private class ImportElemHandler extends DefaultHandler {
  +        public ImportElemHandler(Project project, String qName, Attributes atts) throws SAXException {
  +            String importName = null;
  +
  +            for (int i = 0; i < atts.getLength(); i++) {
  +                if (!isAntNamespace(atts.getURI(i))) {
  +                    continue;
  +                }
  +
  +                String name = atts.getQName(i);
  +                String value = atts.getValue(i);
  +                if (name.equals("name")) {
  +                    importName = value;
  +                }
  +                else {
  +                    throw new SAXParseException("Unexpected attribute \"" + name + "\"", locator);
  +                }
  +            }
  +
  +            if (importName == null) {
  +                throw new SAXParseException("Missing attribute \"name\"",  locator);
  +            }
  +
  +            Import imp = project.createImport(importName);
  +            imp.setLocation(getLocation());
  +        }
  +
  +        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  +            throw new SAXParseException("Unexpected element \"" + qName + "\"", locator);
  +        }
  +
  +        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  +            handlers.pop();
  +        }
  +    }
  +
  +    /**
  +     *  This class handles events that occur with a task element.
  +     */
  +    private class TaskElemHandler extends DefaultHandler {
  +        private TaskData data;
  +
  +        public TaskElemHandler(TaskData data, String qName, Attributes atts) throws SAXException {
  +            this.data = data;
  +
  +            for (int i = 0; i < atts.getLength(); i++) {
  +                if (!isAntNamespace(atts.getURI(i))) {
  +                    continue;
  +                }
  +
  +                String name = atts.getQName(i);
  +                String value = atts.getValue(i);
  +                TaskData child = data.addProperty(name);
  +                child.setLocation(getLocation());
  +                child.setText(value);
  +            }
  +        }
  +
  +        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
  +            if (!isAntNamespace(namespaceURI)) {
  +                throw new SAXParseException("Unexpected element \"" + qName + "\"", locator);
  +            }
  +
  +            TaskData child = data.addProperty(qName);
  +            child.setLocation(getLocation());
  +            handlers.push(new TaskElemHandler(child, qName, atts));
  +        }
  +
  +        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
  +            handlers.pop();
  +        }
  +    }
  +
  +    private static boolean isAntNamespace(String uri) {
  +        return uri == null ? false : uri.equals("");
  +    }
   }
  
  
  
  1.50      +1 -1      jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- ProjectHelper.java	2001/03/02 15:57:58	1.49
  +++ ProjectHelper.java	2001/05/01 07:50:15	1.50
  @@ -195,7 +195,7 @@
   
           /**
            * Called when this element and all elements nested into it have been
  -         * handeled.
  +         * handled.
            */
           protected void finished() {}