Gerrit Client: Retrieve archives formats via REST
Use the /config/server/info REST endpoint to retrieve the supported
archive formats and remove this information from the config that is
embedded in the host page data.
The way how archives formats are included into the ServerInfo JSON was
adapted to the changes done with commit 1e933885
.
Change-Id: Iaf0a3817c5f239e87a0f9c2b29d198e410e4f49e
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:

committed by
David Pursehouse

parent
5a8c9e9649
commit
e55a72f504
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.common.data;
|
package com.google.gerrit.common.data;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class GerritConfig implements Cloneable {
|
public class GerritConfig implements Cloneable {
|
||||||
protected String reportBugUrl;
|
protected String reportBugUrl;
|
||||||
@@ -27,7 +26,6 @@ public class GerritConfig implements Cloneable {
|
|||||||
protected String anonymousCowardName;
|
protected String anonymousCowardName;
|
||||||
protected int suggestFrom;
|
protected int suggestFrom;
|
||||||
protected int changeUpdateDelay;
|
protected int changeUpdateDelay;
|
||||||
protected List<String> archiveFormats;
|
|
||||||
protected int largeChangeSize;
|
protected int largeChangeSize;
|
||||||
protected String replyLabel;
|
protected String replyLabel;
|
||||||
protected String replyTitle;
|
protected String replyTitle;
|
||||||
@@ -116,14 +114,6 @@ public class GerritConfig implements Cloneable {
|
|||||||
this.largeChangeSize = largeChangeSize;
|
this.largeChangeSize = largeChangeSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getArchiveFormats() {
|
|
||||||
return archiveFormats;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArchiveFormats(List<String> formats) {
|
|
||||||
archiveFormats = formats;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReplyTitle() {
|
public String getReplyTitle() {
|
||||||
return replyTitle;
|
return replyTitle;
|
||||||
}
|
}
|
||||||
|
@@ -164,7 +164,7 @@ class DownloadBox extends VerticalPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void insertArchive() {
|
private void insertArchive() {
|
||||||
List<String> activated = Gerrit.getConfig().getArchiveFormats();
|
List<String> activated = Gerrit.info().download().archives();
|
||||||
if (activated.isEmpty()) {
|
if (activated.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -18,16 +18,29 @@ import com.google.gerrit.client.rpc.NativeMap;
|
|||||||
import com.google.gerrit.client.rpc.NativeString;
|
import com.google.gerrit.client.rpc.NativeString;
|
||||||
import com.google.gerrit.client.rpc.Natives;
|
import com.google.gerrit.client.rpc.Natives;
|
||||||
import com.google.gwt.core.client.JavaScriptObject;
|
import com.google.gwt.core.client.JavaScriptObject;
|
||||||
|
import com.google.gwt.core.client.JsArrayString;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class DownloadInfo extends JavaScriptObject {
|
public class DownloadInfo extends JavaScriptObject {
|
||||||
public final Set<String> schemes() {
|
public final Set<String> schemes() {
|
||||||
return Natives.keys(_schemes());
|
return Natives.keys(_schemes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final List<String> archives() {
|
||||||
|
List<String> archives = new ArrayList<>();
|
||||||
|
for (String f : Natives.asList(_archives())) {
|
||||||
|
archives.add(f);
|
||||||
|
}
|
||||||
|
return archives;
|
||||||
|
}
|
||||||
|
|
||||||
public final native DownloadSchemeInfo scheme(String n) /*-{ return this.schemes[n]; }-*/;
|
public final native DownloadSchemeInfo scheme(String n) /*-{ return this.schemes[n]; }-*/;
|
||||||
private final native NativeMap<DownloadSchemeInfo> _schemes() /*-{ return this.schemes; }-*/;
|
private final native NativeMap<DownloadSchemeInfo> _schemes() /*-{ return this.schemes; }-*/;
|
||||||
|
private final native JsArrayString _archives() /*-{ return this.archives; }-*/;
|
||||||
|
|
||||||
protected DownloadInfo() {
|
protected DownloadInfo() {
|
||||||
}
|
}
|
||||||
|
@@ -14,15 +14,9 @@
|
|||||||
|
|
||||||
package com.google.gerrit.httpd;
|
package com.google.gerrit.httpd;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gerrit.common.data.GerritConfig;
|
import com.google.gerrit.common.data.GerritConfig;
|
||||||
import com.google.gerrit.common.data.GitwebConfig;
|
import com.google.gerrit.common.data.GitwebConfig;
|
||||||
import com.google.gerrit.server.change.ArchiveFormat;
|
|
||||||
import com.google.gerrit.server.change.GetArchive;
|
|
||||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||||
import com.google.gerrit.server.config.ConfigUtil;
|
import com.google.gerrit.server.config.ConfigUtil;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
@@ -40,7 +34,6 @@ import javax.servlet.ServletContext;
|
|||||||
|
|
||||||
class GerritConfigProvider implements Provider<GerritConfig> {
|
class GerritConfigProvider implements Provider<GerritConfig> {
|
||||||
private final Config cfg;
|
private final Config cfg;
|
||||||
private final GetArchive.AllowedFormats archiveFormats;
|
|
||||||
private final GitWebConfig gitWebConfig;
|
private final GitWebConfig gitWebConfig;
|
||||||
private final SshInfo sshInfo;
|
private final SshInfo sshInfo;
|
||||||
|
|
||||||
@@ -53,10 +46,8 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
|||||||
GitWebConfig gwc,
|
GitWebConfig gwc,
|
||||||
SshInfo si,
|
SshInfo si,
|
||||||
ServletContext sc,
|
ServletContext sc,
|
||||||
GetArchive.AllowedFormats af,
|
|
||||||
@AnonymousCowardName String acn) {
|
@AnonymousCowardName String acn) {
|
||||||
cfg = gsc;
|
cfg = gsc;
|
||||||
archiveFormats = af;
|
|
||||||
gitWebConfig = gwc;
|
gitWebConfig = gwc;
|
||||||
sshInfo = si;
|
sshInfo = si;
|
||||||
servletContext = sc;
|
servletContext = sc;
|
||||||
@@ -74,24 +65,6 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
|||||||
cfg, "change", null, "updateDelay", 30, TimeUnit.SECONDS));
|
cfg, "change", null, "updateDelay", 30, TimeUnit.SECONDS));
|
||||||
config.setLargeChangeSize(cfg.getInt("change", "largeChange", 500));
|
config.setLargeChangeSize(cfg.getInt("change", "largeChange", 500));
|
||||||
|
|
||||||
// Zip is not supported because it may be interpreted by a Java plugin as a
|
|
||||||
// valid JAR file, whose code would have access to cookies on the domain.
|
|
||||||
config.setArchiveFormats(Lists.newArrayList(Iterables.transform(
|
|
||||||
Iterables.filter(
|
|
||||||
archiveFormats.getAllowed(),
|
|
||||||
new Predicate<ArchiveFormat>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(ArchiveFormat format) {
|
|
||||||
return (format != ArchiveFormat.ZIP);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
new Function<ArchiveFormat, String>() {
|
|
||||||
@Override
|
|
||||||
public String apply(ArchiveFormat in) {
|
|
||||||
return in.getShortName();
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
|
|
||||||
config.setReportBugUrl(cfg.getString("gerrit", null, "reportBugUrl"));
|
config.setReportBugUrl(cfg.getString("gerrit", null, "reportBugUrl"));
|
||||||
config.setReportBugText(cfg.getString("gerrit", null, "reportBugText"));
|
config.setReportBugText(cfg.getString("gerrit", null, "reportBugText"));
|
||||||
|
|
||||||
|
@@ -14,8 +14,10 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.change;
|
package com.google.gerrit.server.change;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||||
@@ -55,7 +57,17 @@ public class GetArchive implements RestReadView<RevisionResource> {
|
|||||||
exts.put(format.name().toLowerCase(), format);
|
exts.put(format.name().toLowerCase(), format);
|
||||||
}
|
}
|
||||||
extensions = ImmutableMap.copyOf(exts);
|
extensions = ImmutableMap.copyOf(exts);
|
||||||
allowed = cfg.getArchiveFormats();
|
|
||||||
|
// Zip is not supported because it may be interpreted by a Java plugin as a
|
||||||
|
// valid JAR file, whose code would have access to cookies on the domain.
|
||||||
|
allowed = Sets.filter(
|
||||||
|
cfg.getArchiveFormats(),
|
||||||
|
new Predicate<ArchiveFormat>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(ArchiveFormat format) {
|
||||||
|
return (format != ArchiveFormat.ZIP);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ArchiveFormat> getAllowed() {
|
public Set<ArchiveFormat> getAllowed() {
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.server.config;
|
package com.google.gerrit.server.config;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.extensions.config.DownloadCommand;
|
import com.google.gerrit.extensions.config.DownloadCommand;
|
||||||
import com.google.gerrit.extensions.config.DownloadScheme;
|
import com.google.gerrit.extensions.config.DownloadScheme;
|
||||||
@@ -24,6 +25,7 @@ import com.google.gerrit.reviewdb.client.Account;
|
|||||||
import com.google.gerrit.reviewdb.client.AuthType;
|
import com.google.gerrit.reviewdb.client.AuthType;
|
||||||
import com.google.gerrit.server.account.Realm;
|
import com.google.gerrit.server.account.Realm;
|
||||||
import com.google.gerrit.server.change.ArchiveFormat;
|
import com.google.gerrit.server.change.ArchiveFormat;
|
||||||
|
import com.google.gerrit.server.change.GetArchive;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
@@ -32,16 +34,15 @@ import java.net.MalformedURLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class GetServerInfo implements RestReadView<ConfigResource> {
|
public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||||
private final Config config;
|
private final Config config;
|
||||||
private final AuthConfig authConfig;
|
private final AuthConfig authConfig;
|
||||||
private final Realm realm;
|
private final Realm realm;
|
||||||
private final DownloadConfig downloadConfig;
|
|
||||||
private final DynamicMap<DownloadScheme> downloadSchemes;
|
private final DynamicMap<DownloadScheme> downloadSchemes;
|
||||||
private final DynamicMap<DownloadCommand> downloadCommands;
|
private final DynamicMap<DownloadCommand> downloadCommands;
|
||||||
|
private final GetArchive.AllowedFormats archiveFormats;
|
||||||
private final AllProjectsName allProjectsName;
|
private final AllProjectsName allProjectsName;
|
||||||
private final AllUsersName allUsersName;
|
private final AllUsersName allUsersName;
|
||||||
|
|
||||||
@@ -50,17 +51,17 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
|||||||
@GerritServerConfig Config config,
|
@GerritServerConfig Config config,
|
||||||
AuthConfig authConfig,
|
AuthConfig authConfig,
|
||||||
Realm realm,
|
Realm realm,
|
||||||
DownloadConfig downloadConfig,
|
|
||||||
DynamicMap<DownloadScheme> downloadSchemes,
|
DynamicMap<DownloadScheme> downloadSchemes,
|
||||||
DynamicMap<DownloadCommand> downloadCommands,
|
DynamicMap<DownloadCommand> downloadCommands,
|
||||||
|
GetArchive.AllowedFormats archiveFormats,
|
||||||
AllProjectsName allProjectsName,
|
AllProjectsName allProjectsName,
|
||||||
AllUsersName allUsersName) {
|
AllUsersName allUsersName) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.authConfig = authConfig;
|
this.authConfig = authConfig;
|
||||||
this.realm = realm;
|
this.realm = realm;
|
||||||
this.downloadConfig = downloadConfig;
|
|
||||||
this.downloadSchemes = downloadSchemes;
|
this.downloadSchemes = downloadSchemes;
|
||||||
this.downloadCommands = downloadCommands;
|
this.downloadCommands = downloadCommands;
|
||||||
|
this.archiveFormats = archiveFormats;
|
||||||
this.allProjectsName = allProjectsName;
|
this.allProjectsName = allProjectsName;
|
||||||
this.allUsersName = allUsersName;
|
this.allUsersName = allUsersName;
|
||||||
}
|
}
|
||||||
@@ -71,7 +72,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
|||||||
info.auth = new AuthInfo(authConfig, realm);
|
info.auth = new AuthInfo(authConfig, realm);
|
||||||
info.contactStore = getContactStoreInfo();
|
info.contactStore = getContactStoreInfo();
|
||||||
info.download =
|
info.download =
|
||||||
new DownloadInfo(downloadConfig, downloadSchemes, downloadCommands);
|
new DownloadInfo(downloadSchemes, downloadCommands, archiveFormats);
|
||||||
info.gerrit = new GerritInfo(allProjectsName, allUsersName);
|
info.gerrit = new GerritInfo(allProjectsName, allUsersName);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
@@ -157,9 +158,9 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
|||||||
public Map<String, DownloadSchemeInfo> schemes;
|
public Map<String, DownloadSchemeInfo> schemes;
|
||||||
public List<String> archives;
|
public List<String> archives;
|
||||||
|
|
||||||
public DownloadInfo(DownloadConfig downloadConfig,
|
public DownloadInfo(DynamicMap<DownloadScheme> downloadSchemes,
|
||||||
DynamicMap<DownloadScheme> downloadSchemes,
|
DynamicMap<DownloadCommand> downloadCommands,
|
||||||
DynamicMap<DownloadCommand> downloadCommands) {
|
GetArchive.AllowedFormats archiveFormats) {
|
||||||
schemes = new HashMap<>();
|
schemes = new HashMap<>();
|
||||||
for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) {
|
for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) {
|
||||||
DownloadScheme scheme = e.getProvider().get();
|
DownloadScheme scheme = e.getProvider().get();
|
||||||
@@ -168,14 +169,14 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
|||||||
new DownloadSchemeInfo(scheme, downloadCommands));
|
new DownloadSchemeInfo(scheme, downloadCommands));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
archives =
|
archives = Lists.newArrayList(Iterables.transform(
|
||||||
Lists.transform(new ArrayList<>(downloadConfig.getArchiveFormats()),
|
archiveFormats.getAllowed(),
|
||||||
new Function<ArchiveFormat, String>() {
|
new Function<ArchiveFormat, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String apply(ArchiveFormat archiveFormat) {
|
public String apply(ArchiveFormat in) {
|
||||||
return archiveFormat.name().toLowerCase(Locale.US);
|
return in.getShortName();
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user