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-ffa450edef68master
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * 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) | * @see Project#demuxOutput(String,boolean) | ||||
| */ | */ | ||||
| protected void processBuffer(ByteArrayOutputStream buffer) { | 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(); | String output = buffer.toString(); | ||||
| project.demuxOutput(output, isErrorStream); | |||||
| project.demuxOutput(output, isErrorStream, terminated); | |||||
| resetBufferInfo(); | resetBufferInfo(); | ||||
| } | } | ||||
| @@ -217,7 +230,7 @@ public class DemuxOutputStream extends OutputStream { | |||||
| public void flush() throws IOException { | public void flush() throws IOException { | ||||
| BufferInfo bufferInfo = getBufferInfo(); | BufferInfo bufferInfo = getBufferInfo(); | ||||
| if (bufferInfo.buffer.size() > 0) { | if (bufferInfo.buffer.size() > 0) { | ||||
| processBuffer(bufferInfo.buffer); | |||||
| processBuffer(bufferInfo.buffer, false); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -1228,18 +1228,35 @@ public class Project { | |||||
| * or information (<code>false</code>). | * or information (<code>false</code>). | ||||
| */ | */ | ||||
| public void demuxOutput(String line, boolean isError) { | 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()); | Task task = (Task) threadTasks.get(Thread.currentThread()); | ||||
| if (task == null) { | if (task == null) { | ||||
| fireMessageLogged(this, line, isError ? MSG_ERR : MSG_INFO); | fireMessageLogged(this, line, isError ? MSG_ERR : MSG_INFO); | ||||
| } else { | } else { | ||||
| if (isError) { | if (isError) { | ||||
| task.handleErrorOutput(line); | |||||
| task.handleErrorOutput(line, terminated); | |||||
| } else { | } else { | ||||
| task.handleOutput(line); | |||||
| task.handleOutput(line, terminated); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Executes the specified target and any targets it depends on. | * Executes the specified target and any targets it depends on. | ||||
| * | * | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * 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>. | * @param line The line of output to log. Should not be <code>null</code>. | ||||
| */ | */ | ||||
| protected void handleOutput(String line) { | 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); | 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>. | * @param line The error line to log. Should not be <code>null</code>. | ||||
| */ | */ | ||||
| protected void handleErrorOutput(String line) { | 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); | log(line, Project.MSG_ERR); | ||||
| } | } | ||||
| @@ -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. | * 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 | * 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. | * (e.g. a data type) then this method does nothing. | ||||
| @@ -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. | * 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. | * Do the execution. | ||||
| */ | */ | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * 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. | * 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); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * 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. | * 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 | * Executes the given classname with the given arguments as it | ||||
| * was a command line application. | * was a command line application. | ||||
| @@ -402,6 +436,8 @@ public class Java extends Task { | |||||
| new PrintStream(new FileOutputStream(out.getAbsolutePath(), | new PrintStream(new FileOutputStream(out.getAbsolutePath(), | ||||
| append)); | append)); | ||||
| exe.execute(getProject()); | exe.execute(getProject()); | ||||
| System.out.flush(); | |||||
| System.err.flush(); | |||||
| } catch (IOException io) { | } catch (IOException io) { | ||||
| throw new BuildException(io, getLocation()); | throw new BuildException(io, getLocation()); | ||||
| } finally { | } finally { | ||||
| @@ -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 | * Pass output sent to System.err to the TestRunner so it can | ||||
| * collect ot for the formatters. | * 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 | // 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 | // whole build. IMHO this method should be avoided and it would be best | ||||
| // to remove it in future versions. TBD. (SBa) | // to remove it in future versions. TBD. (SBa) | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * 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) { | private void sendOutAndErr(String out, String err) { | ||||
| for (int i = 0; i < formatters.size(); i++) { | for (int i = 0; i < formatters.size(); i++) { | ||||
| JUnitResultFormatter formatter = | JUnitResultFormatter formatter = | ||||