KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > bluej > ant > BluejAntLogger


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.bluej.ant;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import org.apache.tools.ant.module.spi.AntEvent;
25 import org.apache.tools.ant.module.spi.AntLogger;
26 import org.apache.tools.ant.module.spi.AntSession;
27 import org.netbeans.api.project.Project;
28 import org.netbeans.api.project.ProjectManager;
29 import org.netbeans.bluej.BluejProject;
30 import org.openide.filesystems.FileUtil;
31
32 /**
33  *
34  * @author mkleint
35  */

36 public class BluejAntLogger extends AntLogger {
37
38     /** Creates a new instance of BluejAntLogger */
39     public BluejAntLogger() {
40     }
41
42     /**
43      * Mark which kinds of targets this logger is interested in.
44      * This applies to both target start and finish events, as well as any other
45      * events for which {@link AntEvent#getTargetName} is not null, such as task
46      * start and finish events, and message log events.
47      * If {@link #NO_TARGETS}, no events with specific targets will be sent to it.
48      * If a specific list, only events with defined target names included in the list
49      * will be sent to it.
50      * If {@link #ALL_TARGETS}, all events not otherwise excluded will be sent to it.
51      *
52      * @param session the relevant session
53      * @return a nonempty (and non-null) list of target names; by default, {@link #NO_TARGETS}
54      */

55     public String JavaDoc[] interestedInTargets(AntSession session) {
56         return AntLogger.ALL_TARGETS;
57     }
58
59     /**
60      * Mark whether this logger is interested in a given Ant session.
61      *
62      * @param session a session which is about to be start
63      * @return true to receive events about it; by default, false
64      */

65     public boolean interestedInSession(AntSession session) {
66         return true;
67     }
68
69     /**
70      * Mark which kinds of message log events this logger is interested in.
71      * This applies only to message log events and no others.
72      * Only events with log levels included in the returned list will be delivered.
73      *
74      * @param session the relevant session
75      * @return a list of levels such as {@link AntEvent#LOG_INFO}; by default, an empty list
76      * @see AntSession#getVerbosity
77      */

78     public int[] interestedInLogLevels(AntSession session) {
79         int[] retValue;
80         
81         retValue = super.interestedInLogLevels(session);
82         return retValue;
83     }
84
85     /**
86      * Mark whether this logger is interested in any Ant script.
87      * If true, no events will be masked due to the script location.
88      * Note that a few events have no defined script and so will only
89      * be delivered to loggers interested in all scripts; typically this
90      * applies to debugging messages when a project is just being configured.
91      *
92      * @param session the relevant session
93      * @return true to receive events for all scripts; by default, false
94      */

95     public boolean interestedInAllScripts(AntSession session) {
96         return true;
97     }
98
99     /**
100      * Fired when a target is started.
101      * It is <em>not</em> guaranteed that {@link AntEvent#getTargetName}
102      * will be non-null (as can happen in some circumstances with
103      * <code>&lt;import&gt;</code>, for example).
104      * The default implementation does nothing.
105      *
106      * @param event the associated event object
107      */

108     public void targetStarted(AntEvent event) {
109         if (event.isConsumed()) {
110             return;
111         }
112         event.consume();
113         super.targetStarted(event);
114     }
115
116     /**
117      * Fired once when a build is started.
118      * The default implementation does nothing.
119      *
120      * @param event the associated event object
121      */

122     public void buildStarted(AntEvent event) {
123         if (event.isConsumed()) {
124             return;
125         }
126         super.buildStarted(event);
127     }
128
129     /**
130      * Fired when a target is finished.
131      * It is <em>not</em> guaranteed that {@link AntEvent#getTargetName}
132      * will be non-null.
133      * The default implementation does nothing.
134      *
135      * @param event the associated event object
136      */

137     public void targetFinished(AntEvent event) {
138         if (event.isConsumed()) {
139             return;
140         }
141         event.consume();
142         super.targetFinished(event);
143     }
144
145     /**
146      * Fired once when a build is finished.
147      * The default implementation does nothing.
148      *
149      * @param event the associated event object
150      * @see AntEvent#getException
151      */

152     public void buildFinished(AntEvent event) {
153         if (event.isConsumed()) {
154             return;
155         }
156         super.buildFinished(event);
157     }
158
159     /**
160      * Fired only if the build could not even be started.
161      * {@link AntEvent#getException} will be non-null.
162      * The default implementation does nothing.
163      *
164      * @param event the associated event object
165      */

166     public void buildInitializationFailed(AntEvent event) {
167         if (event.isConsumed()) {
168             return;
169         }
170         super.buildInitializationFailed(event);
171     }
172
173     /**
174      * Fired when a message is logged.
175      * The task and target fields may or may not be defined.
176      * The default implementation does nothing.
177      *
178      * @param event the associated event object
179      */

180     public void messageLogged(AntEvent event) {
181         if (event.isConsumed()) {
182             return;
183         }
184         super.messageLogged(event);
185     }
186
187     /**
188      * Fired when a task is started.
189      * It is <em>not</em> guaranteed that {@link AntEvent#getTaskName} or
190      * {@link AntEvent#getTaskStructure} will be non-null, though they will
191      * usually be defined.
192      * {@link AntEvent#getTargetName} might also be null.
193      * The default implementation does nothing.
194      *
195      * @param event the associated event object
196      */

197     public void taskStarted(AntEvent event) {
198         if (event.isConsumed()) {
199             return;
200         }
201         super.taskStarted(event);
202     }
203
204     /**
205      * Fired when a task is finished.
206      * It is <em>not</em> guaranteed that {@link AntEvent#getTaskName} or
207      * {@link AntEvent#getTaskStructure} will be non-null.
208      * {@link AntEvent#getTargetName} might also be null.
209      * The default implementation does nothing.
210      *
211      * @param event the associated event object
212      */

213     public void taskFinished(AntEvent event) {
214         if (event.isConsumed()) {
215             return;
216         }
217         super.taskFinished(event);
218     }
219
220     /**
221      * Mark whether this logger is interested in a given Ant script.
222      * Called only if {@link #interestedInAllScripts} is false.
223      * Only events with a defined script according to {@link AntEvent#getScriptLocation}
224      * which this logger is interested in will be delivered.
225      * Note that a few events have no defined script and so will only
226      * be delivered to loggers interested in all scripts; typically this
227      * applies to debugging messages when a project is just being configured.
228      * Note also that a single session can involve many different scripts.
229      *
230      * @param script a particular build script
231      * @param session the relevant session
232      * @return true to receive events sent from this script; by default, false
233      */

234     public boolean interestedInScript(File JavaDoc script, AntSession session) {
235         File JavaDoc folder = script.getParentFile();
236         Project prj = null;
237         try {
238             prj = ProjectManager.getDefault().findProject(FileUtil.toFileObject(folder));
239         } catch (IllegalArgumentException JavaDoc ex) {
240             ex.printStackTrace();
241         } catch (IOException JavaDoc ex) {
242             ex.printStackTrace();
243         }
244         if (prj != null && prj.getLookup().lookup(BluejProject.class) != null) {
245             return true;
246         }
247         return false;
248     }
249     
250 }
251
Popular Tags