@@ -54,7 +54,8 @@ class CtrlXAutomationReporter(override val descriptor: PluginDescriptor = CtrlXA
54
54
55
55
override fun generateReport (input : ReporterInput , outputDir : File ): List <Result <File >> {
56
56
val packages = input.ortResult.getPackages(omitExcluded = true )
57
- val components = packages.mapTo(mutableListOf ()) { (pkg, _) ->
57
+
58
+ val components = packages.mapNotNullTo(mutableListOf ()) { (pkg, _) ->
58
59
val qualifiedName = when (pkg.id.type) {
59
60
// At least for NPM packages, CtrlX requires the component name to be prefixed with the scope name,
60
61
// separated with a slash. Other package managers might require similar handling, but there seems to be
@@ -67,31 +68,45 @@ class CtrlXAutomationReporter(override val descriptor: PluginDescriptor = CtrlXA
67
68
}
68
69
69
70
val resolvedLicenseInfo = input.licenseInfoResolver.resolveLicenseInfo(pkg.id).filterExcluded()
70
- val copyrights = resolvedLicenseInfo.getCopyrights().joinToString(" \n " ).takeUnless { it.isEmpty() }
71
- val effectiveLicense = resolvedLicenseInfo.effectiveLicense(
72
- LicenseView .CONCLUDED_OR_DECLARED_AND_DETECTED ,
73
- input.ortResult.getPackageLicenseChoices(pkg.id),
74
- input.ortResult.getRepositoryLicenseChoices()
71
+ val filteredResolvedLicenseInfo = resolvedLicenseInfo.filterNoCategorizedLicenses(
72
+ input.licenseClassifications,
73
+ input.licenseCategoriesToInclude
75
74
)
76
- val licenses = effectiveLicense?.decompose()?.map {
77
- val name = it.toString()
78
- val spdxId = SpdxLicense .forId(name)?.id
79
- val text = input.licenseTextProvider.getLicenseText(name)
80
- License (name = name, spdx = spdxId, text = text.orEmpty())
81
- }
82
75
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
- )
76
+ // If the license was removed by the classification filter, we don't output it in the report (otherwise it
77
+ // would be included with NOASSERTION (see underneath).
78
+ if (filteredResolvedLicenseInfo.licenses.isEmpty() && resolvedLicenseInfo.licenses.isNotEmpty()) {
79
+ null
80
+ } else {
81
+ val copyrights = filteredResolvedLicenseInfo.getCopyrights().joinToString(" \n " ).takeUnless {
82
+ it.isEmpty()
83
+ }
84
+
85
+ val effectiveLicense = filteredResolvedLicenseInfo.effectiveLicense(
86
+ LicenseView .CONCLUDED_OR_DECLARED_AND_DETECTED ,
87
+ input.ortResult.getPackageLicenseChoices(pkg.id),
88
+ input.ortResult.getRepositoryLicenseChoices()
89
+ )
90
+ val licenses = effectiveLicense?.decompose()?.map {
91
+ val name = it.toString()
92
+ val spdxId = SpdxLicense .forId(name)?.id
93
+ val text = input.licenseTextProvider.getLicenseText(name)
94
+ License (name = name, spdx = spdxId, text = text.orEmpty())
95
+ }
96
+
97
+ // The specification requires at least one license.
98
+ val componentLicenses = licenses.orEmpty().ifEmpty { listOf (LICENSE_NOASSERTION ) }
99
+
100
+ Component (
101
+ name = qualifiedName,
102
+ version = pkg.id.version,
103
+ homepage = pkg.homepageUrl.takeUnless { it.isEmpty() },
104
+ copyright = copyrights?.let { CopyrightInformation (it) },
105
+ licenses = componentLicenses,
106
+ usage = if (pkg.isModified) Usage .Modified else Usage .AsIs
107
+ // TODO: Map the PackageLinkage to an IntegrationMechanism.
108
+ )
109
+ }
95
110
}
96
111
97
112
val reportFileResult = runCatching {
0 commit comments