Skip to content

Commit

Permalink
Mark Transient, Optional, and Input for keyTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jan 28, 2025
1 parent acc9534 commit 58564d3
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional

/**
* Resources transformer that merges Properties files.
Expand Down Expand Up @@ -122,8 +123,10 @@ public open class PropertiesFileTransformer @Inject constructor(
@get:Input
public open val charsetName: Property<String> = objectFactory.property(Charsets.ISO_8859_1.name())

@get:Internal
public open var keyTransformer: (String) -> String = IDENTITY
@Transient // Input property should be Serializable, but we don't want to serialize the lambda.
@get:Optional
@get:Input
public open var keyTransformer: ((String) -> String)? = null

override fun canTransformResource(element: FileTreeElement): Boolean {
val mappings = mappings.get()
Expand Down Expand Up @@ -173,12 +176,12 @@ public open class PropertiesFileTransformer @Inject constructor(
}

private fun transformKeys(properties: Properties): CleanProperties {
if (keyTransformer == IDENTITY) {
if (keyTransformer == null) {
return properties as CleanProperties
}
val result = CleanProperties()
properties.forEach { (key, value) ->
result[keyTransformer(key as String)] = value
result[keyTransformer!!(key as String)] = value
}
return result
}
Expand Down Expand Up @@ -250,6 +253,5 @@ public open class PropertiesFileTransformer @Inject constructor(

private companion object {
private const val PROPERTIES_SUFFIX = ".properties"
private val IDENTITY = { key: String -> key }
}
}

0 comments on commit 58564d3

Please sign in to comment.