From 539ae7c4f489c6602f1da712c33901e1b78db03b Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Tue, 1 Aug 2023 06:08:14 +0800 Subject: [PATCH] fix: Spotbugs plugin dependencies are specified as plugins and cause `NullPointerException` Signed-off-by: Kengo TODA --- .../com/github/spotbugs/snom/Issue910.groovy | 23 +++++++++++++++---- .../spotbugs/snom/SpotBugsBasePlugin.java | 18 +++++++++++---- .../github/spotbugs/snom/SpotBugsPlugin.java | 8 +++++++ .../github/spotbugs/snom/SpotBugsTask.groovy | 7 +++--- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/functionalTest/groovy/com/github/spotbugs/snom/Issue910.groovy b/src/functionalTest/groovy/com/github/spotbugs/snom/Issue910.groovy index c5235844..0753c619 100644 --- a/src/functionalTest/groovy/com/github/spotbugs/snom/Issue910.groovy +++ b/src/functionalTest/groovy/com/github/spotbugs/snom/Issue910.groovy @@ -1,3 +1,16 @@ +/* + * Copyright 2023 SpotBugs team + * + *

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 + * + *

http://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. + */ package com.github.spotbugs.snom import org.gradle.testkit.runner.BuildResult @@ -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 diff --git a/src/main/groovy/com/github/spotbugs/snom/SpotBugsBasePlugin.java b/src/main/groovy/com/github/spotbugs/snom/SpotBugsBasePlugin.java index e602410c..cf62133d 100644 --- a/src/main/groovy/com/github/spotbugs/snom/SpotBugsBasePlugin.java +++ b/src/main/groovy/com/github/spotbugs/snom/SpotBugsBasePlugin.java @@ -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) { diff --git a/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java b/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java index c4abe6c5..bdd5b71f 100644 --- a/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java +++ b/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java @@ -23,6 +23,14 @@ public class SpotBugsPlugin implements Plugin { public static final String CONFIG_NAME = "spotbugs"; public static final String PLUGINS_CONFIG_NAME = "spotbugsPlugins"; + + /** + * The configuration contains SpotBugs plugin jar files only + * + * @see GitHub issue + */ + public static final String INTERNAL_CONFIG_NAME = "actualSpotbugsPlugins"; + public static final String SLF4J_CONFIG_NAME = "spotbugsSlf4j"; public static final String EXTENSION_NAME = "spotbugs"; diff --git a/src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy b/src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy index 9a388a1c..192bd34d 100644 --- a/src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy +++ b/src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy @@ -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 @@ -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 } }