Fix runStep condition for mavenExecuteStaticCodeChecks (#2009)

This change fixes the step mavenExecuteStaticCodeChecks to skip execution
if no tool is configured. Previously, the step was executed even when both 
supported tools, i.e., PMD and SpotBugs were disabled.
This commit is contained in:
Kevin Hudemann
2020-09-11 16:16:00 +02:00
committed by GitHub
parent f1cfca2e76
commit a57e3bf0ce
2 changed files with 6 additions and 8 deletions
+2 -1
View File
@@ -23,7 +23,8 @@ func runMavenStaticCodeChecks(config *mavenExecuteStaticCodeChecksOptions, telem
var goals []string
if !config.SpotBugs && !config.Pmd {
log.Entry().Fatal("Neither SpotBugs nor Pmd are configured. At least one of those tools have to be enabled")
log.Entry().Warnf("Neither SpotBugs nor Pmd are configured. Skipping step execution")
return nil
}
if testModulesExcludes := maven.GetTestModulesExcludes(); testModulesExcludes != nil {
+4 -7
View File
@@ -4,8 +4,6 @@ import (
"os"
"testing"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/SAP/jenkins-library/pkg/maven"
@@ -51,16 +49,15 @@ func TestRunMavenStaticCodeChecks(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, expected, execMockRunner.Calls[0])
})
t.Run("should log fatal if all tools are turned off", func(t *testing.T) {
var hasFailed bool
log.Entry().Logger.ExitFunc = func(int) { hasFailed = true }
t.Run("should warn and skip execution if all tools are turned off", func(t *testing.T) {
execMockRunner := mock.ExecMockRunner{}
config := mavenExecuteStaticCodeChecksOptions{
SpotBugs: false,
Pmd: false,
}
_ = runMavenStaticCodeChecks(&config, nil, &execMockRunner)
assert.True(t, hasFailed, "expected command to exit with fatal")
err := runMavenStaticCodeChecks(&config, nil, &execMockRunner)
assert.Nil(t, err)
assert.Nil(t, execMockRunner.Calls)
})
}