2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.intellij
.compiler
;
18 import com
.intellij
.openapi
.compiler
.CompilerMessageCategory
;
19 import com
.intellij
.openapi
.util
.text
.StringUtil
;
20 import com
.intellij
.compiler
.impl
.javaCompiler
.FileObject
;
21 import org
.jetbrains
.annotations
.NonNls
;
23 import java
.util
.ArrayList
;
24 import java
.util
.List
;
26 public abstract class OutputParser
{
27 protected final List
<ParserAction
> myParserActions
= new ArrayList
<ParserAction
>(10);
29 public interface Callback
{
30 @NonNls String
getNextLine();
31 @NonNls String
getCurrentLine();
32 void setProgressText(String text
);
33 void fileProcessed(@NonNls String path
);
34 void fileGenerated(@NonNls FileObject path
);
35 void message(CompilerMessageCategory category
, String message
, @NonNls String url
, int lineNum
, int columnNum
);
38 public boolean processMessageLine(Callback callback
) {
39 final String line
= callback
.getNextLine();
43 // common statistics messages (javac & jikes)
44 for (ParserAction action
: myParserActions
) {
45 if (action
.execute(line
, callback
)) {
49 if (StringUtil
.startsWithChar(line
, '[') && StringUtil
.endsWithChar(line
, ']')) {
50 // at this point any meaningful output surrounded with '[' and ']' characters is processed, so
51 // suppress messages like "[total 4657ms]" or "[search path for source files: []]"
57 protected static void addMessage(Callback callback
, CompilerMessageCategory type
, String message
) {
58 if(message
== null || message
.trim().length() == 0) {
61 addMessage(callback
, type
, message
, null, -1, -1);
64 protected static void addMessage(Callback callback
, CompilerMessageCategory type
, String text
, String url
, int line
, int column
){
65 callback
.message(type
, text
, url
, line
, column
);
68 public boolean isTrimLines() {