Skip to content

Commit 8d725af

Browse files
author
Adithya Chakilam
committed
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
1 parent 3102fc4 commit 8d725af

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/AttributeFactory.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@
1414

1515
package com.googlesource.gerrit.plugins.examples.changequeryattributes;
1616

17+
import com.google.gerrit.entities.Change;
1718
import com.google.gerrit.extensions.common.PluginDefinedInfo;
18-
import com.google.gerrit.server.DynamicOptions.BeanProvider;
19-
import com.google.gerrit.server.change.ChangeAttributeFactory;
19+
import com.google.gerrit.server.DynamicOptions;
20+
import com.google.gerrit.server.change.ChangePluginDefinedInfoFactory;
2021
import com.google.gerrit.server.query.change.ChangeData;
22+
import java.util.Collection;
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
import org.kohsuke.args4j.Option;
2126

22-
public class AttributeFactory implements ChangeAttributeFactory {
27+
public class AttributeFactory implements ChangePluginDefinedInfoFactory {
28+
protected MyChangeOptions options;
2329

2430
public class PluginAttribute extends PluginDefinedInfo {
2531
public String exampleName;
@@ -32,7 +38,20 @@ public PluginAttribute(ChangeData c) {
3238
}
3339

3440
@Override
35-
public PluginDefinedInfo create(ChangeData c, BeanProvider bp, String plugin) {
36-
return new PluginAttribute(c);
41+
public Map<Change.Id, PluginDefinedInfo> createPluginDefinedInfos(
42+
Collection<ChangeData> cds, DynamicOptions.BeanProvider bp, String plugin) {
43+
Map<Change.Id, PluginDefinedInfo> out = new HashMap<>();
44+
if (options == null) {
45+
options = (MyChangeOptions) bp.getDynamicBean(plugin);
46+
}
47+
if (options.all) {
48+
cds.forEach(cd -> out.put(cd.getId(), new PluginAttribute(cd)));
49+
}
50+
return out;
51+
}
52+
53+
public class MyChangeOptions implements DynamicOptions.DynamicBean {
54+
@Option(name = "--all", usage = "Include plugin output")
55+
public boolean all = false;
3756
}
3857
}

example-changeQueryAttributes/src/main/java/com/googlesource/gerrit/plugins/examples/changequeryattributes/Module.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,33 @@
1515
package com.googlesource.gerrit.plugins.examples.changequeryattributes;
1616

1717
import com.google.gerrit.extensions.annotations.Exports;
18-
import com.google.gerrit.server.change.ChangeAttributeFactory;
18+
import com.google.gerrit.extensions.registration.DynamicSet;
19+
import com.google.gerrit.server.DynamicOptions;
20+
import com.google.gerrit.server.change.ChangePluginDefinedInfoFactory;
21+
import com.google.gerrit.server.restapi.change.GetChange;
22+
import com.google.gerrit.server.restapi.change.QueryChanges;
23+
import com.google.gerrit.sshd.commands.Query;
1924
import com.google.inject.AbstractModule;
2025

2126
public class Module extends AbstractModule {
2227
@Override
2328
protected void configure() {
24-
bind(ChangeAttributeFactory.class)
25-
.annotatedWith(Exports.named("example-changeQueryAttributes"))
26-
.to(AttributeFactory.class);
29+
// Register attribute factory.
30+
DynamicSet.bind(binder(), ChangePluginDefinedInfoFactory.class).to(AttributeFactory.class);
31+
32+
// Register options for GET /changes/X/change and /changes/X/detail.
33+
bind(DynamicOptions.DynamicBean.class)
34+
.annotatedWith(Exports.named(GetChange.class))
35+
.to(AttributeFactory.MyChangeOptions.class);
36+
37+
// Register options for GET /changes/?q=...
38+
bind(DynamicOptions.DynamicBean.class)
39+
.annotatedWith(Exports.named(QueryChanges.class))
40+
.to(AttributeFactory.MyChangeOptions.class);
41+
42+
// Register options for ssh gerrit query.
43+
bind(DynamicOptions.DynamicBean.class)
44+
.annotatedWith(Exports.named(Query.class))
45+
.to(AttributeFactory.MyChangeOptions.class);
2746
}
2847
}

0 commit comments

Comments
 (0)