Skip to content

Commit

Permalink
Pull checkstyle#12154: Use OS specific command and correct errorExtra…
Browse files Browse the repository at this point in the history
…ctingPattern
  • Loading branch information
Vyom-Yadav authored and rnveach committed Sep 20, 2022
1 parent b09cd8a commit 4be4f20
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions .ci/error-prone-check.groovy
Expand Up @@ -6,9 +6,9 @@ import groovy.xml.XmlUtil
import java.util.regex.Matcher
import java.util.regex.Pattern

@Field static final String SEPARATOR = System.getProperty("file.separator")
@Field static final Set<String> PROFILES = Set.of("compile", "test-compile")
@Field static final String USAGE_STRING = "Usage groovy ./.ci/error-prone-check.groovy" +
@Field static final String USAGE_STRING = "Usage groovy " +
".${File.separator}.ci${File.separator}error-prone-check.groovy" +
" (compile | test-compile) [-g | --generate-suppression]\n"

int exitCode = 1
Expand Down Expand Up @@ -58,8 +58,8 @@ private int parseArgumentAndExecute(String argument, String flag) {
private static int checkErrorProneReport(String profile, String flag) {
final XmlParser xmlParser = new XmlParser()
final String suppressedErrorsFileUri =
".${SEPARATOR}.ci${SEPARATOR}" +
"error-prone-suppressions${SEPARATOR}${profile}-phase-suppressions.xml"
".${File.separator}.ci${File.separator}" +
"error-prone-suppressions${File.separator}${profile}-phase-suppressions.xml"
final List<String> errorProneErrors = getErrorProneErrors(profile)
Set<ErrorProneError> errors = Collections.emptySet()
if (!errorProneErrors.isEmpty()) {
Expand All @@ -84,7 +84,7 @@ private static List<String> getErrorProneErrors(String profile) {
final List<String> errorProneErrors = [] as ArrayList
final String command = "mvn -e --no-transfer-progress clean" +
" ${profile} -Perror-prone-${profile}"
final Process process = command.execute()
final Process process = getOsSpecificCmd(command).execute()
process.in.eachLine { line ->
if (line.startsWith("[ERROR]")) {
errorProneErrors.add(line)
Expand All @@ -95,6 +95,23 @@ private static List<String> getErrorProneErrors(String profile) {
return errorProneErrors
}

/**
* Get OS specific command.
*
* @param cmd input command
* @return OS specific command
*/
private static String getOsSpecificCmd(String cmd) {
final String osSpecificCmd
if (System.getProperty("os.name").toLowerCase().contains('windows')) {
osSpecificCmd = "cmd /c ${cmd}"
}
else {
osSpecificCmd = cmd
}
return osSpecificCmd
}

/**
* Get a set of {@link ErrorProneError} from text.
*
Expand All @@ -104,8 +121,8 @@ private static List<String> getErrorProneErrors(String profile) {
private static Set<ErrorProneError> getErrorFromText(List<String> errorsText) {
final Set<ErrorProneError> errors = new HashSet<>()
final Pattern errorExtractingPattern = Pattern
.compile(".*/(.*\\.java):\\[(\\d+).*\\[(\\w+)\\](.*)");
final Pattern filePathExtractingPattern = Pattern.compile("\\[ERROR\\] (.*\\.java)")
.compile(".*[\\\\/](.*\\.java):\\[(\\d+).*\\[(\\w+)](.*)")
final Pattern filePathExtractingPattern = Pattern.compile("\\[ERROR] (.*\\.java)")
final int sourceFileGroup = 1
final int lineNumberGroup = 2
final int bugPatternGroup = 3
Expand Down

0 comments on commit 4be4f20

Please sign in to comment.