001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.project;
021:
022: import java.io.File;
023: import java.io.IOException;
024:
025: import org.apache.tools.ant.module.spi.AntEvent;
026: import org.apache.tools.ant.module.spi.AntLogger;
027: import org.apache.tools.ant.module.spi.AntSession;
028: import org.netbeans.api.project.Project;
029: import org.netbeans.api.project.ProjectManager;
030: import org.openide.ErrorManager;
031: import org.openide.filesystems.FileObject;
032: import org.openide.filesystems.FileUtil;
033:
034: /**
035: * @author radval
036: *
037: * To change the template for this generated type comment go to
038: * Window - Preferences - Java - Code Generation - Code and Comments
039: */
040: public class BpelAntLogger extends AntLogger {
041:
042: public boolean interestedInSession(AntSession session) {
043: // Even if the initiating project is not a J2SEProject, suppress these messages.
044: // However disable our tricks when running at VERBOSE or higher.
045: return session.getVerbosity() <= AntEvent.LOG_INFO;
046: }
047:
048: private static boolean isJ2SEProject(File dir) {
049: FileObject projdir = FileUtil.toFileObject(FileUtil
050: .normalizeFile(dir));
051: try {
052: Project proj = ProjectManager.getDefault().findProject(
053: projdir);
054: if (proj != null) {
055: // Check if it is a J2SEProject.
056: return proj.getLookup().lookup(BpelproProject.class) != null;
057: }
058: } catch (IOException e) {
059: ErrorManager.getDefault().notify(
060: ErrorManager.INFORMATIONAL, e);
061: }
062: return false;
063: }
064:
065: public boolean interestedInScript(File script, AntSession session) {
066: if (script.getName().equals("build-impl.xml")) { // NOI18N
067: File parent = script.getParentFile();
068: if (parent != null && parent.getName().equals("nbproject")) { // NOI18N
069: File parent2 = parent.getParentFile();
070: if (parent2 != null) {
071: return isJ2SEProject(parent2);
072: }
073: }
074: }
075: // Was not a J2SEProject's nbproject/build-impl.xml; ignore it.
076: return false;
077: }
078:
079: public String[] interestedInTargets(AntSession session) {
080: return AntLogger.ALL_TARGETS;
081: }
082:
083: public String[] interestedInTasks(AntSession session) {
084: // XXX will eventually need them all anyway; as is, could list just javac
085: return AntLogger.ALL_TASKS;
086: }
087:
088: public int[] interestedInLogLevels(AntSession session) {
089: return new int[] { AntEvent.LOG_WARN, };
090: }
091:
092: public void taskFinished(AntEvent event) {
093: if ("javac".equals(event.getTaskName())) { // NOI18N
094: Throwable t = event.getException();
095: AntSession session = event.getSession();
096: if (t != null && !session.isExceptionConsumed(t)) {
097: // Some error was thrown from build-impl.xml#compile. Ignore it; generally
098: // it will have been a compilation error which we do not wish to show.
099: session.consumeException(t);
100: }
101: }
102:
103: // System.out.println("BpelAntLogger "+ event.getMessage());
104: }
105:
106: public void messageLogged(AntEvent event) {
107: // #43968 - filter out following message
108: if (!event.isConsumed()
109: && event.getLogLevel() == AntEvent.LOG_WARN
110: && event
111: .getMessage()
112: .startsWith(
113: "Trying to override old definition of "
114: + // NOI18N
115: "task http://www.netbeans.org/ns/j2se-project/")) { // NOI18N
116: event.consume();
117: }
118: }
119:
120: }
|