KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > TestAntLogger


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project;
21
22 import java.io.File JavaDoc;
23 import org.apache.tools.ant.module.spi.AntEvent;
24 import org.apache.tools.ant.module.spi.AntLogger;
25 import org.apache.tools.ant.module.spi.AntSession;
26 import org.openide.util.Lookup;
27
28 /**
29  * Implementation of simple AntLogger. To enable/disable use setEnabled(boolean ) method.
30  *
31  * @author pzajac
32  */

33 public class TestAntLogger extends AntLogger {
34     boolean bEnabled;
35
36
37     public void setEnabled(boolean bEnabled) {
38         this.bEnabled = true;
39     }
40     public void messageLogged(AntEvent event) {
41         if (bEnabled) {
42             System.out.println(event.getMessage());
43         }
44     }
45
46     public boolean interestedInSession(AntSession session) {
47         return bEnabled;
48     }
49
50     public boolean interestedInScript(File JavaDoc script, AntSession session) {
51         return bEnabled;
52     }
53
54     public boolean interestedInAllScripts(AntSession session) {
55         return bEnabled;
56     }
57     
58    public void targetStarted(AntEvent event) {
59         System.out.println("target started:" + event.getTargetName());
60     }
61
62     public String JavaDoc[] interestedInTasks(AntSession session) {
63         return (bEnabled) ? ALL_TASKS : new String JavaDoc[0];
64     }
65
66     public String JavaDoc[] interestedInTargets(AntSession session) {
67         return (bEnabled) ? ALL_TARGETS : new String JavaDoc[0];
68     }
69
70     public int[] interestedInLogLevels(AntSession session) {
71         return (bEnabled) ?
72                  new int[]{AntEvent.LOG_INFO,AntEvent.LOG_WARN,AntEvent.LOG_ERR}:
73                  new int[0];
74     }
75
76     static TestAntLogger getDefault() {
77         return (TestAntLogger) Lookup.getDefault().lookupItem(
78                 new Lookup.Template(AntLogger.class,
79                                    "org.netbeans.modules.apisupport.project.TestAntLogger",
80                                    null)).getInstance();
81     }
82
83 }
84
Popular Tags