Skip to content

Commit

Permalink
fix: Spotbugs plugin dependencies are specified as plugins and cause …
Browse files Browse the repository at this point in the history
…`NullPointerException`

Signed-off-by: Kengo TODA <skypencil@gmail.com>
  • Loading branch information
KengoTODA committed Jul 31, 2023
1 parent 9a51e60 commit b107318
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
23 changes: 18 additions & 5 deletions src/functionalTest/groovy/com/github/spotbugs/snom/Issue910.groovy
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright 2023 SpotBugs team
*
* <p>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
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>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.
*/
package com.github.spotbugs.snom

import org.gradle.testkit.runner.BuildResult
Expand Down Expand Up @@ -43,11 +56,11 @@ public class Foo {
when:
BuildResult result =
GradleRunner.create()
.withProjectDir(rootDir.toFile())
.withArguments("check")
.withPluginClasspath()
.forwardOutput()
.build()
.withProjectDir(rootDir.toFile())
.withArguments("check")
.withPluginClasspath()
.forwardOutput()
.build()

then:
result.task(":spotbugsMain").outcome == TaskOutcome.SUCCESS
Expand Down
18 changes: 13 additions & 5 deletions src/main/groovy/com/github/spotbugs/snom/SpotBugsBasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,20 @@ Properties loadProperties() {
}

private Configuration createPluginConfiguration(Project project) {
return project
Configuration configuration =
project
.getConfigurations()
.create(SpotBugsPlugin.PLUGINS_CONFIG_NAME)
.setDescription("configuration for the external SpotBugs plugins")
.setVisible(false)
.setTransitive(true);
project
.getConfigurations()
.create(SpotBugsPlugin.PLUGINS_CONFIG_NAME)
.setDescription("configuration for the external SpotBugs plugins")
.setVisible(false)
.setTransitive(true);
.create(SpotBugsPlugin.INTERNAL_CONFIG_NAME)
.setDescription(
"configuration for the external SpotBugs plugins excluding transitive dependencies")
.setTransitive(false);
return configuration;
}

void verifyGradleVersion(GradleVersion version) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
public class SpotBugsPlugin implements Plugin<Project> {
public static final String CONFIG_NAME = "spotbugs";
public static final String PLUGINS_CONFIG_NAME = "spotbugsPlugins";

/**
* The configuration contains SpotBugs plugin jar files only
*
* @see <a href="https://github.com/spotbugs/spotbugs-gradle-plugin/issues/910">GitHub issue</a>
*/
public static final String INTERNAL_CONFIG_NAME = "actualSpotbugsPlugins";

public static final String SLF4J_CONFIG_NAME = "spotbugsSlf4j";
public static final String EXTENSION_NAME = "spotbugs";

Expand Down
7 changes: 4 additions & 3 deletions src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,11 @@ abstract class SpotBugsTask extends DefaultTask implements VerificationTask {
useAuxclasspathFile = objects.property(Boolean)
setDescription("Run SpotBugs analysis.")
setGroup(JavaBasePlugin.VERIFICATION_GROUP)
def pluginConfiguration = project.getConfigurations().getByName(SpotBugsPlugin.PLUGINS_CONFIG_NAME)
def internalPluginConfiguration = project.configurations.getByName(SpotBugsPlugin.INTERNAL_CONFIG_NAME)
pluginJarFiles = project.layout.files {
pluginConfiguration.files
internalPluginConfiguration.files
}
def pluginConfiguration = project.configurations.getByName(SpotBugsPlugin.PLUGINS_CONFIG_NAME)

def configuration = project.getConfigurations().getByName(SpotBugsPlugin.CONFIG_NAME)
def logger = this.log
Expand All @@ -377,7 +378,7 @@ abstract class SpotBugsTask extends DefaultTask implements VerificationTask {

def spotbugsSlf4j = project.configurations.getByName(SpotBugsPlugin.SLF4J_CONFIG_NAME)
spotbugsClasspath = project.layout.files {
spotbugsSlf4j.files + configuration.files
spotbugsSlf4j.files + pluginConfiguration.files + configuration.files
}
}

Expand Down

0 comments on commit b107318

Please sign in to comment.