Browse Source

Ensure all generated output gets through the output system to the

generating task

PR:	21636


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274840 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
4ac04f30c2
12 changed files with 164 additions and 151 deletions
  1. +18
    -13
      src/main/org/apache/tools/ant/DemuxOutputStream.java
  2. +19
    -11
      src/main/org/apache/tools/ant/Project.java
  3. +15
    -15
      src/main/org/apache/tools/ant/Task.java
  4. +16
    -16
      src/main/org/apache/tools/ant/UnknownElement.java
  5. +12
    -12
      src/main/org/apache/tools/ant/taskdefs/Ant.java
  6. +12
    -12
      src/main/org/apache/tools/ant/taskdefs/CallTarget.java
  7. +12
    -12
      src/main/org/apache/tools/ant/taskdefs/Java.java
  8. +12
    -12
      src/main/org/apache/tools/ant/taskdefs/Redirector.java
  9. +16
    -16
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  10. +8
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
  11. +15
    -15
      src/testcases/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java
  12. +9
    -9
      src/testcases/org/apache/tools/ant/taskdefs/DemuxOutputTask.java

+ 18
- 13
src/main/org/apache/tools/ant/DemuxOutputStream.java View File

@@ -80,11 +80,10 @@ public class DemuxOutputStream extends OutputStream {
private ByteArrayOutputStream buffer;

/**
* Whether or not the next line-terminator should be skipped in terms
* of processing the buffer. Used to avoid \r\n invoking
* processBuffer twice.
* Indicates we have just seen a carriage return. It may be part of
* a crlf pair or a single cr invoking processBuffer twice.
*/
private boolean skip = false;
private boolean crSeen = false;
}

/** Maximum buffer size. */
@@ -129,7 +128,7 @@ public class DemuxOutputStream extends OutputStream {
if (bufferInfo == null) {
bufferInfo = new BufferInfo();
bufferInfo.buffer = new ByteArrayOutputStream();
bufferInfo.skip = false;
bufferInfo.crSeen = false;
buffers.put(current, bufferInfo);
}
return bufferInfo;
@@ -147,7 +146,7 @@ public class DemuxOutputStream extends OutputStream {
// Shouldn't happen
}
bufferInfo.buffer = new ByteArrayOutputStream();
bufferInfo.skip = false;
bufferInfo.crSeen = false;
}

