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

misc: refine Kotlin styles #1053

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
ij_kotlin_imports_layout = *
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_packages_to_use_import_on_demand = unset
ktlint_code_style = intellij_idea

[*.md]
trim_trailing_whitespace = false

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/github/spotbugs/snom/Confidence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*/
package com.github.spotbugs.snom

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

/**
* The [Confidence] is used to specify the level to report bugs. Lower level contains more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
*/
package com.github.spotbugs.snom

import java.io.IOException
import java.io.UncheckedIOException
import java.util.Properties
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.file.Directory
import org.gradle.api.plugins.ReportingBasePlugin
import org.gradle.api.reporting.ReportingExtension
import org.gradle.util.GradleVersion
import java.io.IOException
import java.io.UncheckedIOException
import java.util.Properties

class SpotBugsBasePlugin : Plugin<Project> {
override fun apply(project: Project) {
Expand Down
173 changes: 85 additions & 88 deletions src/main/kotlin/com/github/spotbugs/snom/SpotBugsReport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package com.github.spotbugs.snom

import groovy.lang.Closure
import java.io.File
import javax.inject.Inject
import org.gradle.api.Action
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
Expand All @@ -25,109 +27,104 @@ import org.gradle.api.reporting.SingleFileReport
import org.gradle.api.resources.TextResource
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import java.io.File
import javax.inject.Inject

abstract class SpotBugsReport
@Inject
constructor(
objects: ObjectFactory,
@get:Internal
protected val task: SpotBugsTask,
) :
SingleFileReport, CustomizableHtmlReport { // to expose CustomizableHtmlReport#setStylesheet to build script
private val destination: RegularFileProperty
private val isRequired: Property<Boolean>

init {
destination = objects.fileProperty()
isRequired = objects.property(Boolean::class.java).convention(true)
}
abstract class SpotBugsReport @Inject constructor(
objects: ObjectFactory,
@get:Internal
protected val task: SpotBugsTask,
) : SingleFileReport, CustomizableHtmlReport { // to expose CustomizableHtmlReport#setStylesheet to build script
private val destination: RegularFileProperty
private val isRequired: Property<Boolean>

init {
destination = objects.fileProperty()
isRequired = objects.property(Boolean::class.java).convention(true)
}

abstract fun toCommandLineOption(): String
abstract fun toCommandLineOption(): String

@Internal
@Deprecated("use {@link #getOutputLocation()} instead.")
fun getDestination(): File {
return destination.get().asFile
}
@Internal
@Deprecated("use {@link #getOutputLocation()} instead.")
fun getDestination(): File {
return destination.get().asFile
}

override fun getOutputLocation(): RegularFileProperty {
return destination
}
override fun getOutputLocation(): RegularFileProperty {
return destination
}

@Internal("This property returns always same value")
override fun getOutputType(): Report.OutputType {
return Report.OutputType.FILE
}
@Internal("This property returns always same value")
override fun getOutputType(): Report.OutputType {
return Report.OutputType.FILE
}

@Input
override fun getRequired(): Property<Boolean> {
return isRequired
}
@Input
override fun getRequired(): Property<Boolean> {
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)
@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 getOutputLocation().set(file)} instead.")
override fun setDestination(file: File) {
destination.set(file)
}
@Deprecated("use {@code getRequired().set(provider)} instead.")
fun setEnabled(provider: Provider<Boolean>) {
isRequired.set(provider)
}

@Deprecated("use {@code getOutputLocation().set(provider)} instead.")
fun setDestination(provider: Provider<File?>) {
destination.set(task.project.layout.file(provider))
}
@Deprecated("use {@code getOutputLocation().set(file)} instead.")
override fun setDestination(file: File) {
destination.set(file)
}

override fun configure(closure: Closure<in Report>): Report {
return configure { report ->
closure.delegate = report
closure.call(report)
}
}
@Deprecated("use {@code getOutputLocation().set(provider)} instead.")
fun setDestination(provider: Provider<File?>) {
destination.set(task.project.layout.file(provider))
}

@Suppress("MemberVisibilityCanBePrivate")
fun configure(action: Action<in Report>): Report {
action.execute(this)
return this
override fun configure(closure: Closure<in Report>): Report {
return configure { report ->
closure.delegate = report
closure.call(report)
}
}

@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)
}
@Suppress("MemberVisibilityCanBePrivate")
fun configure(action: Action<in Report>): Report {
action.execute(this)
return this
}

// TODO adding an @Input triggers 'cannot be serialized' exception
override fun getStylesheet(): TextResource? {
return null
}
@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)
}

override fun setStylesheet(textResource: TextResource?) {
throw UnsupportedOperationException(
String.format(
"stylesheet property is not available in the %s type report",
name,
),
)
}
// TODO adding an @Input triggers 'cannot be serialized' exception
override fun getStylesheet(): TextResource? {
return null
}

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

open fun setStylesheet(path: String?) {
throw UnsupportedOperationException(
String.format(
"stylesheet property is not available in the %s type report",
name,
),
)
}
}
11 changes: 4 additions & 7 deletions src/main/kotlin/com/github/spotbugs/snom/SpotBugsTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.github.spotbugs.snom.internal.SpotBugsRunnerForJavaExec
import com.github.spotbugs.snom.internal.SpotBugsSarifReport
import com.github.spotbugs.snom.internal.SpotBugsTextReport
import com.github.spotbugs.snom.internal.SpotBugsXmlReport
import javax.inject.Inject
import org.gradle.api.Action
import org.gradle.api.DefaultTask
import org.gradle.api.InvalidUserDataException
Expand Down Expand Up @@ -49,7 +50,6 @@ import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.workers.WorkerExecutor
import org.slf4j.LoggerFactory
import javax.inject.Inject

/**
* The Gradle task to run the SpotBugs analysis. All properties are optional.
Expand Down Expand Up @@ -272,12 +272,9 @@ abstract class SpotBugsTask : DefaultTask(), VerificationTask {
@get:SkipWhenEmpty
var classes: FileCollection? = null
get() {
return field
?: (
classDirs.asFileTree.filter {
it.name.endsWith(".class")
}
)
return field ?: classDirs.asFileTree.filter {
it.name.endsWith(".class")
}
}

private var enableWorkerApi: Boolean = true
Expand Down
Loading