/* * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. * SPDX-License-Identifier: GPL-3.0-only */ 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 @get:OutputFile abstract val hookOutput: Property @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, ) ) } }