Pass GerritServer down through SSH command factory

This avoids trying to do a static instance member lookup.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-07-27 21:29:36 -07:00
parent d058b3ebb0
commit b90d4aa90e
3 changed files with 10 additions and 11 deletions

View File

@@ -22,7 +22,6 @@ import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common; import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.BaseServiceImplementation; import com.google.gerrit.server.BaseServiceImplementation;
import com.google.gerrit.server.GerritServer; import com.google.gerrit.server.GerritServer;
import com.google.gwtjsonrpc.server.XsrfException;
import com.google.gwtorm.client.OrmException; import com.google.gwtorm.client.OrmException;
import org.apache.sshd.common.SshException; import org.apache.sshd.common.SshException;
@@ -60,6 +59,7 @@ abstract class AbstractCommand implements Command, SessionAware {
protected OutputStream err; protected OutputStream err;
protected ExitCallback exit; protected ExitCallback exit;
protected ServerSession session; protected ServerSession session;
protected GerritServer server;
protected ReviewDb db; protected ReviewDb db;
private String name; private String name;
@@ -94,14 +94,8 @@ abstract class AbstractCommand implements Command, SessionAware {
return new PrintWriter(new BufferedWriter(new OutputStreamWriter(o, ENC))); return new PrintWriter(new BufferedWriter(new OutputStreamWriter(o, ENC)));
} }
protected GerritServer getGerritServer() throws Failure { protected GerritServer getGerritServer() {
try { return server;
return GerritServer.getInstance();
} catch (OrmException e) {
throw new Failure(128, "fatal: Gerrit is not available", e);
} catch (XsrfException e) {
throw new Failure(128, "fatal: Gerrit is not available", e);
}
} }
protected ReviewDb openReviewDb() throws Failure { protected ReviewDb openReviewDb() throws Failure {

View File

@@ -14,15 +14,19 @@
package com.google.gerrit.server.ssh; package com.google.gerrit.server.ssh;
import com.google.gerrit.server.GerritServer;
import org.apache.sshd.server.CommandFactory; import org.apache.sshd.server.CommandFactory;
import java.util.HashMap; import java.util.HashMap;
/** Creates a command implementation based on the client input. */ /** Creates a command implementation based on the client input. */
class GerritCommandFactory implements CommandFactory { class GerritCommandFactory implements CommandFactory {
private final GerritServer server;
private final HashMap<String, Factory> commands; private final HashMap<String, Factory> commands;
GerritCommandFactory() { GerritCommandFactory(final GerritServer gs) {
server = gs;
commands = new HashMap<String, Factory>(); commands = new HashMap<String, Factory>();
commands.put("gerrit-upload-pack", new Factory() { commands.put("gerrit-upload-pack", new Factory() {
@@ -103,6 +107,7 @@ class GerritCommandFactory implements CommandFactory {
} }
final AbstractCommand c = create(cmd); final AbstractCommand c = create(cmd);
c.server = server;
c.setCommandLine(cmd, args); c.setCommandLine(cmd, args);
return c; return c;
} }

View File

@@ -234,7 +234,7 @@ public class GerritSshDaemon extends SshServer {
initCompression(); initCompression();
initUserAuth(srv); initUserAuth(srv);
setKeyPairProvider(initHostKey(srv)); setKeyPairProvider(initHostKey(srv));
setCommandFactory(new GerritCommandFactory()); setCommandFactory(new GerritCommandFactory(srv));
setShellFactory(new NoShell()); setShellFactory(new NoShell());
setSessionFactory(new SessionFactory() { setSessionFactory(new SessionFactory() {
@Override @Override