Skip to content

Commit

Permalink
refactor(fossid): Add namingScanPattern to FossIdConfig
Browse files Browse the repository at this point in the history
This allows handling the property like all other config properties for
consistency and removes the need to store the plain `options` in the
config class.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Jan 15, 2025
1 parent 3ea4ec5 commit 5c67bcd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
21 changes: 8 additions & 13 deletions plugins/scanners/fossid/src/main/kotlin/FossIdConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ data class FossIdConfig(
/** The name of the FossID project. If `null`, the name will be determined from the repository URL. */
val projectName: String?,

/** The pattern for scan names when scans are created on the FossID instance. If null, a default pattern is used. */
val namingScanPattern: String?,

/** Flag whether the scanner should wait for the completion of FossID scans. */
val waitForResult: Boolean,

Expand Down Expand Up @@ -116,10 +119,7 @@ data class FossIdConfig(
val sensitivity: Int,

/** A comma-separated list of URL mappings. */
val urlMappings: String?,

/** Stores the map with FossID-specific configuration options. */
private val options: Map<String, String>
val urlMappings: String?
) {
companion object {
/** Name of the configuration property for the server URL. */
Expand Down Expand Up @@ -197,6 +197,7 @@ data class FossIdConfig(
?: throw IllegalArgumentException("No FossID API Key configuration found.")

val projectName = options[PROP_PROJECT_NAME]
val namingScanPattern = options[PROP_NAMING_SCAN_PATTERN]

val waitForResult = options[PROP_WAIT_FOR_RESULT]?.toBooleanStrict() ?: true

Expand Down Expand Up @@ -231,6 +232,7 @@ data class FossIdConfig(
user = user,
apiKey = apiKey,
projectName = projectName,
namingScanPattern = namingScanPattern,
waitForResult = waitForResult,
keepFailedScans = keepFailedScans,
deltaScans = deltaScans,
Expand All @@ -239,24 +241,17 @@ data class FossIdConfig(
detectCopyrightStatements = detectCopyrightStatements,
timeout = timeout,
fetchSnippetMatchedLines = fetchSnippetMatchedLines,
options = options,
snippetsLimit = snippetsLimit,
sensitivity = sensitivity,
urlMappings = urlMappings,
urlMappings = urlMappings
)
}
}

/**
* Create a [FossIdNamingProvider] helper object based on the configuration stored in this object.
*/
fun createNamingProvider(): FossIdNamingProvider {
val namingScanPattern = options[PROP_NAMING_SCAN_PATTERN]?.also {
logger.info { "Naming pattern for scans is $it." }
}

return FossIdNamingProvider(namingScanPattern, projectName)
}
fun createNamingProvider() = FossIdNamingProvider(namingScanPattern, projectName)

/**
* Create a [FossIdUrlProvider] helper object based on the configuration stored in this object.
Expand Down
5 changes: 3 additions & 2 deletions plugins/scanners/fossid/src/test/kotlin/FossIdConfigTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class FossIdConfigTest : WordSpec({
val options = mapOf(
"serverUrl" to SERVER_URL,
"projectName" to PROJECT,
"namingScanPattern" to "#repositoryName_#deltaTag",
"waitForResult" to "false",
"keepFailedScans" to "true",
"deltaScans" to "true",
Expand All @@ -68,6 +69,7 @@ class FossIdConfigTest : WordSpec({
user = USER,
apiKey = API_KEY,
projectName = PROJECT,
namingScanPattern = "#repositoryName_#deltaTag",
waitForResult = false,
keepFailedScans = true,
deltaScans = true,
Expand All @@ -76,7 +78,6 @@ class FossIdConfigTest : WordSpec({
detectCopyrightStatements = true,
timeout = 300,
fetchSnippetMatchedLines = true,
options = options,
snippetsLimit = 1000,
sensitivity = 10,
urlMappings = "https://example.org(?<repoPath>.*) -> ssh://example.org\${repoPath}"
Expand All @@ -98,6 +99,7 @@ class FossIdConfigTest : WordSpec({
user = USER,
apiKey = API_KEY,
projectName = null,
namingScanPattern = null,
waitForResult = true,
keepFailedScans = false,
deltaScans = false,
Expand All @@ -106,7 +108,6 @@ class FossIdConfigTest : WordSpec({
detectCopyrightStatements = false,
timeout = 60,
fetchSnippetMatchedLines = false,
options = options,
snippetsLimit = 500,
sensitivity = 10,
urlMappings = null
Expand Down
2 changes: 1 addition & 1 deletion plugins/scanners/fossid/src/test/kotlin/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ internal fun createConfig(
user = USER,
apiKey = API_KEY,
projectName = projectName,
namingScanPattern = null,
waitForResult = waitForResult,
keepFailedScans = false,
deltaScans = deltaScans,
Expand All @@ -138,7 +139,6 @@ internal fun createConfig(
detectCopyrightStatements = false,
timeout = 60,
fetchSnippetMatchedLines = fetchSnippetMatchedLines,
options = emptyMap(),
snippetsLimit = snippetsLimit,
sensitivity = 10,
urlMappings = null
Expand Down

0 comments on commit 5c67bcd

Please sign in to comment.