CommitValidators: Inject UrlFormatter via DynamicItem

If a plugin gets CommitValidators injected, the plugin fails to
load with:

  No implementation for com.google.gerrit.server.config.UrlFormatter was bound.

Since change I375245647 the UrlFormatter is bound as a DynamicItem,
so it should also be injected as such.

Bug: Issue 10500
Change-Id: Ieabb12b2086f8f785c8013e62193c8b811e00500
This commit is contained in:
David Pursehouse
2019-02-20 14:26:45 +09:00
parent d10a06a099
commit eb10cb814c

View File

@@ -28,6 +28,7 @@ import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.FooterConstants; import com.google.gerrit.common.FooterConstants;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo; import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.BooleanProjectConfig; import com.google.gerrit.reviewdb.client.BooleanProjectConfig;
@@ -89,7 +90,7 @@ public class CommitValidators {
@Singleton @Singleton
public static class Factory { public static class Factory {
private final PersonIdent gerritIdent; private final PersonIdent gerritIdent;
private final UrlFormatter urlFormatter; private final DynamicItem<UrlFormatter> urlFormatter;
private final PluginSetContext<CommitValidationListener> pluginValidators; private final PluginSetContext<CommitValidationListener> pluginValidators;
private final GitRepositoryManager repoManager; private final GitRepositoryManager repoManager;
private final AllUsersName allUsers; private final AllUsersName allUsers;
@@ -102,7 +103,7 @@ public class CommitValidators {
@Inject @Inject
Factory( Factory(
@GerritPersonIdent PersonIdent gerritIdent, @GerritPersonIdent PersonIdent gerritIdent,
UrlFormatter urlFormatter, DynamicItem<UrlFormatter> urlFormatter,
@GerritServerConfig Config cfg, @GerritServerConfig Config cfg,
PluginSetContext<CommitValidationListener> pluginValidators, PluginSetContext<CommitValidationListener> pluginValidators,
GitRepositoryManager repoManager, GitRepositoryManager repoManager,
@@ -140,11 +141,16 @@ public class CommitValidators {
new UploadMergesPermissionValidator(perm), new UploadMergesPermissionValidator(perm),
new ProjectStateValidationListener(projectState), new ProjectStateValidationListener(projectState),
new AmendedGerritMergeCommitValidationListener(perm, gerritIdent), new AmendedGerritMergeCommitValidationListener(perm, gerritIdent),
new AuthorUploaderValidator(user, perm, urlFormatter), new AuthorUploaderValidator(user, perm, urlFormatter.get()),
new CommitterUploaderValidator(user, perm, urlFormatter), new CommitterUploaderValidator(user, perm, urlFormatter.get()),
new SignedOffByValidator(user, perm, projectState), new SignedOffByValidator(user, perm, projectState),
new ChangeIdValidator( new ChangeIdValidator(
projectState, user, urlFormatter, installCommitMsgHookCommand, sshInfo, change), projectState,
user,
urlFormatter.get(),
installCommitMsgHookCommand,
sshInfo,
change),
new ConfigValidator(branch, user, rw, allUsers, allProjects), new ConfigValidator(branch, user, rw, allUsers, allProjects),
new BannedCommitsValidator(rejectCommits), new BannedCommitsValidator(rejectCommits),
new PluginCommitValidationListener(pluginValidators), new PluginCommitValidationListener(pluginValidators),
@@ -168,10 +174,15 @@ public class CommitValidators {
new UploadMergesPermissionValidator(perm), new UploadMergesPermissionValidator(perm),
new ProjectStateValidationListener(projectState), new ProjectStateValidationListener(projectState),
new AmendedGerritMergeCommitValidationListener(perm, gerritIdent), new AmendedGerritMergeCommitValidationListener(perm, gerritIdent),
new AuthorUploaderValidator(user, perm, urlFormatter), new AuthorUploaderValidator(user, perm, urlFormatter.get()),
new SignedOffByValidator(user, perm, projectCache.checkedGet(branch.getParentKey())), new SignedOffByValidator(user, perm, projectCache.checkedGet(branch.getParentKey())),
new ChangeIdValidator( new ChangeIdValidator(
projectState, user, urlFormatter, installCommitMsgHookCommand, sshInfo, change), projectState,
user,
urlFormatter.get(),
installCommitMsgHookCommand,
sshInfo,
change),
new ConfigValidator(branch, user, rw, allUsers, allProjects), new ConfigValidator(branch, user, rw, allUsers, allProjects),
new PluginCommitValidationListener(pluginValidators), new PluginCommitValidationListener(pluginValidators),
new ExternalIdUpdateListener(allUsers, externalIdsConsistencyChecker), new ExternalIdUpdateListener(allUsers, externalIdsConsistencyChecker),
@@ -200,8 +211,8 @@ public class CommitValidators {
ImmutableList.of( ImmutableList.of(
new UploadMergesPermissionValidator(perm), new UploadMergesPermissionValidator(perm),
new ProjectStateValidationListener(projectCache.checkedGet(branch.getParentKey())), new ProjectStateValidationListener(projectCache.checkedGet(branch.getParentKey())),
new AuthorUploaderValidator(user, perm, urlFormatter), new AuthorUploaderValidator(user, perm, urlFormatter.get()),
new CommitterUploaderValidator(user, perm, urlFormatter))); new CommitterUploaderValidator(user, perm, urlFormatter.get())));
} }
} }