Skip to content

Commit

Permalink
Improve CompileFailuresService regular expressions (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 authored Mar 15, 2024
1 parent 473eafb commit 0826000
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ interface Parameters extends BuildServiceParameters {
}

private static final Pattern COMPILE_ERROR_FIRST_LINE_PATTERN =
Pattern.compile("^(?<sourcePath>.*):(?<lineNumber>\\d+): (?<errorMessage>error: .*)$");
private static final Pattern COMPILE_ERROR_LAST_LINE_PATTERN = Pattern.compile("^\\d+ error(s)*$");
Pattern.compile("^(?<sourcePath>[^:]*):(?<lineNumber>\\d+): (?<errorMessage>error: .*)$");
private static final Pattern COMPILE_ERROR_LAST_LINE_PATTERN = Pattern.compile("^\\d+ errors?$");
private static final Pattern COMPILE_ERROR_PATTERN =
Pattern.compile("(?m)^(?<sourcePath>.*):(?<lineNumber>\\d+): (?<errorMessage>error: (.|\\s)*)");
Pattern.compile("^(?<sourcePath>[^:]*):(?<lineNumber>\\d+): (?<errorMessage>error: [\\s\\S]*)$");

private final ConcurrentMap<String, Boolean> startedCompileErrorsByTaskPath = new ConcurrentHashMap<>();
private final ConcurrentMap<String, StringBuilder> compilerErrorsByTaskPath = new ConcurrentHashMap<>();

public final <T extends AbstractCompile> void maybeCollectErrorMessage(
T task, CharSequence charSequence, Set<String> taskCompiledSourcePaths) {
Matcher firstCompileErrorMatcher = COMPILE_ERROR_FIRST_LINE_PATTERN.matcher(charSequence);
if (firstCompileErrorMatcher.find()) {
if (firstCompileErrorMatcher.matches()) {
String sourcePathFromError = firstCompileErrorMatcher.group("sourcePath");

// When running in parallel, javaCompileTasks will see the output of other tasks,
Expand All @@ -79,8 +79,8 @@ public final <T extends AbstractCompile> void maybeCollectErrorMessage(
if (!isCompileErrorStarted(task.getPath())) {
return;
}
Matcher lastCompileErrorMessage = COMPILE_ERROR_LAST_LINE_PATTERN.matcher(charSequence);
if (lastCompileErrorMessage.find()) {
Matcher lastCompileErrorMatcher = COMPILE_ERROR_LAST_LINE_PATTERN.matcher(charSequence);
if (lastCompileErrorMatcher.matches()) {
markCompileErrorFinished(task.getPath());
return;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ private boolean isCompileErrorStarted(String taskPath) {

private Optional<FailureReport> maybeGetFailureReport(String multiLineError) {
Matcher matcher = COMPILE_ERROR_PATTERN.matcher(multiLineError);
if (!matcher.find()) {
if (!matcher.matches()) {
return Optional.empty();
}
String sourcePathFromError = matcher.group("sourcePath");
Expand Down

0 comments on commit 0826000

Please sign in to comment.