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

Added matchedText variable to Scancode model and model mapper. #8063

7 changes: 5 additions & 2 deletions model/src/main/kotlin/LicenseFinding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ data class LicenseFinding(
* the finding can be relied on / how confident the scanner is to be right. In most cases this is a percentage where
* 100.0 means that the scanner is 100% confident that the finding is correct.
*/
val score: Float? = null
val score: Float? = null,

val matchedText: String? = null
) {
companion object {
val COMPARATOR = compareBy<LicenseFinding>({ it.license.toString() }, { it.location })
.thenByDescending { it.score }
}

constructor(license: String, location: TextLocation, score: Float? = null) : this(license.toSpdx(), location, score)
constructor(license: String, location: TextLocation, score: Float? = null, matchedText: String? = null) :
this(license.toSpdx(), location, score, matchedText)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion model/src/main/resources/reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ ort:
options:
# Command line options that affect the ScanCode output. If changed, stored scan results that were created with
# different options are not reused.
commandLine: '--copyright --license --info --strip-root --timeout 300'
commandLine: '--copyright --license --info --strip-root --timeout 300 --license-text'

# Command line options that do not affect the ScanCode output.
commandLineNonConfig: '--processes 4'
Expand Down
1 change: 1 addition & 0 deletions plugins/scanners/scancode/src/main/kotlin/ScanCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class ScanCode internal constructor(
"--license",
"--info",
"--strip-root",
"--license-text",
"--timeout", TIMEOUT.toString()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
val licenses: List<LicenseEntry>
val copyrights: List<CopyrightEntry>
val scanErrors: List<String>

// A map of ScanCode license keys associated with their corresponding SPDX license ID.
val scanCodeKeyToSpdxIdMappings: List<Pair<String, String>>

Expand Down Expand Up @@ -100,6 +99,7 @@
data class Version3(
override val path: String,
override val type: String,
val matchedText: String? = null, // This might be explicitly set to null in JSON.
val detectedLicenseExpression: String? = null, // This might be explicitly set to null in JSON.
val detectedLicenseExpressionSpdx: String? = null, // This might be explicitly set to null in JSON.
val licenseDetections: List<LicenseDetection>,
Expand Down Expand Up @@ -135,6 +135,7 @@
)

sealed interface LicenseEntry {
val matchedText: String
val licenseExpression: String
val startLine: Int
val endLine: Int
Expand All @@ -147,14 +148,17 @@
val spdxLicenseKey: String? = null, // This might be explicitly set to null in JSON.
override val startLine: Int,
override val endLine: Int,
val matchedRule: LicenseRule
val matchedRule: LicenseRule,
override val matchedText: String // This might be explicitly set to null in JSON.

) : LicenseEntry {
override val licenseExpression = matchedRule.licenseExpression
}

@Serializable
data class Version3(
override val score: Float,
override val matchedText: String,
override val startLine: Int,
override val endLine: Int,
override val licenseExpression: String
Expand All @@ -175,7 +179,7 @@
data class Version1(
val value: String,
override val startLine: Int,
override val endLine: Int
override val endLine: Int,

Check warning

Code scanning / detekt

Rule to mandate/forbid trailing commas at declaration sites Warning

Unnecessary trailing comma before ")"
) : CopyrightEntry {
override val statement = value
}
Expand All @@ -184,7 +188,8 @@
data class Version2(
val copyright: String,
override val startLine: Int,
override val endLine: Int
override val endLine: Int,
val matchedText: String? = null
) : CopyrightEntry {
override val statement = copyright
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
val expression: String,
val startLine: Int,
val endLine: Int,
val score: Float
val score: Float,
val matchedText: String
)

fun ScanCodeResult.toScanSummary(): ScanSummary {
Expand Down Expand Up @@ -85,7 +86,7 @@
// ScanCode creates separate license entries for each license in an expression. Deduplicate these by grouping by
// the same expression.
val licenses = file.licenses.groupBy {
LicenseMatch(it.licenseExpression, it.startLine, it.endLine, it.score)
LicenseMatch(it.licenseExpression, it.startLine, it.endLine, it.score, it.matchedText)
}.map {
// Arbitrarily take the first of the duplicate license entries.
it.value.first()
Expand All @@ -100,9 +101,10 @@
location = TextLocation(
path = file.path,
startLine = license.startLine,
endLine = license.endLine
endLine = license.endLine,

Check warning

Code scanning / detekt

Rule to mandate/forbid trailing commas at call sites Warning

Unnecessary trailing comma before ")"
),
score = license.score
score = license.score,
matchedText = license.matchedText
)
}

Expand Down
Loading