Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,6 @@ private fun Project.configureResourceAccessorsGeneration(
task.packagingDir.set(packagingDir)
}
task.onlyIf { shouldGenerateCode.get() }
task.generateResourceContentHashAnnotation.set(
project.providers
.systemProperty("compose.resources.generate.ResourceContentHash.annotation")
.map { it.toBoolean() }
.orElse(false)
)
}

//register generated source set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ import java.io.File
import java.nio.file.Path
import kotlin.io.path.relativeTo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please specify Release Notes, with an example how to set this new property

internal abstract class GenerateResourceAccessorsTask : IdeaImportTask() {
/**
* Configuration for resource accessors generation.
*
* ### Properties
* - `generateResourceContentHashAnnotation`:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not by KDoc format. It needs to be moved this way:

/**
 * Configuration for resource accessors generation.
 */
interface ResourceAccessorsConfiguration {
    /**
     * A property that defines whether to generate `@ResourceContentHash` annotation for resource accessors.
     */
    val generateResourceContentHashAnnotation: Property<Boolean>
}

Please, also describe what is ResourceContentHash and why it is needed to override the behavior. Even if it is only for one client, maintainers should understand why this is added.

* A property that defines whether to generate @ResourceContentHash annotation for resource accessors.
*/
interface ResourceAccessorsConfiguration {
val generateResourceContentHashAnnotation: Property<Boolean>
}

internal abstract class GenerateResourceAccessorsTask : IdeaImportTask(), ResourceAccessorsConfiguration {
@get:Input
abstract val packageName: Property<String>

Expand All @@ -32,7 +43,7 @@ internal abstract class GenerateResourceAccessorsTask : IdeaImportTask() {
abstract val makeAccessorsPublic: Property<Boolean>

@get:Input
abstract val generateResourceContentHashAnnotation: Property<Boolean>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an init block with:

init {
  generateResourceContentHashAnnotation.convention(false)
}

https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html#convention(T)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

abstract override val generateResourceContentHashAnnotation: Property<Boolean>

@get:InputFiles
@get:SkipWhenEmpty
Expand All @@ -42,6 +53,10 @@ internal abstract class GenerateResourceAccessorsTask : IdeaImportTask() {
@get:OutputDirectory
abstract val codeDir: DirectoryProperty

init {
generateResourceContentHashAnnotation.convention(false)
}

override fun safeAction() {
val kotlinDir = codeDir.get().asFile
val rootResDir = resDir.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,18 @@ class ResourcesTest : GradlePluginTestBase() {

@Test
fun testGeneratedAccessorsAnnotatedWithResourceContentHash(): Unit = with(testProject("misc/commonResources")) {
file("build.gradle.kts").appendText(
"""
tasks.configureEach {
if (this is org.jetbrains.compose.resources.ResourceAccessorsConfiguration) {
generateResourceContentHashAnnotation.set(true)
}
}
""".trimIndent()
)

//check generated resource's accessors
gradle("prepareKotlinIdeaImport", "-Dcompose.resources.generate.ResourceContentHash.annotation=true").checks {
gradle("prepareKotlinIdeaImport").checks {
val expected = if (System.getProperty("os.name").lowercase().contains("windows")) {
// Windows has different line endings in comparison with Unixes,
// thus the XML resource files differ and produce different content hashes,
Expand Down