Skip to content

Commit

Permalink
Update and sort licenses (#366)
Browse files Browse the repository at this point in the history
* Sort licenses after download

* Update licenses to latest

* Special case another license name
  • Loading branch information
JakeWharton authored Oct 15, 2024
1 parent 1a2d2ca commit 067b876
Show file tree
Hide file tree
Showing 3 changed files with 8,383 additions and 8,003 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
Expand Down Expand Up @@ -122,6 +124,13 @@ tasks.register("downloadLicensesJson", Copy) {
}
}
into(jsonFolder)

doLast {
def destFile = jsonFile.asFile
def json = new JsonSlurper().parse(destFile)
json.licenses = json.licenses.sort { a, b -> a.licenseId <=> b.licenseId }
destFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(json))
}
}

TaskProvider<app.cash.licensee.GenerateSpdxIdTask> generateSpdx = tasks.register('generateSpdx', app.cash.licensee.GenerateSpdxIdTask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ private fun SpdxLicenses.generate(): FileSpec {
private val SpdxId: ClassName = ClassName("app.cash.licensee", "SpdxId")
private val SpdxIdCompanion: ClassName = SpdxId.nestedClass("Companion")

private val SpdxLicenseJson.identifier: String get() = if (id == "0BSD") {
"ZeroBSD" // hardcoded because it is the only id starting with a digit.
} else {
id
.replace("-", "_")
.replace(".", "")
.replace("+", "Plus")
}
private val SpdxLicenseJson.identifier: String
get() = when (id) {
// Special-case IDs which start with a digit:
"0BSD" -> "ZeroBSD"
"3D-Slicer-1.0" -> "ThreeD_Slicer_10"
else -> {
id
.replace("-", "_")
.replace(".", "")
.replace("+", "Plus")
}
}

private fun SpdxLicenses.addSpdxIdInterface(): TypeSpec = TypeSpec.classBuilder("SpdxId").apply {
primaryConstructor(
Expand Down
Loading

0 comments on commit 067b876

Please sign in to comment.