diff --git a/src/antidote/ChangeLog b/src/antidote/ChangeLog index 76657e1ab..251ea73b5 100644 --- a/src/antidote/ChangeLog +++ b/src/antidote/ChangeLog @@ -1,3 +1,14 @@ +2000-11-09 Simeon H.K. Fitch + + * org/apache/tools/ant/gui/ProjectProxy.java: Started rework of + project data model, using elements from the XML parser directly + through the new Ant Construction Set package. + +2000-11-08 Simeon H.K. Fitch + + * org/apache/tools/ant/gui/About.java: Useless tweaking inspired + by procrastination. + 2000-11-05 Simeon H.K. Fitch * org/apache/tools/ant/gui/LogLevelEnum.java: Added log level diff --git a/src/antidote/build.xml b/src/antidote/build.xml index 58141d0f3..40309f5fc 100644 --- a/src/antidote/build.xml +++ b/src/antidote/build.xml @@ -15,11 +15,14 @@ + + + @@ -114,7 +117,7 @@ - + diff --git a/src/antidote/org/apache/tools/ant/gui/About.java b/src/antidote/org/apache/tools/ant/gui/About.java index dd4f3b4cd..6b01bd05d 100644 --- a/src/antidote/org/apache/tools/ant/gui/About.java +++ b/src/antidote/org/apache/tools/ant/gui/About.java @@ -99,9 +99,17 @@ public class About extends JDialog { // presented nicely in box. contributors = props.getProperty("CONTRIBUTORS", "??"); + StringBuffer buf = new StringBuffer(); + StringTokenizer tok = new StringTokenizer(contributors, ","); + while(tok.hasMoreTokens()) { + String name = tok.nextToken(); + buf.append(name); + buf.append("
\n"); + } + String message = context.getResources().getMessage( getClass(), "message", - new Object[] { version, date, contributors }); + new Object[] { version, date, buf.toString() }); String title = context.getResources().getString( getClass(), "title"); @@ -118,6 +126,9 @@ public class About extends JDialog { p.add(ok); getContentPane().add(BorderLayout.SOUTH, p); + getRootPane().setDefaultButton(ok); + + // Just go ahead and show it... pack(); WindowUtils.centerWindow(context.getParentFrame(), this); diff --git a/src/antidote/org/apache/tools/ant/gui/AntTreeCellRenderer.java b/src/antidote/org/apache/tools/ant/gui/AntTreeCellRenderer.java new file mode 100644 index 000000000..360d1d3a4 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/AntTreeCellRenderer.java @@ -0,0 +1,83 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999, 2000 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", "Tomcat", 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 + * . + */ +package org.apache.tools.ant.gui; + +import org.apache.tools.ant.gui.acs.ACSElement; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.JTree; +import java.awt.Component; + +/** + * Cell renderer for displaying the Ant XML file in a JTree. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class AntTreeCellRenderer extends DefaultTreeCellRenderer { + + public Component getTreeCellRendererComponent(JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { + super.getTreeCellRendererComponent(tree, value, sel, expanded, + leaf, row, hasFocus); + if(value instanceof ACSElement) { + setText(((ACSElement)value).getDisplayName()); + } + return this; + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java b/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java index 9a634c9f6..470b271e6 100644 --- a/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java +++ b/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java @@ -82,6 +82,7 @@ class ProjectNavigator extends AntEditor { _tree = new JTree(); _tree.setModel(null); + _tree.setCellRenderer(new AntTreeCellRenderer()); JScrollPane scroller = new JScrollPane(_tree); add(scroller); diff --git a/src/antidote/org/apache/tools/ant/gui/ProjectProxy.java b/src/antidote/org/apache/tools/ant/gui/ProjectProxy.java index 44fd77e9b..2a88ef8e6 100644 --- a/src/antidote/org/apache/tools/ant/gui/ProjectProxy.java +++ b/src/antidote/org/apache/tools/ant/gui/ProjectProxy.java @@ -54,6 +54,7 @@ package org.apache.tools.ant.gui; import org.apache.tools.ant.*; import org.apache.tools.ant.gui.event.*; +import org.apache.tools.ant.gui.acs.*; import java.io.File; import java.io.IOException; import javax.swing.tree.TreeModel; @@ -80,7 +81,7 @@ public class ProjectProxy { /** The file where the project was last saved. */ private File _file = null; /** The real Ant Project instance. */ - private Project _project = null; + private ACSProjectElement _project = null; /** The current thread executing a build. */ private Thread _buildThread = null; /** The selection model for selected targets. */ @@ -102,23 +103,9 @@ public class ProjectProxy { * */ private void loadProject() throws IOException { - _project = new Project(); + _project = ACSFactory.getInstance().load(_file); _selections = new TargetSelectionModel(); _selections.addTreeSelectionListener(new SelectionForwarder()); - synchronized(_project) { - _project.init(); - - // XXX there is a bunch of stuff in the class - // org.apache.tools.ant.Main that needs to be - // abstracted out so that it doesn't have to be - // replicated here. - - // XXX need to provide a way to pass in externally - // defined properties. Perhaps define an external - // Antidote properties file. - _project.setUserProperty("ant.file" , _file.getAbsolutePath()); - ProjectHelper.configureProject(_project, _file); - } } /** @@ -137,9 +124,21 @@ public class ProjectProxy { * */ public void build() throws BuildException { - if(_project == null) return; + Project project = new Project(); + project.init(); + // XXX there is a bunch of stuff in the class + // org.apache.tools.ant.Main that needs to be + // abstracted out so that it doesn't have to be + // replicated here. + + // XXX need to provide a way to pass in externally + // defined properties. Perhaps define an external + // Antidote properties file. + project.setUserProperty("ant.file" , _file.getAbsolutePath()); + ProjectHelper.configureProject(project, _file); - _buildThread = new Thread(new BuildRunner()); + + _buildThread = new Thread(new BuildRunner(project)); _buildThread.start(); } @@ -180,75 +179,75 @@ public class ProjectProxy { * @return Document view on project. */ public Document getDocument() { - if(_project != null) { - // This is what the call should look like - //return new ProjectDocument(_project); - + // This is what the call should look like + //return new ProjectDocument(_project); + if(_file != null) { return new ProjectDocument(_file); } return null; } - /** - * Convenience method for causeing the project to fire a build event. - * Implemented because the corresponding method in the Project class - * is not publically accessible. - * - * @param event Event to fire. - */ - private void fireBuildEvent(BuildEvent event, BuildEventType type) { - synchronized(_project) { + /** Class for executing the build in a separate thread. */ + private class BuildRunner implements Runnable { + private Project _project = null; + public BuildRunner(Project project) { + _project = project; + } + + /** + * Convenience method for causeing the project to fire a build event. + * Implemented because the corresponding method in the Project class + * is not publically accessible. + * + * @param event Event to fire. + */ + private void fireBuildEvent(BuildEvent event, BuildEventType type) { Enumeration enum = _project.getBuildListeners().elements(); while(enum.hasMoreElements()) { BuildListener l = (BuildListener) enum.nextElement(); type.fireEvent(event, l); } } - } - /** Class for executing the build in a separate thread. */ - private class BuildRunner implements Runnable { public void run() { - synchronized(_project) { - // Add the build listener for - // dispatching BuildEvent objects to the - // EventBus. - BuildEventForwarder handler = - new BuildEventForwarder(_context); - _project.addBuildListener(handler); - try { - fireBuildEvent(new BuildEvent( - _project), BuildEventType.BUILD_STARTED); - - // Generate list of targets to execute. - Target[] targets = _selections.getSelectedTargets(); - Vector targetNames = new Vector(); - if(targets.length == 0) { - targetNames.add(_project.getDefaultTarget()); - } - else { - for(int i = 0; i < targets.length; i++) { - targetNames.add(targets[i].getName()); - } - } - - // Execute build on selected targets. XXX It would be - // nice if the Project API supported passing in target - // objects rather than String names. - _project.executeTargets(targetNames); - } - catch(BuildException ex) { - BuildEvent errorEvent = new BuildEvent(_project); - errorEvent.setException(ex); - errorEvent.setMessage(ex.getMessage(), Project.MSG_ERR); - fireBuildEvent(errorEvent, BuildEventType.MESSAGE_LOGGED); + // Add the build listener for + // dispatching BuildEvent objects to the + // EventBus. + BuildEventForwarder handler = + new BuildEventForwarder(_context); + _project.addBuildListener(handler); + try { + fireBuildEvent(new BuildEvent( + _project), BuildEventType.BUILD_STARTED); + + // Generate list of targets to execute. + ACSTargetElement[] targets = _selections.getSelectedTargets(); + Vector targetNames = new Vector(); + if(targets.length == 0) { + targetNames.add(_project.getDefaultTarget()); } - finally { - fireBuildEvent(new BuildEvent( - _project), BuildEventType.BUILD_FINISHED); - _project.removeBuildListener(handler); - _buildThread = null; + else { + for(int i = 0; i < targets.length; i++) { + targetNames.add(targets[i].getName()); + } } + + // Execute build on selected targets. XXX It would be + // nice if the Project API supported passing in target + // objects rather than String names. + _project.executeTargets(targetNames); + } + catch(BuildException ex) { + BuildEvent errorEvent = new BuildEvent(_project); + errorEvent.setException(ex); + errorEvent.setMessage(ex.getMessage(), Project.MSG_ERR); + fireBuildEvent(errorEvent, BuildEventType.MESSAGE_LOGGED); + } + finally { + fireBuildEvent(new BuildEvent( + _project), BuildEventType.BUILD_FINISHED); + _project.removeBuildListener(handler); + _buildThread = null; } } } diff --git a/src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java b/src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java index 2939251d9..047ec61ca 100644 --- a/src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java +++ b/src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java @@ -54,146 +54,18 @@ package org.apache.tools.ant.gui; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; -import javax.swing.event.TreeModelListener; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Target; -import java.util.*; +import javax.swing.tree.DefaultTreeModel; +import org.apache.tools.ant.gui.acs.ACSProjectElement; /** - * Provides a tree model view of the Project class. + * Provides a tree model view of the Project class. XXX This + * is a major hack right now that needs to be cleaned up. * * @version $Revision$ - * @author Simeon H.K. Fitch - */ -public class ProjectTreeModel implements TreeModel { - - private Project _project = null; - private ProjectWrapper _wrapper = null; - - // XXX temp doesn't handle dynamic updates. - /** Defines an ordering for the tasks. */ - private List _targetOrdering = new ArrayList(); - - public ProjectTreeModel(Project project) { - _project = project; - _wrapper = new ProjectWrapper(); - Enumeration enum = _project.getTargets().keys(); - while(enum.hasMoreElements()) { - _targetOrdering.add(enum.nextElement()); - } - } - - /** - * Returns the root of the tree. Returns null only if the tree has - * no nodes. - * - * @return the root of the tree - */ - public Object getRoot() { - return _wrapper; - } - - - /** - * Returns the child of parent at index index in the parent's - * child array. parent must be a node previously obtained from - * this data source. This should not return null if index - * is a valid index for parent (that is index >= 0 && - * index < getChildCount(parent)). - * - * @param parent a node in the tree, obtained from this data source - * @return the child of parent at index index - */ - public Object getChild(Object parent, int index) { - if(parent != _wrapper) return null; - - Object name = _targetOrdering.get(index); - return _project.getTargets().get(name); - } - - - /** - * Returns the number of children of parent. Returns 0 if the node - * is a leaf or if it has no children. parent must be a node - * previously obtained from this data source. - * - * @param parent a node in the tree, obtained from this data source - * @return the number of children of the node parent - */ - public int getChildCount(Object parent) { - return parent == _wrapper ? _project.getTargets().size() : 0; - } - - - /** - * Returns true if node is a leaf. It is possible for this method - * to return false even if node has no children. A directory in a - * filesystem, for example, may contain no files; the node representing - * the directory is not a leaf, but it also has no children. - * - * @param node a node in the tree, obtained from this data source - * @return true if node is a leaf - */ - public boolean isLeaf(Object node) { - return node != _wrapper; + * @author Simeon H.K. Fitch */ +public class ProjectTreeModel extends DefaultTreeModel { + public ProjectTreeModel(ACSProjectElement root) { + super(root); } - - /** - * Messaged when the user has altered the value for the item identified - * by path to newValue. If newValue signifies - * a truly new value the model should post a treeNodesChanged - * event. - * - * @param path path to the node that the user has altered. - * @param newValue the new value from the TreeCellEditor. - */ - public void valueForPathChanged(TreePath path, Object newValue) { - System.out.println(path); - } - - /** - * Returns the index of child in parent. - */ - public int getIndexOfChild(Object parent, Object child) { - return parent == _project ? - _targetOrdering.indexOf(((Target)child).getName()) : -1; - } - - - /** - * Adds a listener for the TreeModelEvent posted after the tree changes. - * - * @see #removeTreeModelListener - * @param l the listener to add - */ - public void addTreeModelListener(TreeModelListener l) { - - } - - /** - * Removes a listener previously added with addTreeModelListener(). - * - * @see #addTreeModelListener - * @param l the listener to remove - */ - public void removeTreeModelListener(TreeModelListener l) { - - } - - /** - * A wrapper around the Project class to provide different - * toString behavior. XXX this is temporary until a custom - * cell renderer is created. - * - */ - private class ProjectWrapper { - public String toString() { - return _project.getName(); - } - } - - } diff --git a/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java index ffffc8955..776fb409c 100644 --- a/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java +++ b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java @@ -52,7 +52,7 @@ * . */ package org.apache.tools.ant.gui; -import org.apache.tools.ant.Target; +import org.apache.tools.ant.gui.acs.ACSTargetElement; import org.apache.tools.ant.gui.event.*; import javax.swing.*; import java.util.*; @@ -86,7 +86,9 @@ class PropertyEditor extends AntEditor { _text.setEditable(false); _text.setOpaque(false); - add(BorderLayout.CENTER, _text); + JScrollPane scroller = new JScrollPane(_text); + + add(BorderLayout.CENTER, scroller); } /** @@ -94,7 +96,7 @@ class PropertyEditor extends AntEditor { * * @param targets Targets to display info for. */ - private void displayTargetInfo(Target[] targets) { + private void displayTargetInfo(ACSTargetElement[] targets) { // The text to display. String text = null; @@ -130,16 +132,16 @@ class PropertyEditor extends AntEditor { * @param target Target to generate params for. * @return Argument list for the formatted message. */ - private Object[] getTargetParams(Target target) { + private Object[] getTargetParams(ACSTargetElement target) { List args = new LinkedList(); args.add(target.getName()); args.add(target.getDescription() == null ? "" : target.getDescription()); StringBuffer buf = new StringBuffer(); - Enumeration enum = target.getDependencies(); - while(enum.hasMoreElements()) { - buf.append(enum.nextElement()); - if(enum.hasMoreElements()) { + String[] depends = target.getDependencyNames(); + for(int i = 0; i < depends.length; i++) { + buf.append(depends[i]); + if(i < depends.length - 1) { buf.append(", "); } } @@ -155,7 +157,7 @@ class PropertyEditor extends AntEditor { * @param target Targets to generate params for. * @return Argument list for the formatted message. */ - private Object[] getTargetParams(Target[] targets) { + private Object[] getTargetParams(ACSTargetElement[] targets) { List args = new LinkedList(); StringBuffer buf = new StringBuffer(); @@ -166,9 +168,9 @@ class PropertyEditor extends AntEditor { buf.append(", "); } - Enumeration enum = targets[i].getDependencies(); - while(enum.hasMoreElements()) { - depends.add(enum.nextElement()); + String[] dependNames = targets[i].getDependencyNames(); + for(int j = 0; j < dependNames.length; j++) { + depends.add(dependNames[j]); } } @@ -209,7 +211,7 @@ class PropertyEditor extends AntEditor { */ public void eventPosted(EventObject event) { TargetSelectionEvent e = (TargetSelectionEvent) event; - Target[] targets = e.getSelectedTargets(); + ACSTargetElement[] targets = e.getSelectedTargets(); displayTargetInfo(targets); } diff --git a/src/antidote/org/apache/tools/ant/gui/TargetSelectionModel.java b/src/antidote/org/apache/tools/ant/gui/TargetSelectionModel.java index 1ccf9d998..83a823685 100644 --- a/src/antidote/org/apache/tools/ant/gui/TargetSelectionModel.java +++ b/src/antidote/org/apache/tools/ant/gui/TargetSelectionModel.java @@ -52,7 +52,7 @@ * . */ package org.apache.tools.ant.gui; -import org.apache.tools.ant.Target; +import org.apache.tools.ant.gui.acs.ACSTargetElement; import javax.swing.tree.DefaultTreeSelectionModel; import javax.swing.tree.TreePath; @@ -79,17 +79,17 @@ class TargetSelectionModel extends DefaultTreeSelectionModel { * * @return the currently selected targets. */ - public Target[] getSelectedTargets() { + public ACSTargetElement[] getSelectedTargets() { TreePath[] path = getSelectionPaths(); List values = new LinkedList(); for(int i = 0; path != null && i < path.length; i++) { Object val = path[i].getLastPathComponent(); - if(val instanceof Target) { + if(val instanceof ACSTargetElement) { values.add(val); } } - Target[] retval = new Target[values.size()]; + ACSTargetElement[] retval = new ACSTargetElement[values.size()]; values.toArray(retval); return retval; } diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSDefaultElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSDefaultElement.java new file mode 100644 index 000000000..504e66fbe --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSDefaultElement.java @@ -0,0 +1,73 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999, 2000 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", "Tomcat", 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 + * . + */ +package org.apache.tools.ant.gui.acs; + +import com.sun.xml.tree.ElementNode; + +/** + * Default element used when no other element is specificed. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ACSDefaultElement extends ACSElement { + /** + * Default ctor. + * + */ + public ACSDefaultElement() { + + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java new file mode 100644 index 000000000..ba4eb24b6 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java @@ -0,0 +1,191 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999, 2000 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", "Tomcat", 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 + * . + */ +package org.apache.tools.ant.gui.acs; + + +import org.w3c.dom.Node; +import com.sun.xml.tree.ElementNode; +import javax.swing.tree.TreeNode; +import java.util.*; + +/** + * Abstract base class for all Ant Construction Set + * elements. Depends on the JAXP XML library from Sun. + * + * @version $Revision$ + * @author Simeon Fitch */ +public abstract class ACSElement extends ElementNode implements TreeNode { + /** Cache of TreeNode only children. */ + private List _treeNodeCache = null; + + /** + * Default ctor. + * + */ + protected ACSElement() { + + } + + /** + * Get the display name of this. + * + * @return Display name. + */ + public String getDisplayName() { + return getTagName(); + } + + /** + * Get the cache of TreeNode only children. + * + * @return List of TreeNodes that are children. + */ + private List getCache() { + if(_treeNodeCache == null) { + _treeNodeCache = new ArrayList(); + + for(int i = 0; i < getLength(); i++) { + if(item(i) instanceof TreeNode) { + _treeNodeCache.add(item(i)); + } + } + } + + return _treeNodeCache; + } + /** + * Returns the child TreeNode at index + * childIndex. + */ + public TreeNode getChildAt(int childIndex) { + List nodes = getCache(); + return (TreeNode) nodes.get(childIndex); + } + + /** + * Returns the number of children TreeNodes the receiver + * contains. + */ + public int getChildCount() { + List nodes = getCache(); + return nodes.size(); + } + + /** + * Returns the parent TreeNode of the receiver. + */ + public TreeNode getParent() { + return (TreeNode) getParent(); + } + + /** + * Returns the index of node in the receivers children. + * If the receiver does not contain node, -1 will be + * returned. + */ + public int getIndex(TreeNode node) { + List nodes = getCache(); + return nodes.indexOf(node); + } + + /** + * Returns true if the receiver allows children. + */ + public boolean getAllowsChildren() { + return true; + } + + /** + * Returns true if the receiver is a leaf. + */ + public boolean isLeaf() { + List nodes = getCache(); + return nodes.size() <= 0; + } + + /** + * Returns the children of the reciever as an Enumeration. + */ + public Enumeration children() { + return new NodeEnum(); + } + + /** Internal iterator for the child nodes. */ + private class NodeEnum implements Enumeration { + /** Current child index. */ + private int _index = 0; + + /** + * Determine if there are more elements to visit. + * + * @return True if nextElement() can be called, false otherwise. + */ + public boolean hasMoreElements() { + List nodes = getCache(); + return _index < nodes.size(); + } + + /** + * Get the next element. hasMoreElements() must currently return true. + * + * @return Next element + */ + public Object nextElement() { + List nodes = getCache(); + return nodes.get(_index++); + } + + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java new file mode 100644 index 000000000..1f53028c4 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java @@ -0,0 +1,164 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999, 2000 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", "Tomcat", 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 + * . + */ +package org.apache.tools.ant.gui.acs; + +import javax.xml.parsers.*; +import java.io.File; +import java.io.IOException; +import org.w3c.dom.*; +import com.sun.xml.parser.Parser; +import com.sun.xml.tree.SimpleElementFactory; +import com.sun.xml.tree.XmlDocument; +import com.sun.xml.tree.XmlDocumentBuilder; +import java.util.Properties; +import com.sun.xml.parser.Resolver; + +/** + * Factory for loading Ant Construction set elements. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ACSFactory { + /** Singleton instance of the factory. */ + private static ACSFactory _instance = null; + + /** Element maping. */ + private static final Properties _elementMap = new Properties(); + + static { + try { + _elementMap.load(ACSFactory.class. + getResourceAsStream("acs-element.properties")); + } + catch(Throwable ex) { + ex.printStackTrace(); + System.exit(1); + } + } + + /** + * Default ctor. + * + */ + private ACSFactory() { + + } + + /** + * Load a project from the given XML file. + * XXX fix me. + * + * @param f File to load. + * @return + */ + public ACSProjectElement load(File f) throws IOException { + XmlDocument doc = null; + + try { + SAXParser sax = SAXParserFactory.newInstance().newSAXParser(); + Parser parser = (Parser) sax.getParser(); + XmlDocumentBuilder builder = new XmlDocumentBuilder(); + builder.setIgnoringLexicalInfo(false); + SimpleElementFactory fact = new SimpleElementFactory(); + fact.addMapping(_elementMap, ACSFactory.class.getClassLoader()); + + builder.setElementFactory(fact); + + parser.setDocumentHandler(builder); + parser.setEntityResolver(new Resolver()); + //parser.setErrorHandler(); + + sax.parse(f, null); + + doc = builder.getDocument(); + } + catch(Exception ex) { + ex.printStackTrace(); + throw new IOException(ex.getMessage()); + } + + return (ACSProjectElement) doc.getDocumentElement(); + } + + /** + * Get an instance of the factory. + * + * @return Factory instance. + */ + public static ACSFactory getInstance() { + if(_instance == null) { + _instance = new ACSFactory(); + } + return _instance; + } + + + /** + * Test code + * + * @param args XML file to parse. + */ + public static void main(String[] args) { + try { + ACSFactory f = ACSFactory.getInstance(); + + System.out.println(f.load(new File(args[0]))); + } + catch(Exception ex) { + ex.printStackTrace(); + } + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java new file mode 100644 index 000000000..983fb044d --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java @@ -0,0 +1,86 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999, 2000 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", "Tomcat", 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 + * . + */ +package org.apache.tools.ant.gui.acs; + +import com.sun.xml.tree.ElementNode; + +/** + * Class representing a project element in the build file. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ACSProjectElement extends ACSElement { + public ACSProjectElement() { + + } + + /** + * Get the project name. + * + * @return Project name. + */ + public String getName() { + return getAttribute("name"); + } + + /** + * Get the display name. + * + * @return Display name. + */ + public String getDisplayName() { + return getTagName() + ": " + getName(); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElement.java new file mode 100644 index 000000000..f010d1841 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElement.java @@ -0,0 +1,118 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999, 2000 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", "Tomcat", 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 + * . + */ +package org.apache.tools.ant.gui.acs; + +import com.sun.xml.tree.ElementNode; +import java.util.StringTokenizer; + +/** + * Class representing a build target. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ACSTargetElement extends ACSElement { + /** + * Default ctor. + * + */ + public ACSTargetElement() { + + } + + /** + * Get the target name. + * + * @return Target name. + */ + public String getName() { + return getAttribute("name"); + } + + /** + * Get the long description of the target. + * + * @return Target description. + */ + public String getDescription() { + return getAttribute("description"); + } + + /** + * Set the set of dependency names. + * + * @return Dependency names. + */ + public String[] getDependencyNames() { + String depends = getAttribute("depends"); + StringTokenizer tok = new StringTokenizer(depends,","); + String[] retval = new String[tok.countTokens()]; + for(int i = 0; i < retval.length; i++) { + retval[i] = tok.nextToken(); + } + + return retval; + } + + /** + * Get the display name. + * + * @return Display name. + */ + public String getDisplayName() { + return getTagName() + ": " + getName(); + } + + +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/acs-element.properties b/src/antidote/org/apache/tools/ant/gui/acs/acs-element.properties new file mode 100644 index 000000000..f4306bc99 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/acs-element.properties @@ -0,0 +1,10 @@ +# +# Property file mapping DOM nodes to Java class names. +# + +# The default element +*Element=org.apache.tools.ant.gui.acs.ACSDefaultElement + +# Specific elements. +project=org.apache.tools.ant.gui.acs.ACSProjectElement +target=org.apache.tools.ant.gui.acs.ACSTargetElement diff --git a/src/antidote/org/apache/tools/ant/gui/acs/package.html b/src/antidote/org/apache/tools/ant/gui/acs/package.html new file mode 100644 index 000000000..73f3f6e14 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/package.html @@ -0,0 +1,9 @@ +

Ant Construction Set

+ +

This package contains the tools for constructing and manipulating an Ant +build file

+ +

NB: Requires the Java API for XML +Parsing from Sun.

+ + diff --git a/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java b/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java index 684fb8859..b8d15c90e 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java @@ -54,6 +54,7 @@ q * package org.apache.tools.ant.gui.command; import org.apache.tools.ant.gui.AppContext; import org.apache.tools.ant.gui.ProjectProxy; +import org.apache.tools.ant.gui.event.ErrorEvent; /** * Starts an Ant build. @@ -84,7 +85,12 @@ public class BuildCmd implements Command { public void execute() { ProjectProxy project = _context.getProject(); if(project != null) { - project.build(); + try { + project.build(); + } + catch(Throwable ex) { + _context.getEventBus().postEvent(new ErrorEvent(_context, ex)); + } } } } diff --git a/src/antidote/org/apache/tools/ant/gui/event/TargetSelectionEvent.java b/src/antidote/org/apache/tools/ant/gui/event/TargetSelectionEvent.java index 3256ceaf0..573cfc0ce 100644 --- a/src/antidote/org/apache/tools/ant/gui/event/TargetSelectionEvent.java +++ b/src/antidote/org/apache/tools/ant/gui/event/TargetSelectionEvent.java @@ -52,7 +52,7 @@ * . */ package org.apache.tools.ant.gui.event; -import org.apache.tools.ant.Target; +import org.apache.tools.ant.gui.acs.ACSTargetElement; import org.apache.tools.ant.gui.command.Command; import org.apache.tools.ant.gui.command.NoOpCmd; import org.apache.tools.ant.gui.AppContext; @@ -66,14 +66,15 @@ import org.apache.tools.ant.gui.AppContext; public class TargetSelectionEvent extends AntEvent { /** New set of selected targets. */ - private Target[] _selectedTargets = null; + private ACSTargetElement[] _selectedTargets = null; /** * Standard ctor. * * @param context application context. */ - public TargetSelectionEvent(AppContext context, Target[] selectedTargets) { + public TargetSelectionEvent(AppContext context, + ACSTargetElement[] selectedTargets) { super(context); _selectedTargets = selectedTargets; } @@ -83,7 +84,7 @@ public class TargetSelectionEvent extends AntEvent { * * @return selected target set. */ - public Target[] getSelectedTargets() { + public ACSTargetElement[] getSelectedTargets() { return _selectedTargets; } diff --git a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties index 5dc235703..83797c9ab 100644 --- a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties +++ b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties @@ -19,17 +19,17 @@ org.apache.tools.ant.gui.SourceEditor.name=Source org.apache.tools.ant.gui.PropertyEditor.name=Target Info org.apache.tools.ant.gui.PropertyEditor.noTargets=No targets selected. org.apache.tools.ant.gui.PropertyEditor.oneTarget=\ -\ -\ -\ -\ -
Name:{0}
Description:{1}
Depends:{2}
+ \ + \ + \ + \ +
Name:{0}
Description:{1}
Depends:{2}
org.apache.tools.ant.gui.PropertyEditor.manyTargets=\ -\ -\ -\ -
Names:{0}
Depends:{1}
+ \ + \ + \ +
Names:{0}
Depends:{1}
org.apache.tools.ant.gui.ProjectNavigator.name=Project org.apache.tools.ant.gui.Console.name=Console @@ -45,12 +45,14 @@ org.apache.tools.ant.gui.About.title=About org.apache.tools.ant.gui.About.ok=OK org.apache.tools.ant.gui.About.message=\

Antidote

\ -

Version: {0}

\ -

Date: {1}

\ -

Contributors: {2}

\ -
\ -

Copyright © 2000 The Apache Software Foundation.

-

All rights reserved.

\ + \ + \ + \ + \ + \ +
Version:{0}
Date:{1}
Contributors:{2}
\
\ +

Copyright © 2000 The Apache Software Foundation.
\ + All rights reserved.

\