Skip to content

Commit

Permalink
feat(CompareCommand): Add a comparison for the ResolvedConfigurations
Browse files Browse the repository at this point in the history
Signed-off-by: Onur Demirci <[email protected]>
  • Loading branch information
bs-ondem authored and oheger-bosch committed Dec 7, 2023
1 parent 69a5a81 commit 34f10c4
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions plugins/commands/compare/src/main/kotlin/CompareCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ import org.ossreviewtoolkit.model.PackageCuration
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.ProvenanceResolutionResult
import org.ossreviewtoolkit.model.Repository
import org.ossreviewtoolkit.model.ResolvedConfiguration
import org.ossreviewtoolkit.model.ResolvedPackageCurations
import org.ossreviewtoolkit.model.RuleViolation
import org.ossreviewtoolkit.model.ScanResult
import org.ossreviewtoolkit.model.ScannerRun
Expand Down Expand Up @@ -219,7 +221,8 @@ private fun OrtResult.diff(other: OrtResult) =
analyzerRunDiff = analyzer.diff(other.analyzer),
scannerRunDiff = scanner.diff(other.scanner),
advisorRunDiff = advisor.diff(other.advisor),
evaluatorRunDiff = evaluator.diff(other.evaluator)
evaluatorRunDiff = evaluator.diff(other.evaluator),
resolvedConfigurationDiff = resolvedConfiguration.diff(other.resolvedConfiguration)
)

private fun Repository.diff(other: Repository): RepositoryDiff? =
Expand Down Expand Up @@ -626,6 +629,21 @@ private fun AdvisorRun?.diff(other: AdvisorRun?): AdvisorRunDiff? {
}
}

private fun ResolvedConfiguration.diff(other: ResolvedConfiguration): ResolvedConfigurationDiff? =
if (this == other) {
null
} else {
ResolvedConfigurationDiff(
packageConfigurationsA = (packageConfigurations.orEmpty() - other.packageConfigurations.orEmpty().toSet())
.takeUnless { it.isEmpty() },
packageConfigurationsB = (other.packageConfigurations.orEmpty() - packageConfigurations.orEmpty().toSet())
.takeUnless { it.isEmpty() },
packageCurationsA = (packageCurations - other.packageCurations.toSet()).takeUnless { it.isEmpty() },
packageCurationsB = (other.packageCurations - packageCurations.toSet()).takeUnless { it.isEmpty() },
resolutionsDiff = resolutions?.diff(other.resolutions)
)
}

private enum class CompareMethod {
SEMANTIC_DIFF,
TEXT_DIFF
Expand All @@ -651,7 +669,8 @@ private data class OrtResultDiff(
val analyzerRunDiff: AnalyzerRunDiff? = null,
val scannerRunDiff: ScannerRunDiff? = null,
val advisorRunDiff: AdvisorRunDiff? = null,
val evaluatorRunDiff: EvaluatorRunDiff? = null
val evaluatorRunDiff: EvaluatorRunDiff? = null,
val resolvedConfigurationDiff: ResolvedConfigurationDiff? = null
)

private data class RepositoryDiff(
Expand Down Expand Up @@ -802,3 +821,11 @@ private data class EvaluatorRunDiff(
val violationsA: List<RuleViolation>? = null,
val violationsB: List<RuleViolation>? = null
)

private data class ResolvedConfigurationDiff(
val packageConfigurationsA: List<PackageConfiguration>? = null,
val packageConfigurationsB: List<PackageConfiguration>? = null,
val packageCurationsA: List<ResolvedPackageCurations>? = null,
val packageCurationsB: List<ResolvedPackageCurations>? = null,
val resolutionsDiff: ResolutionsDiff? = null
)

0 comments on commit 34f10c4

Please sign in to comment.