Skip to content

Commit b7e40cb

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 6bf2ec8 commit b7e40cb

File tree

29 files changed

+93
-72
lines changed

29 files changed

+93
-72
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))

integrations/completions/ort-completion.bash

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,12 +1152,6 @@ _ort_report() {
11521152
[[ ${i} -gt COMP_CWORD ]] && in_param='--copyright-garbage-file' || in_param=''
11531153
continue
11541154
;;
1155-
--custom-license-texts-dir)
1156-
__skip_opt_eq
1157-
(( i = i + 1 ))
1158-
[[ ${i} -gt COMP_CWORD ]] && in_param='--custom-license-texts-dir' || in_param=''
1159-
continue
1160-
;;
11611155
--how-to-fix-text-provider-script)
11621156
__skip_opt_eq
11631157
(( i = i + 1 ))
@@ -1216,7 +1210,7 @@ _ort_report() {
12161210
done
12171211
local word="${COMP_WORDS[$COMP_CWORD]}"
12181212
if [[ "${word}" =~ ^[-] ]]; then
1219-
COMPREPLY=($(compgen -W '--ort-file -i --output-dir -o --report-formats -f --copyright-garbage-file --custom-license-texts-dir --how-to-fix-text-provider-script --license-classifications-file --package-configurations-dir --refresh-resolutions --repository-configuration-file --resolutions-file --report-option -O -h --help' -- "${word}"))
1213+
COMPREPLY=($(compgen -W '--ort-file -i --output-dir -o --report-formats -f --copyright-garbage-file --how-to-fix-text-provider-script --license-classifications-file --package-configurations-dir --refresh-resolutions --repository-configuration-file --resolutions-file --report-option -O -h --help' -- "${word}"))
12201214
return
12211215
fi
12221216
@@ -1237,9 +1231,6 @@ _ort_report() {
12371231
"--copyright-garbage-file")
12381232
__complete_files "${word}"
12391233
;;
1240-
"--custom-license-texts-dir")
1241-
__complete_files "${word}"
1242-
;;
12431234
"--how-to-fix-text-provider-script")
12441235
__complete_files "${word}"
12451236
;;

integrations/completions/ort-completion.fish

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ complete -c ort -n "__fish_seen_subcommand_from report" -l ort-file -s i -r -F -
151151
complete -c ort -n "__fish_seen_subcommand_from report" -l output-dir -s o -r -F -d 'The output directory to store the generated reports in.'
152152
complete -c ort -n "__fish_seen_subcommand_from report" -l report-formats -s f -r -d 'A comma-separated list of report formats to generate, any of [AOSD2.0, AOSD2.1, CtrlXAutomation, CycloneDX, DocBookTemplate, EvaluatedModel, FossID, FossIdSnippet, HtmlTemplate, ManPageTemplate, Opossum, PdfTemplate, PlainTextTemplate, SpdxDocument, StaticHTML, TrustSource, WebApp].'
153153
complete -c ort -n "__fish_seen_subcommand_from report" -l copyright-garbage-file -r -F -d 'A file containing copyright statements which are marked as garbage. This can make the output inconsistent with the evaluator output but is useful when testing copyright garbage.'
154-
complete -c ort -n "__fish_seen_subcommand_from report" -l custom-license-texts-dir -r -F -d 'A directory which maps custom license IDs to license texts. It should contain one text file per license with the license ID as the filename. A custom license text is used only if its ID has a \'LicenseRef-\' prefix and if the respective license text is not known by ORT.'
155154
complete -c ort -n "__fish_seen_subcommand_from report" -l how-to-fix-text-provider-script -r -F -d 'The path to a Kotlin script which returns an instance of a \'HowToFixTextProvider\'. That provider injects how-to-fix texts in Markdown format for ORT issues.'
156155
complete -c ort -n "__fish_seen_subcommand_from report" -l license-classifications-file -r -F -d 'A file containing the license classifications. This can make the output inconsistent with the evaluator output but is useful when testing license classifications.'
157156
complete -c ort -n "__fish_seen_subcommand_from report" -l package-configurations-dir -r -F -d 'A directory that is searched recursively for package configuration files. Each file must only contain a single package configuration. This can make the output inconsistent with the evaluator output but is useful when testing package configurations.'

