Skip to content

Commit

Permalink
refactor(model)!: Simplify constructor of DefaultLicenseInfoProvider
Browse files Browse the repository at this point in the history
All callers have been changed to include the package configuration from
the provider into the `OrtResult` before passing it to that
constructor. So, the parameter `packageConfigurationProvider` has become
redundant and can be removed.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Jan 16, 2024
1 parent 79fcd67 commit 4e4c475
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 20 deletions.
1 change: 0 additions & 1 deletion helper-cli/src/main/kotlin/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ internal fun OrtResult.processAllCopyrightStatements(
val result = mutableListOf<ProcessedCopyrightStatement>()

val licenseInfoResolver = createLicenseInfoResolver(
packageConfigurationProvider = this,
copyrightGarbage = CopyrightGarbage(copyrightGarbage.toSortedSet()),
addAuthorsToCopyrights = addAuthorsToCopyrights
)
Expand Down
8 changes: 2 additions & 6 deletions model/src/main/kotlin/licenses/DefaultLicenseInfoProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@ import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.model.Provenance
import org.ossreviewtoolkit.model.config.LicenseFindingCuration
import org.ossreviewtoolkit.model.config.PathExclude
import org.ossreviewtoolkit.model.utils.PackageConfigurationProvider
import org.ossreviewtoolkit.model.utils.filterByVcsPath
import org.ossreviewtoolkit.utils.ort.ProcessedDeclaredLicense

/**
* The default [LicenseInfoProvider] that collects license information from an [ortResult].
*/
class DefaultLicenseInfoProvider(
val ortResult: OrtResult,
private val packageConfigurationProvider: PackageConfigurationProvider
) : LicenseInfoProvider {
class DefaultLicenseInfoProvider(val ortResult: OrtResult) : LicenseInfoProvider {
private val licenseInfo: ConcurrentMap<Identifier, LicenseInfo> = ConcurrentHashMap()

override fun get(id: Identifier) = licenseInfo.getOrPut(id) { createLicenseInfo(id) }
Expand Down Expand Up @@ -112,7 +108,7 @@ class DefaultLicenseInfoProvider(
ortResult.repository.config.excludes.paths,
ortResult.repository.getRelativePath(project.vcsProcessed).orEmpty()
)
} ?: packageConfigurationProvider.getPackageConfigurations(id, provenance).let { packageConfigurations ->
} ?: ortResult.getPackageConfigurations(id, provenance).let { packageConfigurations ->
Configuration(
packageConfigurations.flatMap { it.licenseFindingCurations },
packageConfigurations.flatMap { it.pathExcludes },
Expand Down
3 changes: 1 addition & 2 deletions model/src/main/kotlin/utils/OrtResultExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ fun OrtResult.setResolutions(resolutionProvider: ResolutionProvider): OrtResult
* instead of calling this function multiple times for better performance.
*/
fun OrtResult.createLicenseInfoResolver(
packageConfigurationProvider: PackageConfigurationProvider = PackageConfigurationProvider.EMPTY,
copyrightGarbage: CopyrightGarbage = CopyrightGarbage(),
addAuthorsToCopyrights: Boolean = false,
archiver: FileArchiver? = null
) = LicenseInfoResolver(
DefaultLicenseInfoProvider(this, packageConfigurationProvider),
DefaultLicenseInfoProvider(this),
copyrightGarbage,
addAuthorsToCopyrights,
archiver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ package org.ossreviewtoolkit.model.licenses
import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.shouldBe

import org.ossreviewtoolkit.model.utils.PackageConfigurationProvider

class DefaultLicenseInfoProviderTest : WordSpec({
val defaultLicenseInfoProvider = DefaultLicenseInfoProvider(ortResult, PackageConfigurationProvider.EMPTY)
val defaultLicenseInfoProvider = DefaultLicenseInfoProvider(ortResult)

"declaredLicenseInfo" should {
"contain author information for package" {
Expand Down
3 changes: 1 addition & 2 deletions model/src/test/kotlin/licenses/LicenseViewTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ import org.ossreviewtoolkit.model.LicenseSource
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.config.CopyrightGarbage
import org.ossreviewtoolkit.model.utils.FileArchiver
import org.ossreviewtoolkit.model.utils.PackageConfigurationProvider
import org.ossreviewtoolkit.utils.spdx.SpdxSingleLicenseExpression
import org.ossreviewtoolkit.utils.test.createDefault
import org.ossreviewtoolkit.utils.test.transformingCollectionMatcher

class LicenseViewTest : WordSpec() {
private val licenseInfoResolver = LicenseInfoResolver(
provider = DefaultLicenseInfoProvider(ortResult, PackageConfigurationProvider.EMPTY),
provider = DefaultLicenseInfoProvider(ortResult),
copyrightGarbage = CopyrightGarbage(),
addAuthorsToCopyrights = false,
archiver = FileArchiver.createDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,7 @@ class EvaluatorCommand : OrtCommand(
val copyrightGarbage = copyrightGarbageFile.takeIf { it.isFile }?.readValue<CopyrightGarbage>().orEmpty()

val licenseInfoResolver = LicenseInfoResolver(
provider = DefaultLicenseInfoProvider(
ortResult = ortResultInput,
packageConfigurationProvider = ortResultInput
),
provider = DefaultLicenseInfoProvider(ortResultInput),
copyrightGarbage = copyrightGarbage,
addAuthorsToCopyrights = ortConfig.addAuthorsToCopyrights,
archiver = ortConfig.scanner.archive.createFileArchiver(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class ReporterCommand : OrtCommand(
val copyrightGarbage = copyrightGarbageFile.takeIf { it.isFile }?.readValue<CopyrightGarbage>().orEmpty()

val licenseInfoResolver = LicenseInfoResolver(
provider = DefaultLicenseInfoProvider(ortResult, packageConfigurationProvider),
provider = DefaultLicenseInfoProvider(ortResult),
copyrightGarbage = copyrightGarbage,
addAuthorsToCopyrights = ortConfig.addAuthorsToCopyrights,
archiver = ortConfig.scanner.archive.createFileArchiver(),
Expand Down
2 changes: 1 addition & 1 deletion reporter/src/main/kotlin/ReporterInput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ data class ReporterInput(
* A resolver for license information for the projects and packages contained in [ortResult].
*/
val licenseInfoResolver: LicenseInfoResolver = LicenseInfoResolver(
provider = DefaultLicenseInfoProvider(ortResult, packageConfigurationProvider),
provider = DefaultLicenseInfoProvider(ortResult),
copyrightGarbage = copyrightGarbage,
addAuthorsToCopyrights = ortConfig.addAuthorsToCopyrights,
archiver = ortConfig.scanner.archive.createFileArchiver(),
Expand Down

0 comments on commit 4e4c475

Please sign in to comment.