Renamed constants, local variables and member variables using "hg" to "git".
[nbgit.git] / src / org / netbeans / modules / git / OutputLogger.java
blobd68e25c902e7aac4565dfcb52fd445b25da11c45
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.netbeans.modules.git;
44 import java.io.IOException;
45 import java.net.URL;
46 import java.util.List;
47 import java.util.logging.Level;
48 import org.openide.awt.HtmlBrowser;
49 import org.openide.util.RequestProcessor;
50 import org.openide.windows.IOProvider;
51 import org.openide.windows.InputOutput;
52 import org.openide.windows.OutputEvent;
53 import org.openide.windows.OutputListener;
54 import org.openide.windows.OutputWriter;
56 /**
58 * @author Tomas Stupka
60 public class OutputLogger {
62 private InputOutput log;
63 private boolean ignoreCommand = false;
64 private String repositoryRootString;
65 private static final RequestProcessor rp = new RequestProcessor("GitOutput", 1);
66 public static final int MAX_LINES_TO_PRINT = 500;
68 private static final String MSG_TOO_MANY_LINES = "The number of output lines is greater than 500; see message log for complete output";
71 public static OutputLogger getLogger(String repositoryRoot) {
72 if (repositoryRoot != null) {
73 return new OutputLogger(repositoryRoot);
74 } else {
75 return new NullLogger();
79 private OutputLogger(String repositoryRoot) {
80 repositoryRootString = repositoryRoot;
81 log = IOProvider.getDefault().getIO(repositoryRootString, false);
84 private OutputLogger() {
87 public void closeLog() {
88 rp.post(new Runnable() {
89 public void run() {
90 log.getOut().flush();
91 log.getOut().close();
92 log.getErr().flush();
93 log.getErr().close();
95 });
98 public void flushLog() {
99 rp.post(new Runnable() {
100 public void run() {
101 log.getOut().flush();
102 log.getErr().flush();
108 * Print contents of list to OutputLogger's tab
110 * @param list to print out
113 public void output(final List<String> list){
114 if( list.isEmpty()) return;
116 rp.post(new Runnable() {
117 public void run() {
118 log.select();
119 OutputWriter out = log.getOut();
121 int lines = list.size();
122 if (lines > MAX_LINES_TO_PRINT) {
123 out.println(list.get(1));
124 out.println(list.get(2));
125 out.println(list.get(3));
126 out.println("...");
127 out.println(list.get(list.size() - 1));
128 out.println(MSG_TOO_MANY_LINES);
129 for (String s : list) {
130 Git.LOG.log(Level.WARNING, s);
132 } else {
133 for (String s : list) {
134 out.println(s);
137 out.flush();
143 * Print msg to OutputLogger's tab
145 * @param String msg to print out
148 public void output(final String msg){
149 if( msg == null) return;
151 rp.post(new Runnable() {
152 public void run() {
153 log.select();
155 log.getOut().println(msg);
156 log.getOut().flush();
162 * Print msg to OutputLogger's tab in Red
164 * @param String msg to print out
167 public void outputInRed(final String msg){
168 if( msg == null) return;
170 rp.post(new Runnable() {
171 public void run() {
172 log.select();
173 log.getErr().println(msg);
174 log.getErr().flush();
180 * Print URL to OutputLogger's tab as an active Hyperlink
182 * @param String sURL to print out
185 public void outputLink(final String sURL){
186 if (sURL == null) return;
188 rp.post(new Runnable() {
189 public void run() {
190 log.select();
191 try {
192 OutputWriter out = log.getOut();
194 OutputListener listener = new OutputListener() {
195 public void outputLineAction(OutputEvent ev) {
196 try {
197 HtmlBrowser.URLDisplayer.getDefault().showURL(new URL(sURL));
198 } catch (IOException ex) {
199 // Ignore
202 public void outputLineSelected(OutputEvent ev) {}
203 public void outputLineCleared(OutputEvent ev) {}
205 out.println(sURL, listener, true);
206 out.flush();
207 } catch (IOException ex) {
208 // Ignore
215 * Select and Clear OutputLogger's tab
217 * @param list to print out
220 public void clearOutput(){
221 rp.post(new Runnable() {
222 public void run() {
223 log.select();
224 OutputWriter out = log.getOut();
226 try {
227 out.reset();
228 } catch (IOException ex) {
229 // Ignore Exception
231 out.flush();
236 private static class NullLogger extends OutputLogger {
238 @Override
239 public void closeLog() {
242 public void flushLog() {
245 public void output(List<String> list){
248 public void output(String msg){
250 public void outputInRed(String msg){
252 public void outputLink(final String sURL){
254 public void clearOutput(){