integrations/completions/ort-completion.zsh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,12 +1157,6 @@ _ort_report() {
11571157
[[ ${i} -gt COMP_CWORD ]] && in_param='--copyright-garbage-file' || in_param=''
11581158
continue
11591159
;;
1160-
--custom-license-texts-dir)
1161-
__skip_opt_eq
1162-
(( i = i + 1 ))
1163-
[[ ${i} -gt COMP_CWORD ]] && in_param='--custom-license-texts-dir' || in_param=''
1164-
continue
1165-
;;
11661160
--how-to-fix-text-provider-script)
11671161
__skip_opt_eq
11681162
(( i = i + 1 ))
@@ -1221,7 +1215,7 @@ _ort_report() {
12211215
done
12221216
local word="${COMP_WORDS[$COMP_CWORD]}"
12231217
if [[ "${word}" =~ ^[-] ]]; then
1224-
COMPREPLY=($(compgen -W '--ort-file -i --output-dir -o --report-formats -f --copyright-garbage-file --custom-license-texts-dir --how-to-fix-text-provider-script --license-classifications-file --package-configurations-dir --refresh-resolutions --repository-configuration-file --resolutions-file --report-option -O -h --help' -- "${word}"))
1218+
COMPREPLY=($(compgen -W '--ort-file -i --output-dir -o --report-formats -f --copyright-garbage-file --how-to-fix-text-provider-script --license-classifications-file --package-configurations-dir --refresh-resolutions --repository-configuration-file --resolutions-file --report-option -O -h --help' -- "${word}"))
12251219
return
12261220
fi
12271221
@@ -1242,9 +1236,6 @@ _ort_report() {
12421236
"--copyright-garbage-file")
12431237
__complete_files "${word}"
12441238
;;
1245-
"--custom-license-texts-dir")
1246-
__complete_files "${word}"
1247-
;;
12481239
"--how-to-fix-text-provider-script")
12491240
__complete_files "${word}"
12501241
;;

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ 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
69-
import org.ossreviewtoolkit.reporter.DefaultLicenseTextProvider
7071
import org.ossreviewtoolkit.reporter.HowToFixTextProvider
7172
import org.ossreviewtoolkit.reporter.ReporterFactory
7273
import org.ossreviewtoolkit.reporter.ReporterInput
@@ -77,13 +78,11 @@ import org.ossreviewtoolkit.utils.common.safeMkdirs
7778
import org.ossreviewtoolkit.utils.config.setPackageConfigurations
7879
import org.ossreviewtoolkit.utils.config.setResolutions
7980
import org.ossreviewtoolkit.utils.ort.ORT_COPYRIGHT_GARBAGE_FILENAME
80-
import org.ossreviewtoolkit.utils.ort.ORT_CUSTOM_LICENSE_TEXTS_DIRNAME
8181
import org.ossreviewtoolkit.utils.ort.ORT_HOW_TO_FIX_TEXT_PROVIDER_FILENAME
8282
import org.ossreviewtoolkit.utils.ort.ORT_LICENSE_CLASSIFICATIONS_FILENAME
8383
import org.ossreviewtoolkit.utils.ort.ORT_RESOLUTIONS_FILENAME
8484
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory
8585
import org.ossreviewtoolkit.utils.ort.showStackTrace
86-
import org.ossreviewtoolkit.utils.spdx.SpdxConstants.LICENSE_REF_PREFIX
8786

