CmakeOutputParser implements BuildOutputParser { @VisibleForTesting static ErrorFields matchErrorFileAndLineNumberErrorParts( @NonNull Matcher matcher, @NonNull String line) { ErrorFields fields = new ErrorFields(); fields.kind = MessageEvent.Kind.WARNING; if (matcher.group(1).equals(ERROR)) { fields.kind = MessageEvent.Kind.ERROR; } fields.lineNumber = 0; if (matcher.group(4) != null) { fields.lineNumber = Integer.valueOf(matcher.group(4)); } fields.columnNumber = 0; if (matcher.group(6) != null) { fields.columnNumber = Integer.valueOf(matcher.group(6)); } fields.errorMessage = line; if (matcher.group(7) != null) { fields.errorMessage = matcher.group(7).trim(); } return fields; }  @Override boolean parse(String line, BuildOutputInstantReader reader, Consumer<? super BuildEvent> messageConsumer);  }
@Test public void testPosixFilePatternMatcherForErrorFileAndLineNumberError() { int lineNumber = 123; int columnNumber = 456; String filePath = "/path/to/file.type"; String error = "CMake Error at %s:%d:%d"; error = String.format(Locale.getDefault(), error, filePath, lineNumber, columnNumber); Matcher matcher = CmakeOutputParser.errorFileAndLineNumber.matcher(error); assertTrue("[match file path]", matcher.matches()); String matchedPath = matcher.group(2); CmakeOutputParser.ErrorFields fields = CmakeOutputParser.matchErrorFileAndLineNumberErrorParts(matcher, error); assertEquals("[source path]", filePath.trim(), matchedPath); assertEquals("[line number]", lineNumber, fields.lineNumber); assertEquals("[column number]", columnNumber, fields.columnNumber); }
@Test public void testWindowsFilePatternMatcherForErrorFileAndLineNumberError() { int lineNumber = 123; int columnNumber = 456; String filePath = "C:\\Path\\to\\file.type"; String error = "CMake Error at %s:%d:%d"; error = String.format(Locale.getDefault(), error, filePath, lineNumber, columnNumber); Matcher matcher = CmakeOutputParser.errorFileAndLineNumber.matcher(error); assertTrue("[match file path]", matcher.matches()); String matchedPath = matcher.group(2); CmakeOutputParser.ErrorFields fields = CmakeOutputParser.matchErrorFileAndLineNumberErrorParts(matcher, error); assertEquals("[source path]", filePath.trim(), matchedPath); assertEquals("[line number]", lineNumber, fields.lineNumber); assertEquals("[column number]", columnNumber, fields.columnNumber); }