Skip to content

Commit d83f69f

Browse files
committed
Add report for 3rd party dependencies
1 parent 6e6f40e commit d83f69f

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

.ci/make.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ output_mount="-v $repo/.ci/output:/elasticsearch-java/build"
137137
build_image() {
138138
echo -e "\033[34;1mINFO: building $product container\033[0m"
139139

140-
141140
docker build --file .ci/Dockerfile --tag $docker_image \
142141
--build-arg USER_ID="$(id -u)" \
143142
--build-arg GROUP_ID="$(id -g)" .
@@ -155,6 +154,7 @@ if [[ "$CMD" == "assemble" ]]; then
155154
publishForReleaseManager
156155

157156
if compgen -G ".ci/output/release/*" > /dev/null; then
157+
cp .ci/output/release/dependencies.csv "$DEPENDENCIES_REPORTS_DIR"/"$DEPENDENCIES_REPORT"
158158
echo -e "\033[32;1mTARGET: successfully assembled client version $VERSION\033[0m"
159159
else
160160
echo -e "\033[31;1mTARGET: assemble failed, empty workspace!\033[0m"

build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ tasks.register<Task>(name = "resolveDependencies") {
5353
tasks.register<Task>(name = "publishForReleaseManager") {
5454
group = "Publishing"
5555
description = "Publishes artifacts in a format suitable for the Elastic release manager"
56-
dependsOn(":java-client:publishAllPublicationsToBuildRepository")
56+
dependsOn(
57+
":java-client:publishAllPublicationsToBuildRepository",
58+
":java-client:generateLicenseReport"
59+
)
5760
doLast {
5861
val version = this.project.version.toString()
5962
val isSnapshot = version.endsWith("SNAPSHOT")

java-client/build.gradle.kts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
* under the License.
1818
*/
1919

20-
import java.time.ZoneOffset
20+
import com.github.jk1.license.ProjectData
21+
import com.github.jk1.license.render.ReportRenderer
22+
import java.io.FileWriter
2123

2224
plugins {
2325
java
2426
checkstyle
2527
`maven-publish`
28+
id("com.github.jk1.dependency-license-report") version "1.17"
2629
}
2730

2831
java {
@@ -144,3 +147,55 @@ dependencies {
144147
testImplementation("org.testcontainers", "testcontainers", "1.15.3")
145148
testImplementation("org.testcontainers", "elasticsearch", "1.15.3")
146149
}
150+
151+
152+
licenseReport {
153+
renderers = arrayOf(SpdxReporter(File(rootProject.buildDir, "release/dependencies.csv")))
154+
excludeGroups = arrayOf("org.elasticsearch.client")
155+
}
156+
157+
class SpdxReporter(val dest: File) : ReportRenderer {
158+
// License names to their SPDX identifier
159+
val spdxIds = mapOf(
160+
"Apache License, Version 2.0" to "Apache-2.0",
161+
"The Apache Software License, Version 2.0" to "Apache-2.0",
162+
"BSD Zero Clause License" to "0BSD",
163+
"Eclipse Public License 2.0" to "EPL-2.0",
164+
"Eclipse Public License v. 2.0" to "EPL-2.0",
165+
"GNU General Public License, version 2 with the GNU Classpath Exception" to "GPL-2.0 WITH Classpath-exception-2.0",
166+
"COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" to "CDDL-1.0"
167+
)
168+
169+
private fun quote(str: String) : String {
170+
return if (str.contains(',') || str.contains("\"")) {
171+
"\"" + str.replace("\"", "\"\"") + "\""
172+
} else {
173+
str
174+
}
175+
}
176+
177+
override fun render(data: ProjectData?) {
178+
dest.parentFile.mkdirs()
179+
FileWriter(dest).use { out ->
180+
out.append("name,url,version,revision,license\n")
181+
data?.allDependencies?.forEach { dep ->
182+
val info = com.github.jk1.license.render.LicenseDataCollector.multiModuleLicenseInfo(dep)
183+
184+
val depVersion = dep.version
185+
val depName = dep.group + ":" + dep.name
186+
val depUrl = info.moduleUrls.first()
187+
188+
val licenseIds = info.licenses.mapNotNull { license ->
189+
license.name?.let {
190+
checkNotNull(spdxIds[it]) { "No SPDX identifier for $license" }
191+
}
192+
}.toSet()
193+
194+
// Combine multiple licenses.
195+
// See https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/#composite-license-expressions
196+
val licenseId = licenseIds.joinToString(" OR ")
197+
out.append("${quote(depName)},${quote(depUrl)},${quote(depVersion)},,${quote(licenseId)}\n")
198+
}
199+
}
200+
}
201+
}

0 commit comments

Comments
 (0)