1 19 20 package org.netbeans.modules.subversion; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import org.openide.ErrorManager; 25 import org.openide.windows.IOProvider; 26 import org.openide.windows.InputOutput; 27 import org.openide.windows.OutputListener; 28 import org.tigris.subversion.svnclientadapter.ISVNNotifyListener; 29 import org.tigris.subversion.svnclientadapter.SVNNodeKind; 30 import org.tigris.subversion.svnclientadapter.SVNUrl; 31 32 37 public class OutputLogger implements ISVNNotifyListener { 38 39 private InputOutput log; 40 private boolean ignoreCommand = false; 41 private String repositoryRootString; 42 43 public static OutputLogger getLogger(SVNUrl repositoryRoot) { 44 if (repositoryRoot != null) { 45 return new OutputLogger(repositoryRoot); 46 } else { 47 return new NullLogger(); 48 } 49 } 50 51 private OutputLogger(SVNUrl repositoryRoot) { 52 repositoryRootString = repositoryRoot.toString(); 53 log = IOProvider.getDefault().getIO(repositoryRootString, false); 54 } 55 56 private OutputLogger() { 57 } 58 59 public void logCommandLine(String commandLine) { 60 logln(commandLine, false); 61 flushLog(); 62 } 63 64 public void logCompleted(String message) { 65 logln(message, ignoreCommand); 66 flushLog(); 67 } 68 69 public void logError(String message) { 70 logln(message, false); 71 flushLog(); 72 } 73 74 public void logMessage(String message) { 75 logln(message, ignoreCommand); 76 flushLog(); 77 } 78 79 public void logRevision(long revision, String path) { 80 } 82 83 public void onNotify(File path, SVNNodeKind kind) { 84 } 86 87 public void setCommand(int command) { 88 ignoreCommand = command == ISVNNotifyListener.Command.INFO || 89 command == ISVNNotifyListener.Command.STATUS || 90 command == ISVNNotifyListener.Command.ANNOTATE || 91 command == ISVNNotifyListener.Command.LOG || 92 command == ISVNNotifyListener.Command.LS; 93 } 94 95 private void logln(String message, boolean ignore) { 96 log(message + "\n", null, ignore); } 98 99 private void log(String message, OutputListener hyperlinkListener, boolean ignore) { 100 if(ignore) { 101 return; 102 } 103 if (log.isClosed()) { 104 log = IOProvider.getDefault().getIO(repositoryRootString, false); 105 try { 106 log.getOut().reset(); 108 } catch (IOException e) { 109 ErrorManager err = ErrorManager.getDefault(); 110 err.notify(e); 111 } 112 } 114 if (hyperlinkListener != null) { 115 try { 116 log.getOut().println(message, hyperlinkListener); 117 } catch (IOException e) { 118 log.getOut().write(message); 119 } 120 } else { 121 log.getOut().write(message); 122 } 123 } 124 125 public void closeLog() { 126 log.getOut().flush(); 127 log.getOut().close(); 128 } 129 130 public void flushLog() { 131 log.getOut().flush(); 132 } 133 134 private static class NullLogger extends OutputLogger { 135 136 public void logCommandLine(String commandLine) { 137 } 138 139 public void logCompleted(String message) { 140 } 141 142 public void logError(String message) { 143 } 144 145 public void logMessage(String message) { 146 } 147 148 public void logRevision(long revision, String path) { 149 } 150 151 public void onNotify(File path, SVNNodeKind kind) { 152 } 153 154 public void setCommand(int command) { 155 } 156 157 public void closeLog() { 158 } 159 160 public void flushLog() { 161 } 162 } 163 } 164 | Popular Tags |