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 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
24 changes: 10 additions & 14 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,24 @@ buildPlugin(/*...*/, configurations: buildPlugin.recommendedConfigurations())
* `tests`: (default: `null`) - a map of parameters to run tests during the build
** `skip` - If `true`, skip all the tests by setting the `-skipTests` profile.
It will also skip FindBugs in modern Plugin POMs.
* `findbugs`: (default: `null`) - a map of parameters to run findbugs and/or archive findbugs reports. (only available for Maven projects)
** `run`: set to `true` to add the `findbugs:findbugs` goal to the maven command.
** `archive`: set to `true` to collect the findbugs report.
** `pattern`: (default: `'**/target/findbugsXml.xml'`) the file pattern for the report.
** `unstableTotalAll`: (default: `null`) the warnings threshold for when to mark the build as unstable, see the `findbugs` step for additional details.
** `unstableNewAll`: (default: `null`) the new warnings threshold for when to mark the build as unstable, see the `findbugs` step for additional details.
* `checkstyle`: (default: `null`) - a map of parameters to run checkstyle and/or archive checkstyle reports. (only available for Maven projects)
** `run`: set to `true` to add the `checkstyle:checkstyle` goal to the maven command.
** `archive`: set to `true` to collect the checkstyle report.
** `pattern`: (default: `'**/target/checkstyle-result.xml'`) the file pattern for the report.
** `unstableTotalAll`: (default: `null`) the violations threshold for when to mark the build as unstable, see the `checkstyle` step for additional details.
** `unstableNewAll`: (default: `null`) the new violations threshold for when to mark the build as unstable, see the `checkstyle` step for additional details.
* `spotbugs`, `checkstyle`, `pmd`, `cpd`: (default: `null`) - a map of parameters to archive SpotBugs, CheckStyle, PMD, or CPD warnings, respectively (only available for Maven projects).
These values can replace or amend the default configuration for the `recordIssues` step of the https://github.com/jenkinsci/warnings-ng-plugin[Warnings NG Plugin].
See https://github.com/jenkinsci/warnings-ng-plugin/blob/master/doc/Documentation.md#configuration[Warnings NG Plugin documentation]
for a list of available configuration parameters.
* `timeout`: (default: `60`) - the number of minutes for build timeout, cannot be bigger than 180, i.e. 3 hours.

NOTE: `findbugs` and `checkstyle` are only run/archived on the first platform/jdkVersion,jenkinsVersion combination. So in the example below it will run for `linux`/`jdk7` but not on `jdk8`.
NOTE: The `recordIssues` steps of the warnings plugin run on the first platform/jdkVersion,jenkinsVersion combination only.
So in the example below it will run for `linux`/`jdk7` but not on `jdk8`.

Usage:

.Jenkinsfile
[source,groovy]
----
buildPlugin(platforms: ['linux'], jdkVersions: [7, 8], findbugs: [archive: true, unstableTotalAll: '0'], checkstyle: [run: true, archive: true])
buildPlugin(platforms: ['linux'],
jdkVersions: [7, 8],
checkstyle: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]],
pmd: [trendChartType: 'TOOLS_ONLY', qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]])
----

=== buildPluginWithGradle()
Expand Down
13 changes: 11 additions & 2 deletions test/groovy/BaseTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class BaseTest extends BasePipelineTest {

helper.registerAllowedMethod('archiveArtifacts', [Map.class], { true })
helper.registerAllowedMethod('checkout', [String.class], { 'OK' })
helper.registerAllowedMethod('checkstyle', [Map.class], { true })
helper.registerAllowedMethod('configFile', [Map.class], { 'OK' })
helper.registerAllowedMethod('configFileProvider', [List.class, Closure.class], { l, body -> body() })
helper.registerAllowedMethod('deleteDir', [], { true })
Expand All @@ -38,7 +37,6 @@ class BaseTest extends BasePipelineTest {
throw new Exception(s)
})
helper.registerAllowedMethod('fileExists', [String.class], { s -> s })
helper.registerAllowedMethod('findbugs', [Map.class], { true })
helper.registerAllowedMethod('fingerprint', [String.class], { s -> s })
helper.registerAllowedMethod('git', [String.class], { 'OK' })
helper.registerAllowedMethod('hasDockerLabel', [], { true })
Expand All @@ -54,6 +52,17 @@ class BaseTest extends BasePipelineTest {
Yaml yaml = new Yaml()
return yaml.load('')
})
helper.registerAllowedMethod('recordIssues', [Map.class], { true })
helper.registerAllowedMethod('mavenConsole', [], { 'maven' })
helper.registerAllowedMethod('java', [], { 'java' })
helper.registerAllowedMethod('javaDoc', [], { 'javadoc' })
helper.registerAllowedMethod('spotBugs', [Map.class], { 'spotbugs' })
helper.registerAllowedMethod('checkStyle', [Map.class], { 'checkstyle' })
helper.registerAllowedMethod('pmdParser', [Map.class], { 'pmd' })
helper.registerAllowedMethod('cpd', [Map.class], { 'cpd' })
helper.registerAllowedMethod('taskScanner', [Map.class], { 'tasks' })
helper.registerAllowedMethod('excludeFile', [String.class], { true })

