Skip to content

Commit 9f81e17

Browse files
SONARIAC-2199 Improve licensing plugin for use in sonar-php (#78)
1 parent 87ef973 commit 9f81e17

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

gradle-modules/src/main/kotlin/org.sonarsource.cloud-native.license-file-generator.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ tasks.register("generateLicenseResources") {
102102

103103
doLast {
104104
val sonarLicenseFile = project.layout.projectDirectory.asFile.parentFile.resolve("LICENSE.txt")
105+
Files.createDirectories(resourceLicenseDir.asFile.toPath())
105106
Files.copy(
106107
sonarLicenseFile.toPath(),
107108
resourceLicenseDir.file("LICENSE.txt").asFile.toPath(),

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,20 @@ class AnalyzerLicensingPackagingRenderer(
3636
private val licenseTitleToResourceFile: Map<String, String> = buildMap {
3737
put("Apache License, Version 2.0", apacheLicenseFileName)
3838
put("Apache License Version 2.0", apacheLicenseFileName)
39+
put("The Apache License, Version 2.0", apacheLicenseFileName)
3940
put("Apache 2", apacheLicenseFileName)
4041
put("Apache-2.0", apacheLicenseFileName)
4142
put("The Apache Software License, Version 2.0", apacheLicenseFileName)
4243
put("BSD-3-Clause", "BSD-3.txt")
44+
put("BSD", "BSD-2.txt")
4345
put("GNU LGPL 3", "GNU-LGPL-3.txt")
4446
put("Go License", "Go.txt")
4547
}
4648
private val dependenciesWithUnusableLicenseFileInside: Set<String> = setOf(
4749
"com.fasterxml.jackson.dataformat.jackson-dataformat-smile",
48-
"com.fasterxml.jackson.dataformat.jackson-dataformat-yaml"
50+
"com.fasterxml.jackson.dataformat.jackson-dataformat-yaml",
51+
"com.fasterxml.woodstox.woodstox-core",
52+
"org.codehaus.woodstox.stax2-api"
4953
)
5054
private val exceptions: ArrayList<String> = ArrayList()
5155

@@ -121,8 +125,7 @@ class AnalyzerLicensingPackagingRenderer(
121125
return Status.failure("No license found in pom data.")
122126
}
123127

124-
copyLicenseFromResources(data, pomLicense.get().name)
125-
return Status.success
128+
return copyLicenseFromResources(data, pomLicense.get().name)
126129
}
127130

128131
@Throws(IOException::class)
@@ -147,6 +150,9 @@ class AnalyzerLicensingPackagingRenderer(
147150
licenseName: String,
148151
): Status {
149152
val licenseResourceFileName = licenseTitleToResourceFile[licenseName]
153+
if (licenseResourceFileName == null) {
154+
return Status.failure("License file '$licenseName' could not be found.")
155+
}
150156
val resourceAsStream = AnalyzerLicensingPackagingRenderer::class.java.getResourceAsStream("/licenses/$licenseResourceFileName")
151157
?: throw IOException("Resource not found for license: $licenseName")
152158
Files.copy(resourceAsStream, generateLicensePath(data), StandardCopyOption.REPLACE_EXISTING)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Copyright <YEAR> <COPYRIGHT HOLDER>
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
5+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
7+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8+
9+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)