Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin idioms #1063

Merged
merged 42 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fce39db
Replace String.format
Goooler Dec 3, 2023
e40236e
Use `check` function to check version requirement
Goooler Dec 5, 2023
a3da155
Suppress magic nums in SemanticVersion
Goooler Dec 5, 2023
ce9a412
Refine Kdoc
Goooler Dec 5, 2023
53a74ba
Suppress MaxLineLength for PATTERN
Goooler Dec 5, 2023
c1fa650
Suppress MaxLineLength for SUPPORTED_VERSION
Goooler Dec 5, 2023
83e56c2
Fix MaxLineLength for SpotBugsExtension
Goooler Dec 5, 2023
0aae482
Fix MaxLineLength for SpotBugsRunnerForHybrid
Goooler Dec 5, 2023
899e17e
Remove lines
Goooler Dec 5, 2023
6644b14
Fix TooGenericExceptionCaught for SpotBugsRunner
Goooler Dec 5, 2023
abdca8a
Suppress LongMethod
Goooler Dec 5, 2023
36d0d7e
Remove baseline file
Goooler Dec 5, 2023
eac92e6
Fix style
Goooler Dec 5, 2023
f4f42c1
Fix detekt issues
Goooler Dec 5, 2023
0e508ef
Replace @see
Goooler Dec 5, 2023
11e2b04
Replace Stream usages
Goooler Dec 5, 2023
9612a10
Use buildList
Goooler Dec 5, 2023
594a90d
Rearrange
Goooler Dec 5, 2023
94e4dd6
Use more Sequence
Goooler Dec 5, 2023
a80e824
Replace Path usages
Goooler Dec 5, 2023
d45c82c
Don't use File::toURI
Goooler Dec 5, 2023
d614242
Remove Optional usages
Goooler Dec 5, 2023
66afb5a
Rename toCommandLineOption
Goooler Dec 5, 2023
dd5b52c
Rearrange
Goooler Dec 6, 2023
cbec46e
Use error
Goooler Dec 6, 2023
0f1c35f
Use apply
Goooler Dec 6, 2023
de8c96a
Rearrange
Goooler Dec 6, 2023
317e9c5
Remove redundant this
Goooler Dec 6, 2023
7dcf2ec
Remove separator params
Goooler Dec 6, 2023
60b7d3e
Replace hasProperty usage
Goooler Dec 6, 2023
efceb42
Use require
Goooler Dec 7, 2023
5ca4f7b
Refine comment
Goooler Dec 7, 2023
b4d0f4b
Clean up unnecessary context params
Goooler Dec 7, 2023
cd380cf
Less nesting
Goooler Dec 7, 2023
552c205
Simplify Action types
Goooler Dec 7, 2023
243fe33
Inline getSourceSetContainer
Goooler Dec 7, 2023
2789bbd
Suppress unused for Extensions.kt
Goooler Dec 7, 2023
d598905
Merge remote-tracking branch 'origin/master' into fix-detekt-rules
Goooler Dec 7, 2023
9967884
Api dump
Goooler Dec 7, 2023
36f894a
Mark internal classes
Goooler Dec 7, 2023
1efac1c
Refined comments by AI
Goooler Dec 7, 2023
3ca15da
Inline values
Goooler Dec 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions detekt-baseline.xml

This file was deleted.

26 changes: 12 additions & 14 deletions src/main/kotlin/com/github/spotbugs/snom/Confidence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package com.github.spotbugs.snom

import java.util.Optional
import org.gradle.api.tasks.Internal

/**
Expand All @@ -22,21 +21,19 @@ import org.gradle.api.tasks.Internal
*
* ### Usage
*
* Set via the {@code spotbugs} extension to configure all tasks in your project:
* Set via the [SpotBugsExtension] to configure all tasks in your project:
* ```kotlin
* // require Gradle 8.2+
* import com.github.spotbugs.snom.Confidence
* spotbugs {
* reportLevel = Confidence.LOW
* reportLevel = com.github.spotbugs.snom.Confidence.LOW
* }
* ```
*
* Or via [SpotBugsTask] to configure the specific task in your project:
* ```kotlin
* // require Gradle 8.2+
* import com.github.spotbugs.snom.Confidence
* spotbugsMain { // or name of another task
* reportLevel = Confidence.LOW
* reportLevel = com.github.spotbugs.snom.Confidence.LOW
* }
* ```
*
Expand All @@ -45,24 +42,25 @@ import org.gradle.api.tasks.Internal
enum class Confidence {
/** The report level to report all detected bugs in the report. */
LOW {
override fun toCommandLineOption(): Optional<String> = Optional.of("-low")
override val commandLineOption: String = "-low"
},

