Browse Source

Added logging of stacktraces of exceptions in logmessage when loglevel = debug.

Made first use of this logging in the Delete task.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@475788 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 18 years ago
parent
commit
13bdae7c19
7 changed files with 139 additions and 11 deletions
  1. +6
    -4
      src/main/org/apache/tools/ant/BuildEvent.java
  2. +1
    -0
      src/main/org/apache/tools/ant/BuildListener.java
  3. +4
    -0
      src/main/org/apache/tools/ant/DefaultLogger.java
  4. +88
    -6
      src/main/org/apache/tools/ant/Project.java
  5. +32
    -0
      src/main/org/apache/tools/ant/Task.java
  6. +7
    -0
      src/main/org/apache/tools/ant/XmlLogger.java
  7. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Delete.java

+ 6
- 4
src/main/org/apache/tools/ant/BuildEvent.java View File

@@ -46,7 +46,7 @@ public class BuildEvent extends EventObject {
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 @@ public class BuildEvent extends EventObject {

/**
* 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 @@ public class BuildEvent extends EventObject {

/**
* 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)


+ 1
- 0
src/main/org/apache/tools/ant/BuildListener.java View File

@@ -99,6 +99,7 @@ public interface BuildListener extends EventListener {
* Must not be <code>null</code>.
*
* @see BuildEvent#getMessage()
* @see BuildEvent#getException()
* @see BuildEvent#getPriority()
*/
void messageLogged(BuildEvent event);


+ 4
- 0
src/main/org/apache/tools/ant/DefaultLogger.java View File

@@ -277,6 +277,10 @@ public class DefaultLogger implements BuildLogger {
} 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) {


+ 88
- 6
src/main/org/apache/tools/ant/Project.java View File

@@ -425,9 +425,19 @@ public class Project implements ResourceFactory {
* @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>.
@@ -435,9 +445,20 @@ public class Project implements ResourceFactory {
* @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.
@@ -446,9 +467,22 @@ public class Project implements ResourceFactory {
* @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.
*
@@ -2150,10 +2184,26 @@ public class Project implements ResourceFactory {
*/
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 @@ public class Project implements ResourceFactory {
*/
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 @@ public class Project implements ResourceFactory {
* @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.


+ 32
- 0
src/main/org/apache/tools/ant/Task.java View File

@@ -327,6 +327,38 @@ public abstract class Task extends ProjectComponent {
}
}

/**
* 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.


+ 7
- 0
src/main/org/apache/tools/ant/XmlLogger.java View File

@@ -398,6 +398,13 @@ public class XmlLogger implements BuildLogger {
}
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);



+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Delete.java View File

@@ -621,7 +621,7 @@ public class Delete extends MatchingTask {
throw (e instanceof BuildException)
? (BuildException) e : new BuildException(e);
}
log(e.getMessage(), quiet ? Project.MSG_VERBOSE : verbosity);
log(e, quiet ? Project.MSG_VERBOSE : verbosity);
}

/**


Loading…
Cancel
Save