1 | /*
|
---|
2 | * Copyright 2000,2002-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs;
|
---|
18 |
|
---|
19 | import java.io.BufferedReader;
|
---|
20 | import java.io.IOException;
|
---|
21 | import java.io.InputStream;
|
---|
22 | import java.io.InputStreamReader;
|
---|
23 | import java.io.OutputStream;
|
---|
24 | import org.apache.tools.ant.Project;
|
---|
25 | import org.apache.tools.ant.Task;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Parses output from jikes and
|
---|
29 | * passes errors and warnings
|
---|
30 | * into the right logging channels of Project.
|
---|
31 | *
|
---|
32 | * <p><strong>As of Ant 1.2, this class is considered to be dead code
|
---|
33 | * by the Ant developers and is unmaintained. Don't use
|
---|
34 | * it.</strong></p>
|
---|
35 | *
|
---|
36 | * @deprecated use Jikes' exit value to detect compilation failure.
|
---|
37 | */
|
---|
38 | public class JikesOutputParser implements ExecuteStreamHandler {
|
---|
39 | protected Task task;
|
---|
40 | protected boolean errorFlag = false; // no errors so far
|
---|
41 | protected int errors;
|
---|
42 | protected int warnings;
|
---|
43 | protected boolean error = false;
|
---|
44 | protected boolean emacsMode;
|
---|
45 |
|
---|
46 | protected BufferedReader br;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Ignore.
|
---|
50 | */
|
---|
51 | public void setProcessInputStream(OutputStream os) {
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Ignore.
|
---|
56 | */
|
---|
57 | public void setProcessErrorStream(InputStream is) {
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Set the inputstream
|
---|
62 | */
|
---|
63 | public void setProcessOutputStream(InputStream is) throws IOException {
|
---|
64 | br = new BufferedReader(new InputStreamReader(is));
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Invokes parseOutput.
|
---|
69 | */
|
---|
70 | public void start() throws IOException {
|
---|
71 | parseOutput(br);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Ignore.
|
---|
76 | */
|
---|
77 | public void stop() {
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Construct a new Parser object
|
---|
82 | * @param task - task in which context we are called
|
---|
83 | */
|
---|
84 | protected JikesOutputParser(Task task, boolean emacsMode) {
|
---|
85 | super();
|
---|
86 |
|
---|
87 | System.err.println("As of Ant 1.2 released in October 2000, the "
|
---|
88 | + "JikesOutputParser class");
|
---|
89 | System.err.println("is considered to be dead code by the Ant "
|
---|
90 | + "developers and is unmaintained.");
|
---|
91 | System.err.println("Don\'t use it!");
|
---|
92 |
|
---|
93 | this.task = task;
|
---|
94 | this.emacsMode = emacsMode;
|
---|
95 | }
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Parse the output of a jikes compiler
|
---|
99 | * @param reader - Reader used to read jikes's output
|
---|
100 | */
|
---|
101 | protected void parseOutput(BufferedReader reader) throws IOException {
|
---|
102 | if (emacsMode) {
|
---|
103 | parseEmacsOutput(reader);
|
---|
104 | } else {
|
---|
105 | parseStandardOutput(reader);
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | private void parseStandardOutput(BufferedReader reader) throws IOException {
|
---|
110 | String line;
|
---|
111 | String lower;
|
---|
112 | // We assume, that every output, jikes does, stands for an error/warning
|
---|
113 | // XXX
|
---|
114 | // Is this correct?
|
---|
115 |
|
---|
116 | // TODO:
|
---|
117 | // A warning line, that shows code, which contains a variable
|
---|
118 | // error will cause some trouble. The parser should definitely
|
---|
119 | // be much better.
|
---|
120 |
|
---|
121 | while ((line = reader.readLine()) != null) {
|
---|
122 | lower = line.toLowerCase();
|
---|
123 | if (line.trim().equals("")) {
|
---|
124 | continue;
|
---|
125 | }
|
---|
126 | if (lower.indexOf("error") != -1) {
|
---|
127 | setError(true);
|
---|
128 | } else if (lower.indexOf("warning") != -1) {
|
---|
129 | setError(false);
|
---|
130 | } else {
|
---|
131 | // If we don't know the type of the line
|
---|
132 | // and we are in emacs mode, it will be
|
---|
133 | // an error, because in this mode, jikes won't
|
---|
134 | // always print "error", but sometimes other
|
---|
135 | // keywords like "Syntax". We should look for
|
---|
136 | // all those keywords.
|
---|
137 | if (emacsMode) {
|
---|
138 | setError(true);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | log(line);
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | private void parseEmacsOutput(BufferedReader reader) throws IOException {
|
---|
146 | // This may change, if we add advanced parsing capabilities.
|
---|
147 | parseStandardOutput(reader);
|
---|
148 | }
|
---|
149 |
|
---|
150 | private void setError(boolean err) {
|
---|
151 | error = err;
|
---|
152 | if (error) {
|
---|
153 | errorFlag = true;
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | private void log(String line) {
|
---|
158 | if (!emacsMode) {
|
---|
159 | task.log("", (error ? Project.MSG_ERR : Project.MSG_WARN));
|
---|
160 | }
|
---|
161 | task.log(line, (error ? Project.MSG_ERR : Project.MSG_WARN));
|
---|
162 | }
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Indicate if there were errors during the compile
|
---|
166 | * @return if errors occurred
|
---|
167 | */
|
---|
168 | protected boolean getErrorFlag() {
|
---|
169 | return errorFlag;
|
---|
170 | }
|
---|
171 | }
|
---|