Adapt to changes in gerrit core Remove the deprecated ChangeAttributeFactory after it was deleted with change https://gerrit-review.googlesource.com/c/285979. Change-Id: I555832317943a9614b64f7851856c7c5fad9e05e
diff --git a/java/com/google/gerrit/plugins/checks/Module.java b/java/com/google/gerrit/plugins/checks/Module.java index 3431ec1..4787df6 100644 --- a/java/com/google/gerrit/plugins/checks/Module.java +++ b/java/com/google/gerrit/plugins/checks/Module.java
@@ -31,8 +31,8 @@ import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.ServerInitiated; import com.google.gerrit.server.UserInitiated; -import com.google.gerrit.server.change.ChangeAttributeFactory; import com.google.gerrit.server.change.ChangeETagComputation; +import com.google.gerrit.server.change.ChangePluginDefinedInfoFactory; import com.google.gerrit.server.git.validators.CommitValidationListener; import com.google.gerrit.server.git.validators.MergeValidationListener; import com.google.gerrit.server.git.validators.RefOperationValidationListener; @@ -67,7 +67,8 @@ .to(ChecksETagComputation.class) .in(SINGLETON); - DynamicSet.bind(binder(), ChangeAttributeFactory.class).to(ChangeCheckAttributeFactory.class); + DynamicSet.bind(binder(), ChangePluginDefinedInfoFactory.class) + .to(ChangeCheckAttributeFactory.class); bind(DynamicOptions.DynamicBean.class) .annotatedWith(Exports.named(GetChange.class)) .to(GetChangeOptions.class);
diff --git a/java/com/google/gerrit/plugins/checks/api/ChangeCheckAttributeFactory.java b/java/com/google/gerrit/plugins/checks/api/ChangeCheckAttributeFactory.java index 9c48851..f456279 100644 --- a/java/com/google/gerrit/plugins/checks/api/ChangeCheckAttributeFactory.java +++ b/java/com/google/gerrit/plugins/checks/api/ChangeCheckAttributeFactory.java
@@ -14,13 +14,22 @@ package com.google.gerrit.plugins.checks.api; +import com.google.common.collect.ImmutableMap; +import com.google.gerrit.entities.Change; +import com.google.gerrit.extensions.common.PluginDefinedInfo; import com.google.gerrit.plugins.checks.CombinedCheckStateCache; import com.google.gerrit.server.DynamicOptions.BeanProvider; import com.google.gerrit.server.DynamicOptions.DynamicBean; -import com.google.gerrit.server.change.ChangeAttributeFactory; +import com.google.gerrit.server.change.ChangePluginDefinedInfoFactory; import com.google.gerrit.server.query.change.ChangeData; import com.google.inject.Inject; import com.google.inject.Singleton; +import java.util.AbstractMap; +import java.util.AbstractMap.SimpleImmutableEntry; +import java.util.Collection; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; import org.kohsuke.args4j.Option; /** @@ -28,7 +37,7 @@ * a {@code ChangeInfo}. */ @Singleton -public class ChangeCheckAttributeFactory implements ChangeAttributeFactory { +public class ChangeCheckAttributeFactory implements ChangePluginDefinedInfoFactory { private static final String COMBINED_OPTION_NAME = "--combined"; private static final String COMBINED_OPTION_USAGE = "include combined check state"; @@ -50,19 +59,37 @@ } @Override - public ChangeCheckInfo create(ChangeData cd, BeanProvider beanProvider, String plugin) { + public Map<Change.Id, PluginDefinedInfo> createPluginDefinedInfos( + Collection<ChangeData> cds, BeanProvider beanProvider, String plugin) { DynamicBean opts = beanProvider.getDynamicBean(plugin); if (opts == null) { - return null; + return ImmutableMap.of(); } if (opts instanceof GetChangeOptions) { - return forGetChange(cd, (GetChangeOptions) opts); + return evalAndCollect( + cds, + cd -> + new AbstractMap.SimpleImmutableEntry<>( + cd.getId(), forGetChange(cd, (GetChangeOptions) opts))); } else if (opts instanceof QueryChangesOptions) { - return forQueryChanges(cd, (QueryChangesOptions) opts); + return evalAndCollect( + cds, + cd -> + new AbstractMap.SimpleImmutableEntry<>( + cd.getId(), forQueryChanges(cd, (QueryChangesOptions) opts))); } throw new IllegalStateException("unexpected options type: " + opts); } + private Map<Change.Id, PluginDefinedInfo> evalAndCollect( + Collection<ChangeData> cds, + Function<ChangeData, SimpleImmutableEntry<Change.Id, ChangeCheckInfo>> transformFn) { + return cds.stream() + .map(transformFn) + .filter(e -> e.getKey() != null && e.getValue() != null) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + private ChangeCheckInfo forGetChange(ChangeData cd, GetChangeOptions opts) { if (opts == null || !opts.combined) { return null;