Skip to content

Commit

Permalink
refactor!: Replace is{False,True}() with toBooleanStrictOrNull()
Browse files Browse the repository at this point in the history
Remove these custom extension functions in favor of standard
functionality. The resulting code is a bit longer, but makes more clear
what the default value is.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Jul 19, 2024
1 parent 5fdc763 commit 0137bde
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import org.ossreviewtoolkit.model.utils.toPurl
import org.ossreviewtoolkit.model.vulnerabilities.Vulnerability
import org.ossreviewtoolkit.reporter.Reporter
import org.ossreviewtoolkit.reporter.ReporterInput
import org.ossreviewtoolkit.utils.common.isFalse
import org.ossreviewtoolkit.utils.ort.Environment
import org.ossreviewtoolkit.utils.ort.ORT_FULL_NAME
import org.ossreviewtoolkit.utils.ort.ORT_NAME
Expand Down Expand Up @@ -147,7 +146,7 @@ class CycloneDxReporter : Reporter {
} ?: DEFAULT_SCHEMA_VERSION

val dataLicense = config.options[OPTION_DATA_LICENSE] ?: DEFAULT_DATA_LICENSE.id
val createSingleBom = !config.options[OPTION_SINGLE_BOM].isFalse()
val createSingleBom = config.options[OPTION_SINGLE_BOM]?.toBooleanStrictOrNull() ?: true

val outputFileExtensions = config.options[OPTION_OUTPUT_FILE_FORMATS]
?.split(",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import kotlinx.serialization.json.JsonNamingStrategy
import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.reporter.Reporter
import org.ossreviewtoolkit.reporter.ReporterInput
import org.ossreviewtoolkit.utils.common.isTrue

/**
* Creates YAML documents according to the GitLab license model schema version 2.1, see
Expand Down Expand Up @@ -56,7 +55,7 @@ class GitLabLicenseModelReporter : Reporter {
private val reportFilename = "gl-license-scanning-report.json"

override fun generateReport(input: ReporterInput, outputDir: File, config: PluginConfiguration): List<File> {
val skipExcluded = config.options[OPTION_SKIP_EXCLUDED].isTrue()
val skipExcluded = config.options[OPTION_SKIP_EXCLUDED]?.toBooleanStrictOrNull() ?: false

val licenseModel = GitLabLicenseModelMapper.map(input.ortResult, skipExcluded)
val licenseModelJson = JSON.encodeToString(licenseModel)
Expand Down
10 changes: 0 additions & 10 deletions utils/common/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,6 @@ fun String.fileSystemEncode() =
.replace(Regex("(^\\.|\\.$)"), "%2E")
.take(255)

/**
* Return true if the string represents a false value, otherwise return false.
*/
fun String?.isFalse() = this?.toBoolean()?.not() == true

/**
* Return true if the string represents a true value, otherwise return false.
*/
fun String?.isTrue() = this?.toBoolean() == true

/**
* True if the string is a valid [URI], false otherwise.
*/
Expand Down

0 comments on commit 0137bde

Please sign in to comment.