Skip to content

Commit 8ed8f3e

Browse files
committed
license-gather: add license normalization to GatherLicenseTask
1 parent f61a3cc commit 8ed8f3e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

plugins/license-gather-plugin/src/main/kotlin/com/github/vlsi/gradle/license/GatherLicenseTask.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import com.github.vlsi.gradle.license.api.License
2323
import com.github.vlsi.gradle.license.api.LicenseExpression
2424
import com.github.vlsi.gradle.license.api.LicenseExpressionParser
2525
import com.github.vlsi.gradle.license.api.OsgiBundleLicenseParser
26-
import com.github.vlsi.gradle.license.api.ParseException
2726
import com.github.vlsi.gradle.license.api.SpdxLicense
2827
import com.github.vlsi.gradle.license.api.asExpression
2928
import com.github.vlsi.gradle.license.api.text
@@ -329,9 +328,15 @@ open class GatherLicenseTask @Inject constructor(
329328
spdxPredictor
330329
workerExecutor.await()
331330

331+
val licenseNormalizer =
332+
GuessBasedNormalizer(logger, similarityThreshold.get().toDouble())
333+
332334
if (predictor != null) {
333335
findManifestLicenses(allDependencies, licenseExpressionParser)
334-
findPomLicenses(allDependencies)
336+
findPomLicenses(
337+
allDependencies,
338+
licenseNormalizer
339+
)
335340
findLicenseFromFiles(allDependencies, predictor)
336341
}
337342

@@ -341,6 +346,11 @@ open class GatherLicenseTask @Inject constructor(
341346
val metadata = mutableMapOf<ModuleComponentIdentifier, LicenseInfo>()
342347

343348
val licenseTextCache = mutableMapOf<SpdxLicense, String>()
349+
350+
val ignoreMissingLicenseFor = ignoreMissingLicenseFor.get().map {
351+
licenseNormalizer.normalize(it)
352+
}
353+
344354
for ((id, licenseInfo) in allDependencies) {
345355
if (licenseInfo.license == null) {
346356
missingLicenseId.add(id)
@@ -349,7 +359,7 @@ open class GatherLicenseTask @Inject constructor(
349359
if (licenseFiles != null && !licenseFiles.containsLicenseFile()) {
350360
// Add default license text if needed
351361
val licenseExpression = licenseInfo.license
352-
if (licenseExpression != null && licenseExpression in ignoreMissingLicenseFor.get()) {
362+
if (licenseExpression != null && licenseExpression in ignoreMissingLicenseFor) {
353363
logger.debug(
354364
"No LICENSE file detected for component ${id.displayName}" +
355365
" however licenseid $licenseExpression is included in ignoreMissingLicenseFor set." +
@@ -521,7 +531,8 @@ open class GatherLicenseTask @Inject constructor(
521531
operator fun GPathResult.get(name: String) = getProperty(name) as GPathResult
522532

523533
private fun findPomLicenses(
524-
detectedLicenses: MutableMap<ComponentIdentifier, LicenseInfo>
534+
detectedLicenses: MutableMap<ComponentIdentifier, LicenseInfo>,
535+
licenseNormalizer: GuessBasedNormalizer
525536
) {
526537
val compIds =
527538
detectedLicenses
@@ -533,9 +544,7 @@ open class GatherLicenseTask @Inject constructor(
533544
return
534545
}
535546

536-
val normalizer = GuessBasedNormalizer(logger, similarityThreshold.get().toDouble())
537-
538-
val licenses = loadLicenses(compIds, project, licenseOverrides, normalizer)
547+
val licenses = loadLicenses(compIds, project, licenseOverrides, licenseNormalizer)
539548
val failures = mutableListOf<Throwable>()
540549
for ((id, licenseResult) in compIds.zip(licenses)) {
541550
if (licenseResult.isFailure) {

plugins/license-gather-plugin/src/main/kotlin/com/github/vlsi/gradle/license/GuessBasedNormalizer.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import java.net.URI
3030
class GuessBasedNormalizer(
3131
private val logger: Logger,
3232
private val similarityThreshold: Double = 42.0
33-
) :
34-
LicenseExpressionNormalizer() {
33+
) : LicenseExpressionNormalizer() {
3534

3635
private val nameGuesser = TfIdfBuilder<LicenseExpression>().apply {
3736
SpdxLicense.values().forEach { addDocument(it.asExpression(), it.title) }

0 commit comments

Comments
 (0)