Remove DEFAULT_SCHEMES and DEFAULT_COMMANDS
Using these sentinels complicated the implementation of the core download-commands plugin, and inadvertently allowed for undocumented enum values when reading from the config. Simplify callers by prepopulating the sets with the proper default values when nothing is specified in the config. Change-Id: Ib1cb8a255110adec241608bf62d5331fd706794e
This commit is contained in:
parent
c6fa065223
commit
f01551975f
@ -55,8 +55,7 @@ public class GitOverHttpModule extends ServletModule {
|
||||
}
|
||||
|
||||
private boolean isHttpEnabled(){
|
||||
return downloadConfig.getDownloadSchemes().contains(DownloadScheme.DEFAULT_DOWNLOADS)
|
||||
|| downloadConfig.getDownloadSchemes().contains(DownloadScheme.ANON_HTTP)
|
||||
return downloadConfig.getDownloadSchemes().contains(DownloadScheme.ANON_HTTP)
|
||||
|| downloadConfig.getDownloadSchemes().contains(DownloadScheme.HTTP);
|
||||
}
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ public final class AccountGeneralPreferences {
|
||||
|
||||
/** Preferred scheme type to download a change. */
|
||||
public static enum DownloadScheme {
|
||||
ANON_GIT, ANON_HTTP, HTTP, SSH, REPO_DOWNLOAD, DEFAULT_DOWNLOADS
|
||||
ANON_GIT, ANON_HTTP, HTTP, SSH, REPO_DOWNLOAD
|
||||
}
|
||||
|
||||
/** Preferred method to download a change. */
|
||||
public static enum DownloadCommand {
|
||||
REPO_DOWNLOAD, PULL, CHECKOUT, CHERRY_PICK, FORMAT_PATCH, DEFAULT_DOWNLOADS
|
||||
REPO_DOWNLOAD, PULL, CHECKOUT, CHERRY_PICK, FORMAT_PATCH
|
||||
}
|
||||
|
||||
public static enum DateFormat {
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
|
||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
|
||||
import com.google.gerrit.server.change.ArchiveFormat;
|
||||
@ -39,15 +40,25 @@ public class DownloadConfig {
|
||||
DownloadConfig(@GerritServerConfig final Config cfg) {
|
||||
List<DownloadScheme> allSchemes =
|
||||
ConfigUtil.getEnumList(cfg, "download", null, "scheme",
|
||||
DownloadScheme.DEFAULT_DOWNLOADS);
|
||||
downloadSchemes =
|
||||
Collections.unmodifiableSet(new HashSet<>(allSchemes));
|
||||
DownloadScheme.values(), null);
|
||||
if (isOnlyNull(allSchemes)) {
|
||||
downloadSchemes = ImmutableSet.of(
|
||||
DownloadScheme.SSH,
|
||||
DownloadScheme.HTTP,
|
||||
DownloadScheme.ANON_HTTP);
|
||||
} else {
|
||||
downloadSchemes = ImmutableSet.copyOf(allSchemes);
|
||||
}
|
||||
|
||||
DownloadCommand[] downloadCommandValues = DownloadCommand.values();
|
||||
List<DownloadCommand> allCommands =
|
||||
ConfigUtil.getEnumList(cfg, "download", null, "command",
|
||||
DownloadCommand.DEFAULT_DOWNLOADS);
|
||||
downloadCommands =
|
||||
Collections.unmodifiableSet(new HashSet<>(allCommands));
|
||||
downloadCommandValues, null);
|
||||
if (isOnlyNull(allCommands)) {
|
||||
downloadCommands = ImmutableSet.copyOf(downloadCommandValues);
|
||||
} else {
|
||||
downloadCommands = ImmutableSet.copyOf(allCommands);
|
||||
}
|
||||
|
||||
String v = cfg.getString("download", null, "archive");
|
||||
if (v == null) {
|
||||
@ -61,6 +72,10 @@ public class DownloadConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isOnlyNull(List<?> list) {
|
||||
return list.size() == 1 && list.get(0) == null;
|
||||
}
|
||||
|
||||
/** Scheme used to download. */
|
||||
public Set<DownloadScheme> getDownloadSchemes() {
|
||||
return downloadSchemes;
|
||||
|
@ -130,8 +130,6 @@ public class DefaultCommandModule extends CommandModule {
|
||||
}
|
||||
|
||||
private boolean sshEnabled() {
|
||||
return downloadConfig.getDownloadSchemes().contains(DownloadScheme.SSH)
|
||||
|| downloadConfig.getDownloadSchemes().contains(
|
||||
DownloadScheme.DEFAULT_DOWNLOADS);
|
||||
return downloadConfig.getDownloadSchemes().contains(DownloadScheme.SSH);
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 99e61fb06a4505a9558c23a56213cb32ceaa9cca
|
||||
Subproject commit 18b0f6d098a3bacaac022529140be85394549ff1
|
Loading…
Reference in New Issue
Block a user