From 62c181f4549c1a507665534eb4ef75edae02822b Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Wed, 5 Jul 2000 19:38:31 +0000 Subject: [PATCH] Override the logging of Javadoc output in order to filter out Generating messages. Generating messages are set to a priority of VERBOSE unless they appear after what could be an informational message. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267738 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Exec.java | 33 +++++++++++-------- .../apache/tools/ant/taskdefs/Javadoc.java | 32 ++++++++++++++++++ 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Exec.java b/src/main/org/apache/tools/ant/taskdefs/Exec.java index 63beb567a..b15fdc58c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Exec.java +++ b/src/main/org/apache/tools/ant/taskdefs/Exec.java @@ -69,6 +69,7 @@ public class Exec extends Task { private String out; private File dir; private String command; + protected PrintWriter fos = null; private static final int BUFFER_SIZE = 512; @@ -110,7 +111,6 @@ public class Exec extends Task { // exec command on system runtime Process proc = Runtime.getRuntime().exec(command); - PrintWriter fos=null; if( out!=null ) { fos=new PrintWriter( new FileWriter( out ) ); project.log("Output redirected to " + out, Project.MSG_VERBOSE); @@ -118,9 +118,9 @@ public class Exec extends Task { // copy input and error to the output stream StreamPumper inputPumper = - new StreamPumper(proc.getInputStream(), Project.MSG_INFO, project, fos); + new StreamPumper(proc.getInputStream(), Project.MSG_INFO, this); StreamPumper errorPumper = - new StreamPumper(proc.getErrorStream(), Project.MSG_WARN, project, fos); + new StreamPumper(proc.getErrorStream(), Project.MSG_WARN, this); // starts pumping away the generated output/error inputPumper.start(); @@ -133,7 +133,7 @@ public class Exec extends Task { proc.destroy(); // close the output file if required - if (fos != null) fos.close(); + logFlush(); // check its exit value err = proc.exitValue(); @@ -163,6 +163,18 @@ public class Exec extends Task { this.out = out; } + protected void outputLog(String line, int messageLevel) { + if (fos == null) { + project.log(line, messageLevel); + } else { + fos.println(line); + } + }; + + protected void logFlush() { + if (fos != null) fos.close(); + } + // Inner class for continually pumping the input stream during // Process's runtime. class StreamPumper extends Thread { @@ -170,14 +182,12 @@ public class Exec extends Task { private int messageLevel; private boolean endOfStream = false; private int SLEEP_TIME = 5; - private Project project; - private PrintWriter fos; + private Exec parent; - public StreamPumper(InputStream is, int messageLevel, Project project, PrintWriter fos) { + public StreamPumper(InputStream is, int messageLevel, Exec parent) { this.din = new BufferedReader(new InputStreamReader(is)); this.messageLevel = messageLevel; - this.project = project; - this.fos = fos; + this.parent = parent; } public void pumpStream() @@ -188,10 +198,7 @@ public class Exec extends Task { String line = din.readLine(); if (line != null) { - if (fos == null) - project.log(line, messageLevel); - else - fos.println(line); + outputLog(line, messageLevel); } else { endOfStream = true; } diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java index 8ff31e6dc..5e0d9d078 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java @@ -727,6 +727,38 @@ public class Javadoc extends Exec { return name; } + // + // Override the logging of output in order to filter out Generating + // messages. Generating messages are set to a priority of VERBOSE + // unless they appear after what could be an informational message. + // + private String queuedLine = null; + protected void outputLog(String line, int messageLevel) { + if (messageLevel==project.MSG_INFO && line.startsWith("Generating ")) { + if (queuedLine != null) { + super.outputLog(queuedLine, project.MSG_VERBOSE); + } + queuedLine = line; + } else { + if (queuedLine != null) { + if (line.startsWith("Building ")) + super.outputLog(queuedLine, project.MSG_VERBOSE); + else + super.outputLog(queuedLine, project.MSG_INFO); + queuedLine = null; + } + super.outputLog(line, messageLevel); + } + } + + protected void logFlush() { + if (queuedLine != null) { + super.outputLog(queuedLine, project.MSG_VERBOSE); + queuedLine = null; + } + super.logFlush(); + } + /** * This is a java comment and string stripper reader that filters * these lexical tokens out for purposes of simple Java parsing.