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

[INFRA-2294][INFRA-2000] Enable Warnings Next Generation Plugin #121

Merged
merged 17 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 12 additions & 20 deletions src/test/groovy/BuildPluginStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ class BuildPluginStepTests extends BasePipelineTest {
helper.registerAllowedMethod('stage', [String.class], { s -> s })
helper.registerAllowedMethod('fileExists', [String.class], { s -> s })
helper.registerAllowedMethod('readFile', [String.class], { s -> s })
helper.registerAllowedMethod('checkstyle', [Map.class], { true })
helper.registerAllowedMethod('recordIssues', [Map.class], { s -> s })
helper.registerAllowedMethod('mavenConsole', [], { true })
helper.registerAllowedMethod('java', [], { true })
helper.registerAllowedMethod('javaDoc', [], { true })
helper.registerAllowedMethod('spotBugs', [], { true })
helper.registerAllowedMethod('checkStyle', [], { true })
helper.registerAllowedMethod('pmdParser', [], { true })
helper.registerAllowedMethod('taskScanner', [Map.class], { true })
helper.registerAllowedMethod('fingerprint', [String.class], { s -> s })
helper.registerAllowedMethod('archiveArtifacts', [Map.class], { true })
helper.registerAllowedMethod('deleteDir', [], { true })
Expand All @@ -46,7 +53,6 @@ class BuildPluginStepTests extends BasePipelineTest {
def res = closure.call()
return res
})
helper.registerAllowedMethod('findbugs', [Map.class], { true })
helper.registerAllowedMethod('durabilityHint', [String.class], { s -> s })
helper.registerAllowedMethod('pwd', [Map.class], { '/tmp' })
helper.registerAllowedMethod('echo', [String.class], { s -> s })
Expand Down Expand Up @@ -298,28 +304,14 @@ class BuildPluginStepTests extends BasePipelineTest {
}

@Test
void test_buildPlugin_with_findbugs_archive() throws Exception {
void test_buildPlugin_with_warnings_ng() throws Exception {
def script = loadScript(scriptName)
script.call(findbugs: [archive: true])
script.call()
printCallStack()
// then it runs the findbugs
assertTrue(helper.callStack.findAll { call ->
call.methodName == 'findbugs'
call.methodName == 'recordIssues'
}.any { call ->
callArgsToString(call).contains('pattern=**/target/findbugsXml.xml')
})
}

@Test
void test_buildPlugin_with_checkstyle_archive() throws Exception {
def script = loadScript(scriptName)
script.call(checkstyle: [archive: true])
printCallStack()
// then it runs the findbugs
assertTrue(helper.callStack.findAll { call ->
call.methodName == 'checkstyle'
}.any { call ->
callArgsToString(call).contains('**/target/checkstyle-result.xml')
callArgsToString(call).contains('{enabledForFailure=true, tools=[true]}')
})
}

Expand Down
54 changes: 16 additions & 38 deletions vars/buildPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def call(Map params = [:]) {

String stageIdentifier = "${label}-${jdk}${jenkinsVersion ? '-' + jenkinsVersion : ''}"
boolean first = tasks.size() == 1
boolean runFindbugs = first && params?.findbugs?.run
boolean runCheckstyle = first && params?.checkstyle?.run
boolean archiveFindbugs = first && params?.findbugs?.archive
boolean archiveCheckstyle = first && params?.checkstyle?.archive
boolean skipTests = params?.tests?.skip
boolean reallyUseAci = (useAci && label == 'linux') || forceAci
boolean addToolEnv = !reallyUseAci
Expand Down Expand Up @@ -93,22 +89,10 @@ def call(Map params = [:]) {
if (javaLevel) {
mavenOptions += "-Djava.level=${javaLevel}"
}
if (params?.findbugs?.run || params?.findbugs?.archive) {
mavenOptions += "-Dfindbugs.failOnError=false"
timja marked this conversation as resolved.
Show resolved Hide resolved
}
if (skipTests) {
mavenOptions += "-DskipTests"
}
if (params?.checkstyle?.run || params?.checkstyle?.archive) {
mavenOptions += "-Dcheckstyle.failOnViolation=false -Dcheckstyle.failsOnError=false"
timja marked this conversation as resolved.
Show resolved Hide resolved
}
mavenOptions += "clean install"
if (runFindbugs) {
mavenOptions += "findbugs:findbugs"
}
if (runCheckstyle) {
mavenOptions += "checkstyle:checkstyle"
}
try {
infra.runMaven(mavenOptions, jdk, null, null, addToolEnv)
} finally {
Expand Down Expand Up @@ -142,29 +126,23 @@ def call(Map params = [:]) {
}

stage("Archive (${stageIdentifier})") {
if (isMaven && archiveFindbugs) {
def fp = [pattern: params?.findbugs?.pattern ?: '**/target/findbugsXml.xml']
if (params?.findbugs?.unstableNewAll) {
fp['unstableNewAll'] = "${params.findbugs.unstableNewAll}"
}
if (params?.findbugs?.unstableTotalAll) {
fp['unstableTotalAll'] = "${params.findbugs.unstableTotalAll}"
}
findbugs(fp)
}
if (isMaven && archiveCheckstyle) {
def cp = [pattern: params?.checkstyle?.pattern ?: '**/target/checkstyle-result.xml']
if (params?.checkstyle?.unstableNewAll) {
cp['unstableNewAll'] = "${params.checkstyle.unstableNewAll}"
}
if (params?.checkstyle?.unstableTotalAll) {
cp['unstableTotalAll'] = "${params.checkstyle.unstableTotalAll}"
}
checkstyle(cp)
}
if (failFast && currentBuild.result == 'UNSTABLE') {
error 'There were test failures; halting early'
}

if (first) {
timja marked this conversation as resolved.
Show resolved Hide resolved
recordIssues(enabledForFailure: true, tools: [mavenConsole()])
recordIssues(enabledForFailure: true, tools: [java(), javaDoc()], sourceCodeEncoding: 'UTF-8')
recordIssues(tools: [spotBugs(), checkStyle(), pmdParser()], sourceCodeEncoding: 'UTF-8')
recordIssues(enabledForFailure: true, tool: taskScanner(
includePattern:'**/*.java',
excludePattern:'target/**',
highTags:'FIXME',
normalTags:'TODO'), sourceCodeEncoding: 'UTF-8')
if (failFast && currentBuild.result == 'UNSTABLE') {
error 'There were static analysis warnings; halting early'
}
}
if (doArchiveArtifacts) {
if (incrementals) {
String changelist = readFile(changelistF)
Expand All @@ -178,15 +156,15 @@ def call(Map params = [:]) {
} else {
String artifacts
if (isMaven) {
artifacts = '**/target/*.hpi,**/target/*.jpi'
artifacts = '**/target/*.hpi,**/target/*.jpi,**/target/*.jar'
} else {
artifacts = '**/build/libs/*.hpi,**/build/libs/*.jpi'
}
archiveArtifacts artifacts: artifacts, fingerprint: true
}
}
}
}
}
} finally {
if (hasDockerLabel()) {
if(isUnix()) {
Expand Down