Update example-changeQueryAttributes
Replace the deprecated ChangeAttributeFactory class with the
ChangePluginDefinedInfoFactory class.
Introduced in change:
https://gerrit-review.googlesource.com/c/gerrit/+/280758
Change-Id: I188f3f40eadcaf70aab74c8f1fee96797dd2d540
diff --git a/example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/AttributeFactory.java b/example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/AttributeFactory.java
index e67d5c9..e1e5978 100644
--- a/example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/AttributeFactory.java
+++ b/example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/AttributeFactory.java
@@ -14,12 +14,18 @@
package com.googlesource.gerrit.plugins.examples.changequeryattributes;
+import com.google.gerrit.entities.Change;
import com.google.gerrit.extensions.common.PluginDefinedInfo;
-import com.google.gerrit.server.DynamicOptions.BeanProvider;
-import com.google.gerrit.server.change.ChangeAttributeFactory;
+import com.google.gerrit.server.DynamicOptions;
+import com.google.gerrit.server.change.ChangePluginDefinedInfoFactory;
import com.google.gerrit.server.query.change.ChangeData;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.kohsuke.args4j.Option;
-public class AttributeFactory implements ChangeAttributeFactory {
+public class AttributeFactory implements ChangePluginDefinedInfoFactory {
+ protected MyChangeOptions options;
public class PluginAttribute extends PluginDefinedInfo {
public String exampleName;
@@ -32,7 +38,20 @@
}
@Override
- public PluginDefinedInfo create(ChangeData c, BeanProvider bp, String plugin) {
- return new PluginAttribute(c);
+ public Map<Change.Id, PluginDefinedInfo> createPluginDefinedInfos(
+ Collection<ChangeData> cds, DynamicOptions.BeanProvider bp, String plugin) {
+ Map<Change.Id, PluginDefinedInfo> out = new HashMap<>();
+ if (options == null) {
+ options = (MyChangeOptions) bp.getDynamicBean(plugin);
+ }
+ if (options.all) {
+ cds.forEach(cd -> out.put(cd.getId(), new PluginAttribute(cd)));
+ }
+ return out;
+ }
+
+ public class MyChangeOptions implements DynamicOptions.DynamicBean {
+ @Option(name = "--all", usage = "Include plugin output")
+ public boolean all = false;
}
}
diff --git a/example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/Module.java b/example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/Module.java
index 9db4619..77759bc 100644
--- a/example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/Module.java
+++ b/example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/Module.java
@@ -15,14 +15,33 @@
package com.googlesource.gerrit.plugins.examples.changequeryattributes;
import com.google.gerrit.extensions.annotations.Exports;
-import com.google.gerrit.server.change.ChangeAttributeFactory;
+import com.google.gerrit.extensions.registration.DynamicSet;
+import com.google.gerrit.server.DynamicOptions;
+import com.google.gerrit.server.change.ChangePluginDefinedInfoFactory;
+import com.google.gerrit.server.restapi.change.GetChange;
+import com.google.gerrit.server.restapi.change.QueryChanges;
+import com.google.gerrit.sshd.commands.Query;
import com.google.inject.AbstractModule;
public class Module extends AbstractModule {
@Override
protected void configure() {
- bind(ChangeAttributeFactory.class)
- .annotatedWith(Exports.named("example-changeQueryAttributes"))
- .to(AttributeFactory.class);
+ // Register attribute factory.
+ DynamicSet.bind(binder(), ChangePluginDefinedInfoFactory.class).to(AttributeFactory.class);
+
+ // Register options for GET /changes/X/change and /changes/X/detail.
+ bind(DynamicOptions.DynamicBean.class)
+ .annotatedWith(Exports.named(GetChange.class))
+ .to(AttributeFactory.MyChangeOptions.class);
+
+ // Register options for GET /changes/?q=...
+ bind(DynamicOptions.DynamicBean.class)
+ .annotatedWith(Exports.named(QueryChanges.class))
+ .to(AttributeFactory.MyChangeOptions.class);
+
+ // Register options for ssh gerrit query.
+ bind(DynamicOptions.DynamicBean.class)
+ .annotatedWith(Exports.named(Query.class))
+ .to(AttributeFactory.MyChangeOptions.class);
}
}