if (hookProcess == null) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.REPOS_HOOK_FAILURE, "Failed to start ''{0}'' hook", hook);
SVNErrorManager.error(err, SVNLogType.FSFS);
}
SVNStreamGobbler inputGobbler = new SVNStreamGobbler(hookProcess.getInputStream());
SVNStreamGobbler errorGobbler = new SVNStreamGobbler(hookProcess.getErrorStream());
inputGobbler.start();
errorGobbler.start();
if (stdInValue != null) {
OutputStream osToStdIn = hookProcess.getOutputStream();
try {
for (int i = 0; i < stdInValue.length; i += 1024) {
osToStdIn.write(stdInValue, i, Math.min(1024, stdInValue.length - i));
osToStdIn.flush();
}
} catch (IOException ioe) {
//
} finally {
SVNFileUtil.closeFile(osToStdIn);
}
}
int rc = -1;
try {
inputGobbler.waitFor();
errorGobbler.waitFor();
rc = hookProcess.waitFor();
} catch (InterruptedException ie) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.REPOS_HOOK_FAILURE, "Failed to start ''{0}'' hook: {1}", new Object[] {
hook, ie.getLocalizedMessage()
});
SVNErrorManager.error(err, ie, SVNLogType.FSFS);
} finally {
errorGobbler.close();
inputGobbler.close();
hookProcess.destroy();
}
if (rc == 0 ) {
if (errorGobbler.getError() != null) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.REPOS_HOOK_FAILURE, "''{0}'' hook succeeded, but error output could not be read", hookName);
SVNErrorManager.error(err, errorGobbler.getError(), SVNLogType.FSFS);
}
} else {
String actionName = null;
if (SVN_REPOS_HOOK_START_COMMIT.equals(hookName) || SVN_REPOS_HOOK_PRE_COMMIT.equals(hookName)) {
actionName = "Commit";
} else if (SVN_REPOS_HOOK_PRE_REVPROP_CHANGE.equals(hookName)) {
actionName = "Revprop change";
} else if (SVN_REPOS_HOOK_PRE_LOCK.equals(hookName)) {
actionName = "Lock";
} else if (SVN_REPOS_HOOK_PRE_UNLOCK.equals(hookName)) {
actionName = "Unlock";
}
String stdErrMessage = errorGobbler.getError() != null ? "[Error output could not be read.]" : errorGobbler.getResult();
String errorMessage = actionName != null ?
actionName + " blocked by {0} hook (exit code {1})" : "{0} hook failed (exit code {1})";
if (stdErrMessage != null && stdErrMessage.length() > 0) {
errorMessage += " with output:\n{2}";
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.REPOS_HOOK_FAILURE, errorMessage, new Object[] {hookName, new Integer(rc), stdErrMessage});