Skip to content

Commit b1a1450

Browse files
nnobelismnonnenmacher
authored andcommitted
feat(cli): Also merge the includes
Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent ac3df58 commit b1a1450

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cli-helper/src/main/kotlin/utils/Extensions.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import org.ossreviewtoolkit.model.config.CopyrightGarbage
4949
import org.ossreviewtoolkit.model.config.Curations
5050
import org.ossreviewtoolkit.model.config.DownloaderConfiguration
5151
import org.ossreviewtoolkit.model.config.Excludes
52+
import org.ossreviewtoolkit.model.config.Includes
5253
import org.ossreviewtoolkit.model.config.IssueResolution
5354
import org.ossreviewtoolkit.model.config.LicenseFindingCuration
5455
import org.ossreviewtoolkit.model.config.PackageConfiguration
@@ -58,6 +59,7 @@ import org.ossreviewtoolkit.model.config.Resolutions
5859
import org.ossreviewtoolkit.model.config.RuleViolationResolution
5960
import org.ossreviewtoolkit.model.config.ScopeExclude
6061
import org.ossreviewtoolkit.model.config.VulnerabilityResolution
62+
import org.ossreviewtoolkit.model.config.config.PathInclude
6163
import org.ossreviewtoolkit.model.readValue
6264
import org.ossreviewtoolkit.model.utils.FindingCurationMatcher
6365
import org.ossreviewtoolkit.model.utils.createLicenseInfoResolver
@@ -571,6 +573,25 @@ internal fun Collection<PathExclude>.mergePathExcludes(
571573
return result.values.toList()
572574
}
573575

576+
/**
577+
* Merge the given [PathInclude]s replacing entries with equal [PathInclude.pattern].
578+
* If the given [updateOnlyExisting] is true then only entries with matching [PathInclude.pattern] are merged.
579+
*/
580+
internal fun Collection<PathInclude>.mergePathIncludes(
581+
other: Collection<PathInclude>,
582+
updateOnlyExisting: Boolean = false
583+
): List<PathInclude> {
584+
val result = mutableMapOf<String, PathInclude>()
585+
586+
associateByTo(result) { it.pattern }
587+
588+
other.forEach {
589+
if (!updateOnlyExisting || it.pattern in result) result[it.pattern] = it
590+
}
591+
592+
return result.values.toList()
593+
}
594+
574595
/**
575596
* Return a copy with the [PathExclude]s sorted.
576597
*/
@@ -622,6 +643,9 @@ internal fun Collection<VulnerabilityResolution>.mergeVulnerabilityResolutions(
622643
*/
623644
internal fun RepositoryConfiguration.merge(other: RepositoryConfiguration): RepositoryConfiguration =
624645
RepositoryConfiguration(
646+
includes = Includes(
647+
paths = includes.paths.mergePathIncludes(other.includes.paths)
648+
),
625649
excludes = Excludes(
626650
paths = excludes.paths.mergePathExcludes(other.excludes.paths),
627651
scopes = excludes.scopes.mergeScopeExcludes(other.excludes.scopes)

0 commit comments

Comments
 (0)