From 40ea40eae5001e893c3408de42d32c00b68d8f43 Mon Sep 17 00:00:00 2001 From: metasim Date: Tue, 21 Nov 2000 01:06:16 +0000 Subject: [PATCH] Cleaned up error reporting for build.xml parse errors. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268217 13f79535-47bb-0310-9956-ffa450edef68 --- src/antidote/ChangeLog | 5 +++ .../apache/tools/ant/gui/acs/ACSFactory.java | 6 ++-- .../ant/gui/command/DisplayErrorCmd.java | 36 +++++++++++++++++-- .../tools/ant/gui/command/LoadFileCmd.java | 4 +-- .../ant/gui/resources/antidote.properties | 3 +- 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/antidote/ChangeLog b/src/antidote/ChangeLog index d33973158..fec366058 100644 --- a/src/antidote/ChangeLog +++ b/src/antidote/ChangeLog @@ -1,3 +1,8 @@ +2000-11-20 Simeon H.K. Fitch + + * org/apache/tools/ant/gui/command/DisplayErrorCmd.java: Added + code to allow display of stack backtrace if needed. + 2000-11-18 Simeon H.K. Fitch * org/apache/tools/ant/gui/customizer/PropertiesPropertyEditor.java: diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java index 64b7228ae..0fdbf2c2a 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java @@ -57,6 +57,7 @@ import javax.xml.parsers.*; import java.io.File; import java.io.IOException; import org.w3c.dom.*; +import org.xml.sax.SAXException; import com.sun.xml.parser.Parser; import com.sun.xml.tree.SimpleElementFactory; import com.sun.xml.tree.XmlDocument; @@ -119,7 +120,7 @@ public class ACSFactory { * @param f File to load. * @return */ - public ACSProjectElement load(File f) throws IOException { + public ACSProjectElement load(File f) throws IOException, SAXException { XmlDocument doc = null; try { @@ -139,8 +140,9 @@ public class ACSFactory { sax.parse(f, null); doc = builder.getDocument(); + } - catch(Exception ex) { + catch(ParserConfigurationException ex) { ex.printStackTrace(); throw new IOException(ex.getMessage()); } diff --git a/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java b/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java index eb247aa61..079532ca8 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java @@ -53,7 +53,11 @@ */ package org.apache.tools.ant.gui.command; import org.apache.tools.ant.gui.AppContext; -import javax.swing.JOptionPane; +import org.apache.tools.ant.gui.util.StackFrame; +import javax.swing.*; +import java.awt.FlowLayout; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; /** * Command for displaying an arbitrary error message to the user. @@ -101,7 +105,35 @@ public class DisplayErrorCmd implements Command { String title = _context.getResources().getString(getClass(), "title"); JOptionPane.showMessageDialog( - _context.getParentFrame(), _message, + _context.getParentFrame(), new MsgPanel(), title, JOptionPane.ERROR_MESSAGE); } + + // Panel for assembling the error information. + private class MsgPanel extends JPanel implements ActionListener { + public MsgPanel() { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + add(new JLabel(_message)); + if(_ex != null) { + add(new JLabel(_ex.getMessage())); + JButton b = new JButton(_context.getResources(). + getString(DisplayErrorCmd.class, + "expand")); + b.addActionListener(this); + add(Box.createVerticalStrut(20)); + add(b); + } + } + // Called when the user clicks the expand button. + public void actionPerformed(ActionEvent e) { + JComponent source = (JComponent) e.getSource(); + JComponent parent = (JComponent) source.getParent(); + parent.remove(source); + JTextArea text = new JTextArea(); + text.setEditable(false); + text.setText(StackFrame.toString(_ex)); + parent.add(new JScrollPane(text)); + SwingUtilities.windowForComponent(parent).pack(); + } + } } diff --git a/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java b/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java index 3fd3f8fa9..c69f37955 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java @@ -98,13 +98,13 @@ public class LoadFileCmd implements Command { ProjectProxy project = new ProjectProxy(_context, _file); _context.setProject(project); } - catch(IOException ex) { + catch(Exception ex) { String message = _context.getResources().getMessage( getClass(), "loadError", new Object[] { _file.toString() }); _context.getEventBus(). - postEvent(new ErrorEvent(_context, message)); + postEvent(new ErrorEvent(_context, message, ex)); } } } 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 d199188dd..3add07f97 100644 --- a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties +++ b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties @@ -34,7 +34,8 @@ org.apache.tools.ant.gui.XMLFileFilter.description=XML Files org.apache.tools.ant.gui.command.LoadFileCmd.noFile=The file "{0}" was not found. org.apache.tools.ant.gui.command.LoadFileCmd.loadError=The file "{0}" could not be loaded. -org.apache.tools.ant.gui.command.DisplayErrorCmd.title=Error... +org.apache.tools.ant.gui.command.DisplayErrorCmd.title=Antidote Error... +org.apache.tools.ant.gui.command.DisplayErrorCmd.expand=Details >> org.apache.tools.ant.gui.command.SaveCmd.saveError=Could not save to "{0}". org.apache.tools.ant.gui.command.SaveCmd.noProject=No project to save.