diff --git a/checkstyle-tester/diff.groovy b/checkstyle-tester/diff.groovy index 5524949d..0d6874dc 100644 --- a/checkstyle-tester/diff.groovy +++ b/checkstyle-tester/diff.groovy @@ -1,5 +1,6 @@ import static java.lang.System.err import static java.nio.file.StandardCopyOption.REPLACE_EXISTING +import org.yaml.snakeyaml.Yaml import java.nio.file.Files import java.nio.file.Paths @@ -77,6 +78,8 @@ def getCliOptions(args) { + ' \'diff\' or \'single\'. (optional, default is \'diff\')') xm(longOpt: 'extraMvnRegressionOptions', args: 1, required: false, 'Extra arguments to pass to Maven' \ + 'for Checkstyle Regression run (optional, ex: -Dmaven.prop=true)') + p(longOpt: 'projects', args: 1, required: false, argName: 'projects', + 'Comma-separated list of projects to include (optional)') } return cli.parse(args) } @@ -246,6 +249,29 @@ def launchCheckstyleReport(cfg) { return reportInfo } +def parseProjects(listOfProjectsFile, allowExcludes, includedProjects) { + def projects = [] + def yaml = new Yaml() + def input = new File(listOfProjectsFile).text + def data = yaml.load(input) + + data.projects.each { project -> + project.each { name, details -> + if (includedProjects.contains(name) && details.enabled != false) { + def projectConfig = new ProjectConfig( + repoName: name, + repoType: details.type, + repoUrl: details.url, + commitId: details.commit_id, + excludes: allowExcludes ? details.excludes?.join(",") : "" + ) + projects << projectConfig + } + } + } + return projects +} + def generateCheckstyleReport(cfg) { println 'Testing Checkstyle started' @@ -255,62 +281,29 @@ def generateCheckstyleReport(cfg) { def reportsDir = 'reports' makeWorkDirsIfNotExist(srcDir, reposDir, reportsDir) - final repoNameParamNo = 0 - final repoTypeParamNo = 1 - final repoURLParamNo = 2 - final repoCommitIDParamNo = 3 - final repoExcludesParamNo = 4 - final fullParamListSize = 5 - - def checkstyleConfig = cfg.checkstyleCfg - def checkstyleVersion = cfg.checkstyleVersion - def allowExcludes = cfg.allowExcludes - def useShallowClone = cfg.useShallowClone - def listOfProjectsFile = new File(cfg.listOfProjects) - def projects = listOfProjectsFile.readLines() - def extraMvnRegressionOptions = cfg.extraMvnRegressionOptions - - projects.each { - project -> - if (!project.startsWith('#') && !project.isEmpty()) { - def params = project.split('\\|', -1) - if (params.length < fullParamListSize) { - throw new InvalidPropertiesFormatException("Error: line '$project' " + - "in file '$listOfProjectsFile.name' should have $fullParamListSize " + - "pipe-delimited sections!") - } + def projects = parseProjects(cfg.listOfProjects, cfg.allowExcludes, cfg.includedProjects) - def repoName = params[repoNameParamNo] - def repoType = params[repoTypeParamNo] - def repoUrl = params[repoURLParamNo] - def commitId = params[repoCommitIDParamNo] - - def excludes = "" - if (allowExcludes) { - excludes = params[repoExcludesParamNo] - } - - deleteDir(srcDir) - if (repoType == 'local') { - copyDir(repoUrl, getOsSpecificPath("$srcDir", "$repoName")) - } else { - if (useShallowClone && !isGitSha(commitId)) { - shallowCloneRepository(repoName, repoType, repoUrl, commitId, reposDir) - } else { - cloneRepository(repoName, repoType, repoUrl, commitId, reposDir) - } - copyDir(getOsSpecificPath("$reposDir", "$repoName"), getOsSpecificPath("$srcDir", "$repoName")) - } - runMavenExecution(srcDir, excludes, checkstyleConfig, - checkstyleVersion, extraMvnRegressionOptions) - def repoPath = repoUrl - if (repoType != 'local') { - repoPath = new File(getOsSpecificPath("$reposDir", "$repoName")).absolutePath - } - postProcessCheckstyleReport(targetDir, repoName, repoPath) - deleteDir(getOsSpecificPath("$srcDir", "$repoName")) - moveDir(targetDir, getOsSpecificPath("$reportsDir", "$repoName")) + projects.each { ProjectConfig projectConfig -> + deleteDir(srcDir) + if (projectConfig.repoType == 'local') { + copyDir(projectConfig.repoUrl, getOsSpecificPath("$srcDir", projectConfig.repoName)) + } else { + if (cfg.useShallowClone && !isGitSha(projectConfig.commitId)) { + shallowCloneRepository(projectConfig.repoName, projectConfig.repoType, projectConfig.repoUrl, projectConfig.commitId, reposDir) + } else { + cloneRepository(projectConfig.repoName, projectConfig.repoType, projectConfig.repoUrl, projectConfig.commitId, reposDir) } + copyDir(getOsSpecificPath("$reposDir", projectConfig.repoName), getOsSpecificPath("$srcDir", projectConfig.repoName)) + } + runMavenExecution(srcDir, projectConfig.excludes, cfg.checkstyleCfg, + cfg.checkstyleVersion, cfg.extraMvnRegressionOptions) + def repoPath = projectConfig.repoUrl + if (projectConfig.repoType != 'local') { + repoPath = new File(getOsSpecificPath("$reposDir", projectConfig.repoName)).absolutePath + } + postProcessCheckstyleReport(targetDir, projectConfig.repoName, repoPath) + deleteDir(getOsSpecificPath("$srcDir", projectConfig.repoName)) + moveDir(targetDir, getOsSpecificPath("$reportsDir", projectConfig.repoName)) } // restore empty_file to make src directory tracked by git @@ -793,6 +786,7 @@ class Config { def shortFilePaths def listOfProjects def mode + def includedProjects def baseBranch def patchBranch @@ -823,6 +817,7 @@ class Config { shortFilePaths = cliOptions.shortFilePaths listOfProjects = cliOptions.listOfProjects extraMvnRegressionOptions = cliOptions.extraMvnRegressionOptions + includedProjects = cliOptions.projects?.split(',') checkstyleVersion = cliOptions.checkstyleVersion allowExcludes = cliOptions.allowExcludes @@ -876,6 +871,7 @@ class Config { extraMvnRegressionOptions: extraMvnRegressionOptions, allowExcludes:allowExcludes, useShallowClone: useShallowClone, + includedProjects: includedProjects, ] } @@ -889,6 +885,7 @@ class Config { extraMvnRegressionOptions: extraMvnRegressionOptions, allowExcludes: allowExcludes, useShallowClone: useShallowClone, + includedProjects: includedProjects, ] } @@ -903,6 +900,7 @@ class Config { mode: mode, allowExcludes: allowExcludes, useShallowClone: useShallowClone, + includedProjects: includedProjects, ] } } @@ -920,3 +918,19 @@ class CheckstyleReportInfo { this.commitTime = commitTime } } + +class ProjectConfig { + String repoName + String repoType + String repoUrl + String commitId + String excludes + + ProjectConfig(Map config) { + this.repoName = config.repoName + this.repoType = config.repoType + this.repoUrl = config.repoUrl + this.commitId = config.commitId + this.excludes = config.excludes + } +}