Adjust more classes to inject UrlFormatter via DynamicItem
Since change I375245647 the UrlFormatter is bound as a DynamicItem, so it should also be injected as such. Adjust most remaining classes to do that. The only one remaining is the ChangeCleanupConfig which requires slightly more invasive changes and will be done in a separate commit. Bug: Issue 10500 Change-Id: Ie9eeef11bd5ce63168bb339e22ee3062482ddd25
This commit is contained in:
@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.account.externalids.ExternalId;
|
||||
@@ -58,7 +59,7 @@ public class GerritPublicKeyChecker extends PublicKeyChecker {
|
||||
@Singleton
|
||||
public static class Factory {
|
||||
private final Provider<InternalAccountQuery> accountQueryProvider;
|
||||
private final UrlFormatter urlFormatter;
|
||||
private final DynamicItem<UrlFormatter> urlFormatter;
|
||||
private final IdentifiedUser.GenericFactory userFactory;
|
||||
private final int maxTrustDepth;
|
||||
private final ImmutableMap<Long, Fingerprint> trusted;
|
||||
@@ -68,7 +69,7 @@ public class GerritPublicKeyChecker extends PublicKeyChecker {
|
||||
@GerritServerConfig Config cfg,
|
||||
Provider<InternalAccountQuery> accountQueryProvider,
|
||||
IdentifiedUser.GenericFactory userFactory,
|
||||
UrlFormatter urlFormatter) {
|
||||
DynamicItem<UrlFormatter> urlFormatter) {
|
||||
this.accountQueryProvider = accountQueryProvider;
|
||||
this.urlFormatter = urlFormatter;
|
||||
this.userFactory = userFactory;
|
||||
@@ -101,7 +102,7 @@ public class GerritPublicKeyChecker extends PublicKeyChecker {
|
||||
}
|
||||
|
||||
private final Provider<InternalAccountQuery> accountQueryProvider;
|
||||
private final UrlFormatter urlFormatter;
|
||||
private final DynamicItem<UrlFormatter> urlFormatter;
|
||||
private final IdentifiedUser.GenericFactory userFactory;
|
||||
|
||||
private IdentifiedUser expectedUser;
|
||||
@@ -144,7 +145,7 @@ public class GerritPublicKeyChecker extends PublicKeyChecker {
|
||||
private CheckResult checkIdsForExpectedUser(PGPPublicKey key) throws PGPException {
|
||||
Set<String> allowedUserIds = getAllowedUserIds(expectedUser);
|
||||
if (allowedUserIds.isEmpty()) {
|
||||
Optional<String> settings = urlFormatter.getSettingsUrl("Identities");
|
||||
Optional<String> settings = urlFormatter.get().getSettingsUrl("Identities");
|
||||
return CheckResult.bad(
|
||||
"No identities found for user"
|
||||
+ (settings.isPresent() ? "; check " + settings.get() : ""));
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.SubmitRecord;
|
||||
import com.google.gerrit.common.data.SubmitRequirement;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.index.IndexConfig;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
@@ -85,7 +86,7 @@ public class EventFactory {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private final AccountCache accountCache;
|
||||
private final UrlFormatter urlFormatter;
|
||||
private final DynamicItem<UrlFormatter> urlFormatter;
|
||||
private final Emails emails;
|
||||
private final PatchListCache patchListCache;
|
||||
private final Provider<PersonIdent> myIdent;
|
||||
@@ -100,7 +101,7 @@ public class EventFactory {
|
||||
EventFactory(
|
||||
AccountCache accountCache,
|
||||
Emails emails,
|
||||
UrlFormatter urlFormatter,
|
||||
DynamicItem<UrlFormatter> urlFormatter,
|
||||
PatchListCache patchListCache,
|
||||
@GerritPersonIdent Provider<PersonIdent> myIdent,
|
||||
ChangeData.Factory changeDataFactory,
|
||||
@@ -678,7 +679,7 @@ public class EventFactory {
|
||||
/** Get a link to the change; null if the server doesn't know its own address. */
|
||||
private String getChangeUrl(Change change) {
|
||||
if (change != null) {
|
||||
return urlFormatter.getChangeViewUrl(change.getProject(), change.getId()).orElse(null);
|
||||
return urlFormatter.get().getChangeViewUrl(change.getProject(), change.getId()).orElse(null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.git;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.config.UrlFormatter;
|
||||
import com.google.inject.Inject;
|
||||
@@ -27,10 +28,10 @@ public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
||||
private static final String SUBJECT_CROP_APPENDIX = "...";
|
||||
private static final int SUBJECT_CROP_RANGE = 10;
|
||||
|
||||
private final UrlFormatter urlFormatter;
|
||||
private final DynamicItem<UrlFormatter> urlFormatter;
|
||||
|
||||
@Inject
|
||||
DefaultChangeReportFormatter(UrlFormatter urlFormatter) {
|
||||
DefaultChangeReportFormatter(DynamicItem<UrlFormatter> urlFormatter) {
|
||||
this.urlFormatter = urlFormatter;
|
||||
}
|
||||
|
||||
@@ -49,7 +50,10 @@ public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
||||
Change c = input.change();
|
||||
return String.format(
|
||||
"change %s closed",
|
||||
urlFormatter.getChangeViewUrl(c.getProject(), c.getId()).orElse(c.getId().toString()));
|
||||
urlFormatter
|
||||
.get()
|
||||
.getChangeViewUrl(c.getProject(), c.getId())
|
||||
.orElse(c.getId().toString()));
|
||||
}
|
||||
|
||||
protected String cropSubject(String subject) {
|
||||
@@ -69,7 +73,7 @@ public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
||||
|
||||
protected String formatChangeUrl(Input input) {
|
||||
Change c = input.change();
|
||||
Optional<String> changeUrl = urlFormatter.getChangeViewUrl(c.getProject(), c.getId());
|
||||
Optional<String> changeUrl = urlFormatter.get().getChangeViewUrl(c.getProject(), c.getId());
|
||||
checkState(changeUrl.isPresent());
|
||||
|
||||
StringBuilder m =
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.google.common.collect.Sets;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.MergeConflictException;
|
||||
@@ -164,7 +165,7 @@ public class MergeUtil {
|
||||
|
||||
private final Provider<ReviewDb> db;
|
||||
private final IdentifiedUser.GenericFactory identifiedUserFactory;
|
||||
private final UrlFormatter urlFormatter;
|
||||
private final DynamicItem<UrlFormatter> urlFormatter;
|
||||
private final ApprovalsUtil approvalsUtil;
|
||||
private final ProjectState project;
|
||||
private final boolean useContentMerge;
|
||||
@@ -176,7 +177,7 @@ public class MergeUtil {
|
||||
@GerritServerConfig Config serverConfig,
|
||||
Provider<ReviewDb> db,
|
||||
IdentifiedUser.GenericFactory identifiedUserFactory,
|
||||
UrlFormatter urlFormatter,
|
||||
DynamicItem<UrlFormatter> urlFormatter,
|
||||
ApprovalsUtil approvalsUtil,
|
||||
PluggableCommitMessageGenerator commitMessageGenerator,
|
||||
@Assisted ProjectState project) {
|
||||
@@ -196,7 +197,7 @@ public class MergeUtil {
|
||||
@GerritServerConfig Config serverConfig,
|
||||
Provider<ReviewDb> db,
|
||||
IdentifiedUser.GenericFactory identifiedUserFactory,
|
||||
UrlFormatter urlFormatter,
|
||||
DynamicItem<UrlFormatter> urlFormatter,
|
||||
ApprovalsUtil approvalsUtil,
|
||||
@Assisted ProjectState project,
|
||||
PluggableCommitMessageGenerator commitMessageGenerator,
|
||||
@@ -491,7 +492,7 @@ public class MergeUtil {
|
||||
msgbuf.append('\n');
|
||||
}
|
||||
|
||||
Optional<String> url = urlFormatter.getChangeViewUrl(null, c.getId());
|
||||
Optional<String> url = urlFormatter.get().getChangeViewUrl(null, c.getId());
|
||||
if (url.isPresent()) {
|
||||
if (!contains(footers, FooterConstants.REVIEWED_ON, url.get())) {
|
||||
msgbuf
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||
import com.google.gerrit.extensions.client.Side;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.registration.Extension;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
@@ -98,7 +99,7 @@ public class MailProcessor {
|
||||
private final CommentAdded commentAdded;
|
||||
private final ApprovalsUtil approvalsUtil;
|
||||
private final AccountCache accountCache;
|
||||
private final UrlFormatter urlFormatter;
|
||||
private final DynamicItem<UrlFormatter> urlFormatter;
|
||||
|
||||
@Inject
|
||||
public MailProcessor(
|
||||
@@ -116,7 +117,7 @@ public class MailProcessor {
|
||||
ApprovalsUtil approvalsUtil,
|
||||
CommentAdded commentAdded,
|
||||
AccountCache accountCache,
|
||||
UrlFormatter urlFormatter) {
|
||||
DynamicItem<UrlFormatter> urlFormatter) {
|
||||
this.emails = emails;
|
||||
this.emailRejectionSender = emailRejectionSender;
|
||||
this.retryHelper = retryHelper;
|
||||
@@ -242,7 +243,10 @@ public class MailProcessor {
|
||||
// If URL is not defined, we won't be able to parse line comments. We still attempt to get the
|
||||
// other ones.
|
||||
String changeUrl =
|
||||
urlFormatter.getChangeViewUrl(cd.project(), cd.getId()).orElse("http://gerrit.invalid/");
|
||||
urlFormatter
|
||||
.get()
|
||||
.getChangeViewUrl(cd.project(), cd.getId())
|
||||
.orElse("http://gerrit.invalid/");
|
||||
|
||||
List<MailComment> parsedComments;
|
||||
if (useHtmlParser(message)) {
|
||||
|
||||
@@ -220,7 +220,10 @@ public abstract class ChangeEmail extends NotificationEmail {
|
||||
/** Get a link to the change; null if the server doesn't know its own address. */
|
||||
@Nullable
|
||||
public String getChangeUrl() {
|
||||
return args.urlFormatter.getChangeViewUrl(change.getProject(), change.getId()).orElse(null);
|
||||
return args.urlFormatter
|
||||
.get()
|
||||
.getChangeViewUrl(change.getProject(), change.getId())
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public String getChangeMessageThreadId() {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.mail.send;
|
||||
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.AnonymousUser;
|
||||
@@ -68,7 +69,7 @@ public class EmailArguments {
|
||||
final AnonymousUser anonymousUser;
|
||||
final String anonymousCowardName;
|
||||
final PersonIdent gerritPersonIdent;
|
||||
final UrlFormatter urlFormatter;
|
||||
final DynamicItem<UrlFormatter> urlFormatter;
|
||||
final AllProjectsName allProjectsName;
|
||||
final List<String> sshAddresses;
|
||||
final SitePaths site;
|
||||
@@ -102,7 +103,7 @@ public class EmailArguments {
|
||||
AnonymousUser anonymousUser,
|
||||
@AnonymousCowardName String anonymousCowardName,
|
||||
GerritPersonIdentProvider gerritPersonIdentProvider,
|
||||
UrlFormatter urlFormatter,
|
||||
DynamicItem<UrlFormatter> urlFormatter,
|
||||
AllProjectsName allProjectsName,
|
||||
ChangeQueryBuilder queryBuilder,
|
||||
Provider<ReviewDb> db,
|
||||
|
||||
@@ -299,7 +299,7 @@ public abstract class OutgoingEmail {
|
||||
}
|
||||
|
||||
public String getGerritUrl() {
|
||||
return args.urlFormatter.getWebUrl().orElse(null);
|
||||
return args.urlFormatter.get().getWebUrl().orElse(null);
|
||||
}
|
||||
|
||||
/** Set a header in the outgoing message. */
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.server.project;
|
||||
import com.google.gerrit.common.data.ContributorAgreement;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.common.data.PermissionRule.Action;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.metrics.Counter0;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
@@ -38,7 +39,7 @@ import java.util.List;
|
||||
@Singleton
|
||||
public class ContributorAgreementsChecker {
|
||||
|
||||
private final UrlFormatter urlFormatter;
|
||||
private final DynamicItem<UrlFormatter> urlFormatter;
|
||||
private final ProjectCache projectCache;
|
||||
private final Metrics metrics;
|
||||
|
||||
@@ -57,7 +58,7 @@ public class ContributorAgreementsChecker {
|
||||
|
||||
@Inject
|
||||
ContributorAgreementsChecker(
|
||||
UrlFormatter urlFormatter, ProjectCache projectCache, Metrics metrics) {
|
||||
DynamicItem<UrlFormatter> urlFormatter, ProjectCache projectCache, Metrics metrics) {
|
||||
this.urlFormatter = urlFormatter;
|
||||
this.projectCache = projectCache;
|
||||
this.metrics = metrics;
|
||||
@@ -110,7 +111,7 @@ public class ContributorAgreementsChecker {
|
||||
.append(iUser.getAccountId())
|
||||
.append(")");
|
||||
|
||||
msg.append(urlFormatter.getSettingsUrl("Agreements").orElse(""));
|
||||
msg.append(urlFormatter.get().getSettingsUrl("Agreements").orElse(""));
|
||||
throw new AuthException(msg.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import com.google.gerrit.common.data.GarbageCollectionResult;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
@@ -55,14 +56,14 @@ public class GarbageCollect
|
||||
private final boolean canGC;
|
||||
private final GarbageCollection.Factory garbageCollectionFactory;
|
||||
private final WorkQueue workQueue;
|
||||
private final UrlFormatter urlFormatter;
|
||||
private final DynamicItem<UrlFormatter> urlFormatter;
|
||||
|
||||
@Inject
|
||||
GarbageCollect(
|
||||
GitRepositoryManager repoManager,
|
||||
GarbageCollection.Factory garbageCollectionFactory,
|
||||
WorkQueue workQueue,
|
||||
UrlFormatter urlFormatter) {
|
||||
DynamicItem<UrlFormatter> urlFormatter) {
|
||||
this.workQueue = workQueue;
|
||||
this.urlFormatter = urlFormatter;
|
||||
this.canGC = repoManager instanceof LocalDiskRepositoryManager;
|
||||
@@ -99,7 +100,9 @@ public class GarbageCollect
|
||||
WorkQueue.Task<Void> task = (WorkQueue.Task<Void>) workQueue.getDefaultQueue().submit(job);
|
||||
|
||||
Optional<String> url =
|
||||
urlFormatter.getRestUrl("a/config/server/tasks/" + HexFormat.fromInt(task.getTaskId()));
|
||||
urlFormatter
|
||||
.get()
|
||||
.getRestUrl("a/config/server/tasks/" + HexFormat.fromInt(task.getTaskId()));
|
||||
// We're in a HTTP handler, so must be present.
|
||||
checkState(url.isPresent());
|
||||
return Response.accepted(url.get());
|
||||
|
||||
Reference in New Issue
Block a user