Skip to content

Commit

Permalink
fix: remove the deprecated SpotBugsReport.isEnabled() API
Browse files Browse the repository at this point in the history
refs #928

Signed-off-by: Kengo TODA <[email protected]>
  • Loading branch information
KengoTODA committed Aug 13, 2023
1 parent f829ca8 commit 04eedc6
Showing 7 changed files with 16 additions and 42 deletions.
14 changes: 0 additions & 14 deletions src/main/kotlin/com/github/spotbugs/snom/SpotBugsReport.kt
Original file line number Diff line number Diff line change
@@ -64,20 +64,6 @@ abstract class SpotBugsReport @Inject constructor(
return isRequired
}

@get:Deprecated("use {@link #getRequired()} instead.")
@get:Internal
@set:Deprecated("use {@code getRequired().set(value)} instead.")
var isEnabled: Boolean
get() = isRequired.get()
set(b) {
isRequired.set(b)
}

@Deprecated("use {@code getRequired().set(provider)} instead.")
fun setEnabled(provider: Provider<Boolean>) {
isRequired.set(provider)
}

@Deprecated("use {@code getOutputLocation().set(file)} instead.")
override fun setDestination(file: File) {
destination.set(file)
23 changes: 6 additions & 17 deletions src/main/kotlin/com/github/spotbugs/snom/SpotBugsTask.kt
Original file line number Diff line number Diff line change
@@ -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<SpotBugsReport> {
return reports.matching { report -> report.isEnabled }
}

@Internal
fun getBaseName(): String {
var prunedName = name.replaceFirst("spotbugs", "")
@@ -444,4 +427,10 @@ abstract class SpotBugsTask : DefaultTask(), VerificationTask {
append(prunedName.substring(1))
}
}

@Internal
internal fun getRequiredReports() =
reports.matching {
it.required.get()
}
}
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ abstract class SpotBugsHtmlReport @Inject constructor(objects: ObjectFactory, ta

override fun setStylesheet(path: String?) {
if (path == null) {
stylesheet.set(null as TextResource)
stylesheet.set(null as TextResource?)
} else {
val configuration = task
.project
Original file line number Diff line number Diff line change
@@ -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()
@@ -82,15 +81,15 @@ abstract class SpotBugsRunner {
args.add("-omitVisitors")
args.add(task.omitVisitors.get().stream().collect(Collectors.joining(",")))
}
if (task.includeFilter.isPresent && task.includeFilter.get() != null) {
if (task.includeFilter.isPresent) {
args.add("-include")
args.add(task.includeFilter.get().asFile.absolutePath)
}
if (task.excludeFilter.isPresent && task.excludeFilter.get() != null) {
if (task.excludeFilter.isPresent) {
args.add("-exclude")
args.add(task.excludeFilter.get().asFile.absolutePath)
}
if (task.baselineFile.isPresent && task.baselineFile.get() != null) {
if (task.baselineFile.isPresent) {
args.add("-excludeBugs")
args.add(task.baselineFile.get().asFile.absolutePath)
}
Original file line number Diff line number Diff line change
@@ -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) {
Original file line number Diff line number Diff line change
@@ -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(","))
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 04eedc6

Please sign in to comment.