@@ -32,13 +32,27 @@ import org.ossreviewtoolkit.reporter.ReporterFactory
3232import org.ossreviewtoolkit.reporter.ReporterInput
3333import org.ossreviewtoolkit.utils.spdx.SpdxConstants
3434import org.ossreviewtoolkit.utils.spdx.SpdxLicense
35+ import org.ossreviewtoolkit.utils.spdx.toSpdx
36+
37+ data class CtrlXAutomationReporterConfig (
38+ /* *
39+ * The categories of the licenses of the packages to include in the report. If a component has a license which has a
40+ * category not present in this parameter, the license is removed from the component and not visible in the report.
41+ * If a component has ALL its licenses removed this way, it is not displayed in the report. If the parameter is not
42+ * set for the reporter, all components and all licenses are present in the report.
43+ */
44+ val licenseCategoriesToInclude : List <String >?
45+ )
3546
3647@OrtPlugin(
3748 displayName = " CtrlX Automation Reporter" ,
3849 description = " A reporter for the ctrlX Automation format." ,
3950 factory = ReporterFactory ::class
4051)
41- class CtrlXAutomationReporter (override val descriptor : PluginDescriptor = CtrlXAutomationReporterFactory .descriptor) :
52+ class CtrlXAutomationReporter (
53+ override val descriptor : PluginDescriptor = CtrlXAutomationReporterFactory .descriptor,
54+ private val config : CtrlXAutomationReporterConfig
55+ ) :
4256 Reporter {
4357 companion object {
4458 const val REPORT_FILENAME = " fossinfo.json"
@@ -54,7 +68,11 @@ class CtrlXAutomationReporter(override val descriptor: PluginDescriptor = CtrlXA
5468
5569 override fun generateReport (input : ReporterInput , outputDir : File ): List <Result <File >> {
5670 val packages = input.ortResult.getPackages(omitExcluded = true )
57- val components = packages.mapTo(mutableListOf ()) { (pkg, _) ->
71+ val licensesToInclude = config.licenseCategoriesToInclude?.flatMap {
72+ input.licenseClassifications.licensesByCategory[it].orEmpty()
73+ }.orEmpty()
74+
75+ val components = packages.mapNotNullTo(mutableListOf ()) { (pkg, _) ->
5876 val qualifiedName = when (pkg.id.type) {
5977 // At least for NPM packages, CtrlX requires the component name to be prefixed with the scope name,
6078 // separated with a slash. Other package managers might require similar handling, but there seems to be
@@ -73,25 +91,41 @@ class CtrlXAutomationReporter(override val descriptor: PluginDescriptor = CtrlXA
7391 input.ortResult.getPackageLicenseChoices(pkg.id),
7492 input.ortResult.getRepositoryLicenseChoices()
7593 )
76- val licenses = effectiveLicense?.decompose()?.map {
94+ var licenses = effectiveLicense?.decompose()?.map {
7795 val name = it.toString()
7896 val spdxId = SpdxLicense .forId(name)?.id
7997 val text = input.licenseTextProvider.getLicenseText(name)
8098 License (name = name, spdx = spdxId, text = text.orEmpty())
8199 }
82100
83- // The specification requires at least one license.
84- val componentLicenses = licenses.orEmpty().ifEmpty { listOf (LICENSE_NOASSERTION ) }
85-
86- Component (
87- name = qualifiedName,
88- version = pkg.id.version,
89- homepage = pkg.homepageUrl.takeUnless { it.isEmpty() },
90- copyright = copyrights?.let { CopyrightInformation (it) },
91- licenses = componentLicenses,
92- usage = if (pkg.isModified) Usage .Modified else Usage .AsIs
93- // TODO: Map the PackageLinkage to an IntegrationMechanism.
94- )
101+ var componentShouldBeExcluded = false
102+
103+ if (config.licenseCategoriesToInclude != null ) {
104+ val filteredLicenses = licenses?.filter { it.name.toSpdx() in licensesToInclude }
105+
106+ if (filteredLicenses != null && filteredLicenses.isEmpty()) {
107+ componentShouldBeExcluded = true
108+ } else {
109+ licenses = filteredLicenses
110+ }
111+ }
112+
113+ if (componentShouldBeExcluded) {
114+ null
115+ } else {
116+ // The specification requires at least one license.
117+ val componentLicenses = licenses.orEmpty().ifEmpty { listOf (LICENSE_NOASSERTION ) }
118+
119+ Component (
120+ name = qualifiedName,
121+ version = pkg.id.version,
122+ homepage = pkg.homepageUrl.takeUnless { it.isEmpty() },
123+ copyright = copyrights?.let { CopyrightInformation (it) },
124+ licenses = componentLicenses,
125+ usage = if (pkg.isModified) Usage .Modified else Usage .AsIs
126+ // TODO: Map the PackageLinkage to an IntegrationMechanism.
127+ )
128+ }
95129 }
96130
97131 val reportFileResult = runCatching {
0 commit comments