~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to ide/projectimport/bluej/src/org/netbeans/bluej/ant/BluejAntLogger.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
package org.netbeans.bluej.ant;
 
43
 
 
44
import java.io.File;
 
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;
 
53
 
 
54
/**
 
55
 *
 
56
 * @author mkleint
 
57
 */
 
58
public class BluejAntLogger extends AntLogger {
 
59
 
 
60
    /** Creates a new instance of BluejAntLogger */
 
61
    public BluejAntLogger() {
 
62
    }
 
63
 
 
64
    /**
 
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
 
71
     * will be sent to it.
 
72
     * If {@link #ALL_TARGETS}, all events not otherwise excluded will be sent to it.
 
73
     * 
 
74
     * @param session the relevant session
 
75
     * @return a nonempty (and non-null) list of target names; by default, {@link #NO_TARGETS}
 
76
     */
 
77
    public String[] interestedInTargets(AntSession session) {
 
78
        return AntLogger.ALL_TARGETS;
 
79
    }
 
80
 
 
81
    /**
 
82
     * Mark whether this logger is interested in a given Ant session.
 
83
     * 
 
84
     * @param session a session which is about to be start
 
85
     * @return true to receive events about it; by default, false
 
86
     */
 
87
    public boolean interestedInSession(AntSession session) {
 
88
        return true;
 
89
    }
 
90
 
 
91
    /**
 
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.
 
95
     * 
 
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
 
99
     */
 
100
    public int[] interestedInLogLevels(AntSession session) {
 
101
        int[] retValue;
 
102
        
 
103
        retValue = super.interestedInLogLevels(session);
 
104
        return retValue;
 
105
    }
 
106
 
 
107
    /**
 
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.
 
113
     * 
 
114
     * @param session the relevant session
 
115
     * @return true to receive events for all scripts; by default, false
 
116
     */
 
117
    public boolean interestedInAllScripts(AntSession session) {
 
118
        return true;
 
119
    }
 
120
 
 
121
    /**
 
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>&lt;import&gt;</code>, for example).
 
126
     * The default implementation does nothing.
 
127
     * 
 
128
     * @param event the associated event object
 
129
     */
 
130
    public void targetStarted(AntEvent event) {
 
131
        if (event.isConsumed()) {
 
132
            return;
 
133
        }
 
134
        event.consume();
 
135
        super.targetStarted(event);
 
136
    }
 
137
 
 
138
    /**
 
139
     * Fired once when a build is started.
 
140
     * The default implementation does nothing.
 
141
     * 
 
142
     * @param event the associated event object
 
143
     */
 
144
    public void buildStarted(AntEvent event) {
 
145
        if (event.isConsumed()) {
 
146
            return;
 
147
        }
 
148
        super.buildStarted(event);
 
149
    }
 
150
 
 
151
    /**
 
152
     * Fired when a target is finished.
 
153
     * It is <em>not</em> guaranteed that {@link AntEvent#getTargetName}
 
154
     * will be non-null.
 
155
     * The default implementation does nothing.
 
156
     * 
 
157
     * @param event the associated event object
 
158
     */
 
159
    public void targetFinished(AntEvent event) {
 
160
        if (event.isConsumed()) {
 
161
            return;
 
162
        }
 
163
        event.consume();
 
164
        super.targetFinished(event);
 
165
    }
 
166
 
 
167
    /**
 
168
     * Fired once when a build is finished.
 
169
     * The default implementation does nothing.
 
170
     * 
 
171
     * @param event the associated event object
 
172
     * @see AntEvent#getException
 
173
     */
 
174
    public void buildFinished(AntEvent event) {
 
175
        if (event.isConsumed()) {
 
176
            return;
 
177
        }
 
178
        super.buildFinished(event);
 
179
    }
 
180
 
 
181
    /**
 
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.
 
185
     * 
 
186
     * @param event the associated event object
 
187
     */
 
188
    public void buildInitializationFailed(AntEvent event) {
 
189
        if (event.isConsumed()) {
 
190
            return;
 
191
        }
 
192
        super.buildInitializationFailed(event);
 
193
    }
 
194
 
 
195
    /**
 
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.
 
199
     * 
 
200
     * @param event the associated event object
 
201
     */
 
202
    public void messageLogged(AntEvent event) {
 
203
        if (event.isConsumed()) {
 
204
            return;
 
205
        }
 
206
        super.messageLogged(event);
 
207
    }
 
208
 
 
209
    /**
 
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.
 
216
     * 
 
217
     * @param event the associated event object
 
218
     */
 
219
    public void taskStarted(AntEvent event) {
 
220
        if (event.isConsumed()) {
 
221
            return;
 
222
        }
 
223
        super.taskStarted(event);
 
224
    }
 
225
 
 
226
    /**
 
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.
 
232
     * 
 
233
     * @param event the associated event object
 
234
     */
 
235
    public void taskFinished(AntEvent event) {
 
236
        if (event.isConsumed()) {
 
237
            return;
 
238
        }
 
239
        super.taskFinished(event);
 
240
    }
 
241
 
 
242
    /**
 
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.
 
251
     * 
 
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
 
255
     */
 
256
    public boolean interestedInScript(File script, AntSession session) {
 
257
        File folder = script.getParentFile();
 
258
        Project prj = null;
 
259
        try {
 
260
            prj = ProjectManager.getDefault().findProject(FileUtil.toFileObject(folder));
 
261
        } catch (IllegalArgumentException ex) {
 
262
            ex.printStackTrace();
 
263
        } catch (IOException ex) {
 
264
            ex.printStackTrace();
 
265
        }
 
266
        if (prj != null && prj.getLookup().lookup(BluejProject.class) != null) {
 
267
            return true;
 
268
        }
 
269
        return false;
 
270
    }
 
271
    
 
272
}