/** The report level to report medium and high priority detected bugs in the report. */
MEDIUM {
override fun toCommandLineOption(): Optional<String> = Optional.of("-medium")
override val commandLineOption: String = "-medium"
},

/** The default level that provides the same feature with {@link #MEDIUM}. */
/** The default level that provides the same feature with [MEDIUM]. */
DEFAULT {
override fun toCommandLineOption(): Optional<String> = Optional.empty()
override val commandLineOption: String? = null
},

/** The report level to report high priority detected bugs in the report. */
HIGH {
override fun toCommandLineOption(): Optional<String> = Optional.of("-high")
}, ;
override val commandLineOption: String = "-high"
},
;

@Internal("This is internally used property so no need to refer to judge out-of-date or not.")
abstract fun toCommandLineOption(): Optional<String>
@get:Internal("This is internally used property so no need to refer to judge out-of-date or not.")
internal abstract val commandLineOption: String?
Goooler marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 2 additions & 4 deletions src/main/kotlin/com/github/spotbugs/snom/Effort.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ package com.github.spotbugs.snom
* Set via the `spotbugs` extension to configure all tasks in your project:
* ```kotlin
* // require Gradle 8.2+
* import com.github.spotbugs.snom.Effort
* spotbugs {
* effort = Effort.LESS
* effort = com.github.spotbugs.snom.Effort.LESS
* }
* ```
*
* Or via [SpotBugsTask] to configure the specific task in your project:
* ```kotlin
* // require Gradle 8.2+
* import com.github.spotbugs.snom.Effort
* spotbugsMain { // or name of another task
* effort = Effort.MAX
* effort = com.github.spotbugs.snom.Effort.MAX
* }
* ```
*
Expand Down
11 changes: 3 additions & 8 deletions src/main/kotlin/com/github/spotbugs/snom/SpotBugsBasePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,8 @@ class SpotBugsBasePlugin : Plugin<Project> {
}