/**
@@ -169,17 +168,23 @@ public class DemuxOutputStream extends OutputStream {
final byte c = (byte) cc;

BufferInfo bufferInfo = getBufferInfo();
if ((c == '\n') || (c == '\r')) {
if (!bufferInfo.skip) {
processBuffer(bufferInfo.buffer);
}
} else {

if (c == '\n') {
// LF is always end of line (i.e. CRLF or single LF)
bufferInfo.buffer.write(cc);
if (bufferInfo.buffer.size() > MAX_SIZE) {
processBuffer(bufferInfo.buffer);
} else {
if (bufferInfo.crSeen) {
// CR without LF - send buffer then add char
processBuffer(bufferInfo.buffer);
}
// add into buffer
bufferInfo.buffer.write(cc);
}
bufferInfo.crSeen = (c == '\r');
if (!bufferInfo.crSeen && bufferInfo.buffer.size() > MAX_SIZE) {
processBuffer(bufferInfo.buffer);
}
bufferInfo.skip = (c == '\r');
}

/**


+ 19
- 11
src/main/org/apache/tools/ant/Project.java View File

@@ -75,6 +75,8 @@ import org.apache.tools.ant.types.Description;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.StringUtils;


/**
* Central representation of an Ant project. This class defines an
@@ -1089,19 +1091,19 @@ public class Project {
* messages. If the current thread is not currently executing a task,
* the message is logged directly.
*
* @param line Message to handle. Should not be <code>null</code>.
* @param output Message to handle. Should not be <code>null</code>.
* @param isError Whether the text represents an error (<code>true</code>)
* or information (<code>false</code>).
*/
public void demuxOutput(String line, boolean isError) {
public void demuxOutput(String output, boolean isError) {
Task task = getThreadTask(Thread.currentThread());
if (task == null) {
fireMessageLogged(this, line, isError ? MSG_ERR : MSG_INFO);
log(output, isError ? MSG_ERR : MSG_INFO);
} else {
if (isError) {
task.handleErrorOutput(line);
task.handleErrorOutput(output);
} else {
task.handleOutput(line);
task.handleOutput(output);
}
}
}
@@ -1158,19 +1160,19 @@ public class Project {
*
* @since Ant 1.5.2
*
* @param line Message to handle. Should not be <code>null</code>.
* @param output Message to handle. Should not be <code>null</code>.
* @param isError Whether the text represents an error (<code>true</code>)
* or information (<code>false</code>).
*/
public void demuxFlush(String line, boolean isError) {
public void demuxFlush(String output, boolean isError) {
Task task = getThreadTask(Thread.currentThread());
if (task == null) {
fireMessageLogged(this, line, isError ? MSG_ERR : MSG_INFO);
fireMessageLogged(this, output, isError ? MSG_ERR : MSG_INFO);
} else {
if (isError) {
task.handleErrorFlush(line);
task.handleErrorFlush(output);
} else {
task.handleFlush(line);
task.handleFlush(output);
}
}
}
@@ -1915,7 +1917,13 @@ public class Project {
*/
private void fireMessageLoggedEvent(BuildEvent event, String message,
int priority) {
event.setMessage(message, priority);

if (message.endsWith(StringUtils.LINE_SEP)) {
int endIndex = message.length() - StringUtils.LINE_SEP.length();
event.setMessage(message.substring(0, endIndex), priority);
} else {
event.setMessage(message, priority);
}
Vector listeners = getBuildListeners();
synchronized (this) {
if (loggingMessage) {


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

@@ -305,23 +305,23 @@ public abstract class Task extends ProjectComponent {
}

/**
* Handles a line of output by logging it with the INFO priority.
* Handles output by logging it with the INFO priority.
*
* @param line The line of output to log. Should not be <code>null</code>.
* @param output The output to log. Should not be <code>null</code>.
*/
protected void handleOutput(String line) {
log(line, Project.MSG_INFO);
protected void handleOutput(String output) {
log(output, Project.MSG_INFO);
}

/**
* Handles a line of output by logging it with the INFO priority.
* Handles output by logging it with the INFO priority.
*
* @param line The line of output to log. Should not be <code>null</code>.
* @param output The output to log. Should not be <code>null</code>.
*
* @since Ant 1.5.2
*/
protected void handleFlush(String line) {
handleOutput(line);
protected void handleFlush(String output) {
handleOutput(output);
}

/**
@@ -342,23 +342,23 @@ public abstract class Task extends ProjectComponent {
}

/**
* Handles an error line by logging it with the INFO priority.
* Handles an error output by logging it with the INFO priority.
*
* @param line The error line to log. Should not be <code>null</code>.
* @param output The error output to log. Should not be <code>null</code>.
*/
protected void handleErrorOutput(String line) {
log(line, Project.MSG_ERR);
protected void handleErrorOutput(String output) {
log(output, Project.MSG_ERR);
}

/**
* Handles an error line by logging it with the INFO priority.
*
* @param line The error line to log. Should not be <code>null</code>.
* @param output The error output to log. Should not be <code>null</code>.
*
* @since Ant 1.5.2
*/
protected void handleErrorFlush(String line) {
handleErrorOutput(line);
protected void handleErrorFlush(String output) {
handleErrorOutput(output);
}

/**


+ 16
- 16
src/main/org/apache/tools/ant/UnknownElement.java View File

@@ -192,13 +192,13 @@ 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 <code>null</code>.
* @param output The output to log. Should not be <code>null</code>.
*/
protected void handleOutput(String line) {
protected void handleOutput(String output) {
if (realThing instanceof Task) {
((Task) realThing).handleOutput(line);
((Task) realThing).handleOutput(output);
} else {
super.handleOutput(line);
super.handleOutput(output);
}
}

@@ -219,26 +219,26 @@ 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 <code>null</code>.
* @param output The output to log. Should not be <code>null</code>.
*/
protected void handleFlush(String line) {
protected void handleFlush(String output) {
if (realThing instanceof Task) {
((Task) realThing).handleFlush(line);
((Task) realThing).handleFlush(output);
} else {
super.handleFlush(line);
super.handleFlush(output);
}
}

/**
* Handles error output sent to System.err by this task or its real task.
*
* @param line The error line to log. Should not be <code>null</code>.
* @param output The error output to log. Should not be <code>null</code>.
*/
protected void handleErrorOutput(String line) {
protected void handleErrorOutput(String output) {
if (realThing instanceof Task) {
((Task) realThing).handleErrorOutput(line);
((Task) realThing).handleErrorOutput(output);
} else {
super.handleErrorOutput(line);
super.handleErrorOutput(output);
}
}

@@ -246,13 +246,13 @@ 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 <code>null</code>.
* @param output The error output to log. Should not be <code>null</code>.
*/
protected void handleErrorFlush(String line) {
protected void handleErrorFlush(String output) {
if (realThing instanceof Task) {
((Task) realThing).handleErrorOutput(line);
((Task) realThing).handleErrorOutput(output);
} else {
super.handleErrorOutput(line);
super.handleErrorOutput(output);
}
}



+ 12
- 12
src/main/org/apache/tools/ant/taskdefs/Ant.java View File

@@ -263,11 +263,11 @@ public class Ant extends Task {
*
* @since Ant 1.5
*/
public void handleOutput(String line) {
public void handleOutput(String output) {
if (newProject != null) {
newProject.demuxOutput(line, false);
newProject.demuxOutput(output, false);
} else {
super.handleOutput(line);
super.handleOutput(output);
}
}

@@ -290,11 +290,11 @@ public class Ant extends Task {
*
* @since Ant 1.5.2
*/
public void handleFlush(String line) {
public void handleFlush(String output) {
if (newProject != null) {
newProject.demuxFlush(line, false);
newProject.demuxFlush(output, false);
} else {
super.handleFlush(line);
super.handleFlush(output);
}
}

@@ -303,11 +303,11 @@ public class Ant extends Task {
*
* @since Ant 1.5
*/
public void handleErrorOutput(String line) {
public void handleErrorOutput(String output) {
if (newProject != null) {
newProject.demuxOutput(line, true);
newProject.demuxOutput(output, true);
} else {
super.handleErrorOutput(line);
super.handleErrorOutput(output);
}
}

@@ -316,11 +316,11 @@ public class Ant extends Task {
*
* @since Ant 1.5.2
*/
public void handleErrorFlush(String line) {
public void handleErrorFlush(String output) {
if (newProject != null) {
newProject.demuxFlush(line, true);
newProject.demuxFlush(output, true);
} else {
super.handleErrorFlush(line);
super.handleErrorFlush(output);
}
}



+ 12
- 12
src/main/org/apache/tools/ant/taskdefs/CallTarget.java View File

@@ -190,11 +190,11 @@ public class CallTarget extends Task {
*
* @since Ant 1.5
*/
public void handleOutput(String line) {
public void handleOutput(String output) {
if (callee != null) {
callee.handleOutput(line);
callee.handleOutput(output);
} else {
super.handleOutput(line);
super.handleOutput(output);
}
}

@@ -217,11 +217,11 @@ public class CallTarget extends Task {
*
* @since Ant 1.5.2
*/
public void handleFlush(String line) {
public void handleFlush(String output) {
if (callee != null) {
callee.handleFlush(line);
callee.handleFlush(output);
} else {
super.handleFlush(line);
super.handleFlush(output);
}
}

@@ -230,11 +230,11 @@ public class CallTarget extends Task {
*
* @since Ant 1.5
*/
public void handleErrorOutput(String line) {
public void handleErrorOutput(String output) {
if (callee != null) {
callee.handleErrorOutput(line);
callee.handleErrorOutput(output);
} else {
super.handleErrorOutput(line);
super.handleErrorOutput(output);
}
}

@@ -243,11 +243,11 @@ public class CallTarget extends Task {
*
* @since Ant 1.5.2
*/
public void handleErrorFlush(String line) {
public void handleErrorFlush(String output) {
if (callee != null) {
callee.handleErrorFlush(line);
callee.handleErrorFlush(output);
} else {
super.handleErrorFlush(line);
super.handleErrorFlush(output);
}
}
}

+ 12
- 12
src/main/org/apache/tools/ant/taskdefs/Java.java View File

@@ -460,11 +460,11 @@ public class Java extends Task {
*
* @since Ant 1.5
*/
protected void handleOutput(String line) {
protected void handleOutput(String output) {
if (redirector.getOutputStream() != null) {
redirector.handleOutput(line);
redirector.handleOutput(output);
} else {
super.handleOutput(line);
super.handleOutput(output);
}
}

@@ -482,11 +482,11 @@ public class Java extends Task {
*
* @since Ant 1.5.2
*/
protected void handleFlush(String line) {
protected void handleFlush(String output) {
if (redirector.getOutputStream() != null) {
redirector.handleFlush(line);
redirector.handleFlush(output);
} else {
super.handleFlush(line);
super.handleFlush(output);
}
}

@@ -495,11 +495,11 @@ public class Java extends Task {
*
* @since Ant 1.5
*/
protected void handleErrorOutput(String line) {
protected void handleErrorOutput(String output) {
if (redirector.getErrorStream() != null) {
redirector.handleErrorOutput(line);
redirector.handleErrorOutput(output);
} else {
super.handleErrorOutput(line);
super.handleErrorOutput(output);
}
}

@@ -508,11 +508,11 @@ public class Java extends Task {
*
* @since Ant 1.5.2
*/
protected void handleErrorFlush(String line) {
protected void handleErrorFlush(String output) {
if (redirector.getErrorStream() != null) {
redirector.handleErrorFlush(line);
redirector.handleErrorFlush(output);
} else {
super.handleErrorOutput(line);
super.handleErrorOutput(output);
}
}



+ 12
- 12
src/main/org/apache/tools/ant/taskdefs/Redirector.java View File

@@ -359,13 +359,13 @@ public class Redirector {
/**
* Pass output sent to System.out to specified output.
*
* @param line the data to be output
* @param output the data to be output
*/
protected void handleOutput(String line) {
protected void handleOutput(String output) {
if (outPrintStream == null) {
outPrintStream = new PrintStream(outputStream);
}
outPrintStream.println(line);
outPrintStream.print(output);
}

/**
@@ -392,38 +392,38 @@ public class Redirector {
/**
* Process data due to a flush operation.
*
* @param line the data being flushed.
* @param output the data being flushed.
*/
protected void handleFlush(String line) {
protected void handleFlush(String output) {
if (outPrintStream == null) {
outPrintStream = new PrintStream(outputStream);
}
outPrintStream.print(line);
outPrintStream.print(output);
outPrintStream.flush();
}

/**
* Process error output
*
* @param line the error output data.
* @param output the error output data.
*/
protected void handleErrorOutput(String line) {
protected void handleErrorOutput(String output) {
if (errorPrintStream == null) {
errorPrintStream = new PrintStream(errorStream);
}
errorPrintStream.println(line);
errorPrintStream.print(output);
}

/**
* Handle a flush operation on the error stream
*
* @param line the error information being flushed.
* @param output the error information being flushed.
*/
protected void handleErrorFlush(String line) {
protected void handleErrorFlush(String output) {
if (errorPrintStream == null) {
errorPrintStream = new PrintStream(errorStream);
}
errorPrintStream.print(line);
errorPrintStream.print(output);
}

/**


+ 16
- 16
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -748,14 +748,14 @@ public class JUnitTask extends Task {
*
* @since Ant 1.5
*/
protected void handleOutput(String line) {
protected void handleOutput(String output) {
if (runner != null) {
runner.handleOutput(line);
runner.handleOutput(output);
if (showOutput) {
super.handleOutput(line);
super.handleOutput(output);
}
} else {
super.handleOutput(line);
super.handleOutput(output);
}
}

@@ -780,14 +780,14 @@ public class JUnitTask extends Task {
*
* @since Ant 1.5.2
*/
protected void handleFlush(String line) {
protected void handleFlush(String output) {
if (runner != null) {
runner.handleFlush(line);
runner.handleFlush(output);
if (showOutput) {
super.handleFlush(line);
super.handleFlush(output);
}
} else {
super.handleFlush(line);
super.handleFlush(output);
}
}

@@ -797,14 +797,14 @@ public class JUnitTask extends Task {
*
* @since Ant 1.5
*/
public void handleErrorOutput(String line) {
public void handleErrorOutput(String output) {
if (runner != null) {
runner.handleErrorOutput(line);
runner.handleErrorOutput(output);
if (showOutput) {
super.handleErrorOutput(line);
super.handleErrorOutput(output);
}
} else {
super.handleErrorOutput(line);
super.handleErrorOutput(output);
}
}

@@ -815,14 +815,14 @@ public class JUnitTask extends Task {
*
* @since Ant 1.5.2
*/
public void handleErrorFlush(String line) {
public void handleErrorFlush(String output) {
if (runner != null) {
runner.handleErrorFlush(line);
runner.handleErrorFlush(output);
if (showOutput) {
super.handleErrorFlush(line);
super.handleErrorFlush(output);
}
} else {
super.handleErrorFlush(line);
super.handleErrorFlush(output);
}
}



+ 8
- 8
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -398,9 +398,9 @@ public class JUnitTestRunner implements TestListener {
}
}

protected void handleOutput(String line) {
protected void handleOutput(String output) {
if (systemOut != null) {
systemOut.println(line);
systemOut.print(output);
}
}

@@ -414,21 +414,21 @@ public class JUnitTestRunner implements TestListener {
return -1;
}

protected void handleErrorOutput(String line) {
protected void handleErrorOutput(String output) {
if (systemError != null) {
systemError.println(line);
systemError.print(output);
}
}

protected void handleFlush(String line) {
protected void handleFlush(String output) {
if (systemOut != null) {
systemOut.print(line);
systemOut.print(output);
}
}

protected void handleErrorFlush(String line) {
protected void handleErrorFlush(String output) {
if (systemError != null) {
systemError.print(line);
systemError.print(output);
}
}



+ 15
- 15
src/testcases/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java View File

@@ -57,20 +57,20 @@ package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.BuildFileTest;

/**
* @author Gus Heck <gus.heck@olin.edu>
* @author Gus Heck <gus.heck@olin.edu>
*/
public class DefaultExcludesTest extends BuildFileTest {
public DefaultExcludesTest(String name) {
public class DefaultExcludesTest extends BuildFileTest {
public DefaultExcludesTest(String name) {
super(name);
}
public void setUp() {
}
public void setUp() {
configureProject("src/etc/testcases/taskdefs/defaultexcludes.xml");
}
// Output the default excludes
public void test1() {
public void test1() {
expectLog("test1", "Current Default Excludes:\n"+
" **/*~\n"+
" **/#*#\n"+
@@ -85,11 +85,11 @@ public class DefaultExcludesTest extends BuildFileTest {
" **/vssver.scc\n"+
" **/.svn\n"+
" **/.svn/**\n"+
" **/.DS_Store\n");
" **/.DS_Store");
}
// adding something to the excludes'
public void test2() {
public void test2() {
expectLog("test2", "Current Default Excludes:\n"+
" **/*~\n"+
" **/#*#\n"+
@@ -105,11 +105,11 @@ public class DefaultExcludesTest extends BuildFileTest {
" **/.svn\n"+
" **/.svn/**\n"+
" **/.DS_Store\n"+
" foo\n"); // foo added
" foo"); // foo added
}

// removing something from the defaults
public void test3() {
public void test3() {
expectLog("test3", "Current Default Excludes:\n"+
" **/*~\n"+
" **/#*#\n"+
@@ -124,6 +124,6 @@ public class DefaultExcludesTest extends BuildFileTest {
" **/vssver.scc\n"+
" **/.svn\n"+
" **/.svn/**\n"+
" **/.DS_Store\n");
" **/.DS_Store");
}
}

+ 9
- 9
src/testcases/org/apache/tools/ant/taskdefs/DemuxOutputTask.java View File

@@ -71,41 +71,41 @@ public class DemuxOutputTask extends Task {
private String randomErrValue;
private boolean outputReceived = false;
private boolean errorReceived = false;
public void execute() {
Random generator = new Random();
randomOutValue = "Output Value is " + generator.nextInt();
randomErrValue = "Error Value is " + generator.nextInt();
System.out.println(randomOutValue);
System.err.println(randomErrValue);
if (!outputReceived) {
throw new BuildException("Did not receive output");
}
}
if (!errorReceived) {
throw new BuildException("Did not receive error");
}
}

protected void handleOutput(String line) {
line = line.trim();
if (line.length() != 0 && !line.equals(randomOutValue)) {
String message = "Received = [" + line + "], expected = ["
String message = "Received = [" + line + "], expected = ["
+ randomOutValue + "]";
throw new BuildException(message);
}
outputReceived = true;
}
protected void handleErrorOutput(String line) {
line = line.trim();
if (line.length() != 0 && !line.equals(randomErrValue)) {
String message = "Received = [" + line + "], expected = ["
String message = "Received = [" + line + "], expected = ["
+ randomErrValue + "]";
throw new BuildException(message);
}
errorReceived = true;
}
}


Loading…
Cancel
Save