From c57c48e1eba38aa2c9d68a968bfb3d608b5931d4 Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Sat, 5 May 2012 21:40:22 +0100 Subject: [PATCH] Set GERRIT_SITE in Gerrit Hooks as env. variable. Allows development of hooks parametrised on Gerrit location. This can be useful to allow hooks to load Gerrit configuration when needed (from $GERRIT_SITE) or even store their additional config files under $GERRIT_SITE/etc and retrieve them at startup. Change-Id: I642c73ab2a5efd875e17f384a0870893b8bbd3fe Signed-off-by: Luca Milanesio --- .../com/google/gerrit/common/ChangeHookRunner.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/common/ChangeHookRunner.java b/gerrit-server/src/main/java/com/google/gerrit/common/ChangeHookRunner.java index 09c33c0573..727207fca6 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/common/ChangeHookRunner.java +++ b/gerrit-server/src/main/java/com/google/gerrit/common/ChangeHookRunner.java @@ -30,6 +30,7 @@ import com.google.gerrit.server.account.AccountCache; import com.google.gerrit.server.account.AccountState; import com.google.gerrit.server.config.AnonymousCowardName; import com.google.gerrit.server.config.GerritServerConfig; +import com.google.gerrit.server.config.SitePath; import com.google.gerrit.server.config.SitePaths; import com.google.gerrit.server.events.ApprovalAttribute; import com.google.gerrit.server.events.ChangeAbandonedEvent; @@ -133,6 +134,8 @@ public class ChangeHookRunner implements ChangeHooks { private final EventFactory eventFactory; + private final SitePaths sitePaths; + /** * Create a new ChangeHookRunner. * @@ -149,7 +152,7 @@ public class ChangeHookRunner implements ChangeHooks { final @AnonymousCowardName String anonymousCowardName, final SitePaths sitePath, final ProjectCache projectCache, final AccountCache accountCache, final ApprovalTypes approvalTypes, - final EventFactory eventFactory) { + final EventFactory eventFactory, final SitePaths sitePaths) { this.anonymousCowardName = anonymousCowardName; this.repoManager = repoManager; this.hookQueue = queue.createQueue(1, "hook"); @@ -157,6 +160,7 @@ public class ChangeHookRunner implements ChangeHooks { this.accountCache = accountCache; this.approvalTypes = approvalTypes; this.eventFactory = eventFactory; + this.sitePaths = sitePath; final File hooksPath = sitePath.resolve(getValue(config, "hooks", "path", sitePath.hooks_dir.getAbsolutePath())); @@ -481,10 +485,12 @@ public class ChangeHookRunner implements ChangeHooks { repo = openRepository(project); } + final Map env = pb.environment(); + env.put("GERRIT_SITE", sitePaths.site_path.getAbsolutePath()); + if (repo != null) { pb.directory(repo.getDirectory()); - final Map env = pb.environment(); env.put("GIT_DIR", repo.getDirectory().getAbsolutePath()); }