KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > NoBannerLogger


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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 JavaDoc targetName;
38     // CheckStyle:VisibilityModifier ON
39

40     /** Sole constructor. */
41     public NoBannerLogger() {
42     }
43
44     /**
45      * Notes the name of the target so it can be logged
46      * if it generates any messages.
47      *
48      * @param event A BuildEvent containing target information.
49      * Must not be <code>null</code>.
50      */

51     public void targetStarted(BuildEvent event) {
52         targetName = event.getTarget().getName();
53     }
54
55     /**
56      * Resets the current target name to <code>null</code>.
57      *
58      * @param event Ignored in this implementation.
59      */

60     public void targetFinished(BuildEvent event) {
61         targetName = null;
62     }
63
64     /**
65      * Logs a message for a target if it is of an appropriate
66      * priority, also logging the name of the target if this
67      * is the first message which needs to be logged for the
68      * target.
69      *
70      * @param event A BuildEvent containing message information.
71      * Must not be <code>null</code>.
72      */

73     public void messageLogged(BuildEvent event) {
74
75         if (event.getPriority() > msgOutputLevel
76             || null == event.getMessage()
77             || "".equals(event.getMessage().trim())) {
78                 return;
79         }
80
81         if (null != targetName) {
82             out.println(StringUtils.LINE_SEP + targetName + ":");
83             targetName = null;
84         }
85
86         super.messageLogged(event);
87     }
88 }
89
Popular Tags