1 19 20 package org.netbeans.modules.web.jspcompiler; 21 22 import java.io.File ; 23 import java.util.regex.Matcher ; 24 import java.util.regex.Pattern ; 25 import org.apache.tools.ant.module.spi.AntEvent; 26 import org.apache.tools.ant.module.spi.AntLogger; 27 import org.apache.tools.ant.module.spi.AntSession; 28 import org.netbeans.modules.web.api.webmodule.WebModule; 29 import org.openide.ErrorManager; 30 import org.openide.filesystems.FileObject; 31 import org.openide.filesystems.FileStateInvalidException; 32 import org.openide.filesystems.FileUtil; 33 34 38 public final class TldAntLogger extends AntLogger { 39 40 44 private static final Pattern TLD_ERROR = Pattern.compile( 45 "(.*)(org.apache.jasper.JasperException:)(.*)( file )(.*)"); 47 private static final Pattern FILE_PATTERN = Pattern.compile( 48 "([^\\(]*)(: )\\(line ([0-9]+), col ([0-9-]+)\\)"); 50 private static final String [] TASKS_OF_INTEREST = AntLogger.ALL_TASKS; 51 52 private static final int[] LEVELS_OF_INTEREST = { 53 AntEvent.LOG_INFO, AntEvent.LOG_WARN, AntEvent.LOG_ERR, }; 59 60 private static final ErrorManager ERR = ErrorManager.getDefault().getInstance(TldAntLogger.class.getName()); 61 private static final boolean LOGGABLE = ERR.isLoggable(ErrorManager.INFORMATIONAL); 62 63 64 public TldAntLogger() { 65 } 66 67 public boolean interestedInSession(AntSession session) { 68 return true; 69 } 70 71 public boolean interestedInAllScripts(AntSession session) { 72 return true; 73 } 74 75 public String [] interestedInTargets(AntSession session) { 76 return AntLogger.ALL_TARGETS; 77 } 78 79 public boolean interestedInScript(File script, AntSession session) { 80 return true; 81 } 82 83 public String [] interestedInTasks(AntSession session) { 84 return TASKS_OF_INTEREST; 85 } 86 87 public int[] interestedInLogLevels(AntSession session) { 88 return LEVELS_OF_INTEREST; 90 } 91 92 public void messageLogged(AntEvent event) { 93 AntSession session = event.getSession(); 94 int messageLevel = event.getLogLevel(); 95 int sessionLevel = session.getVerbosity(); 96 String line = event.getMessage(); 97 assert line != null; 98 99 Matcher m = TLD_ERROR.matcher(line); 100 if (m.matches()) { if (LOGGABLE) ERR.log("matched line: " + line); 102 String errorText = m.group(3) + m.group(4); 104 session.println(m.group(2) + errorText, true, null); 105 106 String filePart = m.group(5).trim(); 108 if (LOGGABLE) ERR.log("file part: " + filePart); 109 110 Matcher fileMatcher = FILE_PATTERN.matcher(filePart); 112 if (fileMatcher.matches()) { 113 String tldFile = fileMatcher.group(1).trim(); 114 if (LOGGABLE) ERR.log("tld file: " + tldFile); 115 116 int lineNumber = Integer.parseInt(fileMatcher.group(3)); 117 int columnNumber = Integer.parseInt(fileMatcher.group(4)); 118 if (LOGGABLE) ERR.log("linking line: " + lineNumber + ", column: " + columnNumber); 119 120 File scriptLoc = event.getScriptLocation(); 121 FileObject scriptLocFO = FileUtil.toFileObject(scriptLoc); 122 WebModule wm = WebModule.getWebModule(scriptLocFO); 123 if (LOGGABLE) ERR.log("wm: " + wm); 124 125 if (wm == null) { 126 session.println(tldFile, true, null); 127 event.consume(); 128 return; 129 } 130 131 FileObject tldSource = wm.getDocumentBase().getFileObject(tldFile); 132 if (LOGGABLE) ERR.log("tldSource: " + tldSource); 133 134 if (tldSource == null) { 135 session.println(tldFile, true, null); 136 event.consume(); 137 return; 138 } 139 140 if (messageLevel <= sessionLevel && !event.isConsumed()) { 141 try { 142 session.println(tldFile, true, session.createStandardHyperlink(tldSource.getURL(), errorText + tldFile, lineNumber, columnNumber, -1, -1)); 143 } catch (FileStateInvalidException e) { 144 assert false : e; 145 } 146 } 147 } 148 event.consume(); 149 } 150 } 151 } 152 | Popular Tags |