From 2ab3c45bf6215ba1f35e87427893d4c97a7190bc Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Mon, 14 Aug 2023 06:22:25 +0800 Subject: [PATCH] fix: remove deprecated methods `SpotBugsTask.getEnabledReports()` and `SpotBugsTask.getFirstEnabledReport` Signed-off-by: Kengo TODA --- .../com/github/spotbugs/snom/SpotBugsTask.kt | 21 ++++--------------- .../spotbugs/snom/internal/SpotBugsRunner.kt | 3 +-- .../snom/internal/SpotBugsRunnerForHybrid.kt | 2 +- .../internal/SpotBugsRunnerForJavaExec.kt | 6 +++--- .../snom/internal/SpotBugsRunnerForWorker.kt | 2 +- 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/com/github/spotbugs/snom/SpotBugsTask.kt b/src/main/kotlin/com/github/spotbugs/snom/SpotBugsTask.kt index 83149c8a..2e133d06 100644 --- a/src/main/kotlin/com/github/spotbugs/snom/SpotBugsTask.kt +++ b/src/main/kotlin/com/github/spotbugs/snom/SpotBugsTask.kt @@ -20,8 +20,6 @@ import com.github.spotbugs.snom.internal.SpotBugsRunnerForWorker import com.github.spotbugs.snom.internal.SpotBugsSarifReport import com.github.spotbugs.snom.internal.SpotBugsTextReport import com.github.spotbugs.snom.internal.SpotBugsXmlReport -import edu.umd.cs.findbugs.annotations.NonNull -import edu.umd.cs.findbugs.annotations.Nullable import groovy.lang.Closure import org.gradle.api.Action import org.gradle.api.DefaultTask @@ -417,21 +415,6 @@ abstract class SpotBugsTask : DefaultTask(), VerificationTask { return reports } - @Nullable - @Optional - @Nested - fun getFirstEnabledReport(): SpotBugsReport? { - val report = reports.stream().filter { report -> report.isEnabled }.findFirst() - return report.orElse(null) - } - - @NonNull - @Optional - @Nested - fun getEnabledReports(): Set { - return reports.matching { report -> report.isEnabled } - } - @Internal fun getBaseName(): String { var prunedName = name.replaceFirst("spotbugs", "") @@ -444,4 +427,8 @@ abstract class SpotBugsTask : DefaultTask(), VerificationTask { append(prunedName.substring(1)) } } + + @Internal + internal fun getRequiredReports() = + reports.matching { it.required.get() }.asMap.values } diff --git a/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunner.kt b/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunner.kt index eb726f5e..b5a7b639 100644 --- a/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunner.kt +++ b/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunner.kt @@ -13,7 +13,6 @@ */ package com.github.spotbugs.snom.internal -import com.github.spotbugs.snom.SpotBugsReport import com.github.spotbugs.snom.SpotBugsTask import org.gradle.api.GradleException import org.gradle.api.file.FileCollection @@ -58,7 +57,7 @@ abstract class SpotBugsRunner { if (task.showProgress.getOrElse(Boolean.FALSE)) { args.add("-progress") } - for (report: SpotBugsReport in task.getEnabledReports()) { + task.getRequiredReports().forEach { report -> val reportFile = report.outputLocation.asFile.get() val dir = reportFile.parentFile dir.mkdirs() diff --git a/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForHybrid.kt b/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForHybrid.kt index dc5acfcc..044dce31 100644 --- a/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForHybrid.kt +++ b/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForHybrid.kt @@ -61,7 +61,7 @@ class SpotBugsRunnerForHybrid( } params.getIgnoreFailures().set(task.ignoreFailures) params.getShowStackTraces().set(task.showStackTraces) - task.getEnabledReports().stream() + task.getRequiredReports() .map(SpotBugsReport::getOutputLocation) .forEach(params.getReports()::add) if (javaLauncher.isPresent) { diff --git a/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForJavaExec.kt b/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForJavaExec.kt index 9a904e66..ba52bb41 100644 --- a/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForJavaExec.kt +++ b/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForJavaExec.kt @@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory import java.io.File import java.net.URI import java.nio.file.Path -import java.util.stream.Collectors import javax.inject.Inject class SpotBugsRunnerForJavaExec @Inject constructor( @@ -56,7 +55,8 @@ class SpotBugsRunnerForJavaExec @Inject constructor( val errorMessage = buildString { append("Verification failed: SpotBugs execution thrown exception.") val reportPaths = - task.getEnabledReports().stream() + task.getRequiredReports() + .asSequence() .map(SpotBugsReport::getOutputLocation) .map(RegularFileProperty::getAsFile) .map { @@ -65,7 +65,7 @@ class SpotBugsRunnerForJavaExec @Inject constructor( .map(File::toPath) .map(Path::toUri) .map(URI::toString) - .collect(Collectors.toList()) + .toList() if (reportPaths.isNotEmpty()) { append("See the report at: ") append(reportPaths.joinToString(",")) diff --git a/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForWorker.kt b/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForWorker.kt index 4a34b3f3..e3f59287 100644 --- a/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForWorker.kt +++ b/src/main/kotlin/com/github/spotbugs/snom/internal/SpotBugsRunnerForWorker.kt @@ -65,7 +65,7 @@ class SpotBugsRunnerForWorker @Inject constructor( params.getArguments().addAll(buildArguments(task)) params.getIgnoreFailures().set(task.getIgnoreFailures()) params.getShowStackTraces().set(task.showStackTraces) - task.getEnabledReports().stream() + task.getRequiredReports() .map(SpotBugsReport::getOutputLocation) .forEach(params.getReports()::add) }