fun verifyGradleVersion(version: GradleVersion) {
if (version < SUPPORTED_VERSION) {
val message =
String.format(
"Gradle version %s is unsupported. Please use %s or later.",
version,
SUPPORTED_VERSION,
)
throw IllegalArgumentException(message)
check(version >= SUPPORTED_VERSION) {
Goooler marked this conversation as resolved.
Show resolved Hide resolved
"Gradle version $version is unsupported. Please use $SUPPORTED_VERSION or later."
}
}

Expand All @@ -167,6 +161,7 @@ class SpotBugsBasePlugin : Plugin<Project> {
* Supported Gradle version described at [official manual site](http://spotbugs.readthedocs.io/en/latest/gradle.html).
* The convention API provides replacement from 7.1 and later, so we use this value as minimal required version.
*/
@Suppress("MaxLineLength")
Goooler marked this conversation as resolved.
Show resolved Hide resolved
private val SUPPORTED_VERSION = GradleVersion.version("7.1")
}
}
16 changes: 9 additions & 7 deletions src/main/kotlin/com/github/spotbugs/snom/SpotBugsExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property

/**
* The extension to configure the SpotBugs Gradle plugin. Most of properties in this extension will be used as the default property of all {@link SpotBugsTask}.
* All properties are optional.
* The extension to configure the SpotBugs Gradle plugin. Most of properties in this extension will be used as
* the default property of all [SpotBugsTask]. All properties are optional.
*
* ### Usage
* After you apply the SpotBugs Gradle plugin to project, write extension like below:
Expand Down Expand Up @@ -89,7 +89,7 @@ interface SpotBugsExtension {
* Property to set the filter file to limit which bug should be reported.
*
* Note that this property will NOT limit which bug should be detected. To limit the target classes to analyze,
* use [#onlyAnalyze] instead.
* use [onlyAnalyze] instead.
* To limit the visitors (detectors) to run, use [visitors] and [omitVisitors] instead.
*
* See also [SpotBugs Manual about Filter file](https://spotbugs.readthedocs.io/en/stable/filter.html).
Expand All @@ -108,8 +108,8 @@ interface SpotBugsExtension {
val excludeFilter: RegularFileProperty

/**
* Property to set the baseline file. This file is a Spotbugs result file, and all bugs reported in this file will not be
* reported in the final output.
* Property to set the baseline file. This file is a Spotbugs result file, and all bugs reported in this file
* will not be reported in the final output.
*/
val baselineFile: RegularFileProperty

Expand All @@ -119,7 +119,8 @@ interface SpotBugsExtension {
val onlyAnalyze: ListProperty<String>

/**
* Property to specify the name of project. Some reporting formats use this property. Default value is the name of your Gradle project.
* Property to specify the name of project. Some reporting formats use this property.
* Default value is the name of your Gradle project.
*/
val projectName: Property<String>

Expand All @@ -136,7 +137,8 @@ interface SpotBugsExtension {
val extraArgs: ListProperty<String>

/**
* Property to specify the extra arguments for JVM process. Default value is empty so JVM process will get no extra argument.
* Property to specify the extra arguments for JVM process. Default value is empty so JVM process will get
* no extra argument.
*/
val jvmArgs: ListProperty<String>

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/github/spotbugs/snom/SpotBugsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SpotBugsPlugin : Plugin<Project> {
/**
* The configuration contains SpotBugs plugin jar files only
*
* @see <a href="https://github.com/spotbugs/spotbugs-gradle-plugin/issues/910">GitHub issue</a>
* See [GitHub issue](https://github.com/spotbugs/spotbugs-gradle-plugin/issues/910)
*/
const val PLUGINS_CONFIG_NAME = "spotbugsPlugins"
const val SLF4J_CONFIG_NAME = "spotbugsSlf4j"
Expand Down
29 changes: 10 additions & 19 deletions src/main/kotlin/com/github/spotbugs/snom/SpotBugsReport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.gradle.api.resources.TextResource
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal

@Suppress("TooManyFunctions")
abstract class SpotBugsReport @Inject constructor(
objects: ObjectFactory,
@get:Internal
Expand All @@ -44,7 +45,7 @@ abstract class SpotBugsReport @Inject constructor(
abstract fun toCommandLineOption(): String

@Internal
@Deprecated("use {@link #getOutputLocation()} instead.")
@Deprecated("use `getOutputLocation()` instead.")
fun getDestination(): File {
return destination.get().asFile
}
Expand All @@ -63,26 +64,26 @@ abstract class SpotBugsReport @Inject constructor(
return isRequired
}

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

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

@Deprecated("use {@code getOutputLocation().set(file)} instead.")
@Deprecated("use `getOutputLocation().set(file)` instead.")
override fun setDestination(file: File) {
destination.set(file)
}

@Deprecated("use {@code getOutputLocation().set(provider)} instead.")
@Deprecated("use `getOutputLocation().set(provider)` instead.")
fun setDestination(provider: Provider<File?>) {
destination.set(task.project.layout.file(provider))
}
Expand All @@ -102,7 +103,7 @@ abstract class SpotBugsReport @Inject constructor(

@Internal("This property provides only a human readable name.")
override fun getDisplayName(): String {
return String.format("%s type report generated by the task %s", name, task.path)
return "$name type report generated by the task ${task.path}"
}

// TODO adding an @Input triggers 'cannot be serialized' exception
Expand All @@ -111,20 +112,10 @@ abstract class SpotBugsReport @Inject constructor(
}

override fun setStylesheet(textResource: TextResource?) {
throw UnsupportedOperationException(
String.format(
"stylesheet property is not available in the %s type report",
name,
),
)
throw UnsupportedOperationException("stylesheet property is not available in the $name type report")
}

open fun setStylesheet(path: String?) {
throw UnsupportedOperationException(
String.format(
"stylesheet property is not available in the %s type report",
name,
),
)
throw UnsupportedOperationException("stylesheet property is not available in the $name type report")
}
}
Loading