Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying the diff.groovy with yaml project-to-test-on.yaml #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 68 additions & 54 deletions checkstyle-tester/diff.groovy
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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'

Expand All @@ -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
Expand Down Expand Up @@ -793,6 +786,7 @@ class Config {
def shortFilePaths
def listOfProjects
def mode
def includedProjects

def baseBranch
def patchBranch
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -876,6 +871,7 @@ class Config {
extraMvnRegressionOptions: extraMvnRegressionOptions,
allowExcludes:allowExcludes,
useShallowClone: useShallowClone,
includedProjects: includedProjects,
]
}

Expand All @@ -889,6 +885,7 @@ class Config {
extraMvnRegressionOptions: extraMvnRegressionOptions,
allowExcludes: allowExcludes,
useShallowClone: useShallowClone,
includedProjects: includedProjects,
]
}

Expand All @@ -903,6 +900,7 @@ class Config {
mode: mode,
allowExcludes: allowExcludes,
useShallowClone: useShallowClone,
includedProjects: includedProjects,
]
}
}
Expand All @@ -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
}
}