You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

JikesOutputParser.java 6.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2000,2002 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "Ant" and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package org.apache.tools.ant.taskdefs;
  55. import java.io.BufferedReader;
  56. import java.io.IOException;
  57. import java.io.InputStream;
  58. import java.io.InputStreamReader;
  59. import java.io.OutputStream;
  60. import org.apache.tools.ant.Project;
  61. import org.apache.tools.ant.Task;
  62. /**
  63. * Parses output from jikes and
  64. * passes errors and warnings
  65. * into the right logging channels of Project.
  66. *
  67. * <p><strong>As of Ant 1.2, this class is considered to be dead code
  68. * by the Ant developers and is unmaintained. Don't use
  69. * it.</strong></p>
  70. *
  71. * @author skanthak@muehlheim.de
  72. * @deprecated use Jikes' exit value to detect compilation failure.
  73. */
  74. public class JikesOutputParser implements ExecuteStreamHandler {
  75. protected Task task;
  76. protected boolean errorFlag = false; // no errors so far
  77. protected int errors;
  78. protected int warnings;
  79. protected boolean error = false;
  80. protected boolean emacsMode;
  81. protected BufferedReader br;
  82. /**
  83. * Ignore.
  84. */
  85. public void setProcessInputStream(OutputStream os) {
  86. }
  87. /**
  88. * Ignore.
  89. */
  90. public void setProcessErrorStream(InputStream is) {
  91. }
  92. /**
  93. * Set the inputstream
  94. */
  95. public void setProcessOutputStream(InputStream is) throws IOException {
  96. br = new BufferedReader(new InputStreamReader(is));
  97. }
  98. /**
  99. * Invokes parseOutput.
  100. */
  101. public void start() throws IOException {
  102. parseOutput(br);
  103. }
  104. /**
  105. * Ignore.
  106. */
  107. public void stop() {
  108. }
  109. /**
  110. * Construct a new Parser object
  111. * @param task - task in whichs context we are called
  112. */
  113. protected JikesOutputParser(Task task, boolean emacsMode) {
  114. super();
  115. System.err.println("As of Ant 1.2 released in October 2000, the "
  116. + "JikesOutputParser class");
  117. System.err.println("is considered to be dead code by the Ant "
  118. + "developers and is unmaintained.");
  119. System.err.println("Don\'t use it!");
  120. this.task = task;
  121. this.emacsMode = emacsMode;
  122. }
  123. /**
  124. * Parse the output of a jikes compiler
  125. * @param reader - Reader used to read jikes's output
  126. */
  127. protected void parseOutput(BufferedReader reader) throws IOException {
  128. if (emacsMode) {
  129. parseEmacsOutput(reader);
  130. } else {
  131. parseStandardOutput(reader);
  132. }
  133. }
  134. private void parseStandardOutput(BufferedReader reader) throws IOException {
  135. String line;
  136. String lower;
  137. // We assume, that every output, jike does, stands for an error/warning
  138. // XXX
  139. // Is this correct?
  140. // TODO:
  141. // A warning line, that shows code, which contains a variable
  142. // error will cause some trouble. The parser should definitely
  143. // be much better.
  144. while ((line = reader.readLine()) != null) {
  145. lower = line.toLowerCase();
  146. if (line.trim().equals("")) {
  147. continue;
  148. }
  149. if (lower.indexOf("error") != -1) {
  150. setError(true);
  151. } else if (lower.indexOf("warning") != -1) {
  152. setError(false);
  153. } else {
  154. // If we don't know the type of the line
  155. // and we are in emacs mode, it will be
  156. // an error, because in this mode, jikes won't
  157. // always print "error", but sometimes other
  158. // keywords like "Syntax". We should look for
  159. // all those keywords.
  160. if (emacsMode) {
  161. setError(true);
  162. }
  163. }
  164. log(line);
  165. }
  166. }
  167. private void parseEmacsOutput(BufferedReader reader) throws IOException {
  168. // This may change, if we add advanced parsing capabilities.
  169. parseStandardOutput(reader);
  170. }
  171. private void setError(boolean err) {
  172. error = err;
  173. if (error) {
  174. errorFlag = true;
  175. }
  176. }
  177. private void log(String line) {
  178. if (!emacsMode) {
  179. task.log("", (error ? Project.MSG_ERR : Project.MSG_WARN));
  180. }
  181. task.log(line, (error ? Project.MSG_ERR : Project.MSG_WARN));
  182. }
  183. /**
  184. * Indicate if there were errors during the compile
  185. * @return if errors ocured
  186. */
  187. protected boolean getErrorFlag() {
  188. return errorFlag;
  189. }
  190. }