Skip to content

Commit

Permalink
Merge pull request #1004 from spotbugs/issue-907
Browse files Browse the repository at this point in the history
Apply remaining TODOs to the beta channel
  • Loading branch information
KengoTODA authored Oct 15, 2023
2 parents fbc45be + 368f915 commit bdd1b70
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 193 deletions.
1 change: 1 addition & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- beta
pull_request: {}
workflow_dispatch: {}

Expand Down
3 changes: 0 additions & 3 deletions detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
<ID>MaxLineLength:SpotBugsExtension.kt$SpotBugsExtension$* Property to specify the name of project. Some reporting formats use this property. Default value is the name of your Gradle project.</ID>
<ID>MaxLineLength:SpotBugsHtmlReport.kt$SpotBugsHtmlReport$configuration.files { dependency: Dependency -> dependency.group == "com.github.spotbugs" &amp;&amp; dependency.name == "spotbugs" }</ID>
<ID>MaxLineLength:SpotBugsRunnerForHybrid.kt$SpotBugsRunnerForHybrid.Companion$*</ID>
<ID>MaxLineLength:SpotBugsRunnerForWorker.kt$SpotBugsRunnerForWorker$"Spotbugs will be executed using Java Toolchain configuration: Vendor: {} | Version: {}"</ID>
<ID>MaxLineLength:SpotBugsTask.kt$SpotBugsTask$*</ID>
<ID>MaxLineLength:SpotBugsTask.kt$SpotBugsTask$* Property to set the directory to generate report files. Default is {@code "$buildDir/reports/spotbugs/$taskName"}.</ID>
<ID>MaxLineLength:SpotBugsTask.kt$SpotBugsTask$* Property to specify the extra arguments for JVM process. Default value is empty so JVM process will get no extra argument.</ID>
<ID>MaxLineLength:SpotBugsTask.kt$SpotBugsTask$* Property to specify the extra arguments for SpotBugs. Default value is empty so SpotBugs will get no extra argument.</ID>
<ID>MaxLineLength:SpotBugsTask.kt$SpotBugsTask$* Property to specify the release identifier of project. Some reporting formats use this property. Default value is the version of your Gradle project.</ID>
<ID>MaxLineLength:SpotBugsTask.kt$SpotBugsTask$fun</ID>
<ID>NestedBlockDepth:SpotBugsRunnerForWorker.kt$SpotBugsRunnerForWorker.SpotBugsExecutor$override fun execute()</ID>
<ID>TooGenericExceptionCaught:SpotBugsRunner.kt$SpotBugsRunner$e: Exception</ID>
<ID>TooGenericExceptionCaught:SpotBugsRunnerForWorker.kt$SpotBugsRunnerForWorker.SpotBugsExecutor$e: Exception</ID>
<ID>TooManyFunctions:SpotBugsReport.kt$SpotBugsReport : SingleFileReportCustomizableHtmlReport</ID>
</CurrentIssues>
</SmellBaseline>
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"branches": [
{
"name": "master"
},
{
"channel": "beta",
"name": "beta",
"prerelease": true
}
],
"plugins": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ task spotbugsMain(type: com.github.spotbugs.snom.SpotBugsTask) {
}
def runner = gradleRunner
.withArguments(arguments)
.withDebug(true)
def result = runner.buildAndFail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,13 @@ public class Foo {
"""
new File(rootDir, "settings.gradle.kts") << """
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version("0.6.0")
id("org.gradle.toolchains.foojay-resolver-convention") version("0.7.0")
}
"""
}

@Unroll
def 'Supports Gradle Java Toolchains (#processConfiguration)'() {
setup:
buildFile << """
spotbugs {
useJavaToolchains = true
}"""
when:
def arguments = [':spotbugsMain', '-is']
arguments.add(processConfigurationArgument)
Expand All @@ -82,11 +76,16 @@ plugins {
processConfiguration | processConfigurationArgument
'javaexec' | '-Pcom.github.spotbugs.snom.worker=false'
'worker-api' | '-Pcom.github.spotbugs.snom.worker=true'
'javaexec-in-worker' | '-Pcom.github.spotbugs.snom.javaexec-in-worker=true'
}
@Unroll
def 'Do not use Gradle Java Toolchains if extension is not configured (#processConfiguration)'() {
def 'Do not use Gradle Java Toolchains if extension is disabled explicitly (#processConfiguration)'() {
setup:
buildFile << """
spotbugs {
useJavaToolchains = false
}"""
when:
def arguments = [':spotbugsMain', '-is']
arguments.add(processConfigurationArgument)
Expand All @@ -105,6 +104,5 @@ plugins {
processConfiguration | processConfigurationArgument
'javaexec' | '-Pcom.github.spotbugs.snom.worker=false'
'worker-api' | '-Pcom.github.spotbugs.snom.worker=true'
'javaexec-in-worker' | '-Pcom.github.spotbugs.snom.javaexec-in-worker=true'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package com.github.spotbugs.snom

import org.gradle.testkit.runner.BuildResult
import org.gradle.util.GradleVersion
import spock.lang.Ignore
import spock.lang.IgnoreIf

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
Expand Down Expand Up @@ -86,6 +87,7 @@ spotbugs {
result.task(":spotbugsMain").outcome == SUCCESS
}

@Ignore("because output does not contain the message generated by SpotBugs")
def "can add plugins by spotbugsPlugins configuration"() {
setup:
buildFile << """
Expand All @@ -96,7 +98,7 @@ dependencies {

when:
def result = gradleRunner
.withArguments('check', "-Pcom.github.spotbugs.snom.javaexec-in-worker=false")
.withArguments('check')
.build()

then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package com.github.spotbugs.snom

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Ignore
import spock.lang.Unroll

import java.nio.file.Paths
Expand Down Expand Up @@ -167,7 +168,7 @@ spotbugsMain {
TaskOutcome.UP_TO_DATE == result.task(":spotbugsMain").outcome
}
def 'ignore missing classes (Hybrid API? #isHybridApi)'() {
def 'ignore missing classes'() {
given:
def code = new File(rootDir, 'src/main/java/Bar.java')
code << '''
Expand All @@ -191,17 +192,13 @@ spotbugsMain {
':spotbugsMain',
'-is'
]
arguments.add('-Pcom.github.spotbugs.snom.javaexec-in-worker=' + isHybridApi)
def runner = gradleRunner
.withArguments(arguments)
def result = runner.build()
then:
result.task(':spotbugsMain').outcome == SUCCESS
where:
isHybridApi << [true, false]
}
@Unroll
Expand Down Expand Up @@ -412,6 +409,7 @@ public class Foo {
result.task(":spotbugsMain").outcome == SUCCESS
}
@Ignore("because output does not contain the message generated by SpotBugs")
def "can apply plugin"() {
given:
buildFile << """
Expand All @@ -420,7 +418,7 @@ dependencies{
}"""
when:
BuildResult result = gradleRunner
.withArguments("spotbugsMain", "-Pcom.github.spotbugs.snom.javaexec-in-worker=false")
.withArguments("spotbugsMain")
.build()
then:
Expand All @@ -429,6 +427,7 @@ dependencies{
!result.output.contains("Trying to add already registered factory")
}
@Ignore("because output does not contain the message generated by SpotBugs")
def "can apply plugin to multiple tasks"() {
given:
buildFile << """
Expand All @@ -450,7 +449,7 @@ public class FooTest {
}"""
when:
BuildResult result = gradleRunner
.withArguments("spotbugsMain", "spotbugsTest", "-Pcom.github.spotbugs.snom.javaexec-in-worker=false")
.withArguments("spotbugsMain", "spotbugsTest")
.build()
then:
Expand Down Expand Up @@ -585,7 +584,6 @@ spotbugsMain {
}
def runner = gradleRunner
.withArguments(arguments)
.withDebug(true)
def result = runner.buildAndFail()
Expand Down Expand Up @@ -653,7 +651,6 @@ spotbugs {
}
def runner = gradleRunner
.withArguments(arguments)
.withDebug(true)
def result = runner.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ class SpotBugsBasePlugin : Plugin<Project> {
createConfiguration(project, extension)
createPluginConfiguration(project.configurations)
val enableWorkerApi = getPropertyOrDefault(project, FEATURE_FLAG_WORKER_API, "true")
val enableHybridWorker = getPropertyOrDefault(project, FEATURE_FLAG_HYBRID_WORKER, "true")
project
.tasks
.withType(SpotBugsTask::class.java)
.configureEach { task ->
task.init(
extension,
enableWorkerApi.toBoolean(),
enableHybridWorker.toBoolean(),
)
}
}
Expand Down Expand Up @@ -77,7 +75,7 @@ class SpotBugsBasePlugin : Plugin<Project> {
},
)
extension.useAuxclasspathFile.convention(true)
extension.useJavaToolchains.convention(false)
extension.useJavaToolchains.convention(true)
return extension
}

Expand Down Expand Up @@ -163,7 +161,6 @@ class SpotBugsBasePlugin : Plugin<Project> {

companion object {
private const val FEATURE_FLAG_WORKER_API = "com.github.spotbugs.snom.worker"
private const val FEATURE_FLAG_HYBRID_WORKER = "com.github.spotbugs.snom.javaexec-in-worker"
private const val DEFAULT_REPORTS_DIR_NAME = "spotbugs"

/**
Expand Down
21 changes: 6 additions & 15 deletions src/main/kotlin/com/github/spotbugs/snom/SpotBugsTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package com.github.spotbugs.snom
import com.github.spotbugs.snom.internal.SpotBugsHtmlReport
import com.github.spotbugs.snom.internal.SpotBugsRunnerForHybrid
import com.github.spotbugs.snom.internal.SpotBugsRunnerForJavaExec
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
Expand Down Expand Up @@ -50,7 +49,6 @@ import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.workers.WorkerExecutor
import org.slf4j.LoggerFactory
import java.nio.file.Path
import javax.inject.Inject

/**
Expand Down Expand Up @@ -263,7 +261,7 @@ abstract class SpotBugsTask : DefaultTask(), VerificationTask {
abstract val useAuxclasspathFile: Property<Boolean>

@get:Internal
lateinit var auxclasspathFile: Path
abstract val auxclasspathFile: RegularFileProperty

/**
* Property to specify the target classes to analyse by SpotBugs.
Expand All @@ -283,7 +281,6 @@ abstract class SpotBugsTask : DefaultTask(), VerificationTask {
}

private var enableWorkerApi: Boolean = true
private var enableHybridWorker: Boolean = true

@get:Internal
abstract val pluginJarFiles: ConfigurableFileCollection
Expand Down Expand Up @@ -328,10 +325,8 @@ abstract class SpotBugsTask : DefaultTask(), VerificationTask {
fun init(
extension: SpotBugsExtension,
enableWorkerApi: Boolean,
enableHybridWorker: Boolean,
) {
// TODO use Property
this.auxclasspathFile = project.layout.buildDirectory.file("spotbugs/auxclasspath/$name").get().asFile.toPath()
this.auxclasspathFile.convention(project.layout.buildDirectory.file("spotbugs/auxclasspath/$name"))

ignoreFailures.convention(extension.ignoreFailures)
showStackTraces.convention(extension.showStackTraces)
Expand All @@ -358,9 +353,8 @@ abstract class SpotBugsTask : DefaultTask(), VerificationTask {
}

this.enableWorkerApi = enableWorkerApi
this.enableHybridWorker = enableHybridWorker

analyseClassFile.set(project.buildDir.resolve(this.name + "-analyse-class-file.txt"))
analyseClassFile.set(project.layout.buildDirectory.file("${this.name}-analyse-class-file.txt"))

val pluginConfiguration = project.configurations.getByName(SpotBugsPlugin.PLUGINS_CONFIG_NAME)
pluginJarFiles.from(
Expand Down Expand Up @@ -388,15 +382,12 @@ abstract class SpotBugsTask : DefaultTask(), VerificationTask {

@TaskAction
fun run() {
if (!enableWorkerApi) {
log.info("Running SpotBugs by JavaExec...")
SpotBugsRunnerForJavaExec(launcher).run(this)
} else if (enableHybridWorker) {
if (enableWorkerApi) {
log.info("Running SpotBugs by Gradle no-isolated Worker...")
SpotBugsRunnerForHybrid(workerExecutor, launcher).run(this)
} else {
log.info("Running SpotBugs by Gradle process-isolated Worker...")
SpotBugsRunnerForWorker(workerExecutor, launcher).run(this)
log.info("Running SpotBugs by JavaExec...")
SpotBugsRunnerForJavaExec(launcher).run(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ abstract class SpotBugsRunner {
.map { obj: File -> obj.absolutePath }
.collect(Collectors.joining("\n"))
try {
val auxClasspathFile = task.auxclasspathFile
val auxClasspathFile =
task.auxclasspathFile.map {
it.asFile.toPath()
}.get()
try {
Files.createDirectories(auxClasspathFile.parent)
if (!Files.exists(auxClasspathFile)) {
Expand Down
Loading

0 comments on commit bdd1b70

Please sign in to comment.