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.ReviewDb;
|
||||
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.ssh.GerritSshDaemon;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
@@ -40,6 +41,7 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
&& ip.getHostName().equals(ip.getHostAddress());
|
||||
}
|
||||
|
||||
private final Config cfg;
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
|
||||
@@ -48,7 +50,9 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
private ContactStore contactStore;
|
||||
|
||||
@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;
|
||||
schema = sf;
|
||||
}
|
||||
@@ -69,7 +73,6 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
}
|
||||
|
||||
private GerritConfig create() throws OrmException {
|
||||
final Config cfg = server.getGerritConfig();
|
||||
final GerritConfig config = new GerritConfig();
|
||||
config.setCanonicalUrl(server.getCanonicalURL());
|
||||
config.setUseContributorAgreements(cfg.getBoolean("auth",
|
||||
|
||||
@@ -316,14 +316,13 @@ public class GerritServer {
|
||||
return u;
|
||||
}
|
||||
|
||||
/** Get the parsed <code>$site_path/gerrit.config</code> file. */
|
||||
public Config getGerritConfig() {
|
||||
private Config getGerritConfig() {
|
||||
return gerritConfigFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get (or open) a repository by name.
|
||||
*
|
||||
*
|
||||
* @param name the repository name, relative to the base directory.
|
||||
* @return the cached Repository instance. Caller must call {@code close()}
|
||||
* when done to decrement the resource handle.
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server;
|
||||
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -42,12 +43,12 @@ class MimeUtilFileTypeRegistry implements FileTypeRegistry {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(MimeUtilFileTypeRegistry.class);
|
||||
|
||||
private final GerritServer server;
|
||||
private final Config cfg;
|
||||
private MimeUtil2 mimeUtil;
|
||||
|
||||
@Inject
|
||||
MimeUtilFileTypeRegistry(final GerritServer gs) {
|
||||
server = gs;
|
||||
MimeUtilFileTypeRegistry(@GerritServerConfig final Config gsc) {
|
||||
cfg = gsc;
|
||||
mimeUtil = new MimeUtil2();
|
||||
register("eu.medsea.mimeutil.detector.ExtensionMimeDetector");
|
||||
register("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
|
||||
@@ -109,7 +110,6 @@ class MimeUtilFileTypeRegistry implements FileTypeRegistry {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Config cfg = server.getGerritConfig();
|
||||
final boolean any = isSafe(cfg, "*/*", false);
|
||||
final boolean genericMedia = isSafe(cfg, type.getMediaType() + "/*", any);
|
||||
return isSafe(cfg, type.toString(), genericMedia);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.ssh;
|
||||
|
||||
import com.google.gerrit.server.GerritServer;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -129,10 +130,10 @@ public class GerritSshDaemon extends SshServer {
|
||||
@Inject
|
||||
public GerritSshDaemon(final GerritServer srv,
|
||||
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 */);
|
||||
|
||||
final Config cfg = srv.getGerritConfig();
|
||||
listen = parseListen(cfg);
|
||||
reuseAddress = cfg.getBoolean("sshd", "reuseaddress", true);
|
||||
keepAlive = cfg.getBoolean("sshd", "tcpkeepalive", true);
|
||||
|
||||
Reference in New Issue
Block a user