use of com.gitblit.utils.ClientLogger in project gitblit by gitblit.
the class GitblitReceivePack method runGroovy.
/**
* Runs the specified Groovy hook scripts.
*
* @param repository
* @param user
* @param commands
* @param scripts
*/
private void runGroovy(Collection<ReceiveCommand> commands, Set<String> scripts) {
if (scripts == null || scripts.size() == 0) {
// no Groovy scripts to execute
return;
}
Binding binding = new Binding();
binding.setVariable("gitblit", gitblit);
binding.setVariable("repository", repository);
binding.setVariable("receivePack", this);
binding.setVariable("user", user);
binding.setVariable("commands", commands);
binding.setVariable("url", gitblitUrl);
binding.setVariable("logger", LOGGER);
binding.setVariable("clientLogger", new ClientLogger(this));
for (String script : scripts) {
if (StringUtils.isEmpty(script)) {
continue;
}
// allow script to be specified without .groovy extension
// this is easier to read in the settings
File file = new File(groovyDir, script);
if (!file.exists() && !script.toLowerCase().endsWith(".groovy")) {
file = new File(groovyDir, script + ".groovy");
if (file.exists()) {
script = file.getName();
}
}
try {
Object result = gse.run(script, binding);
if (result instanceof Boolean) {
if (!((Boolean) result)) {
LOGGER.error(MessageFormat.format("Groovy script {0} has failed! Hook scripts aborted.", script));
break;
}
}
} catch (Exception e) {
LOGGER.error(MessageFormat.format("Failed to execute Groovy script {0}", script), e);
}
}
}
Aggregations