Remove usage of GerritConfig from GitWebServlet
Instead of injecting GerritConfig into GitWebServlet inject what is needed to get the SSHD listen address and the canonical git URL, since this is everything GitWebServlet needs. Removing the injection of GerritConfig allows us to remove the SSHD listen address and the canonical git URL from GerritConfig and in a later step to get rid of GerritConfig. Change-Id: I74c134edb34a26a49424c4ee1337dab642c249f3 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -16,29 +16,8 @@ package com.google.gerrit.common.data;
|
|||||||
|
|
||||||
|
|
||||||
public class GerritConfig implements Cloneable {
|
public class GerritConfig implements Cloneable {
|
||||||
protected String gitDaemonUrl;
|
|
||||||
protected String sshdAddress;
|
|
||||||
protected boolean documentationAvailable;
|
protected boolean documentationAvailable;
|
||||||
|
|
||||||
public String getGitDaemonUrl() {
|
|
||||||
return gitDaemonUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGitDaemonUrl(String url) {
|
|
||||||
if (url != null && !url.endsWith("/")) {
|
|
||||||
url += "/";
|
|
||||||
}
|
|
||||||
gitDaemonUrl = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSshdAddress() {
|
|
||||||
return sshdAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSshdAddress(final String addr) {
|
|
||||||
sshdAddress = addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDocumentationAvailable() {
|
public boolean isDocumentationAvailable() {
|
||||||
return documentationAvailable;
|
return documentationAvailable;
|
||||||
}
|
}
|
||||||
|
@@ -15,44 +15,26 @@
|
|||||||
package com.google.gerrit.httpd;
|
package com.google.gerrit.httpd;
|
||||||
|
|
||||||
import com.google.gerrit.common.data.GerritConfig;
|
import com.google.gerrit.common.data.GerritConfig;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
|
||||||
import com.google.gerrit.server.ssh.SshInfo;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.ProvisionException;
|
import com.google.inject.ProvisionException;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.Config;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
class GerritConfigProvider implements Provider<GerritConfig> {
|
class GerritConfigProvider implements Provider<GerritConfig> {
|
||||||
private final Config cfg;
|
|
||||||
private final SshInfo sshInfo;
|
|
||||||
|
|
||||||
private final ServletContext servletContext;
|
private final ServletContext servletContext;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
GerritConfigProvider(
|
GerritConfigProvider(ServletContext sc) {
|
||||||
@GerritServerConfig Config gsc,
|
|
||||||
SshInfo si,
|
|
||||||
ServletContext sc) {
|
|
||||||
cfg = gsc;
|
|
||||||
sshInfo = si;
|
|
||||||
servletContext = sc;
|
servletContext = sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GerritConfig create() throws MalformedURLException {
|
private GerritConfig create() throws MalformedURLException {
|
||||||
final GerritConfig config = new GerritConfig();
|
final GerritConfig config = new GerritConfig();
|
||||||
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
|
|
||||||
config.setDocumentationAvailable(servletContext
|
config.setDocumentationAvailable(servletContext
|
||||||
.getResource("/Documentation/index.html") != null);
|
.getResource("/Documentation/index.html") != null);
|
||||||
|
|
||||||
if (sshInfo != null && !sshInfo.getHostKeys().isEmpty()) {
|
|
||||||
config.setSshdAddress(sshInfo.getHostKeys().get(0).getHost());
|
|
||||||
}
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,23 +32,25 @@ package com.google.gerrit.httpd.gitweb;
|
|||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
import com.google.gerrit.common.data.GerritConfig;
|
|
||||||
import com.google.gerrit.extensions.restapi.Url;
|
import com.google.gerrit.extensions.restapi.Url;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.AnonymousUser;
|
import com.google.gerrit.server.AnonymousUser;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.config.GitWebConfig;
|
import com.google.gerrit.server.config.GitWebConfig;
|
||||||
import com.google.gerrit.server.config.SitePaths;
|
import com.google.gerrit.server.config.SitePaths;
|
||||||
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
|
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
|
||||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
|
import com.google.gerrit.server.ssh.SshInfo;
|
||||||
import com.google.gwtexpui.server.CacheHeaders;
|
import com.google.gwtexpui.server.CacheHeaders;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
|
import org.eclipse.jgit.lib.Config;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -96,12 +98,14 @@ class GitWebServlet extends HttpServlet {
|
|||||||
private final EnvList _env;
|
private final EnvList _env;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
GitWebServlet(final LocalDiskRepositoryManager repoManager,
|
GitWebServlet(LocalDiskRepositoryManager repoManager,
|
||||||
final ProjectControl.Factory projectControl,
|
ProjectControl.Factory projectControl,
|
||||||
final Provider<AnonymousUser> anonymousUserProvider,
|
Provider<AnonymousUser> anonymousUserProvider,
|
||||||
final Provider<CurrentUser> userProvider,
|
Provider<CurrentUser> userProvider,
|
||||||
final SitePaths site,
|
SitePaths site,
|
||||||
final GerritConfig gerritConfig, final GitWebConfig gitWebConfig)
|
@GerritServerConfig Config cfg,
|
||||||
|
SshInfo sshInfo,
|
||||||
|
GitWebConfig gitWebConfig)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
this.repoManager = repoManager;
|
this.repoManager = repoManager;
|
||||||
this.projectControl = projectControl;
|
this.projectControl = projectControl;
|
||||||
@@ -128,7 +132,7 @@ class GitWebServlet extends HttpServlet {
|
|||||||
deniedActions.add("project_index");
|
deniedActions.add("project_index");
|
||||||
|
|
||||||
_env = new EnvList();
|
_env = new EnvList();
|
||||||
makeSiteConfig(site, gerritConfig);
|
makeSiteConfig(site, cfg, sshInfo);
|
||||||
|
|
||||||
if (!_env.envMap.containsKey("SystemRoot")) {
|
if (!_env.envMap.containsKey("SystemRoot")) {
|
||||||
String os = System.getProperty("os.name");
|
String os = System.getProperty("os.name");
|
||||||
@@ -146,8 +150,8 @@ class GitWebServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeSiteConfig(final SitePaths site,
|
private void makeSiteConfig(SitePaths site, Config cfg, SshInfo sshInfo)
|
||||||
final GerritConfig gerritConfig) throws IOException {
|
throws IOException {
|
||||||
if (!Files.exists(site.tmp_dir)) {
|
if (!Files.exists(site.tmp_dir)) {
|
||||||
Files.createDirectories(site.tmp_dir);
|
Files.createDirectories(site.tmp_dir);
|
||||||
}
|
}
|
||||||
@@ -231,8 +235,8 @@ class GitWebServlet extends HttpServlet {
|
|||||||
|
|
||||||
// Generate URLs using anonymous git://
|
// Generate URLs using anonymous git://
|
||||||
//
|
//
|
||||||
if (gerritConfig.getGitDaemonUrl() != null) {
|
String url = cfg.getString("gerrit", null, "canonicalGitUrl");
|
||||||
String url = gerritConfig.getGitDaemonUrl();
|
if (url != null) {
|
||||||
if (url.endsWith("/")) {
|
if (url.endsWith("/")) {
|
||||||
url = url.substring(0, url.length() - 1);
|
url = url.substring(0, url.length() - 1);
|
||||||
}
|
}
|
||||||
@@ -245,8 +249,8 @@ class GitWebServlet extends HttpServlet {
|
|||||||
|
|
||||||
// Generate URLs using authenticated ssh://
|
// Generate URLs using authenticated ssh://
|
||||||
//
|
//
|
||||||
if (gerritConfig.getSshdAddress() != null) {
|
if (sshInfo != null && !sshInfo.getHostKeys().isEmpty()) {
|
||||||
String sshAddr = gerritConfig.getSshdAddress();
|
String sshAddr = sshInfo.getHostKeys().get(0).getHost();
|
||||||
p.print("if ($ENV{'GERRIT_USER_NAME'}) {\n");
|
p.print("if ($ENV{'GERRIT_USER_NAME'}) {\n");
|
||||||
p.print(" push @git_base_url_list, join('', 'ssh://'");
|
p.print(" push @git_base_url_list, join('', 'ssh://'");
|
||||||
p.print(", $ENV{'GERRIT_USER_NAME'}");
|
p.print(", $ENV{'GERRIT_USER_NAME'}");
|
||||||
|
Reference in New Issue
Block a user