Store preferred download scheme as arbitrary strings
Although plugins can register download schemes with arbitrary names, the getter/setter in AccountGeneralPreferences were allowing only a specific enum type corresponding to the core download schemes. Get rid of that enum type, and store arbitrary strings in the database. To avoid a schema upgrade (which would be an annoying multi-step process for a zero-downtime upgrade), convert to/from the old enum-string values in AccountGeneralPreferences. Everywhere else, use the key from the scheme map, e.g. "anonymous http" instead of "ANON_HTTP". This eliminates the special-case code when sending RPCs from the client, and avoids weird undocumented behavior in the set preferences REST API call. Change-Id: I3e2397d8dfa15d20329cc83e1e3fe069c8e021c4
This commit is contained in:
@@ -25,11 +25,6 @@ public final class AccountGeneralPreferences {
|
||||
/** Valid choices for the page size. */
|
||||
public static final short[] PAGESIZE_CHOICES = {10, 25, 50, 100};
|
||||
|
||||
/** Preferred scheme type to download a change. */
|
||||
public static enum DownloadScheme {
|
||||
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
|
||||
@@ -187,19 +182,49 @@ public final class AccountGeneralPreferences {
|
||||
useFlashClipboard = b;
|
||||
}
|
||||
|
||||
public DownloadScheme getDownloadUrl() {
|
||||
if (downloadUrl == null) {
|
||||
return null;
|
||||
public String getDownloadUrl() {
|
||||
// Translate from legacy enum names to modern display names. (May be removed
|
||||
// if accompanied by a 2-phase schema upgrade.)
|
||||
if (downloadUrl != null) {
|
||||
switch (downloadUrl) {
|
||||
case "ANON_GIT":
|
||||
return CoreDownloadSchemes.ANON_GIT;
|
||||
case "ANON_HTTP":
|
||||
return CoreDownloadSchemes.ANON_HTTP;
|
||||
case "HTTP":
|
||||
return CoreDownloadSchemes.HTTP;
|
||||
case "SSH":
|
||||
return CoreDownloadSchemes.SSH;
|
||||
case "REPO_DOWNLOAD":
|
||||
return CoreDownloadSchemes.REPO_DOWNLOAD;
|
||||
}
|
||||
}
|
||||
return DownloadScheme.valueOf(downloadUrl);
|
||||
return downloadUrl;
|
||||
}
|
||||
|
||||
public void setDownloadUrl(DownloadScheme url) {
|
||||
if (url != null) {
|
||||
downloadUrl = url.name();
|
||||
} else {
|
||||
downloadUrl = null;
|
||||
public void setDownloadUrl(String url) {
|
||||
// Translate from modern display names to legacy enum names. (May be removed
|
||||
// if accompanied by a 2-phase schema upgrade.)
|
||||
if (downloadUrl != null) {
|
||||
switch (url) {
|
||||
case CoreDownloadSchemes.ANON_GIT:
|
||||
url = "ANON_GIT";
|
||||
break;
|
||||
case CoreDownloadSchemes.ANON_HTTP:
|
||||
url = "ANON_HTTP";
|
||||
break;
|
||||
case CoreDownloadSchemes.HTTP:
|
||||
url = "HTTP";
|
||||
break;
|
||||
case CoreDownloadSchemes.SSH:
|
||||
url = "SSH";
|
||||
break;
|
||||
case CoreDownloadSchemes.REPO_DOWNLOAD:
|
||||
url = "REPO_DOWNLOAD";
|
||||
break;
|
||||
}
|
||||
}
|
||||
downloadUrl = url;
|
||||
}
|
||||
|
||||
public DownloadCommand getDownloadCommand() {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// 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.reviewdb.client;
|
||||
|
||||
/**
|
||||
* Download scheme string constants supported by the download-commands core
|
||||
* plugin.
|
||||
*/
|
||||
public class CoreDownloadSchemes {
|
||||
public static final String ANON_GIT = "git";
|
||||
public static final String ANON_HTTP = "anonymous http";
|
||||
public static final String HTTP = "http";
|
||||
public static final String SSH = "ssh";
|
||||
public static final String REPO_DOWNLOAD = "repo";
|
||||
|
||||
private CoreDownloadSchemes() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user