Skip to content

Commit 457439d

Browse files
SONARIAC-2685 Make the project license path configurable for the license validation plugin (#103)
1 parent c1ed4df commit 457439d

File tree

7 files changed

+566
-3
lines changed

7 files changed

+566
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ val generateDartLicenseResources = tasks.register("generateDartLicenseResources"
127127
}
128128
}
129129

130+
tasks.named("validateLicenseFiles") {
131+
dependsOn(validateDartLicenses)
132+
}
133+
134+
tasks.named("generateLicenseResources") {
135+
dependsOn(generateDartLicenseResources)
136+
}
137+
130138
/**
131139
* Runs `dart pub deps --no-dev --style=compact` in the analyzer directory and parses the output
132140
* to extract non-dev dependency package names.

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.github.jk1.license.render.ReportRenderer
1818
import java.nio.file.Files
1919
import java.nio.file.StandardCopyOption
2020
import org.sonarsource.cloudnative.gradle.AnalyzerLicensingPackagingRenderer
21+
import org.sonarsource.cloudnative.gradle.LicenseGenerationConfig
2122
import org.sonarsource.cloudnative.gradle.areDirectoriesEqual
2223
import org.sonarsource.cloudnative.gradle.copyDirectory
2324

@@ -29,8 +30,16 @@ plugins {
2930
* This plugin is used for generating license files for third-party runtime-dependencies into the resources folder.
3031
* It provides a validation task to ensure that the license files in the resource folder are up-to-date.
3132
* It provides a task to regenerate the license files into the resources folder.
32-
* This tasks expects the license of the analyzer to be present one level above the (project-)plugin directory.
3333
*/
34+
35+
val licenseGenerationConfig =
36+
extensions.findByType<LicenseGenerationConfig>()
37+
?: extensions.create<LicenseGenerationConfig>("licenseGenerationConfig")
38+
39+
licenseGenerationConfig.projectLicenseFile.convention(
40+
project.layout.projectDirectory.asFile.parentFile.resolve("LICENSE.txt")
41+
)
42+
3443
var buildLicenseReportDirectory = project.layout.buildDirectory.dir("reports/dependency-license")
3544
var buildLicenseOutputToCopyDir = buildLicenseReportDirectory.get().dir("licenses")
3645
var resourceLicenseDir = project.layout.projectDirectory.dir("src/main/resources/licenses")
@@ -97,14 +106,13 @@ tasks.named("generateLicenseReport") {
97106
}
98107
}
99108

100-
// Requires LICENSE.txt to be present one level above the (project-)plugin directory
101109
tasks.register("generateLicenseResources") {
102110
description = "Copies generated license files to the resources directory"
103111
group = "licenses"
104112
dependsOn("generateLicenseReport")
105113

106114
doLast {
107-
val sonarLicenseFile = project.layout.projectDirectory.asFile.parentFile.resolve("LICENSE.txt")
115+
val sonarLicenseFile = licenseGenerationConfig.projectLicenseFile.get()
108116
Files.createDirectories(resourceLicenseDir.asFile.toPath())
109117
Files.copy(
110118
sonarLicenseFile.toPath(),

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ val generateSwiftLicenseResources = tasks.register("generateSwiftLicenseResource
127127
}
128128
}
129129

130+
tasks.named("validateLicenseFiles") {
131+
dependsOn(validateSwiftLicenses)
132+
}
133+
134+
tasks.named("generateLicenseResources") {
135+
dependsOn(generateSwiftLicenseResources)
136+
}
137+
130138
/**
131139
* Runs `swift package show-dependencies --format json` in the analyzer directory and parses the output
132140
* to extract non-dev dependency packages (all resolved packages, since Swift SPM dependencies

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ val LICENSE_TITLE_TO_RESOURCE_FILE: Map<String, String> = buildMap {
4444
put("Go License", "Go.txt")
4545
put("MIT License", "MIT.txt")
4646
put("MIT", "MIT.txt")
47+
put("0BSD", "0BSD.txt")
48+
put("GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1", "lgpl-2.1.txt")
4749
}
4850

4951
class AnalyzerLicensingPackagingRenderer(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* SonarSource Cloud Native Gradle Modules
3+
* Copyright (C) 2024-2026 SonarSource Sàrl
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource Sàrl.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
* See the Sonar Source-Available License for more details.
13+
*
14+
* You should have received a copy of the Sonar Source-Available License
15+
* along with this program; if not, see https://sonarsource.com/license/ssal/
16+
*/
17+
package org.sonarsource.cloudnative.gradle
18+
19+
import java.io.File
20+
import org.gradle.api.provider.Property
21+
22+
interface LicenseGenerationConfig {
23+
/** The project's own license file (defaults to LICENSE.txt one level above the project directory). */
24+
val projectLicenseFile: Property<File>
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Permission to use, copy, modify, and/or distribute this
2+
software for any purpose with or without fee is hereby granted.
3+
4+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
5+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
6+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
7+
THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
8+
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
9+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
10+
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
11+
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

0 commit comments

Comments
 (0)