8887
@OrtPlugin(
8988
displayName = "Report",
@@ -127,17 +126,6 @@ class ReportCommand(descriptor: PluginDescriptor = ReportCommandFactory.descript
127126
.default(ortConfigDirectory / ORT_COPYRIGHT_GARBAGE_FILENAME)
128127
.configurationGroup()
129128

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

223-
val licenseTextDirectories = listOfNotNull(customLicenseTextsDir.takeIf { it.isDirectory })
224-
225211
val resolvedPackageConfigurations = ortResult.resolvedConfiguration.packageConfigurations
226212
val packageConfigurationProvider = when {
227213
resolvedPackageConfigurations != null && packageConfigurationsDir == null -> {
@@ -265,12 +251,20 @@ class ReportCommand(descriptor: PluginDescriptor = ReportCommandFactory.descript
265251
HowToFixTextProvider.fromKotlinScript(it.readText(), ortResult)
266252
} ?: HowToFixTextProvider.NONE
267253

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

270264
val input = ReporterInput(
271265
ortResult,
272266
ortConfig,
273-
DefaultLicenseTextProvider(licenseTextDirectories),
267+
licenseFactProvider,
274268
copyrightGarbage,
275269
licenseInfoResolver,
276270
licenseClassifications,

plugins/reporters/aosd/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ dependencies {
3939

4040
funTestImplementation(testFixtures(projects.reporter))
4141

42+
funTestImplementation(projects.plugins.licenseFactProviders.spdxLicenseFactProvider)
43+
4244
funTestImplementation(libs.kotest.assertions.json)
4345
}

plugins/reporters/aosd/src/funTest/kotlin/Aosd20ReporterFunTest.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import io.kotest.matchers.collections.shouldHaveSize
2828
import io.kotest.matchers.result.shouldBeSuccess
2929
import io.kotest.matchers.should
3030

31+
import org.ossreviewtoolkit.plugins.licensefactproviders.spdx.SpdxLicenseFactProviderFactory
3132
import org.ossreviewtoolkit.reporter.ORT_RESULT
3233
import org.ossreviewtoolkit.reporter.ReporterInput
3334
import org.ossreviewtoolkit.utils.test.getResource
@@ -54,7 +55,13 @@ class Aosd20ReporterFunTest : WordSpec({
5455
}
5556

5657
"The generated report" should {
57-
val reportFiles = Aosd20Reporter().generateReport(ReporterInput(ORT_RESULT), tempdir())
58+
val reportFiles = Aosd20Reporter().generateReport(
59+
ReporterInput(
60+
ORT_RESULT,
61+
licenseFactProvider = SpdxLicenseFactProviderFactory.create()
62+
),
63+
tempdir()
64+
)
5865

5966
"be valid according to the schema" {
6067
val schemaJson = readResource("/aosd20/aosd.schema.json")

plugins/reporters/aosd/src/funTest/kotlin/Aosd21ReporterFunTest.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import io.kotest.matchers.result.shouldBeSuccess
2929
import io.kotest.matchers.should
3030
import io.kotest.matchers.shouldBe
3131

32+
import org.ossreviewtoolkit.plugins.licensefactproviders.spdx.SpdxLicenseFactProviderFactory
3233
import org.ossreviewtoolkit.reporter.ORT_RESULT
3334
import org.ossreviewtoolkit.reporter.ReporterInput
3435
import org.ossreviewtoolkit.utils.test.getResource
@@ -58,7 +59,13 @@ class Aosd21ReporterFunTest : WordSpec({
5859
}
5960

6061
"The generated report" should {
61-
val reportFiles = Aosd21Reporter().generateReport(ReporterInput(ORT_RESULT), tempdir())
62+
val reportFiles = Aosd21Reporter().generateReport(
63+
ReporterInput(
64+
ORT_RESULT,
65+
licenseFactProvider = SpdxLicenseFactProviderFactory.create()
66+
),
67+
tempdir()
68+
)
6269

6370
"be valid according to the schema" {
6471
val schemaJson = readResource("/aosd21/AOSD2.1_Importscheme_V2.1.0.json")

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) {

0 commit comments

Comments
 (0)