Skip to content

Commit

Permalink
Make reduced classpath fallback locale-independent
Browse files Browse the repository at this point in the history
Fixes #1342

--
PiperOrigin-RevId: 145144856
MOS_MIGRATED_REVID=145144856
  • Loading branch information
cushon authored and laszlocsomor committed Jan 23, 2017
1 parent 09f42d5 commit 83c6465
Showing 1 changed file with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.devtools.build.buildjar.javac.FormattedDiagnostic;
import com.google.devtools.build.buildjar.javac.JavacRunner;
import java.io.IOException;
import java.util.regex.Pattern;

/**
* A variant of SimpleJavaLibraryBuilder that attempts to reduce the compile-time classpath right
Expand Down Expand Up @@ -78,7 +77,16 @@ private static boolean shouldFallBack(BlazeJavacResult result) {
return false;
}
for (FormattedDiagnostic diagnostic : result.diagnostics()) {
if (hasRecognizedError(diagnostic.getFormatted())) {
System.err.println(diagnostic.getCode());
String code = diagnostic.getCode();
if (code.contains("doesnt.exist")
|| code.contains("cant.resolve")
|| code.contains("cant.access")) {
return true;
}
// handle -Xdoclint:reference errors, which don't have a diagnostic code
// TODO(cushon): this is locale-dependent
if (diagnostic.getFormatted().contains("error: reference not found")) {
return true;
}
}
Expand All @@ -87,16 +95,4 @@ private static boolean shouldFallBack(BlazeJavacResult result) {
}
return false;
}

private static final Pattern MISSING_PACKAGE =
Pattern.compile("error: package ([\\p{javaJavaIdentifierPart}\\.]+) does not exist");

private static boolean hasRecognizedError(String output) {
// TODO(cushon): usage diagnostic codes instead
return output.contains("error: cannot access")
|| output.contains("error: cannot find symbol")
|| MISSING_PACKAGE.matcher(output).find()
// TODO(cushon): -Xdoclint:reference is probably a bad idea
|| output.contains("error: reference not found");
}
}

0 comments on commit 83c6465

Please sign in to comment.