aboutsummaryrefslogtreecommitdiff
path: root/build-logic/automation-plugins
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-10-07 18:06:22 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-10-07 18:06:22 +0530
commit48ae52f9cfef9193207c4697b12873f01db339c5 (patch)
tree70af0e390a9321ea86e3a41d4c639060699a0d4a /build-logic/automation-plugins
parentfe666e9ecb066a5a221c7c8d761760f5928f908b (diff)
refactor(build-logic): make `GitHooksTask` more lazy
Diffstat (limited to 'build-logic/automation-plugins')
-rw-r--r--build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt4
-rw-r--r--build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt22
2 files changed, 17 insertions, 9 deletions
diff --git a/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt b/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt
index 0b2b299c..f1b7c39d 100644
--- a/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt
+++ b/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt
@@ -11,8 +11,8 @@ class GitHooksPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.tasks.register<GitHooks>("installGitHooks") {
val projectDirectory = project.layout.projectDirectory
- hookScript.set(projectDirectory.file("scripts/pre-push-hook.sh").asFile.readText())
- hookOutput.set(projectDirectory.file(".git/hooks/pre-push").asFile)
+ hookSource.set(projectDirectory.file("scripts/pre-push-hook.sh"))
+ hookOutput.set(projectDirectory.file(".git/hooks/pre-push"))
}
}
}
diff --git a/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt b/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt
index f563ada0..37fad7ef 100644
--- a/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt
+++ b/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt
@@ -5,8 +5,8 @@
package app.passwordstore.gradle.tasks
-import java.io.File
import java.nio.file.Files
+import java.nio.file.StandardCopyOption
import java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE
import java.nio.file.attribute.PosixFilePermission.GROUP_READ
import java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE
@@ -15,23 +15,31 @@ import java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE
import java.nio.file.attribute.PosixFilePermission.OWNER_READ
import java.nio.file.attribute.PosixFilePermission.OWNER_WRITE
import org.gradle.api.DefaultTask
-import org.gradle.api.provider.Property
+import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.CacheableTask
-import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
+import org.gradle.api.tasks.PathSensitive
+import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
@CacheableTask
abstract class GitHooks : DefaultTask() {
- @get:Input abstract val hookScript: Property<String>
+ @get:InputFile
+ @get:PathSensitive(PathSensitivity.RELATIVE)
+ abstract val hookSource: RegularFileProperty
- @get:OutputFile abstract val hookOutput: Property<File>
+ @get:OutputFile abstract val hookOutput: RegularFileProperty
@TaskAction
fun install() {
- hookOutput.get().writeText(hookScript.get())
+ Files.copy(
+ hookSource.asFile.get().toPath(),
+ hookOutput.asFile.get().toPath(),
+ StandardCopyOption.REPLACE_EXISTING,
+ )
Files.setPosixFilePermissions(
- hookOutput.get().toPath(),
+ hookOutput.asFile.get().toPath(),
setOf(
OWNER_READ,
OWNER_WRITE,