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.subversion;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.util.logging.Level;
047: import org.openide.util.RequestProcessor;
048: import org.openide.windows.IOProvider;
049: import org.openide.windows.InputOutput;
050: import org.openide.windows.OutputListener;
051: import org.tigris.subversion.svnclientadapter.ISVNNotifyListener;
052: import org.tigris.subversion.svnclientadapter.SVNNodeKind;
053: import org.tigris.subversion.svnclientadapter.SVNUrl;
054:
055: /**
056: *
057: * @author Tomas Stupka
058: */
059: public class OutputLogger implements ISVNNotifyListener {
060:
061: private InputOutput log;
062: private boolean ignoreCommand = false;
063: private String repositoryRootString;
064: private static final RequestProcessor rp = new RequestProcessor(
065: "SubversionOutput", 1);
066:
067: public static OutputLogger getLogger(SVNUrl repositoryRoot) {
068: if (repositoryRoot != null) {
069: return new OutputLogger(repositoryRoot);
070: } else {
071: return new NullLogger();
072: }
073: }
074:
075: private OutputLogger(SVNUrl repositoryRoot) {
076: repositoryRootString = repositoryRoot.toString();
077: log = IOProvider.getDefault()
078: .getIO(repositoryRootString, false);
079: }
080:
081: private OutputLogger() {
082: }
083:
084: public void logCommandLine(final String commandLine) {
085: rp.post(new Runnable() {
086: public void run() {
087: logln(commandLine, false);
088: log.getOut().flush();
089: }
090: });
091: }
092:
093: public void logCompleted(final String message) {
094: rp.post(new Runnable() {
095: public void run() {
096: logln(message, ignoreCommand);
097: log.getOut().flush();
098: }
099: });
100: }
101:
102: public void logError(final String message) {
103: rp.post(new Runnable() {
104: public void run() {
105: logln(message, false);
106: log.getOut().flush();
107: }
108: });
109: }
110:
111: public void logMessage(final String message) {
112: rp.post(new Runnable() {
113: public void run() {
114: logln(message, ignoreCommand);
115: log.getOut().flush();
116: }
117: });
118: }
119:
120: public void logRevision(long revision, String path) {
121: // logln(" revision " + revision + ", path = '" + path + "'");
122: }
123:
124: public void onNotify(File path, SVNNodeKind kind) {
125: //logln(" file " + path + ", kind " + kind);
126: }
127:
128: public void setCommand(final int command) {
129: rp.post(new Runnable() {
130: public void run() {
131: ignoreCommand = command == ISVNNotifyListener.Command.INFO
132: || command == ISVNNotifyListener.Command.STATUS
133: || command == ISVNNotifyListener.Command.ANNOTATE
134: || command == ISVNNotifyListener.Command.LOG
135: || command == ISVNNotifyListener.Command.LS;
136: }
137: });
138: }
139:
140: public void closeLog() {
141: rp.post(new Runnable() {
142: public void run() {
143: log.getOut().flush();
144: log.getOut().close();
145: }
146: });
147: }
148:
149: public void flushLog() {
150: rp.post(new Runnable() {
151: public void run() {
152: log.getOut().flush();
153: }
154: });
155: }
156:
157: private void logln(String message, boolean ignore) {
158: log(message + "\n", null, ignore); // NOI18N
159: }
160:
161: private void log(String message, OutputListener hyperlinkListener,
162: boolean ignore) {
163: if (ignore) {
164: return;
165: }
166: if (log.isClosed()) {
167: log = IOProvider.getDefault().getIO(repositoryRootString,
168: false);
169: try {
170: // HACK (mystic logic) workaround, otherwise it writes to nowhere
171: log.getOut().reset();
172: } catch (IOException e) {
173: Subversion.LOG.log(Level.SEVERE, null, e);
174: }
175: //log.select();
176: }
177: if (hyperlinkListener != null) {
178: try {
179: log.getOut().println(message, hyperlinkListener);
180: } catch (IOException e) {
181: log.getOut().write(message);
182: }
183: } else {
184: log.getOut().write(message);
185: }
186: }
187:
188: private static class NullLogger extends OutputLogger {
189:
190: public void logCommandLine(String commandLine) {
191: }
192:
193: public void logCompleted(String message) {
194: }
195:
196: public void logError(String message) {
197: }
198:
199: public void logMessage(String message) {
200: }
201:
202: public void logRevision(long revision, String path) {
203: }
204:
205: public void onNotify(File path, SVNNodeKind kind) {
206: }
207:
208: public void setCommand(int command) {
209: }
210:
211: public void closeLog() {
212: }
213:
214: public void flushLog() {
215: }
216: }
217:
218: }
|