From 3554c7fb9888dc9a6bf828b711d06a8c10ab0752 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Wed, 4 Mar 2020 09:00:10 +0800 Subject: [PATCH 1/5] chore: update IDEA config to follow project renaming --- .idea/compiler.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index cf7d3df9..a0ec8843 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -30,7 +30,7 @@ - + From 7fa066075e4dad64e9f36746420879b232191687 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Wed, 4 Mar 2020 09:00:38 +0800 Subject: [PATCH 2/5] test: reproduce the reported problem as #196 --- .../spotbugs/snom/StandardFunctionalTest.groovy | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/functionalTest/groovy/com/github/spotbugs/snom/StandardFunctionalTest.groovy b/src/functionalTest/groovy/com/github/spotbugs/snom/StandardFunctionalTest.groovy index 4ab8d4f6..e91a9f5b 100644 --- a/src/functionalTest/groovy/com/github/spotbugs/snom/StandardFunctionalTest.groovy +++ b/src/functionalTest/groovy/com/github/spotbugs/snom/StandardFunctionalTest.groovy @@ -377,4 +377,19 @@ public class Foo { result.task(":classes").outcome == TaskOutcome.SUCCESS result.task(":spotbugsMain").outcome == TaskOutcome.NO_SOURCE } + + def "can run analysis when check task is triggered"() { + when: + BuildResult result = + GradleRunner.create() + .withProjectDir(rootDir) + .withArguments("clean", "check") + .withPluginClasspath() + .forwardOutput() + .withGradleVersion(version) + .build() + + then: + result.task(":spotbugsMain").outcome == TaskOutcome.SUCCESS + } } From 86ac4fa4bc92bca2c07b37d9af4030fdba70f0b4 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Wed, 4 Mar 2020 09:27:44 +0800 Subject: [PATCH 3/5] fix: task is not created if user does not refer directly https://docs.gradle.org/current/userguide/task_configuration_avoidance.html --- .../com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java index c64b9184..4ff3a9b1 100644 --- a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java +++ b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java @@ -47,7 +47,7 @@ private void generateForJava(Project project, Action confi log.debug("Creating SpotBugsTaskForJava for {}", sourceSet); project .getTasks() - .register( + .create( name, SpotBugsTask.class, task -> { From 9d41093528a5597b80fbe349384568d423065f3f Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Wed, 4 Mar 2020 09:21:16 +0800 Subject: [PATCH 4/5] chore: enhance logging for better tracability --- src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java | 5 +++++ .../github/spotbugs/snom/internal/SpotBugsTaskFactory.java | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java b/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java index 29c282aa..d196d358 100644 --- a/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java +++ b/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java @@ -18,6 +18,8 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class SpotBugsPlugin implements Plugin { public static final String CONFIG_NAME = "spotbugs"; @@ -25,6 +27,8 @@ public class SpotBugsPlugin implements Plugin { public static final String SLF4J_CONFIG_NAME = "spotbugsSlf4j"; public static final String EXTENSION_NAME = "spotbugs"; + private final Logger log = LoggerFactory.getLogger(SpotBugsPlugin.class); + @Override public void apply(Project project) { project.getPluginManager().apply(SpotBugsBasePlugin.class); @@ -34,6 +38,7 @@ public void apply(Project project) { private void createTasks(Project project, SpotBugsExtension extension) { @Nullable Task check = project.getTasks().findByName("check"); + log.debug("check task {}", check == null ? "not found" : "found"); new SpotBugsTaskFactory() .generate( project, diff --git a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java index 4ff3a9b1..f3c138ed 100644 --- a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java +++ b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java @@ -44,7 +44,7 @@ private void generateForJava(Project project, Action confi .all( sourceSet -> { String name = sourceSet.getTaskName("spotbugs", null); - log.debug("Creating SpotBugsTaskForJava for {}", sourceSet); + log.debug("Creating SpotBugsTask for {}", sourceSet); project .getTasks() .create( @@ -74,7 +74,7 @@ private void generateForAndroid( .all( task -> { String name = GUtil.toLowerCamelCase("spotbugs " + task.getVariantName()); - log.debug("Creating SpotBugsTaskForAndroid for {}", task); + log.debug("Creating SpotBugsTask for {}", task); project .getTasks() .register( From a5fb1ff2ff59f104733d26c2bb6578d2a24a8ee6 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Thu, 5 Mar 2020 13:18:18 +0800 Subject: [PATCH 5/5] refactor: make logger creation copy-paste friendly --- src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java b/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java index d196d358..59470b48 100644 --- a/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java +++ b/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java @@ -27,7 +27,7 @@ public class SpotBugsPlugin implements Plugin { public static final String SLF4J_CONFIG_NAME = "spotbugsSlf4j"; public static final String EXTENSION_NAME = "spotbugs"; - private final Logger log = LoggerFactory.getLogger(SpotBugsPlugin.class); + private final Logger log = LoggerFactory.getLogger(getClass()); @Override public void apply(Project project) {