1

refac: смена группы и пакета

This commit is contained in:
2025-08-19 14:07:13 +03:00
parent 51cf6fc83c
commit d27769b950
5 changed files with 9 additions and 9 deletions

View File

@@ -0,0 +1,55 @@
package ru.di9.gradle.githooks
import org.gradle.api.DefaultTask
import org.gradle.api.InvalidUserDataException
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.tasks.TaskAction
import java.nio.file.Path
class GitHooksTask extends DefaultTask {
private static final String hookDir = ".git/hooks"
private static final List<String> hooks = [
"applypatch-msg",
"commit-msg",
"fsmonitor-watchman",
"post-update",
"pre-applypatch",
"pre-commit",
"pre-merge-commit",
"prepare-commit-msg",
"pre-push",
"pre-rebase",
"pre-receive",
"push-to-checkout",
"sendemail-validate",
"update"
]
@TaskAction
void execute() throws IOException {
def gitHooks = getProject().getExtensions().getByName("githooks") as NamedDomainObjectContainer<GitHook>
gitHooks.each { hook ->
if (!hooks.contains(hook.name)) {
throw new InvalidUserDataException("Unknown hook '${hook.name}'")
}
if (hook.task == null || hook.task.isEmpty() || hook.task.isBlank()) {
throw new InvalidUserDataException("Error set hook '${hook.task}': field 'task' must not be empty")
}
def hookFile = Path.of(hookDir, hook.name).toFile()
if (hookFile.exists()) {
logger.warn("Hook '${hook.name}' already exists. It will be overwritten.")
}
hookFile.write(
"""#!/bin/sh
|./gradlew --console=plain -q ${hook.task}"""
.stripMargin())
hookFile.setExecutable(true)
}
}
}