Get commentlinks per-project in UI code

Remove commentlinks from GerritConfig and instead provide them in JSON
form from GET /projects/X/config. On the client side, create new
CommentLinkProcessor instances when loading a change or patch.
Fortunately, even though this requires another RPC to get the project
config, in all existing screen instances, there is already an RPC we
can parallelize it with.

In the long term we may want to enable server-side HTML rendering, but
that requires enabling this option on a variety of RPC endpoints, not
all of which are converted to the new REST API. In addition, there is
the problem of defining a stable HTML fragment style. For example, the
commit message template is currently implemented using a
not-quite-trivial template in GWT's UiBinder, so some of that
formatting and styling would need to be hoisted out into the server
side; doable, but we're not there yet.

Change-Id: Iaecbeff939c8fcbc1c6f500e0b04ce03f35e1fd3
This commit is contained in:
Dave Borowitz
2013-04-08 10:42:23 -07:00
parent 39f5688fdb
commit 2002789f41
22 changed files with 266 additions and 167 deletions

View File

@@ -14,9 +14,12 @@
package com.google.gerrit.server.project;
import com.google.common.collect.Maps;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.git.GitRepositoryManager;
import java.util.Map;
public class GetConfig implements RestReadView<ProjectResource> {
public static class ConfigInfo {
public final String kind = "gerritcodereview#project_config";
@@ -25,6 +28,8 @@ public class GetConfig implements RestReadView<ProjectResource> {
public Boolean useContentMerge;
public Boolean useSignedOffBy;
public Boolean requireChangeId;
public Map<String, CommentLinkInfo> commentlinks;
}
@Override
@@ -39,6 +44,13 @@ public class GetConfig implements RestReadView<ProjectResource> {
result.useSignedOffBy = project.isUseSignedOffBy();
result.requireChangeId = project.isRequireChangeID();
}
// commentlinks are visible to anyone, as they are used for linkification
// on the client side.
result.commentlinks = Maps.newLinkedHashMap();
for (CommentLinkInfo cl : project.getCommentLinks()) {
result.commentlinks.put(cl.name, cl);
}
return result;
}
}

View File

@@ -69,6 +69,7 @@ public class ProjectState {
private final PrologEnvironment.Factory envFactory;
private final GitRepositoryManager gitMgr;
private final RulesCache rulesCache;
private final List<CommentLinkInfo> commentLinks;
private final ProjectConfig config;
private final Set<AccountGroup.UUID> localOwners;
@@ -93,6 +94,7 @@ public class ProjectState {
final PrologEnvironment.Factory envFactory,
final GitRepositoryManager gitMgr,
final RulesCache rulesCache,
final List<CommentLinkInfo> commentLinks,
@Assisted final ProjectConfig config) {
this.projectCache = projectCache;
this.isAllProjects = config.getProject().getNameKey().equals(allProjectsName);
@@ -101,6 +103,7 @@ public class ProjectState {
this.envFactory = envFactory;
this.gitMgr = gitMgr;
this.rulesCache = rulesCache;
this.commentLinks = commentLinks;
this.config = config;
this.capabilities = isAllProjects
? new CapabilityCollection(config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES))
@@ -363,6 +366,10 @@ public class ProjectState {
return new LabelTypes(Collections.unmodifiableList(all));
}
public List<CommentLinkInfo> getCommentLinks() {
return commentLinks;
}
private boolean getInheritableBoolean(Function<Project, InheritableBoolean> func) {
for (ProjectState s : tree()) {
switch (func.apply(s.getProject())) {