Skip to content

Commit 1d20461

Browse files
committed
Use properties in CopyFile task
1 parent 0a489fa commit 1d20461

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ private fun Project.configureCheckTasks(
308308
isEnabled = apiCheckEnabled(projectName, extension) && apiBuild.map { it.enabled }.getOrElse(true)
309309
group = "other"
310310
description = "Syncs API from build dir to ${targetConfig.apiDir} dir for $projectName"
311-
from = apiBuildDir.get().resolve(dumpFileName)
312-
to = apiCheckDir.get().resolve(dumpFileName)
311+
from.fileProvider(apiBuildDir.map { it.resolve(dumpFileName) })
312+
to.fileProvider(apiCheckDir.map { it.resolve(dumpFileName) })
313313
dependsOn(apiBuild)
314314
}
315315

@@ -385,12 +385,15 @@ private class KlibValidationPipelineBuilder(
385385

386386
val klibMerge = project.mergeKlibsUmbrellaTask(klibDumpConfig, klibMergeDir)
387387
val klibMergeInferred = project.mergeInferredKlibsUmbrellaTask(klibDumpConfig, klibMergeInferredDir)
388-
val klibDump = project.dumpKlibsTask(klibDumpConfig, klibApiDir, klibMergeInferredDir)
388+
val klibDump = project.dumpKlibsTask(klibDumpConfig)
389389
val klibExtractAbiForSupportedTargets = project.extractAbi(klibDumpConfig, klibApiDir, klibExtractedFileDir)
390390
val klibCheck = project.checkKlibsTask(klibDumpConfig, project.provider { klibExtractedFileDir }, klibMergeDir)
391-
391+
klibDump.configure {
392+
it.from.set(klibMergeInferred.flatMap { it.mergedApiFile })
393+
val filename = project.klibDumpFileName
394+
it.to.fileProvider(klibApiDir.map { it.resolve(filename) })
395+
}
392396
commonApiDump.configure { it.dependsOn(klibDump) }
393-
commonApiCheck.configure { it.dependsOn(klibCheck) }
394397

395398
klibDump.configure { it.dependsOn(klibMergeInferred) }
396399
// Extraction task depends on supportedTargets() provider which returns a set of targets supported
@@ -404,7 +407,7 @@ private class KlibValidationPipelineBuilder(
404407
klibCheck.configure {
405408
it.dependsOn(klibExtractAbiForSupportedTargets)
406409
}
407-
410+
commonApiCheck.configure { it.dependsOn(klibCheck) }
408411
project.configureTargets(klibApiDir, klibMerge, klibMergeInferred)
409412
}
410413

@@ -423,16 +426,10 @@ private class KlibValidationPipelineBuilder(
423426
onlyIf("There are no klibs compiled for the project") { hasCompilableTargets.get() }
424427
}
425428

426-
private fun Project.dumpKlibsTask(
427-
klibDumpConfig: TargetConfig,
428-
klibApiDir: Provider<File>,
429-
klibMergeDir: File
430-
) = project.task<CopyFile>(klibDumpConfig.apiTaskName("Dump")) {
429+
private fun Project.dumpKlibsTask(klibDumpConfig: TargetConfig) = project.task<CopyFile>(klibDumpConfig.apiTaskName("Dump")) {
431430
isEnabled = klibAbiCheckEnabled(project.name, extension)
432431
description = "Syncs a KLib ABI dump from a build dir to the ${klibDumpConfig.apiDir} dir for ${project.name}"
433432
group = "other"
434-
from = klibMergeDir.resolve(klibDumpFileName)
435-
to = klibApiDir.get().resolve(klibDumpFileName)
436433
val hasCompilableTargets = project.hasCompilableTargetsPredicate()
437434
onlyIf("There are no klibs compiled for the project") { hasCompilableTargets.get() }
438435
}

src/main/kotlin/CopyFile.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package kotlinx.validation
77

88
import org.gradle.api.DefaultTask
9+
import org.gradle.api.file.RegularFileProperty
10+
import org.gradle.api.tasks.InputFile
911
import org.gradle.api.tasks.InputFiles
1012
import org.gradle.api.tasks.OutputFile
1113
import org.gradle.api.tasks.TaskAction
@@ -17,15 +19,15 @@ import java.nio.file.StandardCopyOption
1719
// and registers it as an output dependency. If there's another task reading from that particular
1820
// directory or writing into it, their input/output dependencies would clash and as long as
1921
// there will be no explicit ordering or dependencies between these tasks, Gradle would be unhappy.
20-
internal open class CopyFile : DefaultTask() {
21-
@InputFiles
22-
lateinit var from: File
22+
internal abstract class CopyFile : DefaultTask() {
23+
@get:InputFile
24+
abstract val from: RegularFileProperty
2325

24-
@OutputFile
25-
lateinit var to: File
26+
@get:OutputFile
27+
abstract val to: RegularFileProperty
2628

2729
@TaskAction
2830
fun copy() {
29-
Files.copy(from.toPath(), to.toPath(), StandardCopyOption.REPLACE_EXISTING)
31+
Files.copy(from.asFile.get().toPath(), to.asFile.get().toPath(), StandardCopyOption.REPLACE_EXISTING)
3032
}
3133
}

0 commit comments

Comments
 (0)