helper.registerAllowedMethod('runATH', [Map.class], { })
helper.registerAllowedMethod('runPCT', [Map.class], { })
helper.registerAllowedMethod('sh', [String.class], { s -> s })
Expand Down
73 changes: 65 additions & 8 deletions test/groovy/BuildPluginStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BuildPluginStepTests extends BaseTest {
void setUp() throws Exception {
super.setUp()
env.NODE_LABELS = 'docker'
env.JOB_NAME = 'build/plugin/test'
}

@Test
Expand Down Expand Up @@ -215,21 +216,77 @@ class BuildPluginStepTests extends BaseTest {
}

@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(assertMethodCallContainsPattern('findbugs', 'pattern=**/target/findbugsXml.xml'))

assertTrue(assertMethodCall('mavenConsole'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{enabledForFailure=true, tool=maven, trendChartType=TOOLS_ONLY, referenceJobName=build/plugin/master}'))

assertTrue(assertMethodCall('java'))
assertTrue(assertMethodCall('javaDoc'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{enabledForFailure=true, tools=[java, javadoc], filters=[true], sourceCodeEncoding=UTF-8, trendChartType=TOOLS_ONLY, referenceJobName=build/plugin/master}'))

assertTrue(assertMethodCall('spotBugs'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=spotbugs, sourceCodeEncoding=UTF-8, trendChartType=TOOLS_ONLY, referenceJobName=build/plugin/master, qualityGates=[{threshold=1, type=NEW, unstable=true}]}'))

assertTrue(assertMethodCall('checkStyle'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=checkstyle, sourceCodeEncoding=UTF-8, trendChartType=TOOLS_ONLY, qualityGates=[{threshold=1, type=TOTAL, unstable=true}], referenceJobName=build/plugin/master}'))

assertTrue(assertMethodCall('pmdParser'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=pmd, sourceCodeEncoding=UTF-8, trendChartType=NONE, referenceJobName=build/plugin/master}'))

assertTrue(assertMethodCall('cpd'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=cpd, sourceCodeEncoding=UTF-8, trendChartType=NONE, referenceJobName=build/plugin/master}'))


assertTrue(assertMethodCallContainsPattern('taskScanner', '{includePattern=**/*.java, excludePattern=**/target/**, highTags=FIXME, normalTags=TODO}'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{enabledForFailure=true, tool=tasks, sourceCodeEncoding=UTF-8, trendChartType=NONE, referenceJobName=build/plugin/master}'))
}

@Test
void test_buildPlugin_with_warnings_ng_and_thresholds() throws Exception {
def script = loadScript(scriptName)
script.call(spotbugs: [
qualityGates: [
[threshold: 3, type: 'TOTAL', unstable: true],
[threshold: 4, type: 'NEW', unstable: true]],
sourceCodeEncoding: 'UTF-16'])
printCallStack()

assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=spotbugs, sourceCodeEncoding=UTF-16, trendChartType=TOOLS_ONLY, referenceJobName=build/plugin/master, qualityGates=[{threshold=3, type=TOTAL, unstable=true}, {threshold=4, type=NEW, unstable=true}]}'))
}

@Test
void test_buildPlugin_with_checkstyle_archive() throws Exception {
void test_buildPlugin_with_warnings_ng_and_checkstyle() throws Exception {
def script = loadScript(scriptName)
script.call(checkstyle: [archive: true])
script.call(checkstyle: [
qualityGates: [
[threshold: 3, type: 'TOTAL', unstable: true],
[threshold: 4, type: 'NEW', unstable: true]],
filters: '[includeFile(\'MyFile.*.java\'), excludeCategory(\'WHITESPACE\')]'])
printCallStack()
// then it runs the findbugs
assertTrue(assertMethodCallContainsPattern('checkstyle', '**/target/checkstyle-result.xml'))

assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=checkstyle, sourceCodeEncoding=UTF-8, trendChartType=TOOLS_ONLY, qualityGates=[{threshold=3, type=TOTAL, unstable=true}, {threshold=4, type=NEW, unstable=true}], referenceJobName=build/plugin/master, filters=[includeFile(\'MyFile.*.java\'), excludeCategory(\'WHITESPACE\')]}'))
}

@Test
void test_buildPlugin_with_warnings_ng_and_pmd_chart() throws Exception {
def script = loadScript(scriptName)
script.call(pmd: [trendChartType: 'TOOLS_ONLY'])
printCallStack()

assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=pmd, sourceCodeEncoding=UTF-8, trendChartType=TOOLS_ONLY, referenceJobName=build/plugin/master}'))
}

@Test
void test_buildPlugin_with_warnings_ng_and_cpd() throws Exception {
def script = loadScript(scriptName)
script.call(cpd: [enabledForFailure: true])
printCallStack()

assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=cpd, sourceCodeEncoding=UTF-8, trendChartType=NONE, referenceJobName=build/plugin/master, enabledForFailure=true}'))
}

@Test
Expand Down
Loading