Skip to content

Commit c123d9f

Browse files
authored
Support more license types (#98)
1 parent 6223297 commit c123d9f

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

gradle-modules/src/main/kotlin/org/sonarsource/cloudnative/gradle/AnalyzerLicensingPackagingRenderer.kt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,28 @@ import java.nio.file.StandardCopyOption
2828
import java.nio.file.StandardOpenOption
2929
import java.util.ArrayList
3030

31+
private const val APACHE_LICENSE_FILE_NAME: String = "Apache-2.0.txt"
32+
val LICENSE_TITLE_TO_RESOURCE_FILE: Map<String, String> = buildMap {
33+
put("Apache License, Version 2.0", APACHE_LICENSE_FILE_NAME)
34+
put("Apache License Version 2.0", APACHE_LICENSE_FILE_NAME)
35+
put("The Apache License, Version 2.0", APACHE_LICENSE_FILE_NAME)
36+
put("Apache 2", APACHE_LICENSE_FILE_NAME)
37+
put("Apache-2.0", APACHE_LICENSE_FILE_NAME)
38+
put("Apache 2.0", APACHE_LICENSE_FILE_NAME)
39+
put("The Apache Software License, Version 2.0", APACHE_LICENSE_FILE_NAME)
40+
put("BSD-3-Clause", "BSD-3.txt")
41+
put("BSD", "BSD-2.txt")
42+
put("GWT Terms", APACHE_LICENSE_FILE_NAME) // See https://www.gwtproject.org/terms.html
43+
put("GNU LGPL 3", "GNU-LGPL-3.txt")
44+
put("Go License", "Go.txt")
45+
put("MIT License", "MIT.txt")
46+
put("MIT", "MIT.txt")
47+
}
48+
3149
class AnalyzerLicensingPackagingRenderer(
3250
private val buildOutputDir: Path,
3351
) : ReportRenderer {
34-
private var apacheLicenseFileName: String = "Apache-2.0.txt"
3552
private lateinit var generatedLicenseResourcesDirectory: Path
36-
private val licenseTitleToResourceFile: Map<String, String> = buildMap {
37-
put("Apache License, Version 2.0", apacheLicenseFileName)
38-
put("Apache License Version 2.0", apacheLicenseFileName)
39-
put("The Apache License, Version 2.0", apacheLicenseFileName)
40-
put("Apache 2", apacheLicenseFileName)
41-
put("Apache-2.0", apacheLicenseFileName)
42-
put("The Apache Software License, Version 2.0", apacheLicenseFileName)
43-
put("BSD-3-Clause", "BSD-3.txt")
44-
put("BSD", "BSD-2.txt")
45-
put("GNU LGPL 3", "GNU-LGPL-3.txt")
46-
put("Go License", "Go.txt")
47-
put("MIT License", "MIT.txt")
48-
put("MIT", "MIT.txt")
49-
}
5053
private val dependenciesWithUnusableLicenseFileInside: Set<String> = setOf(
5154
"com.fasterxml.jackson.dataformat.jackson-dataformat-smile",
5255
"com.fasterxml.jackson.dataformat.jackson-dataformat-yaml",
@@ -151,10 +154,8 @@ class AnalyzerLicensingPackagingRenderer(
151154
data: ModuleData,
152155
licenseName: String,
153156
): Status {
154-
val licenseResourceFileName = licenseTitleToResourceFile[licenseName]
155-
if (licenseResourceFileName == null) {
156-
return Status.failure("License file '$licenseName' could not be found.")
157-
}
157+
val licenseResourceFileName = LICENSE_TITLE_TO_RESOURCE_FILE[licenseName]
158+
?: return Status.failure("License file '$licenseName' could not be found.")
158159
val resourceAsStream = AnalyzerLicensingPackagingRenderer::class.java.getResourceAsStream("/licenses/$licenseResourceFileName")
159160
?: throw IOException("Resource not found for license: $licenseName")
160161
Files.copy(resourceAsStream, generateLicensePath(data), StandardCopyOption.REPLACE_EXISTING)

0 commit comments

Comments
 (0)