KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > EjbJarProjectAntLogger


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.j2ee.ejbjarproject;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.regex.Pattern JavaDoc;
25 import org.apache.tools.ant.module.spi.AntEvent;
26 import org.apache.tools.ant.module.spi.AntLogger;
27 import org.apache.tools.ant.module.spi.AntSession;
28 import org.netbeans.api.project.Project;
29 import org.netbeans.api.project.ProjectManager;
30 import org.openide.ErrorManager;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileUtil;
33
34 /**
35  * Logger which should suppress or prettify typical Ant output from a
36  * web project's build-impl.xml.
37  * @author Marek Fukala
38  */

39 public final class EjbJarProjectAntLogger extends AntLogger {
40     
41     /** Default constructor for lookup. */
42     public EjbJarProjectAntLogger() {
43     }
44     
45     public boolean interestedInSession(AntSession session) {
46         // Even if the initiating project is not a Web Project, suppress these messages.
47
// However disable our tricks when running at VERBOSE or higher.
48
//return session.getVerbosity() <= AntEvent.LOG_INFO;
49
return true;
50     }
51     
52     private static boolean isEjbJarProject(File JavaDoc dir) {
53         FileObject projdir = FileUtil.toFileObject(FileUtil.normalizeFile(dir));
54         try {
55             Project proj = ProjectManager.getDefault().findProject(projdir);
56             if (proj != null) {
57                 // Check if it is a WebProject.
58
return proj instanceof EjbJarProject;
59             }
60         } catch (IOException JavaDoc e) {
61             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
62         }
63         return false;
64     }
65     
66     public boolean interestedInScript(File JavaDoc script, AntSession session) {
67         if (script.getName().equals("build-impl.xml")) { // NOI18N
68
File JavaDoc parent = script.getParentFile();
69             if (parent != null && parent.getName().equals("nbproject")) { // NOI18N
70
File JavaDoc parent2 = parent.getParentFile();
71                 if (parent2 != null) {
72                     return isEjbJarProject(parent2);
73                 }
74             }
75         }
76         // Was not a Web Project's nbproject/build-impl.xml; ignore it.
77
return false;
78     }
79     
80     public String JavaDoc[] interestedInTargets(AntSession session) {
81         return AntLogger.ALL_TARGETS;
82     }
83     
84     public String JavaDoc[] interestedInTasks(AntSession session) {
85         // XXX will eventually need them all anyway; as is, could list just javac
86
return AntLogger.ALL_TASKS;
87     }
88     
89     public int[] interestedInLogLevels(AntSession session) {
90         return new int[] {
91             AntEvent.LOG_WARN
92         };
93     }
94     
95     public void messageLogged(AntEvent event) {
96         // filter out following message
97
if (!event.isConsumed() && event.getLogLevel() == AntEvent.LOG_WARN &&
98             event.getMessage().startsWith("Trying to override old definition of " + // NOI18N
99
"task http://www.netbeans.org/ns/j2ee-ejbjarproject/")) { // NOI18N
100
event.consume();
101         }
102     }
103
104 }
105
Popular Tags