git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270150 13f79535-47bb-0310-9956-ffa450edef68master
@@ -58,6 +58,8 @@ import java.io.PrintStream; | |||||
import java.io.PrintWriter; | import java.io.PrintWriter; | ||||
import java.io.StringWriter; | import java.io.StringWriter; | ||||
import org.apache.tools.ant.util.StringUtils; | |||||
/** | /** | ||||
* Writes build event to a PrintStream. Currently, it | * Writes build event to a PrintStream. Currently, it | ||||
* only writes which targets are being executed, and | * only writes which targets are being executed, and | ||||
@@ -71,8 +73,6 @@ public class DefaultLogger implements BuildLogger { | |||||
protected int msgOutputLevel = Project.MSG_ERR; | protected int msgOutputLevel = Project.MSG_ERR; | ||||
private long startTime = System.currentTimeMillis(); | private long startTime = System.currentTimeMillis(); | ||||
protected static String lSep = System.getProperty("line.separator"); | |||||
protected boolean emacsMode = false; | protected boolean emacsMode = false; | ||||
/** | /** | ||||
@@ -134,29 +134,29 @@ public class DefaultLogger implements BuildLogger { | |||||
StringBuffer message = new StringBuffer(); | StringBuffer message = new StringBuffer(); | ||||
if (error == null) { | if (error == null) { | ||||
message.append(lSep + "BUILD SUCCESSFUL"); | |||||
message.append(StringUtils.LINE_SEP); | |||||
message.append("BUILD SUCCESSFUL"); | |||||
} | } | ||||
else { | else { | ||||
message.append(lSep + "BUILD FAILED" + lSep); | |||||
message.append(StringUtils.LINE_SEP); | |||||
message.append("BUILD FAILED"); | |||||
message.append(StringUtils.LINE_SEP); | |||||
if (Project.MSG_VERBOSE <= msgOutputLevel || | if (Project.MSG_VERBOSE <= msgOutputLevel || | ||||
!(error instanceof BuildException)) { | !(error instanceof BuildException)) { | ||||
StringWriter sw = new StringWriter(); | |||||
PrintWriter pw = new PrintWriter(sw); | |||||
error.printStackTrace(pw); | |||||
message.append(sw.toString()); | |||||
message.append(StringUtils.getStackTrace(error)); | |||||
} | } | ||||
else { | else { | ||||
if (error instanceof BuildException) { | if (error instanceof BuildException) { | ||||
message.append(error.toString() + lSep); | |||||
message.append(error.toString()).append(StringUtils.LINE_SEP); | |||||
} | } | ||||
else { | else { | ||||
message.append(error.getMessage() + lSep); | |||||
message.append(error.getMessage()).append(StringUtils.LINE_SEP); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
message.append(lSep + "Total time: " | |||||
message.append(StringUtils.LINE_SEP); | |||||
message.append("Total time: " | |||||
+ formatTime(System.currentTimeMillis() - startTime)); | + formatTime(System.currentTimeMillis() - startTime)); | ||||
String msg = message.toString(); | String msg = message.toString(); | ||||
@@ -170,7 +170,7 @@ public class DefaultLogger implements BuildLogger { | |||||
public void targetStarted(BuildEvent event) { | public void targetStarted(BuildEvent event) { | ||||
if (Project.MSG_INFO <= msgOutputLevel) { | if (Project.MSG_INFO <= msgOutputLevel) { | ||||
String msg = lSep + event.getTarget().getName() + ":"; | |||||
String msg = StringUtils.LINE_SEP + event.getTarget().getName() + ":"; | |||||
out.println(msg); | out.println(msg); | ||||
log(msg); | log(msg); | ||||
} | } | ||||
@@ -68,6 +68,7 @@ import org.w3c.dom.Document; | |||||
import org.w3c.dom.Element; | import org.w3c.dom.Element; | ||||
import org.w3c.dom.Text; | import org.w3c.dom.Text; | ||||
import org.apache.tools.ant.util.DOMElementWriter; | import org.apache.tools.ant.util.DOMElementWriter; | ||||
import org.apache.tools.ant.util.StringUtils; | |||||
/** | /** | ||||
* Generates a "log.xml" file in the current directory with | * Generates a "log.xml" file in the current directory with | ||||
@@ -133,13 +134,8 @@ public class XmlLogger implements BuildListener { | |||||
buildElement.element.setAttribute(ERROR_ATTR, event.getException().toString()); | buildElement.element.setAttribute(ERROR_ATTR, event.getException().toString()); | ||||
// print the stacktrace in the build file it is always useful... | // print the stacktrace in the build file it is always useful... | ||||
// better have too much info than not enough. | // better have too much info than not enough. | ||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||||
PrintStream ps = new PrintStream(baos,true); | |||||
Throwable t = event.getException(); | Throwable t = event.getException(); | ||||
t.printStackTrace(ps); | |||||
ps.flush(); | |||||
ps.close(); | |||||
Text errText = doc.createCDATASection(baos.toString()); | |||||
Text errText = doc.createCDATASection(StringUtils.getStackTrace(t)); | |||||
Element stacktrace = doc.createElement(STACKTRACE_TAG); | Element stacktrace = doc.createElement(STACKTRACE_TAG); | ||||
stacktrace.appendChild(errText); | stacktrace.appendChild(errText); | ||||
buildElement.element.appendChild(stacktrace); | buildElement.element.appendChild(stacktrace); | ||||
@@ -57,6 +57,8 @@ package org.apache.tools.ant.taskdefs; | |||||
import org.apache.tools.ant.BuildLogger; | import org.apache.tools.ant.BuildLogger; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.BuildEvent; | import org.apache.tools.ant.BuildEvent; | ||||
import org.apache.tools.ant.util.StringUtils; | |||||
import java.io.PrintStream; | import java.io.PrintStream; | ||||
@@ -92,10 +94,6 @@ public class RecorderEntry implements BuildLogger { | |||||
* The start time of the last know target. | * The start time of the last know target. | ||||
*/ | */ | ||||
private long targetStartTime = 0l; | private long targetStartTime = 0l; | ||||
/** | |||||
* Line separator. | |||||
*/ | |||||
private static String lSep = System.getProperty("line.separator"); | |||||
////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////// | ||||
// CONSTRUCTORS / INITIALIZERS | // CONSTRUCTORS / INITIALIZERS | ||||
@@ -136,9 +134,9 @@ public class RecorderEntry implements BuildLogger { | |||||
Throwable error = event.getException(); | Throwable error = event.getException(); | ||||
if (error == null) { | if (error == null) { | ||||
out.println(lSep + "BUILD SUCCESSFUL"); | |||||
out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL"); | |||||
} else { | } else { | ||||
out.println(lSep + "BUILD FAILED" + lSep); | |||||
out.println(StringUtils.LINE_SEP + "BUILD FAILED" + StringUtils.LINE_SEP); | |||||
error.printStackTrace(out); | error.printStackTrace(out); | ||||
} | } | ||||
out.flush(); | out.flush(); | ||||
@@ -147,7 +145,7 @@ public class RecorderEntry implements BuildLogger { | |||||
public void targetStarted(BuildEvent event) { | public void targetStarted(BuildEvent event) { | ||||
log( ">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG ); | log( ">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG ); | ||||
log( lSep + event.getTarget().getName() + ":", Project.MSG_INFO ); | |||||
log( StringUtils.LINE_SEP + event.getTarget().getName() + ":", Project.MSG_INFO ); | |||||
targetStartTime = System.currentTimeMillis(); | targetStartTime = System.currentTimeMillis(); | ||||
} | } | ||||
@@ -159,7 +157,7 @@ public class RecorderEntry implements BuildLogger { | |||||
} | } | ||||
public void taskStarted(BuildEvent event) { | public void taskStarted(BuildEvent event) { | ||||
log( ">>> TAST STARTED -- " + event.getTask(), Project.MSG_DEBUG ); | |||||
log( ">>> TASK STARTED -- " + event.getTask(), Project.MSG_DEBUG ); | |||||
} | } | ||||
public void taskFinished(BuildEvent event) { | public void taskFinished(BuildEvent event) { | ||||
@@ -93,6 +93,7 @@ import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.BuildListener; | import org.apache.tools.ant.BuildListener; | ||||
import org.apache.tools.ant.BuildEvent; | import org.apache.tools.ant.BuildEvent; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.util.StringUtils; | |||||
/** | /** | ||||
* This is a simple grafical user interface to provide the information needed | * This is a simple grafical user interface to provide the information needed | ||||
@@ -114,7 +115,7 @@ public class VAJAntToolGUI extends Frame { | |||||
* Members | * Members | ||||
*/ | */ | ||||
private VAJBuildLogger logger = new VAJBuildLogger(); | private VAJBuildLogger logger = new VAJBuildLogger(); | ||||
private String lineSeparator = "\r\n"; | |||||
private final static String lineSeparator = "\r\n"; | |||||
private PrivateEventHandler iEventHandler = new PrivateEventHandler(); | private PrivateEventHandler iEventHandler = new PrivateEventHandler(); | ||||
/** | /** | ||||
@@ -1287,9 +1288,7 @@ public class VAJAntToolGUI extends Frame { | |||||
*/ | */ | ||||
private void handleException(Throwable exception) { | private void handleException(Throwable exception) { | ||||
// Write exceptions to the log-window | // Write exceptions to the log-window | ||||
StringWriter sw = new StringWriter(); | |||||
exception.printStackTrace(new PrintWriter(sw)); | |||||
String trace = new String( sw.getBuffer() ); | |||||
String trace = StringUtils.getStackTrace(exception); | |||||
getMessageTextArea().append(lineSeparator + lineSeparator + trace); | getMessageTextArea().append(lineSeparator + lineSeparator + trace); | ||||
getMessageFrame().show(); | getMessageFrame().show(); | ||||
@@ -66,6 +66,7 @@ import javax.servlet.http.HttpServletResponse; | |||||
import javax.servlet.ServletException; | import javax.servlet.ServletException; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.util.StringUtils; | |||||
/** | /** | ||||
* Abstract base class to provide common services for the | * Abstract base class to provide common services for the | ||||
@@ -145,9 +146,7 @@ public abstract class VAJToolsServlet extends HttpServlet { | |||||
} catch( Exception e ) { | } catch( Exception e ) { | ||||
try { | try { | ||||
if ( ! (e instanceof BuildException) ) { | if ( ! (e instanceof BuildException) ) { | ||||
StringWriter sw = new StringWriter(); | |||||
e.printStackTrace(new PrintWriter(sw)); | |||||
String trace = new String( sw.getBuffer() ); | |||||
String trace = StringUtils.getStackTrace(e); | |||||
util.log("Program error in " + this.getClass().getName() | util.log("Program error in " + this.getClass().getName() | ||||
+ ":\n" + trace, VAJUtil.MSG_ERR); | + ":\n" + trace, VAJUtil.MSG_ERR); | ||||
} | } | ||||
@@ -57,6 +57,7 @@ package org.apache.tools.ant.taskdefs.optional.junit; | |||||
import org.apache.tools.ant.AntClassLoader; | import org.apache.tools.ant.AntClassLoader; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.util.StringUtils; | |||||
import junit.framework.TestListener; | import junit.framework.TestListener; | ||||
import junit.framework.TestResult; | import junit.framework.TestResult; | ||||
@@ -477,11 +478,7 @@ public class JUnitTestRunner implements TestListener { | |||||
* Scott M. Stirling. | * Scott M. Stirling. | ||||
*/ | */ | ||||
public static String getFilteredTrace(Throwable t) { | public static String getFilteredTrace(Throwable t) { | ||||
StringWriter stringWriter = new StringWriter(); | |||||
PrintWriter writer = new PrintWriter(stringWriter); | |||||
t.printStackTrace(writer); | |||||
StringBuffer buffer = stringWriter.getBuffer(); | |||||
String trace = buffer.toString(); | |||||
String trace = StringUtils.getStackTrace(t); | |||||
return JUnitTestRunner.filterStack(trace); | return JUnitTestRunner.filterStack(trace); | ||||
} | } | ||||
@@ -76,6 +76,7 @@ import org.apache.tools.ant.DirectoryScanner; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
import org.apache.tools.ant.util.DOMElementWriter; | import org.apache.tools.ant.util.DOMElementWriter; | ||||
import org.apache.tools.ant.util.StringUtils; | |||||
/** | /** | ||||
@@ -269,9 +270,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { | |||||
// a testcase might have failed and write a zero-length document, | // a testcase might have failed and write a zero-length document, | ||||
// It has already failed, but hey.... mm. just put a warning | // It has already failed, but hey.... mm. just put a warning | ||||
log("The file " + files[i] + " is not a valid XML document. It is possibly corrupted.", Project.MSG_WARN); | log("The file " + files[i] + " is not a valid XML document. It is possibly corrupted.", Project.MSG_WARN); | ||||
StringWriter sw = new StringWriter(); | |||||
e.printStackTrace(new PrintWriter(sw)); | |||||
log(sw.toString(), Project.MSG_DEBUG); | |||||
log(StringUtils.getStackTrace(e), Project.MSG_DEBUG); | |||||
} catch (IOException e){ | } catch (IOException e){ | ||||
log("Error while accessing file " + files[i] + ": " + e.getMessage(), Project.MSG_ERR); | log("Error while accessing file " + files[i] + ": " + e.getMessage(), Project.MSG_ERR); | ||||
} | } | ||||