001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project;
043:
044: import java.io.File;
045: import org.apache.tools.ant.module.spi.AntEvent;
046: import org.apache.tools.ant.module.spi.AntLogger;
047: import org.apache.tools.ant.module.spi.AntSession;
048: import org.openide.util.Lookup;
049:
050: /**
051: * Implementation of simple AntLogger. To enable/disable use setEnabled(boolean ) method.
052: *
053: * @author pzajac
054: */
055: public class TestAntLogger extends AntLogger {
056: boolean bEnabled;
057:
058: public void setEnabled(boolean bEnabled) {
059: this .bEnabled = true;
060: }
061:
062: public void messageLogged(AntEvent event) {
063: if (bEnabled) {
064: System.out.println(event.getMessage());
065: }
066: }
067:
068: public boolean interestedInSession(AntSession session) {
069: return bEnabled;
070: }
071:
072: public boolean interestedInScript(File script, AntSession session) {
073: return bEnabled;
074: }
075:
076: public boolean interestedInAllScripts(AntSession session) {
077: return bEnabled;
078: }
079:
080: public void targetStarted(AntEvent event) {
081: System.out.println("target started:" + event.getTargetName());
082: }
083:
084: public String[] interestedInTasks(AntSession session) {
085: return (bEnabled) ? ALL_TASKS : new String[0];
086: }
087:
088: public String[] interestedInTargets(AntSession session) {
089: return (bEnabled) ? ALL_TARGETS : new String[0];
090: }
091:
092: public int[] interestedInLogLevels(AntSession session) {
093: return (bEnabled) ? new int[] { AntEvent.LOG_INFO,
094: AntEvent.LOG_WARN, AntEvent.LOG_ERR } : new int[0];
095: }
096:
097: static TestAntLogger getDefault() {
098: // XXX would be clearer to remove M-I/s reg and use MockLookup instead
099: return (TestAntLogger) Lookup
100: .getDefault()
101: .lookupItem(
102: new Lookup.Template<AntLogger>(
103: AntLogger.class,
104: "org.netbeans.modules.apisupport.project.TestAntLogger",
105: null)).getInstance();
106: }
107:
108: }
|