Author: jkf
Date: Thu Nov 16 08:08:45 2006
New Revision: 475788

URL: http://svn.apache.org/viewvc?view=rev&rev=475788
Log:
Added logging of stacktraces of exceptions in logmessage when loglevel = debug.
Made first use of this logging in the Delete task.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/BuildEvent.java
    ant/core/trunk/src/main/org/apache/tools/ant/BuildListener.java
    ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java
    ant/core/trunk/src/main/org/apache/tools/ant/Project.java
    ant/core/trunk/src/main/org/apache/tools/ant/Task.java
    ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/BuildEvent.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/BuildEvent.java?view=diff&rev=475788&r1=475787&r2=475788
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/BuildEvent.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/BuildEvent.java Thu Nov 16 
08:08:45 2006
@@ -46,7 +46,7 @@
     private int priority = Project.MSG_VERBOSE;
     /**
      * The exception associated with this event, if any.
-     * This is only used for "taskFinished", "targetFinished",
+     * This is only used for "messageLogged", "taskFinished", "targetFinished",
      * and "buildFinished" events.
      */
     private Throwable exception;
@@ -112,12 +112,13 @@
 
     /**
      * Sets the exception associated with this event. This is used
-     * for "taskFinished", "targetFinished", and "buildFinished"
+     * for "messageLogged", "taskFinished", "targetFinished", and 
"buildFinished"
      * events.
      *
      * @param exception The exception to be associated with this event.
      *                  May be <code>null</code>.
      *
+     * @see BuildListener#messageLogged(BuildEvent)
      * @see BuildListener#taskFinished(BuildEvent)
      * @see BuildListener#targetFinished(BuildEvent)
      * @see BuildListener#buildFinished(BuildEvent)
@@ -183,12 +184,13 @@
 
     /**
      * Returns the exception that was thrown, if any. This field will only
-     * be set for "taskFinished", "targetFinished", and "buildFinished"
+     * be set for "messageLogged", "taskFinished", "targetFinished", and 
"buildFinished"
      * events.
      *
      * @return the exception associated with this exception, or
      *         <code>null</code> if no exception has been set.
-     *
+     *         
+     * @see BuildListener#messageLogged(BuildEvent)
      * @see BuildListener#taskFinished(BuildEvent)
      * @see BuildListener#targetFinished(BuildEvent)
      * @see BuildListener#buildFinished(BuildEvent)

Modified: ant/core/trunk/src/main/org/apache/tools/ant/BuildListener.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/BuildListener.java?view=diff&rev=475788&r1=475787&r2=475788
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/BuildListener.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/BuildListener.java Thu Nov 16 
08:08:45 2006
@@ -99,6 +99,7 @@
      *              Must not be <code>null</code>.
      *
      * @see BuildEvent#getMessage()
+     * @see BuildEvent#getException()
      * @see BuildEvent#getPriority()
      */
     void messageLogged(BuildEvent event);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java?view=diff&rev=475788&r1=475787&r2=475788
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java Thu Nov 16 
08:08:45 2006
@@ -277,6 +277,10 @@
             } else {
                 message.append(event.getMessage());
             }
