Browse Source

Flush output of Java task when finished.

Propagate indication of whether line is terminated or not
through to project and tasks
PR: 16555


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273930 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 23 years ago
parent
commit
987c943d07
9 changed files with 230 additions and 9 deletions
  1. +16
    -3
      src/main/org/apache/tools/ant/DemuxOutputStream.java
  2. +19
    -2
      src/main/org/apache/tools/ant/Project.java
  3. +23
    -1
      src/main/org/apache/tools/ant/Task.java
  4. +27
    -0
      src/main/org/apache/tools/ant/UnknownElement.java
  5. +26
    -0
      src/main/org/apache/tools/ant/taskdefs/Ant.java
  6. +26
    -1
      src/main/org/apache/tools/ant/taskdefs/CallTarget.java
  7. +37
    -1
      src/main/org/apache/tools/ant/taskdefs/Java.java
  8. +35
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  9. +21
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java

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

@@ -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);
}
}
}

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

@@ -1228,18 +1228,35 @@ public class Project {
* or information (<code>false</code>).
*/
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 <code>null</code>.
* @param isError Whether the text represents an error (<code>true</code>)
* or information (<code>false</code>).
* @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.
*


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

@@ -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 <code>null</code>.
*/
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 <code>null</code>.
* @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 <code>null</code>.
*/
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 <code>null</code>.
* @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);
}



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

@@ -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 <code>null</code>.
*/
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 <code>null</code>.
*/
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.


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

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


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

@@ -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);
}
}
}

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

@@ -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 {


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

@@ -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)


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

@@ -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 =


Loading…
Cancel
Save