Merge changes I2b470424,I8b45988a,Ib1f79cf4 into stable-3.3
* changes: Ship a list of default experiments from the backend and allow disabling Revert "Clean up comment experiment flags" Make UI experiments configurable from gerrit.config
This commit is contained in:
@@ -20,6 +20,7 @@ import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.UsedAt;
|
||||
@@ -37,15 +38,21 @@ import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
/** Helper for generating parts of {@code index.html}. */
|
||||
@UsedAt(Project.GOOGLE)
|
||||
public class IndexHtmlUtil {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
static final ImmutableSet<String> DEFAULT_EXPERIMENTS =
|
||||
ImmutableSet.of(
|
||||
"UiFeature__patchset_comments", "UiFeature__patchset_choice_for_comment_links");
|
||||
|
||||
private static final Gson GSON = OutputFormat.JSON_COMPACT.newGson();
|
||||
/**
|
||||
* Returns both static and dynamic parameters of {@code index.html}. The result is to be used when
|
||||
@@ -53,6 +60,7 @@ public class IndexHtmlUtil {
|
||||
*/
|
||||
public static ImmutableMap<String, Object> templateData(
|
||||
GerritApi gerritApi,
|
||||
Config gerritServerConfig,
|
||||
String canonicalURL,
|
||||
String cdnPath,
|
||||
String faviconPath,
|
||||
@@ -66,7 +74,13 @@ public class IndexHtmlUtil {
|
||||
canonicalURL, cdnPath, faviconPath, urlParameterMap, urlInScriptTagOrdainer))
|
||||
.putAll(dynamicTemplateData(gerritApi, requestedURL));
|
||||
|
||||
Set<String> enabledExperiments = experimentData(urlParameterMap);
|
||||
Set<String> enabledExperiments = new HashSet<>();
|
||||
Arrays.stream(gerritServerConfig.getStringList("experiments", null, "enabled"))
|
||||
.forEach(enabledExperiments::add);
|
||||
DEFAULT_EXPERIMENTS.forEach(enabledExperiments::add);
|
||||
Arrays.stream(gerritServerConfig.getStringList("experiments", null, "disabled"))
|
||||
.forEach(enabledExperiments::remove);
|
||||
experimentData(urlParameterMap).forEach(enabledExperiments::add);
|
||||
if (!enabledExperiments.isEmpty()) {
|
||||
data.put("enabledExperiments", serializeObject(GSON, enabledExperiments).toString());
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.function.Function;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
public class IndexServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -42,6 +43,7 @@ public class IndexServlet extends HttpServlet {
|
||||
@Nullable private final String cdnPath;
|
||||
@Nullable private final String faviconPath;
|
||||
private final GerritApi gerritApi;
|
||||
private final Config gerritServerConfig;
|
||||
private final SoySauce soySauce;
|
||||
private final Function<String, SanitizedContent> urlOrdainer;
|
||||
|
||||
@@ -49,11 +51,13 @@ public class IndexServlet extends HttpServlet {
|
||||
@Nullable String canonicalUrl,
|
||||
@Nullable String cdnPath,
|
||||
@Nullable String faviconPath,
|
||||
GerritApi gerritApi) {
|
||||
GerritApi gerritApi,
|
||||
Config gerritServerConfig) {
|
||||
this.canonicalUrl = canonicalUrl;
|
||||
this.cdnPath = cdnPath;
|
||||
this.faviconPath = faviconPath;
|
||||
this.gerritApi = gerritApi;
|
||||
this.gerritServerConfig = gerritServerConfig;
|
||||
this.soySauce =
|
||||
SoyFileSet.builder()
|
||||
.add(Resources.getResource("com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy"))
|
||||
@@ -74,7 +78,14 @@ public class IndexServlet extends HttpServlet {
|
||||
// TODO(hiesel): Remove URL ordainer as parameter once Soy is consistent
|
||||
ImmutableMap<String, Object> templateData =
|
||||
IndexHtmlUtil.templateData(
|
||||
gerritApi, canonicalUrl, cdnPath, faviconPath, parameterMap, urlOrdainer, requestUrl);
|
||||
gerritApi,
|
||||
gerritServerConfig,
|
||||
canonicalUrl,
|
||||
cdnPath,
|
||||
faviconPath,
|
||||
parameterMap,
|
||||
urlOrdainer,
|
||||
requestUrl);
|
||||
renderer = soySauce.renderTemplate("com.google.gerrit.httpd.raw.Index").setData(templateData);
|
||||
} catch (URISyntaxException | RestApiException e) {
|
||||
throw new IOException(e);
|
||||
|
||||
@@ -225,7 +225,7 @@ public class StaticModule extends ServletModule {
|
||||
String cdnPath =
|
||||
options.useDevCdn() ? options.devCdn() : cfg.getString("gerrit", null, "cdnPath");
|
||||
String faviconPath = cfg.getString("gerrit", null, "faviconPath");
|
||||
return new IndexServlet(canonicalUrl, cdnPath, faviconPath, gerritApi);
|
||||
return new IndexServlet(canonicalUrl, cdnPath, faviconPath, gerritApi, cfg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
Reference in New Issue
Block a user