01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant;
20:
21: import org.apache.tools.ant.util.StringUtils;
22:
23: /**
24: * Extends DefaultLogger to strip out empty targets.
25: *
26: */
27: public class NoBannerLogger extends DefaultLogger {
28:
29: // CheckStyle:VisibilityModifier OFF - bc
30: /**
31: * Name of the current target, if it should
32: * be displayed on the next message. This is
33: * set when a target starts building, and reset
34: * to <code>null</code> after the first message for
35: * the target is logged.
36: */
37: protected String targetName;
38:
39: // CheckStyle:VisibilityModifier ON
40:
41: /** Sole constructor. */
42: public NoBannerLogger() {
43: }
44:
45: /**
46: * Notes the name of the target so it can be logged
47: * if it generates any messages.
48: *
49: * @param event A BuildEvent containing target information.
50: * Must not be <code>null</code>.
51: */
52: public void targetStarted(BuildEvent event) {
53: targetName = event.getTarget().getName();
54: }
55:
56: /**
57: * Resets the current target name to <code>null</code>.
58: *
59: * @param event Ignored in this implementation.
60: */
61: public void targetFinished(BuildEvent event) {
62: targetName = null;
63: }
64:
65: /**
66: * Logs a message for a target if it is of an appropriate
67: * priority, also logging the name of the target if this
68: * is the first message which needs to be logged for the
69: * target.
70: *
71: * @param event A BuildEvent containing message information.
72: * Must not be <code>null</code>.
73: */
74: public void messageLogged(BuildEvent event) {
75:
76: if (event.getPriority() > msgOutputLevel
77: || null == event.getMessage()
78: || "".equals(event.getMessage().trim())) {
79: return;
80: }
81:
82: if (null != targetName) {
83: out.println(StringUtils.LINE_SEP + targetName + ":");
84: targetName = null;
85: }
86:
87: super.messageLogged(event);
88: }
89: }
|