Skip to content

Commit 7cad831

Browse files
committed
feat(reporter)!: Use the configured license fact providers
Change the `ReporterInput` to use a `LicenseFactProvider` instead of a `LicenseTextProvider`. The `ReporterCommand` now creates the license fact providers based on the ORT configuration and support for the `--custom-license-texts-dir` option is dropped. Instead, a custom license text directory now has to be configured in the `config.yml`. Templates for the Freemarker or AsciiDoc reporters must also be updated to use `licenseFactProvider` instead of `licenseTextProvider`. Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
1 parent 18b856c commit 7cad831

File tree

18 files changed

+39
-38
lines changed

18 files changed

+39
-38
lines changed

cli/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ dependencies {
4949
} else {
5050
"pluginClasspath"(platform(projects.plugins.advisors))
5151
"pluginClasspath"(platform(projects.plugins.commands))
52+
"pluginClasspath"(platform(projects.plugins.licenseFactProviders))
5253
"pluginClasspath"(platform(projects.plugins.packageConfigurationProviders))
5354
"pluginClasspath"(platform(projects.plugins.packageCurationProviders))
5455
"pluginClasspath"(platform(projects.plugins.packageManagers))

plugins/commands/reporter/src/main/kotlin/ReportCommand.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ import org.ossreviewtoolkit.plugins.commands.api.utils.configurationGroup
6363
import org.ossreviewtoolkit.plugins.commands.api.utils.inputGroup
6464
import org.ossreviewtoolkit.plugins.commands.api.utils.outputGroup
6565
import org.ossreviewtoolkit.plugins.commands.api.utils.readOrtResult
66+
import org.ossreviewtoolkit.plugins.licensefactproviders.api.CompositeLicenseFactProvider
67+
import org.ossreviewtoolkit.plugins.licensefactproviders.api.LicenseFactProviderFactory
6668
import org.ossreviewtoolkit.plugins.packageconfigurationproviders.api.CompositePackageConfigurationProvider
6769
import org.ossreviewtoolkit.plugins.packageconfigurationproviders.api.SimplePackageConfigurationProvider
6870
import org.ossreviewtoolkit.plugins.packageconfigurationproviders.dir.DirPackageConfigurationProvider
@@ -126,17 +128,6 @@ class ReportCommand(descriptor: PluginDescriptor = ReportCommandFactory.descript
126128
.default(ortConfigDirectory.resolve(ORT_COPYRIGHT_GARBAGE_FILENAME))
127129
.configurationGroup()
128130

129-
private val customLicenseTextsDir by option(
130-
"--custom-license-texts-dir",
131-
help = "A directory which maps custom license IDs to license texts. It should contain one text file per " +
132-
"license with the license ID as the filename. A custom license text is used only if its ID has a " +
133-
"'$LICENSE_REF_PREFIX' prefix and if the respective license text is not known by ORT."
134-
).convert { it.expandTilde() }
135-
.file(mustExist = false, canBeFile = false, canBeDir = true, mustBeWritable = false, mustBeReadable = false)
136-
.convert { it.absoluteFile.normalize() }
137-
.default(ortConfigDirectory.resolve(ORT_CUSTOM_LICENSE_TEXTS_DIRNAME))
138-
.configurationGroup()
139-
140131
private val howToFixTextProviderScript by option(
141132
"--how-to-fix-text-provider-script",
142133
help = "The path to a Kotlin script which returns an instance of a 'HowToFixTextProvider'. That provider " +
@@ -219,8 +210,6 @@ class ReportCommand(descriptor: PluginDescriptor = ReportCommandFactory.descript
219210
ortResult = ortResult.setResolutions(resolutionProvider)
220211
}
221212

222-
val licenseTextDirectories = listOfNotNull(customLicenseTextsDir.takeIf { it.isDirectory })
223-
224213
val resolvedPackageConfigurations = ortResult.resolvedConfiguration.packageConfigurations
225214
val packageConfigurationProvider = when {
226215
resolvedPackageConfigurations != null && packageConfigurationsDir == null -> {
@@ -264,12 +253,20 @@ class ReportCommand(descriptor: PluginDescriptor = ReportCommandFactory.descript
264253
HowToFixTextProvider.fromKotlinScript(it.readText(), ortResult)
265254
} ?: HowToFixTextProvider.NONE
266255

256+
val licenseFactProviders = ortConfig.licenseFactProviders.map { (id, config)->
257+
val factory = LicenseFactProviderFactory.ALL[id]
258+
requireNotNull(factory) { "License fact provider '$id' is not available in the classpath." }
259+
factory.create(config)
260+
}
261+
262+
val licenseFactProvider = CompositeLicenseFactProvider(licenseFactProviders)
263+
267264
outputDir.safeMkdirs()
268265

269266
val input = ReporterInput(
270267
ortResult,
271268
ortConfig,
272-
DefaultLicenseTextProvider(licenseTextDirectories),
269+
licenseFactProvider,
273270
copyrightGarbage,
274271
licenseInfoResolver,
275272
licenseClassifications,

plugins/reporters/aosd/src/main/kotlin/Aosd20Reporter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private fun Package.toLicenses(input: ReporterInput): List<AOSD20.License> {
106106

107107
return effectiveLicense?.decompose()?.map { licenseExpression ->
108108
val name = licenseExpression.toString()
109-
val text = input.licenseTextProvider.getLicenseText(name)
109+
val text = input.licenseFactProvider.getLicenseText(name)
110110

111111
AOSD20.License(
112112
name = name,

plugins/reporters/aosd/src/main/kotlin/Aosd21Reporter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private fun Map<Identifier, IndexedValue<CuratedPackage>>.toComponents(
9494
?.takeUnless { it.offersChoice() }
9595

9696
val licenseTexts = licenseExpression?.licenses().orEmpty().mapNotNullTo(mutableSetOf()) { license ->
97-
input.licenseTextProvider.getLicenseText(license)
97+
input.licenseFactProvider.getLicenseText(license)
9898
}.joinToString("\n--\n") { it.trimEnd() }
9999

100100
with(pkg.metadata) {

plugins/reporters/asciidoc/src/main/resources/templates/asciidoc/disclosure_document.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ The following licenses and copyrights were found in the source code of this pack
147147
=== ${resolvedLicense.license}
148148

149149
++++
150-
[#assign licenseText = licenseTextProvider.getLicenseText(resolvedLicense.license.simpleLicense())!""]
150+
[#assign licenseText = licenseFactProvider.getLicenseText(resolvedLicense.license.simpleLicense())!""]
151151
[#if licenseText?has_content]
152152

153153
[#assign copyrights = resolvedLicense.getCopyrights(true)]
@@ -157,7 +157,7 @@ ${copyright}
157157

158158
${licenseText}
159159

160-
[#assign exceptionText = licenseTextProvider.getLicenseText(resolvedLicense.license.exception()!"")!""]
160+
[#assign exceptionText = licenseFactProvider.getLicenseText(resolvedLicense.license.exception()!"")!""]
161161
[#if exceptionText?has_content]
162162

163163
${exceptionText}

plugins/reporters/asciidoc/src/main/resources/templates/freemarker_implicit.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[#-- @ftlvariable name="projects" type="kotlin.collections.Set<org.ossreviewtoolkit.plugins.reporters.freemarker.FreemarkerTemplateProcessor.PackageModel>" --]
55
[#-- @ftlvariable name="packages" type="kotlin.collections.Set<org.ossreviewtoolkit.plugins.reporters.freemarker.FreemarkerTemplateProcessor.PackageModel>" --]
66
[#-- @ftlvariable name="ortResult" type="org.ossreviewtoolkit.model.OrtResult" --]
7-
[#-- @ftlvariable name="licenseTextProvider" type="org.ossreviewtoolkit.reporter.LicenseTextProvider" --]
7+
[#-- @ftlvariable name="licenseFactProvider" type="org.ossreviewtoolkit.plugins.licensefactproviders.api.LicenseFactProvider" --]
88
[#-- @ftlvariable name="LicenseView" type="org.ossreviewtoolkit.model.licenses.LicenseView" --]
99
[#-- @ftlvariable name="helper" type="org.ossreviewtoolkit.plugins.reporters.freemarker.FreemarkerTemplateProcessor.TemplateHelper" --]
1010
[#-- @ftlvariable name="projectsAsPackages" type="kotlin.collections.Set<org.ossreviewtoolkit.model.Identifier>" --]

plugins/reporters/ctrlx/src/main/kotlin/CtrlXAutomationReporter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class CtrlXAutomationReporter(
9494
var licenses = effectiveLicense?.decompose()?.map {
9595
val name = it.toString()
9696
val spdxId = SpdxLicense.forId(name)?.id
97-
val text = input.licenseTextProvider.getLicenseText(name)
97+
val text = input.licenseFactProvider.getLicenseText(name)
9898
License(name = name, spdx = spdxId, text = text.orEmpty())
9999
}
100100

plugins/reporters/cyclonedx/src/main/kotlin/Utils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import org.ossreviewtoolkit.utils.spdx.SpdxLicense
4141
internal fun Collection<String>.mapNamesToLicenses(origin: String, input: ReporterInput): List<License> =
4242
map { licenseName ->
4343
val spdxId = SpdxLicense.forId(licenseName)?.id
44-
val licenseText = input.licenseTextProvider.getLicenseText(licenseName)
44+
val licenseText = input.licenseFactProvider.getLicenseText(licenseName)
4545

4646
// Prefer to set the id in case of an SPDX "core" license and only use the name as a fallback, also
4747
// see https://github.com/CycloneDX/cyclonedx-core-java/issues/8.

plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ private fun createDataModel(input: ReporterInput): Map<String, Any> {
433433
"projects" to projects,
434434
"packages" to packages,
435435
"ortResult" to input.ortResult,
436-
"licenseTextProvider" to input.licenseTextProvider,
436+
"licenseFactProvider" to input.licenseFactProvider,
437437
"LicenseView" to LicenseView,
438438
"helper" to FreemarkerTemplateProcessor.TemplateHelper(input),
439439
"statistics" to input.statistics,

plugins/reporters/freemarker/src/main/resources/templates/freemarker_implicit.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[#-- @ftlvariable name="projects" type="kotlin.collections.Set<org.ossreviewtoolkit.plugins.reporters.freemarker.FreemarkerTemplateProcessor.PackageModel>" --]
55
[#-- @ftlvariable name="packages" type="kotlin.collections.Set<org.ossreviewtoolkit.plugins.reporters.freemarker.FreemarkerTemplateProcessor.PackageModel>" --]
66
[#-- @ftlvariable name="ortResult" type="org.ossreviewtoolkit.model.OrtResult" --]
7-
[#-- @ftlvariable name="licenseTextProvider" type="org.ossreviewtoolkit.reporter.LicenseTextProvider" --]
7+
[#-- @ftlvariable name="licenseFactProvider" type="org.ossreviewtoolkit.plugins.licensefactproviders.api.LicenseFactProvider" --]
88
[#-- @ftlvariable name="LicenseView" type="org.ossreviewtoolkit.model.licenses.LicenseView" --]
99
[#-- @ftlvariable name="helper" type="org.ossreviewtoolkit.plugins.reporters.freemarker.FreemarkerTemplateProcessor.TemplateHelper" --]
1010
[#-- @ftlvariable name="projectsAsPackages" type="kotlin.collections.Set<org.ossreviewtoolkit.model.Identifier>" --]

0 commit comments

Comments
 (0)