Skip to content

Commit

Permalink
Special case another license name
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Oct 15, 2024
1 parent 3185ba2 commit 9984464
Showing 1 changed file with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,13 @@
*/
package app.cash.licensee

import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.LIST
import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.MemberName.Companion.member
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.STRING
import com.squareup.kotlinpoet.TypeSpec
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.*

@CacheableTask
abstract class GenerateSpdxIdTask : DefaultTask() {
Expand Down Expand Up @@ -67,14 +55,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

0 comments on commit 9984464

Please sign in to comment.