Repository: JetBrains/kotlin
File: libraries/tools/kotlin-compose-compiler/src/common/kotlin/org/jetbrains/kotlin/compose/compiler/gradle/internal/ComposeAgpMappingFile.kt (Kotlin)

Code before:

@CacheableTask
internal abstract class MergeMappingFileTask @Inject constructor(
    objects: ObjectFactory,
    providers: ProviderFactory
) : DefaultTask() {

    @get:InputFile
    @get:PathSensitive(PathSensitivity.RELATIVE)
    abstract val originalFile: RegularFileProperty

    @get:InputFiles
    @get:PathSensitive(PathSensitivity.RELATIVE)
    val r8Outputs: FileCollection = objects.fileCollection()
        .from(originalFile.asFile.map { it.parentFile })
        .asFileTree

    @get:InputFile
    @get:PathSensitive(PathSensitivity.RELATIVE)
    abstract val composeMapping: RegularFileProperty

    @get:OutputFile
    abstract val output: RegularFileProperty

    @get:OutputDirectory
    val outputDir: Provider<File> = providers.provider { output.get().asFile.parentFile }

    @TaskAction
    fun taskAction() {
        /*
         * Read the proguard file generated by R8, calculate the new SHA-256 hash for the header, and append Compose mapping.
         */
        val newHeader = buildHeader()

        val originalFile = originalFile.get().asFile

        val outputFile = output.get().asFile
        val outputDir = outputDir.get()

        outputFile.bufferedWriter().use { writer ->
            writer.append(newHeader)

            var skippingHeader = true
            originalFile.forEachLine {
                if (skippingHeader && it.startsWith("#")) {
                    return@forEachLine
                }
                skippingHeader = false

                writer.appendLine(it)
            }

Review comment (suggestion):
```suggestion
    val outputDir: DirectoryProperty = objects.directoryProperty().fileProvider(output.map { it.asFile.parentFile })
```

Code after:

@CacheableTask
internal abstract class MergeMappingFileTask @Inject constructor(
    objects: ObjectFactory,
    providers: ProviderFactory
) : DefaultTask() {

    @get:InputFile
    @get:PathSensitive(PathSensitivity.RELATIVE)
    abstract val originalFile: RegularFileProperty

    @get:InputFiles
    @get:PathSensitive(PathSensitivity.RELATIVE)
    val r8Outputs: FileCollection = objects.fileCollection()
        .from(originalFile.asFile.map { it.parentFile })
        .asFileTree

    @get:InputFile
    @get:PathSensitive(PathSensitivity.RELATIVE)
    abstract val composeMapping: RegularFileProperty

    @get:OutputFile
    abstract val output: RegularFileProperty

    @get:OutputDirectory
    val outputDir: Provider<File> = providers.provider { output.get().asFile.parentFile }

    @TaskAction
    fun taskAction() {
        /*
         * Read the proguard file generated by R8, calculate the new SHA-256 hash for the header, and append Compose mapping.
         */
        val newHeader = buildHeader()

        val originalFile = originalFile.get().asFile

        val outputFile = output.get().asFile
        val outputDir = outputDir.get()

        outputDir.deleteRecursively()
        outputDir.mkdirs()

        outputFile.bufferedWriter().use { writer ->
            writer.append(newHeader)

            var skippingHeader = true
            originalFile.forEachLine {
                if (skippingHeader && it.startsWith("#")) {
                    return@forEachLine
                }
                skippingHeader = false