WebLinks: Convert to java.util, streams, and ImmutableList
Change-Id: I119489c22ce03ec091a81712228bc24bb4909117
This commit is contained in:
committed by
David Pursehouse
parent
60bcae2a3c
commit
9fff4e87fe
@@ -14,10 +14,11 @@
|
||||
|
||||
package com.google.gerrit.server;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.common.DiffWebLinkInfo;
|
||||
import com.google.gerrit.extensions.common.WebLinkInfo;
|
||||
@@ -35,8 +36,8 @@ import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Singleton
|
||||
public class WebLinks {
|
||||
@@ -87,7 +88,7 @@ public class WebLinks {
|
||||
* @param commit SHA1 of commit.
|
||||
* @return Links for patch sets.
|
||||
*/
|
||||
public List<WebLinkInfo> getPatchSetLinks(Project.NameKey project, String commit) {
|
||||
public ImmutableList<WebLinkInfo> getPatchSetLinks(Project.NameKey project, String commit) {
|
||||
return filterLinks(patchSetLinks, webLink -> webLink.getPatchSetWebLink(project.get(), commit));
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ public class WebLinks {
|
||||
* @param revision SHA1 of the parent revision.
|
||||
* @return Links for patch sets.
|
||||
*/
|
||||
public List<WebLinkInfo> getParentLinks(Project.NameKey project, String revision) {
|
||||
public ImmutableList<WebLinkInfo> getParentLinks(Project.NameKey project, String revision) {
|
||||
return filterLinks(parentLinks, webLink -> webLink.getParentWebLink(project.get(), revision));
|
||||
}
|
||||
|
||||
@@ -106,9 +107,9 @@ public class WebLinks {
|
||||
* @param file File name.
|
||||
* @return Links for files.
|
||||
*/
|
||||
public List<WebLinkInfo> getFileLinks(String project, String revision, String file) {
|
||||
public ImmutableList<WebLinkInfo> getFileLinks(String project, String revision, String file) {
|
||||
return Patch.isMagic(file)
|
||||
? Collections.emptyList()
|
||||
? ImmutableList.of()
|
||||
: filterLinks(fileLinks, webLink -> webLink.getFileWebLink(project, revision, file));
|
||||
}
|
||||
|
||||
@@ -118,14 +119,15 @@ public class WebLinks {
|
||||
* @param file File name.
|
||||
* @return Links for file history
|
||||
*/
|
||||
public List<WebLinkInfo> getFileHistoryLinks(String project, String revision, String file) {
|
||||
public ImmutableList<WebLinkInfo> getFileHistoryLinks(
|
||||
String project, String revision, String file) {
|
||||
if (Patch.isMagic(file)) {
|
||||
return Collections.emptyList();
|
||||
return ImmutableList.of();
|
||||
}
|
||||
return FluentIterable.from(fileHistoryLinks)
|
||||
.transform(webLink -> webLink.getFileHistoryWebLink(project, revision, file))
|
||||
return Streams.stream(fileHistoryLinks)
|
||||
.map(webLink -> webLink.getFileHistoryWebLink(project, revision, file))
|
||||
.filter(INVALID_WEBLINK)
|
||||
.toList();
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,20 +140,20 @@ public class WebLinks {
|
||||
* @param fileB File name of side B.
|
||||
* @return Links for file diffs.
|
||||
*/
|
||||
public List<DiffWebLinkInfo> getDiffLinks(
|
||||
final String project,
|
||||
final int changeId,
|
||||
final Integer patchSetIdA,
|
||||
final String revisionA,
|
||||
final String fileA,
|
||||
final int patchSetIdB,
|
||||
final String revisionB,
|
||||
final String fileB) {
|
||||
public ImmutableList<DiffWebLinkInfo> getDiffLinks(
|
||||
String project,
|
||||
int changeId,
|
||||
Integer patchSetIdA,
|
||||
String revisionA,
|
||||
String fileA,
|
||||
int patchSetIdB,
|
||||
String revisionB,
|
||||
String fileB) {
|
||||
if (Patch.isMagic(fileA) || Patch.isMagic(fileB)) {
|
||||
return Collections.emptyList();
|
||||
return ImmutableList.of();
|
||||
}
|
||||
return FluentIterable.from(diffLinks)
|
||||
.transform(
|
||||
return Streams.stream(diffLinks)
|
||||
.map(
|
||||
webLink ->
|
||||
webLink.getDiffLink(
|
||||
project,
|
||||
@@ -163,14 +165,14 @@ public class WebLinks {
|
||||
revisionB,
|
||||
fileB))
|
||||
.filter(INVALID_WEBLINK)
|
||||
.toList();
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param project Project name.
|
||||
* @return Links for projects.
|
||||
*/
|
||||
public List<WebLinkInfo> getProjectLinks(String project) {
|
||||
public ImmutableList<WebLinkInfo> getProjectLinks(String project) {
|
||||
return filterLinks(projectLinks, webLink -> webLink.getProjectWeblink(project));
|
||||
}
|
||||
|
||||
@@ -179,7 +181,7 @@ public class WebLinks {
|
||||
* @param branch Branch name
|
||||
* @return Links for branches.
|
||||
*/
|
||||
public List<WebLinkInfo> getBranchLinks(String project, String branch) {
|
||||
public ImmutableList<WebLinkInfo> getBranchLinks(String project, String branch) {
|
||||
return filterLinks(branchLinks, webLink -> webLink.getBranchWebLink(project, branch));
|
||||
}
|
||||
|
||||
@@ -188,12 +190,15 @@ public class WebLinks {
|
||||
* @param tag Tag name
|
||||
* @return Links for tags.
|
||||
*/
|
||||
public List<WebLinkInfo> getTagLinks(String project, String tag) {
|
||||
public ImmutableList<WebLinkInfo> getTagLinks(String project, String tag) {
|
||||
return filterLinks(tagLinks, webLink -> webLink.getTagWebLink(project, tag));
|
||||
}
|
||||
|
||||
private <T extends WebLink> List<WebLinkInfo> filterLinks(
|
||||
private <T extends WebLink> ImmutableList<WebLinkInfo> filterLinks(
|
||||
DynamicSet<T> links, Function<T, WebLinkInfo> transformer) {
|
||||
return FluentIterable.from(links).transform(transformer).filter(INVALID_WEBLINK).toList();
|
||||
return Streams.stream(links)
|
||||
.map(transformer)
|
||||
.filter(INVALID_WEBLINK)
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import static com.google.gerrit.extensions.client.ListChangesOption.PUSH_CERTIFI
|
||||
import static com.google.gerrit.extensions.client.ListChangesOption.WEB_LINKS;
|
||||
import static com.google.gerrit.server.CommonConverters.toGitPerson;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
@@ -71,7 +72,6 @@ import com.google.inject.assistedinject.Assisted;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -182,7 +182,7 @@ public class RevisionJson {
|
||||
info.message = commit.getFullMessage();
|
||||
|
||||
if (addLinks) {
|
||||
List<WebLinkInfo> links = webLinks.getPatchSetLinks(project, commit.name());
|
||||
ImmutableList<WebLinkInfo> links = webLinks.getPatchSetLinks(project, commit.name());
|
||||
info.webLinks = links.isEmpty() ? null : links;
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ public class RevisionJson {
|
||||
i.commit = parent.name();
|
||||
i.subject = parent.getShortMessage();
|
||||
if (addLinks) {
|
||||
List<WebLinkInfo> parentLinks = webLinks.getParentLinks(project, parent.name());
|
||||
ImmutableList<WebLinkInfo> parentLinks = webLinks.getParentLinks(project, parent.name());
|
||||
i.webLinks = parentLinks.isEmpty() ? null : parentLinks;
|
||||
}
|
||||
info.parents.add(i);
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.server.project;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
import com.google.gerrit.extensions.common.LabelTypeInfo;
|
||||
@@ -29,7 +30,6 @@ import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class ProjectJson {
|
||||
@@ -65,7 +65,7 @@ public class ProjectJson {
|
||||
info.description = Strings.emptyToNull(p.getDescription());
|
||||
info.state = p.getState();
|
||||
info.id = Url.encode(info.name);
|
||||
List<WebLinkInfo> links = webLinks.getProjectLinks(p.getName());
|
||||
ImmutableList<WebLinkInfo> links = webLinks.getProjectLinks(p.getName());
|
||||
info.webLinks = links.isEmpty() ? null : links;
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.extensions.common.DiffWebLinkInfo;
|
||||
import com.google.gerrit.extensions.common.EditInfo;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
@@ -380,7 +381,7 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
|
||||
FileInfo r = new FileInfo();
|
||||
ChangeEdit edit = rsrc.getChangeEdit();
|
||||
Change change = edit.getChange();
|
||||
List<DiffWebLinkInfo> links =
|
||||
ImmutableList<DiffWebLinkInfo> links =
|
||||
webLinks.getDiffLinks(
|
||||
change.getProject().get(),
|
||||
change.getChangeId(),
|
||||
|
||||
@@ -201,7 +201,7 @@ public class GetDiff implements RestReadView<FileResource> {
|
||||
? resource.getRevision().getEdit().get().getRefName()
|
||||
: resource.getRevision().getPatchSet().refName();
|
||||
|
||||
List<DiffWebLinkInfo> links =
|
||||
ImmutableList<DiffWebLinkInfo> links =
|
||||
webLinks.getDiffLinks(
|
||||
state.getName(),
|
||||
resource.getPatchKey().patchSetId().changeId().get(),
|
||||
@@ -273,7 +273,7 @@ public class GetDiff implements RestReadView<FileResource> {
|
||||
}
|
||||
|
||||
private List<WebLinkInfo> getFileWebLinks(Project project, String rev, String file) {
|
||||
List<WebLinkInfo> links = webLinks.getFileLinks(project.getName(), rev, file);
|
||||
ImmutableList<WebLinkInfo> links = webLinks.getFileLinks(project.getName(), rev, file);
|
||||
return links.isEmpty() ? null : links;
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,8 @@ public class ListBranches implements RestReadView<ProjectResource> {
|
||||
info.actions.put(d.getId(), new ActionInfo(d));
|
||||
}
|
||||
|
||||
List<WebLinkInfo> links = webLinks.getBranchLinks(projectState.getName(), ref.getName());
|
||||
ImmutableList<WebLinkInfo> links =
|
||||
webLinks.getBranchLinks(projectState.getName(), ref.getName());
|
||||
info.webLinks = links.isEmpty() ? null : links;
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -505,7 +505,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<WebLinkInfo> links = webLinks.getProjectLinks(projectName.get());
|
||||
ImmutableList<WebLinkInfo> links = webLinks.getProjectLinks(projectName.get());
|
||||
info.webLinks = links.isEmpty() ? null : links;
|
||||
|
||||
if (stdout == null || format.isJson()) {
|
||||
|
||||
@@ -182,7 +182,7 @@ public class ListTags implements RestReadView<ProjectResource> {
|
||||
perm.testOrFalse(RefPermission.DELETE) && projectState.statePermitsWrite() ? true : null;
|
||||
}
|
||||
|
||||
List<WebLinkInfo> webLinks = links.getTagLinks(projectState.getName(), ref.getName());
|
||||
ImmutableList<WebLinkInfo> webLinks = links.getTagLinks(projectState.getName(), ref.getName());
|
||||
if (object instanceof RevTag) {
|
||||
// Annotated or signed tag
|
||||
RevTag tag = (RevTag) object;
|
||||
|
||||
Reference in New Issue
Block a user