1 19 20 25 26 package org.netbeans.modules.tomcat5.util; 27 28 import java.io.File ; 29 import java.io.IOException ; 30 import java.io.Reader ; 31 import java.io.BufferedReader ; 32 import org.netbeans.modules.tomcat5.TomcatManager; 33 import org.openide.ErrorManager; 34 import org.openide.modules.InstalledFileLocator; 35 import org.openide.util.NbBundle; 36 import org.openide.windows.InputOutput; 37 import org.openide.windows.OutputWriter; 38 import org.netbeans.api.java.classpath.GlobalPathRegistry; 39 import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport; 40 import org.netbeans.modules.tomcat5.util.LogSupport.LineInfo; 41 42 46 class ServerLog extends Thread { 47 private InputOutput io; 48 private OutputWriter writer; 49 private OutputWriter errorWriter; 50 private BufferedReader inReader; 51 private BufferedReader errReader; 52 private final boolean autoFlush; 53 private final boolean takeFocus; 54 private volatile boolean done = false; 55 private ServerLogSupport logSupport; 56 57 68 public ServerLog(String url, String displayName, Reader in, Reader err, boolean autoFlush, 69 boolean takeFocus) { 70 super(displayName + " ServerLog - Thread"); setDaemon(true); 72 inReader = new BufferedReader (in); 73 errReader = new BufferedReader (err); 74 this.autoFlush = autoFlush; 75 this.takeFocus = takeFocus; 76 io = UISupport.getServerIO(url); 77 try { 78 io.getOut().reset(); 79 } 80 catch (IOException e) { 81 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 82 } 83 writer = io.getOut(); 84 errorWriter = io.getErr(); 85 io.select(); 86 logSupport = new ServerLogSupport(); 87 } 88 89 private void processLine(String line) { 90 ServerLogSupport.LineInfo lineInfo = logSupport.analyzeLine(line); 91 if (lineInfo.isError()) { 92 if (lineInfo.isAccessible()) { 93 try { 94 errorWriter.println(line, logSupport.getLink(lineInfo.message() , lineInfo.path(), lineInfo.line())); 95 } catch (IOException ex) { 96 ErrorManager.getDefault().notify(ex); 97 } 98 } else { 99 errorWriter.println(line); 100 } 101 } else { 102 writer.println(line); 103 if (line.startsWith("SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.LinkageError:")) { File file = InstalledFileLocator.getDefault().locate("modules/ext/jaxws21/api/jaxws-api.jar", null, false); if (file != null) { 106 writer.println(NbBundle.getMessage(ServerLog.class, "MSG_WSSERVLET11", file.getParent())); 107 } else { 108 writer.println(NbBundle.getMessage(ServerLog.class, "MSG_WSSERVLET11_NOJAR")); 109 } 110 } 111 } 112 } 113 114 public void run() { 115 try { 116 while(!done) { 117 boolean isInReaderReady = false; 118 boolean isErrReaderReady = false; 119 boolean updated = false; 120 int count = 0; 121 while (((isInReaderReady = inReader.ready()) || (isErrReaderReady = errReader.ready())) 124 && count++ < 1024) { 125 if (done) { 126 return; 127 } 128 updated = true; 129 if (isInReaderReady) { 130 String line = inReader.readLine(); 131 if (line == null) { 133 return; 134 } 135 processLine(line); 136 } 137 if (isErrReaderReady) { 138 String line = errReader.readLine(); 139 if (line == null) { 141 return; 142 } 143 processLine(line); 144 } 145 } 146 if (updated) { 147 if (autoFlush) { 148 writer.flush(); 149 errorWriter.flush(); 150 } 151 if (takeFocus) { 152 io.select(); 153 } 154 } 155 sleep(100); } 157 } catch (IOException ex) { 158 TomcatManager.ERR.notify(ErrorManager.INFORMATIONAL, ex); 159 } catch (InterruptedException e) { 160 } finally { 162 logSupport.detachAnnotation(); 163 } 164 } 165 166 172 public boolean isRunning() { 173 return !(done); 174 } 175 176 179 public void takeFocus() { 180 io.select(); 181 } 182 183 public void interrupt() { 184 super.interrupt(); 185 done = true; 186 } 187 188 192 static class ServerLogSupport extends LogSupport { 193 private String prevMessage; 194 private GlobalPathRegistry globalPathRegistry = GlobalPathRegistry.getDefault(); 195 196 public LineInfo analyzeLine(String logLine) { 197 String path = null; 198 int line = -1; 199 String message = null; 200 boolean error = false; 201 boolean accessible = false; 202 203 logLine = logLine.trim(); 204 int lineLenght = logLine.length(); 205 206 if (logLine.startsWith("/")) { 208 error = true; 209 int colonIdx = logLine.indexOf(':'); 210 if (colonIdx > -1) { 211 path = logLine.substring(0, colonIdx); 212 accessible = true; 213 if (lineLenght > colonIdx) { 214 int nextColonIdx = logLine.indexOf(':', colonIdx + 1); 215 if (nextColonIdx > -1) { 216 String lineNum = logLine.substring(colonIdx + 1, nextColonIdx); 217 try { 218 line = Integer.valueOf(lineNum).intValue(); 219 } catch(NumberFormatException nfe) { 220 TomcatManager.ERR.notify(ErrorManager.INFORMATIONAL, nfe); 222 } 223 if (lineLenght > nextColonIdx) { 224 message = logLine.substring(nextColonIdx + 1, lineLenght); 225 } 226 } 227 } 228 } 229 } 230 else if (lineLenght > 3 && Character.isLetter(logLine.charAt(0)) 232 && (logLine.charAt(1) == ':') && (logLine.charAt(2) == '\\')) { 233 error = true; 234 int secondColonIdx = logLine.indexOf(':', 2); 235 if (secondColonIdx > -1) { 236 path = logLine.substring(0, secondColonIdx); 237 accessible = true; 238 if (lineLenght > secondColonIdx) { 239 int thirdColonIdx = logLine.indexOf(':', secondColonIdx + 1); 240 if (thirdColonIdx > -1) { 241 String lineNum = logLine.substring(secondColonIdx + 1, thirdColonIdx); 242 try { 243 line = Integer.valueOf(lineNum).intValue(); 244 } catch(NumberFormatException nfe) { 245 TomcatManager.ERR.notify(ErrorManager.INFORMATIONAL, nfe); 247 } 248 if (lineLenght > thirdColonIdx) { 249 message = logLine.substring(thirdColonIdx + 1, lineLenght); 250 } 251 } 252 } 253 } 254 } 255 else if (logLine.startsWith("at ") && lineLenght > 3) { 258 error = true; 259 int parenthIdx = logLine.indexOf('('); 260 if (parenthIdx > -1) { 261 String classWithMethod = logLine.substring(3, parenthIdx); 262 int lastDotIdx = classWithMethod.lastIndexOf('.'); 263 if (lastDotIdx > -1) { 264 int lastParenthIdx = logLine.lastIndexOf(')'); 265 int lastColonIdx = logLine.lastIndexOf(':'); 266 if (lastParenthIdx > -1 && lastColonIdx > -1) { 267 String lineNum = logLine.substring(lastColonIdx + 1, lastParenthIdx); 268 try { 269 line = Integer.valueOf(lineNum).intValue(); 270 } catch(NumberFormatException nfe) { 271 TomcatManager.ERR.notify(ErrorManager.INFORMATIONAL, nfe); 273 } 274 message = prevMessage; 275 } 276 int firstDolarIdx = classWithMethod.indexOf('$'); String className = classWithMethod.substring(0, firstDolarIdx > -1 ? firstDolarIdx : lastDotIdx); 278 path = className.replace('.','/') + ".java"; accessible = globalPathRegistry.findResource(path) != null; 280 } 281 } 282 } 283 else { 285 prevMessage = logLine; 286 } 287 return new LineInfo(path, line, message, error, accessible); 288 } 289 } 290 } | Popular Tags |