Removing redundant class WeblinksProvider

Change-Id: I06f2117ad16718a7329dd589ca9d95235783363c
This commit is contained in:
Sven Selberg
2014-10-01 12:49:36 +02:00
parent bde6f0933f
commit 6914a8327c
8 changed files with 19 additions and 71 deletions

View File

@@ -21,9 +21,12 @@ import com.google.gerrit.extensions.webui.BranchWebLink;
import com.google.gerrit.extensions.webui.FileWebLink; import com.google.gerrit.extensions.webui.FileWebLink;
import com.google.gerrit.extensions.webui.PatchSetWebLink; import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.extensions.webui.ProjectWebLink; import com.google.gerrit.extensions.webui.ProjectWebLink;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.List; import java.util.List;
@Singleton
public class WebLinks { public class WebLinks {
private final DynamicSet<PatchSetWebLink> patchSetLinks; private final DynamicSet<PatchSetWebLink> patchSetLinks;
@@ -31,6 +34,7 @@ public class WebLinks {
private final DynamicSet<ProjectWebLink> projectLinks; private final DynamicSet<ProjectWebLink> projectLinks;
private final DynamicSet<BranchWebLink> branchLinks; private final DynamicSet<BranchWebLink> branchLinks;
@Inject
public WebLinks(DynamicSet<PatchSetWebLink> patchSetLinks, public WebLinks(DynamicSet<PatchSetWebLink> patchSetLinks,
DynamicSet<FileWebLink> fileLinks, DynamicSet<FileWebLink> fileLinks,
DynamicSet<ProjectWebLink> projectLinks, DynamicSet<ProjectWebLink> projectLinks,

View File

@@ -1,47 +0,0 @@
// Copyright (C) 2014 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.server;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.webui.BranchWebLink;
import com.google.gerrit.extensions.webui.FileWebLink;
import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.extensions.webui.ProjectWebLink;
import com.google.inject.Inject;
import com.google.inject.Provider;
public class WebLinksProvider implements Provider<WebLinks> {
private final DynamicSet<PatchSetWebLink> patchSetLinks;
private final DynamicSet<FileWebLink> fileLinks;
private final DynamicSet<ProjectWebLink> projectLinks;
private final DynamicSet<BranchWebLink> branchLinks;
@Inject
public WebLinksProvider(DynamicSet<PatchSetWebLink> patchSetLinks,
DynamicSet<FileWebLink> fileLinks,
DynamicSet<ProjectWebLink> projectLinks,
DynamicSet<BranchWebLink> branchLinks) {
this.patchSetLinks = patchSetLinks;
this.fileLinks = fileLinks;
this.projectLinks = projectLinks;
this.branchLinks = branchLinks;
}
@Override
public WebLinks get() {
return new WebLinks(patchSetLinks, fileLinks, projectLinks, branchLinks);
}
}

View File

@@ -126,7 +126,7 @@ public class ChangeJson {
private final DynamicMap<DownloadCommand> downloadCommands; private final DynamicMap<DownloadCommand> downloadCommands;
private final DynamicMap<RestView<ChangeResource>> changeViews; private final DynamicMap<RestView<ChangeResource>> changeViews;
private final Revisions revisions; private final Revisions revisions;
private final Provider<WebLinks> webLinks; private final WebLinks webLinks;
private final EnumSet<ListChangesOption> options; private final EnumSet<ListChangesOption> options;
private final ChangeMessagesUtil cmUtil; private final ChangeMessagesUtil cmUtil;
private final PatchLineCommentsUtil plcUtil; private final PatchLineCommentsUtil plcUtil;
@@ -149,7 +149,7 @@ public class ChangeJson {
DynamicMap<DownloadCommand> downloadCommands, DynamicMap<DownloadCommand> downloadCommands,
DynamicMap<RestView<ChangeResource>> changeViews, DynamicMap<RestView<ChangeResource>> changeViews,
Revisions revisions, Revisions revisions,
Provider<WebLinks> webLinks, WebLinks webLinks,
ChangeMessagesUtil cmUtil, ChangeMessagesUtil cmUtil,
PatchLineCommentsUtil plcUtil) { PatchLineCommentsUtil plcUtil) {
this.db = db; this.db = db;
@@ -844,7 +844,7 @@ public class ChangeJson {
if (has(WEB_LINKS)) { if (has(WEB_LINKS)) {
out.webLinks = Lists.newArrayList(); out.webLinks = Lists.newArrayList();
for (WebLinkInfo link : webLinks.get().getPatchSetLinks( for (WebLinkInfo link : webLinks.getPatchSetLinks(
project, in.getRevision().get())) { project, in.getRevision().get())) {
out.webLinks.add(link); out.webLinks.add(link);
} }

View File

@@ -47,8 +47,6 @@ import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import org.eclipse.jgit.diff.Edit; import org.eclipse.jgit.diff.Edit;
import org.eclipse.jgit.diff.ReplaceEdit; import org.eclipse.jgit.diff.ReplaceEdit;
import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineException;
@@ -69,7 +67,7 @@ public class GetDiff implements RestReadView<FileResource> {
private final ProjectCache projectCache; private final ProjectCache projectCache;
private final PatchScriptFactory.Factory patchScriptFactoryFactory; private final PatchScriptFactory.Factory patchScriptFactoryFactory;
private final Revisions revisions; private final Revisions revisions;
private final Provider<WebLinks> webLinks; private final WebLinks webLinks;
@Option(name = "--base", metaVar = "REVISION") @Option(name = "--base", metaVar = "REVISION")
String base; String base;
@@ -87,7 +85,7 @@ public class GetDiff implements RestReadView<FileResource> {
GetDiff(ProjectCache projectCache, GetDiff(ProjectCache projectCache,
PatchScriptFactory.Factory patchScriptFactoryFactory, PatchScriptFactory.Factory patchScriptFactoryFactory,
Revisions revisions, Revisions revisions,
Provider<WebLinks> webLinks) { WebLinks webLinks) {
this.projectCache = projectCache; this.projectCache = projectCache;
this.patchScriptFactoryFactory = patchScriptFactoryFactory; this.patchScriptFactoryFactory = patchScriptFactoryFactory;
this.revisions = revisions; this.revisions = revisions;
@@ -206,7 +204,7 @@ public class GetDiff implements RestReadView<FileResource> {
private List<WebLinkInfo> getFileWebLinks(Project project, String rev, private List<WebLinkInfo> getFileWebLinks(Project project, String rev,
String file) { String file) {
List<WebLinkInfo> fileWebLinks = new ArrayList<>(); List<WebLinkInfo> fileWebLinks = new ArrayList<>();
for (WebLinkInfo link : webLinks.get().getFileLinks(project.getName(), for (WebLinkInfo link : webLinks.getFileLinks(project.getName(),
rev, file)) { rev, file)) {
if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) { if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) {
fileWebLinks.add(link); fileWebLinks.add(link);

View File

@@ -47,8 +47,6 @@ import com.google.gerrit.server.FileTypeRegistry;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.MimeUtilFileTypeRegistry; import com.google.gerrit.server.MimeUtilFileTypeRegistry;
import com.google.gerrit.server.PluginUser; import com.google.gerrit.server.PluginUser;
import com.google.gerrit.server.WebLinks;
import com.google.gerrit.server.WebLinksProvider;
import com.google.gerrit.server.account.AccountByEmailCacheImpl; import com.google.gerrit.server.account.AccountByEmailCacheImpl;
import com.google.gerrit.server.account.AccountCacheImpl; import com.google.gerrit.server.account.AccountCacheImpl;
import com.google.gerrit.server.account.AccountControl; import com.google.gerrit.server.account.AccountControl;
@@ -235,7 +233,6 @@ public class GerritGlobalModule extends FactoryModule {
.in(SINGLETON); .in(SINGLETON);
bind(FromAddressGenerator.class).toProvider( bind(FromAddressGenerator.class).toProvider(
FromAddressGeneratorProvider.class).in(SINGLETON); FromAddressGeneratorProvider.class).in(SINGLETON);
bind(WebLinks.class).toProvider(WebLinksProvider.class).in(SINGLETON);
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class) bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class)
.toProvider(DisableReverseDnsLookupProvider.class).in(SINGLETON); .toProvider(DisableReverseDnsLookupProvider.class).in(SINGLETON);

View File

@@ -29,7 +29,6 @@ import com.google.gerrit.server.WebLinks;
import com.google.gerrit.server.extensions.webui.UiActions; import com.google.gerrit.server.extensions.webui.UiActions;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.google.inject.util.Providers; import com.google.inject.util.Providers;
@@ -51,12 +50,12 @@ import java.util.TreeMap;
public class ListBranches implements RestReadView<ProjectResource> { public class ListBranches implements RestReadView<ProjectResource> {
private final GitRepositoryManager repoManager; private final GitRepositoryManager repoManager;
private final DynamicMap<RestView<BranchResource>> branchViews; private final DynamicMap<RestView<BranchResource>> branchViews;
private final Provider<WebLinks> webLinks; private final WebLinks webLinks;
@Inject @Inject
public ListBranches(GitRepositoryManager repoManager, public ListBranches(GitRepositoryManager repoManager,
DynamicMap<RestView<BranchResource>> branchViews, DynamicMap<RestView<BranchResource>> branchViews,
Provider<WebLinks> webLinks) { WebLinks webLinks) {
this.repoManager = repoManager; this.repoManager = repoManager;
this.branchViews = branchViews; this.branchViews = branchViews;
this.webLinks = webLinks; this.webLinks = webLinks;
@@ -169,7 +168,7 @@ public class ListBranches implements RestReadView<ProjectResource> {
info.actions.put(d.getId(), new ActionInfo(d)); info.actions.put(d.getId(), new ActionInfo(d));
} }
info.webLinks = Lists.newArrayList(); info.webLinks = Lists.newArrayList();
for (WebLinkInfo link : webLinks.get().getBranchLinks( for (WebLinkInfo link : webLinks.getBranchLinks(
refControl.getProjectControl().getProject().getName(), ref.getName())) { refControl.getProjectControl().getProject().getName(), ref.getName())) {
if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) { if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) {
info.webLinks.add(link); info.webLinks.add(link);

View File

@@ -43,8 +43,6 @@ import com.google.gerrit.server.util.RegexListSearcher;
import com.google.gerrit.server.util.TreeFormatter; import com.google.gerrit.server.util.TreeFormatter;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
@@ -112,7 +110,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
private final GroupControl.Factory groupControlFactory; private final GroupControl.Factory groupControlFactory;
private final GitRepositoryManager repoManager; private final GitRepositoryManager repoManager;
private final ProjectNode.Factory projectNodeFactory; private final ProjectNode.Factory projectNodeFactory;
private final Provider<WebLinks> webLinks; private final WebLinks webLinks;
@Deprecated @Deprecated
@Option(name = "--format", usage = "(deprecated) output format") @Option(name = "--format", usage = "(deprecated) output format")
@@ -193,7 +191,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
protected ListProjects(CurrentUser currentUser, ProjectCache projectCache, protected ListProjects(CurrentUser currentUser, ProjectCache projectCache,
GroupCache groupCache, GroupControl.Factory groupControlFactory, GroupCache groupCache, GroupControl.Factory groupControlFactory,
GitRepositoryManager repoManager, ProjectNode.Factory projectNodeFactory, GitRepositoryManager repoManager, ProjectNode.Factory projectNodeFactory,
Provider<WebLinks> webLinks) { WebLinks webLinks) {
this.currentUser = currentUser; this.currentUser = currentUser;
this.projectCache = projectCache; this.projectCache = projectCache;
this.groupCache = groupCache; this.groupCache = groupCache;
@@ -385,7 +383,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
} }
info.webLinks = Lists.newArrayList(); info.webLinks = Lists.newArrayList();
for (WebLinkInfo link : webLinks.get().getProjectLinks(projectName.get())) { for (WebLinkInfo link : webLinks.getProjectLinks(projectName.get())) {
if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) { if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) {
info.webLinks.add(link); info.webLinks.add(link);
} }

View File

@@ -24,18 +24,17 @@ import com.google.gerrit.server.WebLinks;
import com.google.gerrit.server.config.AllProjectsName; import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.config.AllProjectsNameProvider; import com.google.gerrit.server.config.AllProjectsNameProvider;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@Singleton @Singleton
public class ProjectJson { public class ProjectJson {
private final AllProjectsName allProjects; private final AllProjectsName allProjects;
private final Provider<WebLinks> webLinks; private final WebLinks webLinks;
@Inject @Inject
ProjectJson(AllProjectsNameProvider allProjectsNameProvider, ProjectJson(AllProjectsNameProvider allProjectsNameProvider,
Provider<WebLinks> webLinks) { WebLinks webLinks) {
this.allProjects = allProjectsNameProvider.get(); this.allProjects = allProjectsNameProvider.get();
this.webLinks = webLinks; this.webLinks = webLinks;
} }
@@ -54,7 +53,7 @@ public class ProjectJson {
info.id = Url.encode(info.name); info.id = Url.encode(info.name);
info.webLinks = Lists.newArrayList(); info.webLinks = Lists.newArrayList();
for (WebLinkInfo link : webLinks.get().getProjectLinks(p.getName())) { for (WebLinkInfo link : webLinks.getProjectLinks(p.getName())) {
if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) { if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) {
info.webLinks.add(link); info.webLinks.add(link);
} }