+            Throwable ex = event.getException();
+            if (Project.MSG_DEBUG <= msgOutputLevel && ex != null) {
+                    message.append(StringUtils.getStackTrace(ex));
+            }
 
             String msg = message.toString();
             if (priority != Project.MSG_ERR) {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Project.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Project.java?view=diff&rev=475788&r1=475787&r2=475788
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Project.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Project.java Thu Nov 16 
08:08:45 2006
@@ -425,20 +425,41 @@
      * @param msgLevel The log priority level to use.
      */
     public void log(String message, int msgLevel) {
-        fireMessageLogged(this, message, msgLevel);
+        log(message, null, msgLevel);
     }
 
     /**
+     * Write a project level message to the log with the given log level.
+     * @param message The text to log. Should not be <code>null</code>.
+     * @param throwable The exception causing this log, may be 
<code>null</code>.
+     * @param msgLevel The log priority level to use.
+     */
+    public void log(String message, Throwable throwable, int msgLevel) {
+        fireMessageLogged(this, message, throwable, msgLevel);
+    }
+    
+    /**
      * Write a task level message to the log with the given log level.
      * @param task The task to use in the log. Must not be <code>null</code>.
      * @param message The text to log. Should not be <code>null</code>.
      * @param msgLevel The log priority level to use.
      */
     public void log(Task task, String message, int msgLevel) {
-        fireMessageLogged(task, message, msgLevel);
+        fireMessageLogged(task, message, null, msgLevel);
     }
 
     /**
+     * Write a task level message to the log with the given log level.
+     * @param task The task to use in the log. Must not be <code>null</code>.
+     * @param message The text to log. Should not be <code>null</code>.
+     * @param throwable The exception causing this log, may be 
<code>null</code>.
+     * @param msgLevel The log priority level to use.
+     */
+    public void log(Task task, String message, Throwable throwable, int 
msgLevel) {
+        fireMessageLogged(task, message, throwable, msgLevel);
+    }
+    
+    /**
      * Write a target level message to the log with the given log level.
      * @param target The target to use in the log.
      *               Must not be <code>null</code>.
@@ -446,10 +467,23 @@
      * @param msgLevel The log priority level to use.
      */
     public void log(Target target, String message, int msgLevel) {
-        fireMessageLogged(target, message, msgLevel);
+        log(target, message, null, msgLevel);
     }
 
     /**
+     * Write a target level message to the log with the given log level.
+     * @param target The target to use in the log.
+     *               Must not be <code>null</code>.
+     * @param message The text to log. Should not be <code>null</code>.
+     * @param throwable The exception causing this log, may be 
<code>null</code>.
+     * @param msgLevel The log priority level to use.
+     */
+    public void log(Target target, String message, Throwable throwable,
+            int msgLevel) {
+        fireMessageLogged(target, message, throwable, msgLevel);
+    }
+    
+    /**
      * Return the set of global filters.
      *
      * @return the set of global filters.
@@ -2150,10 +2184,26 @@
      */
     protected void fireMessageLogged(Project project, String message,
                                      int priority) {
+        fireMessageLogged(project, message, priority);
+    }
+    
+    /**
+     * Send a &quot;message logged&quot; project level event
+     * to the build listeners for this project.
+     *
+     * @param project  The project generating the event.
+     *                 Should not be <code>null</code>.
+     * @param message  The message to send. Should not be <code>null</code>.
+     * @param throwable The exception that caused this message. May be 
<code>null</code>.
+     * @param priority The priority of the message.
+     */
+    protected void fireMessageLogged(Project project, String message, 
+            Throwable throwable, int priority) {
         BuildEvent event = new BuildEvent(project);
+        event.setException(throwable);
         fireMessageLoggedEvent(event, message, priority);
     }
-
+    
     /**
      * Send a &quot;message logged&quot; target level event
      * to the build listeners for this project.
@@ -2165,10 +2215,26 @@
      */
     protected void fireMessageLogged(Target target, String message,
                                      int priority) {
+        fireMessageLogged(target, message, null, priority);
+    }
+
+    /**
+     * Send a &quot;message logged&quot; target level event
+     * to the build listeners for this project.
+     *
+     * @param target   The target generating the event.
+     *                 Must not be <code>null</code>.
+     * @param message  The message to send. Should not be <code>null</code>.
+     * @param throwable The exception that caused this message. May be 
<code>null</code>.
+     * @param priority The priority of the message.
+     */
+    protected void fireMessageLogged(Target target, String message,
+            Throwable throwable, int priority) {
         BuildEvent event = new BuildEvent(target);
+        event.setException(throwable);
         fireMessageLoggedEvent(event, message, priority);
     }
-
+    
     /**
      * Send a &quot;message logged&quot; task level event
      * to the build listeners for this project.
@@ -2179,10 +2245,26 @@
      * @param priority The priority of the message.
      */
     protected void fireMessageLogged(Task task, String message, int priority) {
+        fireMessageLogged(task, message, null, priority);
+    }
+
+    /**
+     * Send a &quot;message logged&quot; task level event
+     * to the build listeners for this project.
+     *
+     * @param task     The task generating the event.
+     *                 Must not be <code>null</code>.
+     * @param message  The message to send. Should not be <code>null</code>.
+     * @param throwable The exception that caused this message. May be 
<code>null</code>.
+     * @param priority The priority of the message.
+     */
+    protected void fireMessageLogged(Task task, String message, 
+            Throwable throwable, int priority) {
         BuildEvent event = new BuildEvent(task);
+        event.setException(throwable);
         fireMessageLoggedEvent(event, message, priority);
     }
-
+    
     /**
      * Register a task as the current task for a thread.
      * If the task is null, the thread's entry is removed.

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Task.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Task.java?view=diff&rev=475788&r1=475787&r2=475788
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Task.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Task.java Thu Nov 16 08:08:45 
2006
@@ -328,6 +328,38 @@
     }
 
     /**
+     * Logs a message with the given priority. This delegates
+     * the actual logging to the project.
+     *
+     * @param t The exception to be logged. Should not be <code>null</code>.
+     * @param msgLevel The message priority at which this message is to
+     *                 be logged.
+     */
+    public void log(Throwable t, int msgLevel) {
+        if(t != null)
+        {
+            log(t.getMessage(), t, msgLevel);
+        }
+    }
+    
+    /**
+     * Logs a message with the given priority. This delegates
+     * the actual logging to the project.
+     *
+     * @param msg The message to be logged. Should not be <code>null</code>.
+     * @param t The exception to be logged. May be <code>null</code>.
+     * @param msgLevel The message priority at which this message is to
+     *                 be logged.
+     */
+    public void log(String msg, Throwable t, int msgLevel) {
+        if (getProject() != null) {
+            getProject().log(this, msg, t, msgLevel);
+        } else {
+            super.log(msg, msgLevel);
+        }
+    }
+    
+    /**
      * Performs this task if it's still valid, or gets a replacement
      * version and performs that otherwise.
      *

Modified: ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java?view=diff&rev=475788&r1=475787&r2=475788
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java Thu Nov 16 
08:08:45 2006
@@ -398,6 +398,13 @@
         }
         messageElement.setAttribute(PRIORITY_ATTR, name);
 
+        Throwable ex = event.getException();
+        if (Project.MSG_DEBUG <= msgOutputLevel && ex != null) {
+            Text errText = 
doc.createCDATASection(StringUtils.getStackTrace(ex));
+            Element stacktrace = doc.createElement(STACKTRACE_TAG);
+            stacktrace.appendChild(errText);
+            buildElement.element.appendChild(stacktrace);
+        }
         Text messageText = doc.createCDATASection(event.getMessage());
         messageElement.appendChild(messageText);
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java?view=diff&rev=475788&r1=475787&r2=475788
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java Thu Nov 
16 08:08:45 2006
@@ -621,7 +621,7 @@
             throw (e instanceof BuildException)
                 ? (BuildException) e : new BuildException(e);
         }
-        log(e.getMessage(), quiet ? Project.MSG_VERBOSE : verbosity);
+        log(e, quiet ? Project.MSG_VERBOSE : verbosity);
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to