Hide GerritServer.getGerritConfig and use Guice outside of the class
Everyone else can get the configuration via Guice injection, making it a bit cleaner to expose the configuration data. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.gerrit.client.data.GitwebLink;
|
|||||||
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
||||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
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.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.mail.EmailSender;
|
import com.google.gerrit.server.mail.EmailSender;
|
||||||
import com.google.gerrit.server.ssh.GerritSshDaemon;
|
import com.google.gerrit.server.ssh.GerritSshDaemon;
|
||||||
import com.google.gwtorm.client.OrmException;
|
import com.google.gwtorm.client.OrmException;
|
||||||
@@ -40,6 +41,7 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
|||||||
&& ip.getHostName().equals(ip.getHostAddress());
|
&& ip.getHostName().equals(ip.getHostAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Config cfg;
|
||||||
private final GerritServer server;
|
private final GerritServer server;
|
||||||
private final SchemaFactory<ReviewDb> schema;
|
private final SchemaFactory<ReviewDb> schema;
|
||||||
|
|
||||||
@@ -48,7 +50,9 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
|||||||
private ContactStore contactStore;
|
private ContactStore contactStore;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
GerritConfigProvider(final GerritServer gs, final SchemaFactory<ReviewDb> sf) {
|
GerritConfigProvider(@GerritServerConfig final Config gsc,
|
||||||
|
final GerritServer gs, final SchemaFactory<ReviewDb> sf) {
|
||||||
|
cfg = gsc;
|
||||||
server = gs;
|
server = gs;
|
||||||
schema = sf;
|
schema = sf;
|
||||||
}
|
}
|
||||||
@@ -69,7 +73,6 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GerritConfig create() throws OrmException {
|
private GerritConfig create() throws OrmException {
|
||||||
final Config cfg = server.getGerritConfig();
|
|
||||||
final GerritConfig config = new GerritConfig();
|
final GerritConfig config = new GerritConfig();
|
||||||
config.setCanonicalUrl(server.getCanonicalURL());
|
config.setCanonicalUrl(server.getCanonicalURL());
|
||||||
config.setUseContributorAgreements(cfg.getBoolean("auth",
|
config.setUseContributorAgreements(cfg.getBoolean("auth",
|
||||||
|
|||||||
@@ -316,14 +316,13 @@ public class GerritServer {
|
|||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the parsed <code>$site_path/gerrit.config</code> file. */
|
private Config getGerritConfig() {
|
||||||
public Config getGerritConfig() {
|
|
||||||
return gerritConfigFile;
|
return gerritConfigFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get (or open) a repository by name.
|
* Get (or open) a repository by name.
|
||||||
*
|
*
|
||||||
* @param name the repository name, relative to the base directory.
|
* @param name the repository name, relative to the base directory.
|
||||||
* @return the cached Repository instance. Caller must call {@code close()}
|
* @return the cached Repository instance. Caller must call {@code close()}
|
||||||
* when done to decrement the resource handle.
|
* when done to decrement the resource handle.
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server;
|
package com.google.gerrit.server;
|
||||||
|
|
||||||
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
@@ -42,12 +43,12 @@ class MimeUtilFileTypeRegistry implements FileTypeRegistry {
|
|||||||
private static final Logger log =
|
private static final Logger log =
|
||||||
LoggerFactory.getLogger(MimeUtilFileTypeRegistry.class);
|
LoggerFactory.getLogger(MimeUtilFileTypeRegistry.class);
|
||||||
|
|
||||||
private final GerritServer server;
|
private final Config cfg;
|
||||||
private MimeUtil2 mimeUtil;
|
private MimeUtil2 mimeUtil;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
MimeUtilFileTypeRegistry(final GerritServer gs) {
|
MimeUtilFileTypeRegistry(@GerritServerConfig final Config gsc) {
|
||||||
server = gs;
|
cfg = gsc;
|
||||||
mimeUtil = new MimeUtil2();
|
mimeUtil = new MimeUtil2();
|
||||||
register("eu.medsea.mimeutil.detector.ExtensionMimeDetector");
|
register("eu.medsea.mimeutil.detector.ExtensionMimeDetector");
|
||||||
register("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
|
register("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
|
||||||
@@ -109,7 +110,6 @@ class MimeUtilFileTypeRegistry implements FileTypeRegistry {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Config cfg = server.getGerritConfig();
|
|
||||||
final boolean any = isSafe(cfg, "*/*", false);
|
final boolean any = isSafe(cfg, "*/*", false);
|
||||||
final boolean genericMedia = isSafe(cfg, type.getMediaType() + "/*", any);
|
final boolean genericMedia = isSafe(cfg, type.getMediaType() + "/*", any);
|
||||||
return isSafe(cfg, type.toString(), genericMedia);
|
return isSafe(cfg, type.toString(), genericMedia);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.server.ssh;
|
package com.google.gerrit.server.ssh;
|
||||||
|
|
||||||
import com.google.gerrit.server.GerritServer;
|
import com.google.gerrit.server.GerritServer;
|
||||||
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.config.SitePath;
|
import com.google.gerrit.server.config.SitePath;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -129,10 +130,10 @@ public class GerritSshDaemon extends SshServer {
|
|||||||
@Inject
|
@Inject
|
||||||
public GerritSshDaemon(final GerritServer srv,
|
public GerritSshDaemon(final GerritServer srv,
|
||||||
final CommandFactory commandFactory,
|
final CommandFactory commandFactory,
|
||||||
final PublickeyAuthenticator userAuth, @SitePath final File sitePath) {
|
final PublickeyAuthenticator userAuth, @SitePath final File sitePath,
|
||||||
|
@GerritServerConfig final Config cfg) {
|
||||||
setPort(22/* never used */);
|
setPort(22/* never used */);
|
||||||
|
|
||||||
final Config cfg = srv.getGerritConfig();
|
|
||||||
listen = parseListen(cfg);
|
listen = parseListen(cfg);
|
||||||
reuseAddress = cfg.getBoolean("sshd", "reuseaddress", true);
|
reuseAddress = cfg.getBoolean("sshd", "reuseaddress", true);
|
||||||
keepAlive = cfg.getBoolean("sshd", "tcpkeepalive", true);
|
keepAlive = cfg.getBoolean("sshd", "tcpkeepalive", true);
|
||||||
|
|||||||
Reference in New Issue
Block a user