Fix for Bug 11152. RCL_2_4
authorstechong
Fri, 02 Jul 2010 16:58:26 -0500
branchRCL_2_4
changeset 1573 660c89efde83
parent 1571 b1641b8ccefb
child 1575 8ced3afefe5b
Fix for Bug 11152.
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/error/parsers/SBSv2ErrorParser.java
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/error/parsers/SBSv2ErrorParser.java	Fri Jul 02 09:32:59 2010 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/error/parsers/SBSv2ErrorParser.java	Fri Jul 02 16:58:26 2010 -0500
@@ -21,12 +21,11 @@
 
 import org.eclipse.cdt.core.ErrorParserManager;
 import org.eclipse.cdt.core.IMarkerGenerator;
+import org.eclipse.core.runtime.Path;
 
 public class SBSv2ErrorParser extends CarbideBaseErrorParser {
 
-	private static final Pattern warningPattern = Pattern.compile("<warning>(.*)</warning>"); //$NON-NLS-1$
-	private static final Pattern errorPattern = Pattern.compile("<error>(.*)</error>"); //$NON-NLS-1$
-	private static final Pattern infoPattern = Pattern.compile("<info>(.*)</info>"); //$NON-NLS-1$
+	private final Pattern msgPattern = Pattern.compile("(.*):(\\d*):(\\d*):(.*)"); //$NON-NLS-1$
 
 	public SBSv2ErrorParser() {
 	}
@@ -35,51 +34,50 @@
 
 		initialise();
 		
-		Matcher matcher = infoPattern.matcher(line);
-		if (matcher.matches()) {
+		if (line.startsWith("<info>"))
 			return true; // just ignore info messages
-		}
-		matcher = warningPattern.matcher(line);
-		if (matcher.matches()) {
+		
+		// full message detected
+		if (findMessage(errorParserManager, line, "<error>", "</error>", IMarkerGenerator.SEVERITY_ERROR_BUILD)) 
+			return true;
+		if (findMessage(errorParserManager, line, "<warning>", "</warning>", IMarkerGenerator.SEVERITY_WARNING)) 
+			return true;
+		
+		// some messages are split across multiple lines, so for now, at least show the first line (where <error>, etc. are)
+		if (findMessage(errorParserManager, line, "<error>", "", IMarkerGenerator.SEVERITY_ERROR_BUILD)) 
+			return true;
+		if (findMessage(errorParserManager, line, "<warning>", "", IMarkerGenerator.SEVERITY_WARNING)) 
+			return true;
+
+		return false;
+	}
+	
+	protected boolean findMessage(ErrorParserManager errorParserManager, String line, 
+			String startStrip, String endStrip, int severity) {
+		int idx = line.indexOf(startStrip);
+		int endIdx = line.indexOf(endStrip);
+		if (idx >= 0 && endIdx >= 0) {
 			// strip the tags
-			String text = line.substring("<warning>".length(), line.length() - "</warning>".length()); //$NON-NLS-1$ //$NON-NLS-2$
+			int descStart = idx + startStrip.length();
+			int descEnd = line.length() - endStrip.length();
+			
+			String text = line.substring(descStart, descEnd);
 			if (setFirstColon(text)) {
-				if (setFileNameAndLineNumber(text)) {
+				if (setFileNameAndLineNumber(text) || setSBSv2FileNameAndLineNumber(text)) {
 					setFile(errorParserManager);
 					setDescription(text);
-					errorParserManager.generateExternalMarker(msgIFile, msgLineNumber, msgDescription, IMarkerGenerator.SEVERITY_WARNING, null, externalFilePath);
+					errorParserManager.generateExternalMarker(msgIFile, msgLineNumber, msgDescription, severity, null, externalFilePath);
 					return true;
 				}
 			}
 			msgFileName = ""; //$NON-NLS-1$
-			msgDescription = matcher.group(1);
+			msgDescription = text;
 			setFile(errorParserManager);
-			errorParserManager.generateExternalMarker(msgIFile, msgLineNumber, msgDescription, IMarkerGenerator.SEVERITY_WARNING, null, externalFilePath);
+			errorParserManager.generateExternalMarker(msgIFile, msgLineNumber, msgDescription, severity, null, externalFilePath);
 			return true;
 		}
-		
-		matcher = errorPattern.matcher(line);
-		if (matcher.matches()) {
-			// strip the tags
-			String text = line.substring("<error>".length(), line.length() - "</error>".length()); //$NON-NLS-1$ //$NON-NLS-2$
-			if (setFirstColon(text)) {
-				if (setFileNameAndLineNumber(text)) {
-					setFile(errorParserManager);
-					setDescription(text);
-					errorParserManager.generateExternalMarker(msgIFile, msgLineNumber, msgDescription, IMarkerGenerator.SEVERITY_ERROR_BUILD, null, externalFilePath);
-					return true;
-				}
-			}
-			msgFileName = ""; //$NON-NLS-1$
-			msgDescription = matcher.group(1);
-			setFile(errorParserManager);
-			errorParserManager.generateExternalMarker(msgIFile, msgLineNumber, msgDescription, IMarkerGenerator.SEVERITY_ERROR_BUILD, null, externalFilePath);
-			return true;
-		}
-
 		return false;
 	}
-	
 	public void setDescription(String line) {
 		// Get the iDescription
 		msgDescription = line.substring(msgFirstColon + 1).trim();
@@ -88,4 +86,21 @@
 		}
 	}
 
+	protected boolean setSBSv2FileNameAndLineNumber(String line) {
+		// Get the first Substring, which must be in the form of
+		// "fileName:line number:postion"
+		String firstSubstr = line.substring(msgFirstColon + 1).trim();
+		if (firstSubstr != null) {
+			Matcher matcher = msgPattern.matcher(firstSubstr);
+			if (matcher.matches()) {
+				msgFileName = matcher.group(1);
+				if (!Path.EMPTY.isValidPath(msgFileName)) {
+					return false;
+				}
+				msgLineNumber = Integer.parseInt(matcher.group(2));
+				return true;
+			}
+		}
+		return false;
+	}
 }