1 18 package org.apache.tools.ant.taskdefs; 19 20 import java.io.BufferedReader ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.InputStreamReader ; 24 import java.io.OutputStream ; 25 import org.apache.tools.ant.Project; 26 import org.apache.tools.ant.Task; 27 28 40 public class JikesOutputParser implements ExecuteStreamHandler { 41 protected Task task; 43 protected boolean errorFlag = false; protected int errors; 45 protected int warnings; 46 protected boolean error = false; 47 protected boolean emacsMode; 48 49 protected BufferedReader br; 50 52 56 public void setProcessInputStream(OutputStream os) { 57 } 58 59 63 public void setProcessErrorStream(InputStream is) { 64 } 65 66 71 public void setProcessOutputStream(InputStream is) throws IOException { 72 br = new BufferedReader (new InputStreamReader (is)); 73 } 74 75 79 public void start() throws IOException { 80 parseOutput(br); 81 } 82 83 86 public void stop() { 87 } 88 89 94 protected JikesOutputParser(Task task, boolean emacsMode) { 95 super(); 96 97 System.err.println("As of Ant 1.2 released in October 2000, the " 98 + "JikesOutputParser class"); 99 System.err.println("is considered to be dead code by the Ant " 100 + "developers and is unmaintained."); 101 System.err.println("Don\'t use it!"); 102 103 this.task = task; 104 this.emacsMode = emacsMode; 105 } 106 107 112 protected void parseOutput(BufferedReader reader) throws IOException { 113 if (emacsMode) { 114 parseEmacsOutput(reader); 115 } else { 116 parseStandardOutput(reader); 117 } 118 } 119 120 private void parseStandardOutput(BufferedReader reader) throws IOException { 121 String line; 122 String lower; 123 127 132 while ((line = reader.readLine()) != null) { 133 lower = line.toLowerCase(); 134 if (line.trim().equals("")) { 135 continue; 136 } 137 if (lower.indexOf("error") != -1) { 138 setError(true); 139 } else if (lower.indexOf("warning") != -1) { 140 setError(false); 141 } else { 142 if (emacsMode) { 149 setError(true); 150 } 151 } 152 log(line); 153 } 154 } 155 156 private void parseEmacsOutput(BufferedReader reader) throws IOException { 157 parseStandardOutput(reader); 159 } 160 161 private void setError(boolean err) { 162 error = err; 163 if (error) { 164 errorFlag = true; 165 } 166 } 167 168 private void log(String line) { 169 if (!emacsMode) { 170 task.log("", (error ? Project.MSG_ERR : Project.MSG_WARN)); 171 } 172 task.log(line, (error ? Project.MSG_ERR : Project.MSG_WARN)); 173 } 174 175 179 protected boolean getErrorFlag() { 180 return errorFlag; 181 } 182 } 183 | Popular Tags |