@@ -207,28 +207,28 @@ open class PackageRule(
207207 .applyChoices(ruleSet.ortResult.getPackageLicenseChoices(pkg.metadata.id), licenseView)
208208 .applyChoices(ruleSet.ortResult.getRepositoryLicenseChoices(), licenseView).forEach { resolvedLicense ->
209209 resolvedLicense.sources.forEach { licenseSource ->
210- licenseRules + = LicenseRule (name, resolvedLicense, licenseSource).apply (block)
210+ licenseRules + = LicenseRule (name, resolvedLicense, setOf ( licenseSource) ).apply (block)
211211 }
212212 }
213213 }
214214
215215 fun issue (severity : Severity , message : String , howToFix : String ) =
216- issue(severity, pkg.metadata.id, null , null , message, howToFix)
216+ issue(severity, pkg.metadata.id, null , emptySet() , message, howToFix)
217217
218218 /* *
219219 * Add a [hint][Severity.HINT] to the list of [violations].
220220 */
221- fun hint (message : String , howToFix : String ) = hint(pkg.metadata.id, null , null , message, howToFix)
221+ fun hint (message : String , howToFix : String ) = hint(pkg.metadata.id, null , emptySet() , message, howToFix)
222222
223223 /* *
224224 * Add a [warning][Severity.WARNING] to the list of [violations].
225225 */
226- fun warning (message : String , howToFix : String ) = warning(pkg.metadata.id, null , null , message, howToFix)
226+ fun warning (message : String , howToFix : String ) = warning(pkg.metadata.id, null , emptySet() , message, howToFix)
227227
228228 /* *
229229 * Add an [error][Severity.ERROR] to the list of [violations].
230230 */
231- fun error (message : String , howToFix : String ) = error(pkg.metadata.id, null , null , message, howToFix)
231+ fun error (message : String , howToFix : String ) = error(pkg.metadata.id, null , emptySet() , message, howToFix)
232232
233233 /* *
234234 * A [Rule] to check a single license of the [package][pkg].
@@ -242,10 +242,21 @@ open class PackageRule(
242242 val resolvedLicense : ResolvedLicense ,
243243
244244 /* *
245- * The source of the license.
245+ * The license sources to evaluate the license for. Must not be empty and contained in the [resolvedLicense] .
246246 */
247- val licenseSource : LicenseSource
247+ val licenseSources : Set < LicenseSource >
248248 ) : Rule(ruleSet, name) {
249+ init {
250+ require(licenseSources.isNotEmpty()) {
251+ " The given license sources must not be empty."
252+ }
253+
254+ val invalidLicenseSources = (licenseSources - resolvedLicense.sources)
255+ require(invalidLicenseSources.isEmpty()) {
256+ " The license sources ${invalidLicenseSources.joinToString()} are not part of the resolved license."
257+ }
258+ }
259+
249260 /* *
250261 * A shortcut for the [license][ResolvedLicense.license] in [resolvedLicense].
251262 */
@@ -257,11 +268,11 @@ open class PackageRule(
257268 */
258269 fun pkg () = pkg
259270
260- override val description = " \t Evaluating license rule '$name ' for $licenseSource license " +
271+ override val description = " \t Evaluating license rule '$name ' for ${licenseSources.joinToString()} license " +
261272 " '${resolvedLicense.license} '."
262273
263274 override fun issueSource () =
264- " $name - ${pkg.metadata.id.toCoordinates()} - ${resolvedLicense.license} ($licenseSource )"
275+ " $name - ${pkg.metadata.id.toCoordinates()} - ${resolvedLicense.license} (${licenseSources.joinToString()} )"
265276
266277 /* *
267278 * A [RuleMatcher] that checks if a [detected][LicenseSource.DETECTED] license is
@@ -271,7 +282,8 @@ open class PackageRule(
271282 object : RuleMatcher {
272283 override val description = " isDetectedExcluded($license )"
273284
274- override fun matches () = licenseSource == LicenseSource .DETECTED && resolvedLicense.isDetectedExcluded
285+ override fun matches () =
286+ licenseSources.singleOrNull() == LicenseSource .DETECTED && resolvedLicense.isDetectedExcluded
275287 }
276288
277289 /* *
@@ -290,22 +302,23 @@ open class PackageRule(
290302 }
291303
292304 fun issue (severity : Severity , message : String , howToFix : String ) =
293- issue(severity, pkg.metadata.id, license, licenseSource , message, howToFix)
305+ issue(severity, pkg.metadata.id, license, licenseSources , message, howToFix)
294306
295307 /* *
296308 * Add a [hint][Severity.HINT] to the list of [violations].
297309 */
298- fun hint (message : String , howToFix : String ) = hint(pkg.metadata.id, license, licenseSource , message, howToFix)
310+ fun hint (message : String , howToFix : String ) = hint(pkg.metadata.id, license, licenseSources , message, howToFix)
299311
300312 /* *
301313 * Add a [warning][Severity.WARNING] to the list of [violations].
302314 */
303315 fun warning (message : String , howToFix : String ) =
304- warning(pkg.metadata.id, license, licenseSource , message, howToFix)
316+ warning(pkg.metadata.id, license, licenseSources , message, howToFix)
305317
306318 /* *
307319 * Add an [error][Severity.ERROR] to the list of [violations].
308320 */
309- fun error (message : String , howToFix : String ) = error(pkg.metadata.id, license, licenseSource, message, howToFix)
321+ fun error (message : String , howToFix : String ) =
322+ error(pkg.metadata.id, license, licenseSources, message, howToFix)
310323 }
311324}
0 commit comments