diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2021-11-14 12:10:53 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2021-11-16 00:22:17 +0530 |
commit | c3279e65b74c0fc7c38cdf13a4b98e69b5241254 (patch) | |
tree | 60fe198ec4999d0b5b2d5d8e5d1bf1a16eaf3d45 /build-logic/automation-plugins/src/main/kotlin/tasks | |
parent | cfeca2d3ee149f72d3af18844a78f76aaa9fa790 (diff) |
build-logic: add automation convention plugins
Diffstat (limited to 'build-logic/automation-plugins/src/main/kotlin/tasks')
-rw-r--r-- | build-logic/automation-plugins/src/main/kotlin/tasks/GitHooks.kt | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/build-logic/automation-plugins/src/main/kotlin/tasks/GitHooks.kt b/build-logic/automation-plugins/src/main/kotlin/tasks/GitHooks.kt new file mode 100644 index 00000000..ec045227 --- /dev/null +++ b/build-logic/automation-plugins/src/main/kotlin/tasks/GitHooks.kt @@ -0,0 +1,46 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package tasks + +import java.io.File +import java.nio.file.Files +import java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE +import java.nio.file.attribute.PosixFilePermission.GROUP_READ +import java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE +import java.nio.file.attribute.PosixFilePermission.OTHERS_READ +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.tasks.CacheableTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +@CacheableTask +abstract class GitHooks : DefaultTask() { + @get:Input abstract val hookScript: Property<String> + + @get:OutputFile abstract val hookOutput: Property<File> + + @TaskAction + fun install() { + hookOutput.get().writeText(hookScript.get()) + Files.setPosixFilePermissions( + hookOutput.get().toPath(), + setOf( + OWNER_READ, + OWNER_WRITE, + OWNER_EXECUTE, + GROUP_READ, + GROUP_EXECUTE, + OTHERS_READ, + OTHERS_EXECUTE, + ) + ) + } +} |