Retrieve download schemes via REST
Change-Id: I8fee0345ca28742f215b7bdcf7a2b1ec10bf84f6
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java
index b024e64..045591c 100644
--- a/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java
+++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java
@@ -16,7 +16,6 @@
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Account.FieldName;
-import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
import com.google.gerrit.reviewdb.client.AuthType;
import java.util.List;
@@ -35,7 +34,6 @@
protected GitwebConfig gitweb;
protected AuthType authType;
- protected Set<DownloadScheme> downloadSchemes;
protected String gitDaemonUrl;
protected String gitHttpUrl;
protected String sshdAddress;
@@ -135,14 +133,6 @@
authType = t;
}
- public Set<DownloadScheme> getDownloadSchemes() {
- return downloadSchemes;
- }
-
- public void setDownloadSchemes(final Set<DownloadScheme> s) {
- downloadSchemes = s;
- }
-
public GitwebConfig getGitwebLink() {
return gitweb;
}
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/DownloadInfo.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/DownloadInfo.java
new file mode 100644
index 0000000..e97d472
--- /dev/null
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/DownloadInfo.java
@@ -0,0 +1,85 @@
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.client.config;
+
+import com.google.gerrit.client.rpc.NativeMap;
+import com.google.gerrit.client.rpc.NativeString;
+import com.google.gerrit.client.rpc.Natives;
+import com.google.gwt.core.client.JavaScriptObject;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class DownloadInfo extends JavaScriptObject {
+ public final Set<String> schemes() {
+ return Natives.keys(_schemes());
+ }
+ public final native DownloadSchemeInfo scheme(String n) /*-{ return this.schemes[n]; }-*/;
+ private final native NativeMap<DownloadSchemeInfo> _schemes() /*-{ return this.schemes; }-*/;
+
+ protected DownloadInfo() {
+ }
+
+ public static class DownloadSchemeInfo extends JavaScriptObject {
+ public final Set<String> commandNames() {
+ return Natives.keys(_commands());
+ }
+
+ public final Set<DownloadCommandInfo> commands(String project) {
+ Set<DownloadCommandInfo> commands = new HashSet<>();
+ for (String commandName : commandNames()) {
+ commands.add(new DownloadCommandInfo(commandName, command(commandName,
+ project)));
+ }
+ return commands;
+ }
+
+ public final String command(String commandName, String project) {
+ return command(commandName).replaceAll("\\$\\{project\\}", project);
+ }
+
+ public final String getUrl(String project) {
+ return url().replaceAll("\\$\\{project\\}", project);
+ }
+
+ public final native String name() /*-{ return this.name; }-*/;
+ public final native String url() /*-{ return this.url; }-*/;
+ public final native boolean isAuthRequired() /*-{ return this.is_auth_required || false; }-*/;
+ public final native boolean isAuthSupported() /*-{ return this.is_auth_supported || false; }-*/;
+ public final native String command(String n) /*-{ return this.commands[n]; }-*/;
+ private final native NativeMap<NativeString> _commands() /*-{ return this.commands; }-*/;
+
+ protected DownloadSchemeInfo() {
+ }
+ }
+
+ public static class DownloadCommandInfo {
+ private final String name;
+ private final String command;
+
+ DownloadCommandInfo(String name, String command) {
+ this.name = name;
+ this.command = command;
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public String command() {
+ return command;
+ }
+ }
+}
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/ServerInfo.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/ServerInfo.java
index 45b7e2a..a1e8dbc 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/ServerInfo.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/config/ServerInfo.java
@@ -19,6 +19,7 @@
public class ServerInfo extends JavaScriptObject {
public final native AuthInfo auth() /*-{ return this.auth; }-*/;
public final native ContactStoreInfo contactStore() /*-{ return this.contact_store; }-*/;
+ public final native DownloadInfo download() /*-{ return this.download; }-*/;
public final native GerritInfo gerrit() /*-{ return this.gerrit; }-*/;
public final boolean hasContactStore() {
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/download/DownloadUrlLink.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/download/DownloadUrlLink.java
index 5595ec8..275b918 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/download/DownloadUrlLink.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/download/DownloadUrlLink.java
@@ -135,31 +135,27 @@
public static List<DownloadUrlLink> createDownloadUrlLinks(String project,
boolean allowAnonymous) {
List<DownloadUrlLink> urls = new ArrayList<>();
- Set<DownloadScheme> allowedSchemes = Gerrit.getConfig().getDownloadSchemes();
+ Set<String> allowedSchemes = Gerrit.info().download().schemes();
if (allowAnonymous
&& Gerrit.getConfig().getGitDaemonUrl() != null
- && (allowedSchemes.contains(DownloadScheme.ANON_GIT) ||
- allowedSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) {
+ && allowedSchemes.contains("git")) {
urls.add(new DownloadUrlLink.AnonGitLink(project));
}
if (allowAnonymous
- && (allowedSchemes.contains(DownloadScheme.ANON_HTTP) ||
- allowedSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) {
+ && allowedSchemes.contains("anonymous http")) {
urls.add(new DownloadUrlLink.AnonHttpLink(project));
}
if (Gerrit.getConfig().getSshdAddress() != null
&& hasUserName()
- && (allowedSchemes.contains(DownloadScheme.SSH) ||
- allowedSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) {
+ && allowedSchemes.contains("ssh")) {
urls.add(new DownloadUrlLink.SshLink(project));
}
if ((hasUserName() || siteReliesOnHttp())
- && (allowedSchemes.contains(DownloadScheme.HTTP)
- || allowedSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) {
+ && allowedSchemes.contains("http")) {
urls.add(new DownloadUrlLink.HttpLink(project, allowAnonymous));
}
return urls;
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java
index 6850036..eadc536 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java
@@ -27,7 +27,6 @@
import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.ConfigUtil;
-import com.google.gerrit.server.config.DownloadConfig;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.ssh.SshInfo;
import com.google.inject.Inject;
@@ -45,7 +44,6 @@
private final Realm realm;
private final Config cfg;
private final AuthConfig authConfig;
- private final DownloadConfig downloadConfig;
private final GetArchive.AllowedFormats archiveFormats;
private final GitWebConfig gitWebConfig;
private final SshInfo sshInfo;
@@ -60,13 +58,11 @@
GitWebConfig gwc,
SshInfo si,
ServletContext sc,
- DownloadConfig dc,
GetArchive.AllowedFormats af,
@AnonymousCowardName String acn) {
realm = r;
cfg = gsc;
authConfig = ac;
- downloadConfig = dc;
archiveFormats = af;
gitWebConfig = gwc;
sshInfo = si;
@@ -108,7 +104,6 @@
config.setSwitchAccountUrl(cfg.getString("auth", null, "switchAccountUrl"));
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
config.setGitHttpUrl(cfg.getString("gerrit", null, "gitHttpUrl"));
- config.setDownloadSchemes(downloadConfig.getDownloadSchemes());
config.setAuthType(authConfig.getAuthType());
config.setDocumentationAvailable(servletContext
.getResource("/Documentation/index.html") != null);