Skip to content

Commit

Permalink
[releng] Enable jacoco coverage on tests
Browse files Browse the repository at this point in the history
Change-Id: I4e11c25b96611952d707349385b4f1054ae7e97c
Signed-off-by: Philippe DUL <philippe.dul@thalesgroup.com>
  • Loading branch information
pdulth committed Nov 23, 2020
1 parent 898e52a commit 452b66d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions vars/sonar.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


def runSonar(String sonarProjectKey, String githubRepository, String sonarLoginToken, javaVersion = "8"){
withCredentials([string(credentialsId: "${sonarLoginToken}", variable: 'SONARCLOUD_TOKEN')]) {
withEnv(['MAVEN_OPTS=-Xmx4g']) {
def jacocoParameters = "-Dsonar.java.coveragePlugin=jacoco -Dsonar.core.codeCoveragePlugin=jacoco "
def sonarCommon = "sonar:sonar -Dsonar.projectKey=${sonarProjectKey} -Dsonar.organization=eclipse -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${SONARCLOUD_TOKEN} -Dsonar.skipDesign=true -Dsonar.dynamic=reuseReports -Dsonar.java.source=${javaVersion} -Dsonar.scanner.force-deprecated-java-version=true "
def sonarBranchAnalysis = "-Dsonar.branch.name=${BRANCH_NAME}"
def sonarPullRequestAnalysis = "-Dsonar.pullrequest.provider=GitHub -Dsonar.pullrequest.github.repository=${githubRepository} -Dsonar.pullrequest.key=${CHANGE_ID} -Dsonar.pullrequest.branch=${CHANGE_BRANCH}"
def sonar = sonarCommon + jacocoParameters + (github.isPullRequest() ? sonarPullRequestAnalysis : sonarBranchAnalysis)
sh "mvn ${sonar}"
}
}
}
26 changes: 26 additions & 0 deletions vars/tester.groovy
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
private def downloadJacocoIfNeeded() {
def jacoURL = 'https://repo1.maven.org/maven2/org/jacoco/jacoco/0.8.6/jacoco-0.8.6.zip'
def jacoZip = 'jacoco.zip'
sh """
if [ ! -d ${WORKSPACE}/jacoco ]; then
curl -k -o ${jacoZip} ${jacoURL}
unzip ${jacoZip} -d ${WORKSPACE}/jacoco
echo "Jacoco downloaded at ${WORKSPACE}/jacoco"
fi
"""
sh "ls ${WORKSPACE}/jacoco/lib"
}

def generateJacocoReport() {
sh "mvn -Djacoco.dataFile=${WORKSPACE}/jacoco.exec org.jacoco:jacoco-maven-plugin:0.8.6:report"
}

def publishTests() {
junit '*.xml'
generateJacocoReport()
}

private def getRunnerCmd(String capellaProductPath) {
return "${capellaProductPath} " +
"-port 8081 " +
Expand All @@ -9,9 +31,11 @@ private def getJunitCmdTemplate(String capellaProductPath, String applicationPar

// extract the capella path, without the executable name
def capellaPath = capellaProductPath.substring(0, capellaProductPath.lastIndexOf("/"))
def jacocoParameters = "\"-javaagent:${WORKSPACE}/jacoco/lib/jacocoagent.jar=includes=*,excludes=,exclclassloader=sun.reflect.DelegatingClassLoader,destfile=${WORKSPACE}/jacoco.exec,output=file,append=true\" "

return "sleep 10 && " +
"java " +
"${jacocoParameters}" +
"-Xms1024m -Xmx3500m -XX:+CMSClassUnloadingEnabled -ea " +
"-Declipse.p2.data.area=@config.dir/../p2 " +
"-Dfile.encoding=Cp1252 " +
Expand Down Expand Up @@ -40,6 +64,7 @@ private def getNONUIJunitCmd(String capellaProductPath) {
}

def runUITests(String capellaProductPath, String suiteTitle, String testPluginName, List<String> testClassNames) {
downloadJacocoIfNeeded()
def runnerCmd = getRunnerCmd(capellaProductPath)
def junitCmd = getUIJunitCmd(capellaProductPath)
def testClassNamesParam = testClassNames.join(' ')
Expand All @@ -48,6 +73,7 @@ def runUITests(String capellaProductPath, String suiteTitle, String testPluginNa
}

def runNONUITests(String capellaProductPath, String suiteTitle, String testPluginName, List<String> testClassNames) {
downloadJacocoIfNeeded()
def runnerCmd = getRunnerCmd(capellaProductPath)
def junitCmd = getNONUIJunitCmd(capellaProductPath)
def testClassNamesParam = testClassNames.join(' ')
Expand Down

0 comments on commit 452b66d

Please sign in to comment.