2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.bluej.ant;
45
import java.io.IOException;
46
import org.apache.tools.ant.module.spi.AntEvent;
47
import org.apache.tools.ant.module.spi.AntLogger;
48
import org.apache.tools.ant.module.spi.AntSession;
49
import org.netbeans.api.project.Project;
50
import org.netbeans.api.project.ProjectManager;
51
import org.netbeans.bluej.BluejProject;
52
import org.openide.filesystems.FileUtil;
58
public class BluejAntLogger extends AntLogger {
60
/** Creates a new instance of BluejAntLogger */
61
public BluejAntLogger() {
65
* Mark which kinds of targets this logger is interested in.
66
* This applies to both target start and finish events, as well as any other
67
* events for which {@link AntEvent#getTargetName} is not null, such as task
68
* start and finish events, and message log events.
69
* If {@link #NO_TARGETS}, no events with specific targets will be sent to it.
70
* If a specific list, only events with defined target names included in the list
72
* If {@link #ALL_TARGETS}, all events not otherwise excluded will be sent to it.
74
* @param session the relevant session
75
* @return a nonempty (and non-null) list of target names; by default, {@link #NO_TARGETS}
77
public String[] interestedInTargets(AntSession session) {
78
return AntLogger.ALL_TARGETS;
82
* Mark whether this logger is interested in a given Ant session.
84
* @param session a session which is about to be start
85
* @return true to receive events about it; by default, false
87
public boolean interestedInSession(AntSession session) {
92
* Mark which kinds of message log events this logger is interested in.
93
* This applies only to message log events and no others.
94
* Only events with log levels included in the returned list will be delivered.
96
* @param session the relevant session
97
* @return a list of levels such as {@link AntEvent#LOG_INFO}; by default, an empty list
98
* @see AntSession#getVerbosity
100
public int[] interestedInLogLevels(AntSession session) {
103
retValue = super.interestedInLogLevels(session);
108
* Mark whether this logger is interested in any Ant script.
109
* If true, no events will be masked due to the script location.
110
* Note that a few events have no defined script and so will only
111
* be delivered to loggers interested in all scripts; typically this
112
* applies to debugging messages when a project is just being configured.
114
* @param session the relevant session
115
* @return true to receive events for all scripts; by default, false
117
public boolean interestedInAllScripts(AntSession session) {
122
* Fired when a target is started.
123
* It is <em>not</em> guaranteed that {@link AntEvent#getTargetName}
124
* will be non-null (as can happen in some circumstances with
125
* <code><import></code>, for example).
126
* The default implementation does nothing.
128
* @param event the associated event object
130
public void targetStarted(AntEvent event) {
131
if (event.isConsumed()) {
135
super.targetStarted(event);
139
* Fired once when a build is started.
140
* The default implementation does nothing.
142
* @param event the associated event object
144
public void buildStarted(AntEvent event) {
145
if (event.isConsumed()) {
148
super.buildStarted(event);
152
* Fired when a target is finished.
153
* It is <em>not</em> guaranteed that {@link AntEvent#getTargetName}
155
* The default implementation does nothing.
157
* @param event the associated event object
159
public void targetFinished(AntEvent event) {
160
if (event.isConsumed()) {
164
super.targetFinished(event);
168
* Fired once when a build is finished.
169
* The default implementation does nothing.
171
* @param event the associated event object
172
* @see AntEvent#getException
174
public void buildFinished(AntEvent event) {
175
if (event.isConsumed()) {
178
super.buildFinished(event);
182
* Fired only if the build could not even be started.
183
* {@link AntEvent#getException} will be non-null.
184
* The default implementation does nothing.
186
* @param event the associated event object
188
public void buildInitializationFailed(AntEvent event) {
189
if (event.isConsumed()) {
192
super.buildInitializationFailed(event);
196
* Fired when a message is logged.
197
* The task and target fields may or may not be defined.
198
* The default implementation does nothing.
200
* @param event the associated event object
202
public void messageLogged(AntEvent event) {
203
if (event.isConsumed()) {
206
super.messageLogged(event);
210
* Fired when a task is started.
211
* It is <em>not</em> guaranteed that {@link AntEvent#getTaskName} or
212
* {@link AntEvent#getTaskStructure} will be non-null, though they will
213
* usually be defined.
214
* {@link AntEvent#getTargetName} might also be null.
215
* The default implementation does nothing.
217
* @param event the associated event object
219
public void taskStarted(AntEvent event) {
220
if (event.isConsumed()) {
223
super.taskStarted(event);
227
* Fired when a task is finished.
228
* It is <em>not</em> guaranteed that {@link AntEvent#getTaskName} or
229
* {@link AntEvent#getTaskStructure} will be non-null.
230
* {@link AntEvent#getTargetName} might also be null.
231
* The default implementation does nothing.
233
* @param event the associated event object
235
public void taskFinished(AntEvent event) {
236
if (event.isConsumed()) {
239
super.taskFinished(event);
243
* Mark whether this logger is interested in a given Ant script.
244
* Called only if {@link #interestedInAllScripts} is false.
245
* Only events with a defined script according to {@link AntEvent#getScriptLocation}
246
* which this logger is interested in will be delivered.
247
* Note that a few events have no defined script and so will only
248
* be delivered to loggers interested in all scripts; typically this
249
* applies to debugging messages when a project is just being configured.
250
* Note also that a single session can involve many different scripts.
252
* @param script a particular build script
253
* @param session the relevant session
254
* @return true to receive events sent from this script; by default, false
256
public boolean interestedInScript(File script, AntSession session) {
257
File folder = script.getParentFile();
260
prj = ProjectManager.getDefault().findProject(FileUtil.toFileObject(folder));
261
} catch (IllegalArgumentException ex) {
262
ex.printStackTrace();
263
} catch (IOException ex) {
264
ex.printStackTrace();
266
if (prj != null && prj.getLookup().lookup(BluejProject.class) != null) {