Skip to content

Commit

Permalink
feat(scancode): Add support for output format version 4.0.0
Browse files Browse the repository at this point in the history
Resolves #9446.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Nov 21, 2024
1 parent 8d81c6e commit c3145d2
Show file tree
Hide file tree
Showing 4 changed files with 880 additions and 2 deletions.
11 changes: 11 additions & 0 deletions plugins/scanners/scancode/src/main/kotlin/ScanCodeResultModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ sealed interface LicenseEntry {
val fromFile: String? = null, // This might be missing in JSON.
override val matchedText: String? = null
) : LicenseEntry

@Serializable
data class Version4(
override val score: Float,
override val startLine: Int,
override val endLine: Int,
override val licenseExpression: String,
val licenseExpressionSpdx: String? = null, // This might be missing in JSON.
val fromFile: String? = null, // This might be missing in JSON.
override val matchedText: String? = null
) : LicenseEntry
}

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import org.ossreviewtoolkit.model.utils.associateLicensesWithExceptions

import org.semver4j.Semver

const val MAX_SUPPORTED_OUTPUT_FORMAT_MAJOR_VERSION = 3
const val MAX_SUPPORTED_OUTPUT_FORMAT_MAJOR_VERSION = 4

private val TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HHmmss.n").withZone(ZoneId.of("UTC"))

Expand Down Expand Up @@ -120,6 +120,10 @@ fun ScanCodeResult.toScanSummary(preferFileLicense: Boolean = false): ScanSummar
license.spdxLicenseExpression
}

license is LicenseEntry.Version4 && license.licenseExpressionSpdx != null -> {
license.licenseExpressionSpdx
}

else -> license.licenseExpression.mapLicense(scanCodeKeyToSpdxIdMappings)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,17 @@ private fun parseResult(result: JsonElement): ScanCodeResult {
polymorphicDefaultDeserializer(CopyrightEntry::class) { CopyrightEntry.Version2.serializer() }
}

else -> SerializersModule {
3 -> SerializersModule {
polymorphicDefaultDeserializer(FileEntry::class) { FileEntry.Version3.serializer() }
polymorphicDefaultDeserializer(LicenseEntry::class) { LicenseEntry.Version3.serializer() }
polymorphicDefaultDeserializer(CopyrightEntry::class) { CopyrightEntry.Version2.serializer() }
}

else -> SerializersModule {
polymorphicDefaultDeserializer(FileEntry::class) { FileEntry.Version3.serializer() }
polymorphicDefaultDeserializer(LicenseEntry::class) { LicenseEntry.Version4.serializer() }
polymorphicDefaultDeserializer(CopyrightEntry::class) { CopyrightEntry.Version2.serializer() }
}
}

val json = Json {
Expand Down
Loading

0 comments on commit c3145d2

Please sign in to comment.