diff --git a/src/it/check-bug-only-test-sources/invoker.properties b/src/it/check-bug-only-test-sources/invoker.properties new file mode 100644 index 00000000..4d27a3ee --- /dev/null +++ b/src/it/check-bug-only-test-sources/invoker.properties @@ -0,0 +1,4 @@ +invoker.goals = clean package spotbugs:check + +# The expected result of the build, possible values are "success" (default) and "failure" +invoker.buildResult = failure diff --git a/src/it/check-bug-only-test-sources/pom.xml b/src/it/check-bug-only-test-sources/pom.xml new file mode 100644 index 00000000..a9d29bf8 --- /dev/null +++ b/src/it/check-bug-only-test-sources/pom.xml @@ -0,0 +1,47 @@ + + + + + 4.0.0 + + spotbugs-maven-plugin.it + common + testing + ../common.xml + + check-bug-only-test-sources + check-bug-only-test-sources + jar + + + src/main + @project.basedir@/src/it-src/test/java + + + + com.github.spotbugs + spotbugs-maven-plugin + + true + true + @spotbugsTestDebug@ + + + + + diff --git a/src/it/check-bug-only-test-sources/verify.groovy b/src/it/check-bug-only-test-sources/verify.groovy new file mode 100644 index 00000000..0c78ffed --- /dev/null +++ b/src/it/check-bug-only-test-sources/verify.groovy @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2006-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'BugInstance size is 2' ) diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy index 8f02039b..c153f996 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy @@ -479,15 +479,10 @@ abstract class BaseViolationCheckMojo extends AbstractMojo { @Override void execute() { Locale locale = Locale.getDefault() - List sourceFiles log.debug("Executing spotbugs:check") - if (this.classFilesDirectory.exists() && this.classFilesDirectory.isDirectory()) { - sourceFiles = FileUtils.getFiles(classFilesDirectory, SpotBugsInfo.JAVA_REGEX_PATTERN, null) - } - - if (!skip && sourceFiles) { + if (!skip && doSourceFilesExist()) { // this goes @@ -555,6 +550,20 @@ abstract class BaseViolationCheckMojo extends AbstractMojo { } } + private boolean doSourceFilesExist() { + List sourceFiles = new ArrayList() + + if (this.classFilesDirectory.exists() && this.classFilesDirectory.isDirectory()) { + sourceFiles.addAll(FileUtils.getFiles(classFilesDirectory, SpotBugsInfo.JAVA_REGEX_PATTERN, null)) + } + + if (this.includeTests && this.testClassFilesDirectory.exists() && this.testClassFilesDirectory.isDirectory()) { + sourceFiles.addAll(FileUtils.getFiles(testClassFilesDirectory, SpotBugsInfo.JAVA_REGEX_PATTERN, null)) + } + + !sourceFiles.isEmpty() + } + private void printBugs(total, bugs) { for (i in 0..total - 1) { def bug = bugs[i]