Debian Codegraph @

src/com/google/javascript/jscomp/ant/AntErrorManager.java

raw symbols SCIP
1 /*
2 * Copyright 2010 The Closure Compiler Authors.
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 com.google.javascript.jscomp.ant;
18
19 import com.google.javascript.jscomp.BasicErrorManager;
20 import com.google.javascript.jscomp.CheckLevel;
21 import com.google.javascript.jscomp.JSError;
22 import com.google.javascript.jscomp.MessageFormatter;
23
24 import org.apache.tools.ant.Project;
25 import org.apache.tools.ant.Task;
26
27 /**
28 * An error manager that pipes warnings and errors properly into the Ant
29 * task infrastructure.
30 */
31 public final class AntErrorManager
32 extends BasicErrorManager {
33 private final MessageFormatter formatter;
34 private final Task task;
35
36 public AntErrorManager(MessageFormatter formatter, Task task) {
37 this.formatter = formatter;
38 this.task = task;
39 }
40
41 @Override
42 public void println(CheckLevel level, JSError error) {
43 switch (level) {
44 case ERROR:
45 this.task.log(error.format(level, this.formatter), Project.MSG_ERR);
46 break;
47 case WARNING:
48 this.task.log(error.format(level, this.formatter), Project.MSG_WARN);
49 break;
50 case OFF:
51 break;
52 }
53 }
54
55 @Override
56 protected void printSummary() {
57 String message =
58 getErrorCount() + " error(s), " + getWarningCount() + " warning(s)";
59
60 if (getTypedPercent() > 0.0) {
61 message += ", " + getTypedPercent() + " typed";
62 }
63
64 int level = (getErrorCount() + getWarningCount() == 0) ?
65 Project.MSG_INFO : Project.MSG_WARN;
66 this.task.log(message, level);
67 }
68 }