diff --git a/src/main/org/apache/tools/ant/DemuxOutputStream.java b/src/main/org/apache/tools/ant/DemuxOutputStream.java
index 7da083b09..8694ae4be 100644
--- a/src/main/org/apache/tools/ant/DemuxOutputStream.java
+++ b/src/main/org/apache/tools/ant/DemuxOutputStream.java
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -191,8 +191,21 @@ public class DemuxOutputStream extends OutputStream {
* @see Project#demuxOutput(String,boolean)
*/
protected void processBuffer(ByteArrayOutputStream buffer) {
+ processBuffer(buffer, true);
+ }
+
+ /**
+ * Converts the buffer to a string and sends it to the project.
+ *
+ * @param buffer the ByteArrayOutputStream used to collect the output
+ * until a line separator is seen.
+ *
+ * @see Project#demuxOutput(String,boolean)
+ */
+ protected void processBuffer(ByteArrayOutputStream buffer,
+ boolean terminated) {
String output = buffer.toString();
- project.demuxOutput(output, isErrorStream);
+ project.demuxOutput(output, isErrorStream, terminated);
resetBufferInfo();
}
@@ -217,7 +230,7 @@ public class DemuxOutputStream extends OutputStream {
public void flush() throws IOException {
BufferInfo bufferInfo = getBufferInfo();
if (bufferInfo.buffer.size() > 0) {
- processBuffer(bufferInfo.buffer);
+ processBuffer(bufferInfo.buffer, false);
}
}
}
diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java
index 719378daa..5e9cb6497 100644
--- a/src/main/org/apache/tools/ant/Project.java
+++ b/src/main/org/apache/tools/ant/Project.java
@@ -1228,18 +1228,35 @@ public class Project {
* or information (false).
*/
public void demuxOutput(String line, boolean isError) {
+ demuxOutput(line, isError, true);
+ }
+
+ /**
+ * Demultiplexes output so that each task receives the appropriate
+ * messages. If the current thread is not currently executing a task,
+ * the message is logged directly.
+ *
+ * @param line Message to handle. Should not be null.
+ * @param isError Whether the text represents an error (true)
+ * or information (false).
+ * @param terminated true if this line should be terminated with an
+ * end-of-line marker
+ */
+ public void demuxOutput(String line, boolean isError, boolean terminated) {
Task task = (Task) threadTasks.get(Thread.currentThread());
if (task == null) {
fireMessageLogged(this, line, isError ? MSG_ERR : MSG_INFO);
} else {
if (isError) {
- task.handleErrorOutput(line);
+ task.handleErrorOutput(line, terminated);
} else {
- task.handleOutput(line);
+ task.handleOutput(line, terminated);
}
}
}
+
+
/**
* Executes the specified target and any targets it depends on.
*
diff --git a/src/main/org/apache/tools/ant/Task.java b/src/main/org/apache/tools/ant/Task.java
index c12cb5c9d..1f7a788d9 100644
--- a/src/main/org/apache/tools/ant/Task.java
+++ b/src/main/org/apache/tools/ant/Task.java
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -298,6 +298,17 @@ public abstract class Task extends ProjectComponent {
* @param line The line of output to log. Should not be null.
*/
protected void handleOutput(String line) {
+ handleOutput(line + "X7", true);
+ }
+
+ /**
+ * Handles a line of output by logging it with the INFO priority.
+ *
+ * @param line The line of output to log. Should not be null.
+ * @param terminated true if this line should be terminated with an
+ * end-of-line marker
+ */
+ protected void handleOutput(String line, boolean terminated) {
log(line, Project.MSG_INFO);
}
@@ -307,6 +318,17 @@ public abstract class Task extends ProjectComponent {
* @param line The error line to log. Should not be null.
*/
protected void handleErrorOutput(String line) {
+ handleErrorOutput(line, true);
+ }
+
+ /**
+ * Handles an error line by logging it with the INFO priority.
+ *
+ * @param line The error line to log. Should not be null.
+ * @param terminated true if this line should be terminated with an
+ * end-of-line marker
+ */
+ protected void handleErrorOutput(String line, boolean terminated) {
log(line, Project.MSG_ERR);
}
diff --git a/src/main/org/apache/tools/ant/UnknownElement.java b/src/main/org/apache/tools/ant/UnknownElement.java
index 03c9d6df4..e97f7c6aa 100644
--- a/src/main/org/apache/tools/ant/UnknownElement.java
+++ b/src/main/org/apache/tools/ant/UnknownElement.java
@@ -156,6 +156,19 @@ public class UnknownElement extends Task {
}
}
+ /**
+ * Handles output sent to System.out by this task or its real task.
+ *
+ * @param line The line of output to log. Should not be null.
+ */
+ protected void handleOutput(String line, boolean terminated) {
+ if (realThing instanceof Task) {
+ ((Task) realThing).handleOutput(line, terminated);
+ } else {
+ super.handleOutput(line, terminated);
+ }
+ }
+
/**
* Handles error output sent to System.err by this task or its real task.
*
@@ -169,6 +182,20 @@ public class UnknownElement extends Task {
}
}
+
+ /**
+ * Handles error output sent to System.err by this task or its real task.
+ *
+ * @param line The error line to log. Should not be null.
+ */
+ protected void handleErrorOutput(String line, boolean terminated) {
+ if (realThing instanceof Task) {
+ ((Task) realThing).handleErrorOutput(line, terminated);
+ } else {
+ super.handleErrorOutput(line, terminated);
+ }
+ }
+
/**
* Executes the real object if it's a task. If it's not a task
* (e.g. a data type) then this method does nothing.
diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java
index dc060307e..5cbffe269 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Ant.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java
@@ -296,6 +296,19 @@ public class Ant extends Task {
}
}
+ /**
+ * Pass output sent to System.out to the new project.
+ *
+ * @since Ant 1.6
+ */
+ protected void handleOutput(String line, boolean terminated) {
+ if (newProject != null) {
+ newProject.demuxOutput(line, false, terminated);
+ } else {
+ super.handleOutput(line, terminated);
+ }
+ }
+
/**
* Pass output sent to System.err to the new project.
*
@@ -309,6 +322,19 @@ public class Ant extends Task {
}
}
+ /**
+ * Pass output sent to System.err to the new project.
+ *
+ * @since Ant 1.6
+ */
+ protected void handleErrorOutput(String line, boolean terminated) {
+ if (newProject != null) {
+ newProject.demuxOutput(line, true, terminated);
+ } else {
+ super.handleErrorOutput(line, terminated);
+ }
+ }
+
/**
* Do the execution.
*/
diff --git a/src/main/org/apache/tools/ant/taskdefs/CallTarget.java b/src/main/org/apache/tools/ant/taskdefs/CallTarget.java
index ac61ead2b..b94b4a699 100644
--- a/src/main/org/apache/tools/ant/taskdefs/CallTarget.java
+++ b/src/main/org/apache/tools/ant/taskdefs/CallTarget.java
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -185,6 +185,19 @@ public class CallTarget extends Task {
}
}
+ /**
+ * Pass output sent to System.out to the new project.
+ *
+ * @since Ant 1.6
+ */
+ protected void handleOutput(String line, boolean terminated) {
+ if (callee != null) {
+ callee.handleOutput(line, terminated);
+ } else {
+ super.handleOutput(line, terminated);
+ }
+ }
+
/**
* Pass output sent to System.err to the new project.
*
@@ -198,4 +211,16 @@ public class CallTarget extends Task {
}
}
+ /**
+ * Pass output sent to System.err to the new project.
+ *
+ * @since Ant 1.6
+ */
+ protected void handleErrorOutput(String line, boolean terminated) {
+ if (callee != null) {
+ callee.handleErrorOutput(line, terminated);
+ } else {
+ super.handleErrorOutput(line, terminated);
+ }
+ }
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/Java.java b/src/main/org/apache/tools/ant/taskdefs/Java.java
index 675eb6dd7..845a5f33b 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Java.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Java.java
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -373,6 +373,23 @@ public class Java extends Task {
}
}
+ /**
+ * Pass output sent to System.out to specified output file.
+ *
+ * @since Ant 1.6
+ */
+ protected void handleOutput(String line, boolean terminated) {
+ if (outStream != null) {
+ if (terminated) {
+ outStream.println(line);
+ } else {
+ outStream.print(line);
+ }
+ } else {
+ super.handleOutput(line, terminated);
+ }
+ }
+
/**
* Pass output sent to System.err to specified output file.
*
@@ -386,6 +403,23 @@ public class Java extends Task {
}
}
+ /**
+ * Pass output sent to System.err to specified output file.
+ *
+ * @since Ant 1.6
+ */
+ protected void handleErrorOutput(String line, boolean terminated) {
+ if (outStream != null) {
+ if (terminated) {
+ outStream.println(line);
+ } else {
+ outStream.print(line);
+ }
+ } else {
+ super.handleErrorOutput(line, terminated);
+ }
+ }
+
/**
* Executes the given classname with the given arguments as it
* was a command line application.
@@ -402,6 +436,8 @@ public class Java extends Task {
new PrintStream(new FileOutputStream(out.getAbsolutePath(),
append));
exe.execute(getProject());
+ System.out.flush();
+ System.err.flush();
} catch (IOException io) {
throw new BuildException(io, getLocation());
} finally {
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
index 79699e656..2afc74fd2 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
@@ -713,6 +713,23 @@ public class JUnitTask extends Task {
}
}
+ /**
+ * Pass output sent to System.out to the TestRunner so it can
+ * collect ot for the formatters.
+ *
+ * @since Ant 1.6
+ */
+ protected void handleOutput(String line, boolean terminated) {
+ if (runner != null) {
+ runner.handleOutput(line, terminated);
+ if (showOutput) {
+ super.handleOutput(line, terminated);
+ }
+ } else {
+ super.handleOutput(line, terminated);
+ }
+ }
+
/**
* Pass output sent to System.err to the TestRunner so it can
* collect ot for the formatters.
@@ -730,6 +747,24 @@ public class JUnitTask extends Task {
}
}
+
+ /**
+ * Pass output sent to System.err to the TestRunner so it can
+ * collect ot for the formatters.
+ *
+ * @since Ant 1.6
+ */
+ protected void handleErrorOutput(String line, boolean terminated) {
+ if (runner != null) {
+ runner.handleErrorOutput(line, terminated);
+ if (showOutput) {
+ super.handleErrorOutput(line, terminated);
+ }
+ } else {
+ super.handleErrorOutput(line, terminated);
+ }
+ }
+
// in VM is not very nice since it could probably hang the
// whole build. IMHO this method should be avoided and it would be best
// to remove it in future versions. TBD. (SBa)
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
index d79467171..59bb7783d 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -416,6 +416,26 @@ public class JUnitTestRunner implements TestListener {
}
}
+ protected void handleOutput(String line, boolean terminated) {
+ if (systemOut != null) {
+ if (terminated) {
+ systemOut.println(line);
+ } else {
+ systemOut.print(line);
+ }
+ }
+ }
+
+ protected void handleErrorOutput(String line, boolean terminated) {
+ if (systemError != null) {
+ if (terminated) {
+ systemError.println(line);
+ } else {
+ systemError.print(line);
+ }
+ }
+ }
+
private void sendOutAndErr(String out, String err) {
for (int i = 0; i < formatters.size(); i++) {
JUnitResultFormatter formatter =