KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > freeform > jdkselection > Logger


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.java.freeform.jdkselection;
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
27 /**
28  * Suppresses some new Ant messages introduced by jdk.xml that are undesirable.
29  * @author Jesse Glick
30  */

31 public class Logger extends AntLogger {
32
33     /** Public for lookup */
34     public Logger() {}
35
36     @Override JavaDoc
37     public void messageLogged(AntEvent event) {
38         //System.err.println("GOT: " + event);
39
if (!event.isConsumed()) {
40             String JavaDoc msg = event.getMessage();
41             if (isOurs(msg)) {
42                 //System.err.println("task=" + event.getTaskName());
43
event.consume();
44                 event.getSession().deliverMessageLogged(event, msg, AntEvent.LOG_VERBOSE);
45                 return;
46             }
47         }
48     }
49
50     private static boolean isOurs(String JavaDoc msg) {
51         String JavaDoc prefix = "Trying to override old definition of task "; // NOI18N
52
if (msg.startsWith(prefix)) {
53             String JavaDoc task = msg.substring(prefix.length());
54             if (task.equals("javac") || // NOI18N
55
task.equals("java") || // NOI18N
56
task.equals("junit") || // NOI18N
57
task.equals("javadoc") || // NOI18N
58
task.equals("nbjpdastart") || // NOI18N
59
task.equals("http://java.netbeans.org/freeform/jdk.xml:property")) { // NOI18N
60
return true;
61             }
62         }
63         return false;
64     }
65
66     private static final String JavaDoc[] TASKS = {
67         "macrodef", // NOI18N
68
"presetdef", // NOI18N
69
"propertyfile", // NOI18N
70
};
71
72     @Override JavaDoc
73     public String JavaDoc[] interestedInTasks(AntSession session) {
74         return TASKS;
75     }
76
77     @Override JavaDoc
78     public String JavaDoc[] interestedInTargets(AntSession session) {
79         return AntLogger.ALL_TARGETS;
80     }
81
82     @Override JavaDoc
83     public boolean interestedInSession(AntSession session) {
84         return true;
85     }
86
87     @Override JavaDoc
88     public boolean interestedInAllScripts(AntSession session) {
89         // XXX for some reason messages come in from nbjdk.xml, not jdk.xml...?
90
// Also for ide-file-targets.xml etc.
91
return true;
92     }
93
94     @Override JavaDoc
95     public int[] interestedInLogLevels(AntSession session) {
96         return new int[] {
97             AntEvent.LOG_INFO,
98             AntEvent.LOG_WARN,
99         };
100     }
101     
102 }
103
Popular Tags