Merge "Replace Reviewer Label/Hashtag close image with better char"
diff --git a/Documentation/dev-plugins.txt b/Documentation/dev-plugins.txt
index c2f2af4..1aeab2c 100644
--- a/Documentation/dev-plugins.txt
+++ b/Documentation/dev-plugins.txt
@@ -415,6 +415,13 @@
its own custom event class derived from
`com.google.gerrit.server.events.Event`.
+Plugins which define new Events should register them via the
+`com.google.gerrit.server.events.EventTypes.registerClass()`
+method. This will make the EventType known to the system.
+Deserialzing events with the
+`com.google.gerrit.server.events.EventDeserializer` class requires
+that the event be registered in EventTypes.
+
[[validation]]
== Validation Listeners
diff --git a/Documentation/dev-release.txt b/Documentation/dev-release.txt
index 2fe47a3..3d3104c 100644
--- a/Documentation/dev-release.txt
+++ b/Documentation/dev-release.txt
@@ -145,6 +145,12 @@
git tag -a v2.5
----
+Tag the plugins:
+
+----
+ git submodule foreach git tag -a v2.5
+----
+
[[build-gerrit]]
=== Build Gerrit
@@ -313,20 +319,18 @@
[[push-tag]]
==== Push the Release Tag
-* Push the new Release Tag
-+
-For an `RC`:
-+
-----
- git push gerrit-review tag v2.5-rc0
-----
-+
-For a final `stable` release:
-+
+Push the new Release Tag:
+
----
git push gerrit-review tag v2.5
----
+Push the new Release Tag on the plugins:
+
+----
+ git submodule foreach git push gerrit-review tag v2.5
+----
+
[[upload-documentation]]
==== Upload the Documentation
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/Actions.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/Actions.java
index f5fa6dd..71231e4 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/Actions.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/Actions.java
@@ -150,10 +150,6 @@
submit.setVisible(canSubmit);
}
- boolean isSubmitEnabled() {
- return submit.isVisible() && submit.isEnabled();
- }
-
@UiHandler("followUp")
void onFollowUp(@SuppressWarnings("unused") ClickEvent e) {
if (followUpAction == null) {
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/CommitReceivedEvent.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/CommitReceivedEvent.java
index 29dcb17..8843dbb 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/events/CommitReceivedEvent.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/CommitReceivedEvent.java
@@ -21,15 +21,19 @@
import org.eclipse.jgit.transport.ReceiveCommand;
public class CommitReceivedEvent extends RefEvent {
- public final ReceiveCommand command;
- public final Project project;
- public final String refName;
- public final RevCommit commit;
- public final IdentifiedUser user;
+ public ReceiveCommand command;
+ public Project project;
+ public String refName;
+ public RevCommit commit;
+ public IdentifiedUser user;
+
+ public CommitReceivedEvent() {
+ super("commit-received");
+ }
public CommitReceivedEvent(ReceiveCommand command, Project project,
String refName, RevCommit commit, IdentifiedUser user) {
- super("commit-received");
+ this();
this.command = command;
this.project = project;
this.refName = refName;
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/EventDeserializer.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/EventDeserializer.java
new file mode 100644
index 0000000..3508acf
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/EventDeserializer.java
@@ -0,0 +1,49 @@
+// Copyright (C) 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server.events;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+
+import java.lang.reflect.Type;
+
+/**
+ * JSON deserializer for {@link Event}s.
+ * <p>
+ * Deserialized objects are of an appropriate subclass based on the value of the
+ * top-level "type" element.
+ */
+public class EventDeserializer implements JsonDeserializer<Event> {
+ @Override
+ public Event deserialize(JsonElement json, Type typeOfT,
+ JsonDeserializationContext context) throws JsonParseException {
+ if (!json.isJsonObject()) {
+ throw new JsonParseException("Not an object");
+ }
+ JsonElement typeJson = json.getAsJsonObject().get("type");
+ if (typeJson == null || !typeJson.isJsonPrimitive()
+ || !typeJson.getAsJsonPrimitive().isString()) {
+ throw new JsonParseException("Type is not a string: " + typeJson);
+ }
+ String type = typeJson.getAsJsonPrimitive().getAsString();
+ Class<?> cls = EventTypes.getClass(type);
+ if (cls == null) {
+ throw new JsonParseException("Unknown event type: " + type);
+ }
+ return context.deserialize(json, cls);
+ }
+}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/EventTypes.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/EventTypes.java
new file mode 100644
index 0000000..4d26e13
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/EventTypes.java
@@ -0,0 +1,64 @@
+// Copyright (C) 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server.events;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/** Class for registering event types */
+public class EventTypes {
+ private static final Map<String, Class<?>> typesByString = new HashMap<>();
+
+ static {
+ registerClass(new ChangeAbandonedEvent());
+ registerClass(new ChangeMergedEvent());
+ registerClass(new ChangeRestoredEvent());
+ registerClass(new CommentAddedEvent());
+ registerClass(new CommitReceivedEvent());
+ registerClass(new DraftPublishedEvent());
+ registerClass(new HashtagsChangedEvent());
+ registerClass(new MergeFailedEvent());
+ registerClass(new RefUpdatedEvent());
+ registerClass(new RefReceivedEvent());
+ registerClass(new ReviewerAddedEvent());
+ registerClass(new PatchSetCreatedEvent());
+ registerClass(new TopicChangedEvent());
+ }
+
+ /** Register an event.
+ *
+ * @param event The event to register.
+ * @throws IllegalArgumentException if the event's type is already
+ * registered.
+ **/
+ public static void registerClass(Event event) {
+ String type = event.getType();
+ if (typesByString.containsKey(type)) {
+ throw new IllegalArgumentException(
+ "Event type already registered: " + type);
+ }
+ typesByString.put(type, event.getClass());
+ }
+
+ /** Get the class for an event type.
+ *
+ * @param type The type.
+ * @return The event class, or null if no class is registered with the
+ * given type
+ **/
+ public static Class<?> getClass(String type) {
+ return typesByString.get(type);
+ }
+}
diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/events/EventTypesTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/events/EventTypesTest.java
new file mode 100644
index 0000000..c22c7fb
--- /dev/null
+++ b/gerrit-server/src/test/java/com/google/gerrit/server/events/EventTypesTest.java
@@ -0,0 +1,72 @@
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server.events;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.fail;
+
+import com.google.gerrit.server.events.Event;
+import com.google.gerrit.server.events.EventTypes;
+
+import org.junit.Test;
+
+public class EventTypesTest {
+ public static class TestEvent extends Event {
+ public TestEvent() {
+ super("test-event");
+ }
+ }
+
+ public static class TestEvent2 extends Event {
+ public TestEvent2() {
+ super("test-event"); // Intentionally same as in TestEvent
+ }
+ }
+
+ public static class AnotherTestEvent extends Event {
+ public AnotherTestEvent() {
+ super("another-test-event");
+ }
+ }
+
+ @Test
+ public void testEventTypeRegistration() {
+ EventTypes.registerClass(new TestEvent());
+ EventTypes.registerClass(new AnotherTestEvent());
+ assertThat(EventTypes.getClass("test-event")).isEqualTo(TestEvent.class);
+ assertThat(EventTypes.getClass("another-test-event"))
+ .isEqualTo(AnotherTestEvent.class);
+
+ try {
+ EventTypes.registerClass(new TestEvent());
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ assertThat(EventTypes.getClass("test-event")).isEqualTo(TestEvent.class);
+ }
+
+ try {
+ EventTypes.registerClass(new TestEvent2());
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ assertThat(EventTypes.getClass("test-event")).isEqualTo(TestEvent.class);
+ }
+ }
+
+ @Test
+ public void testGetClassForNonExistingType() {
+ Class<?> clazz = EventTypes.getClass("does-not-exist-event");
+ assertThat(clazz).isNull();
+ }
+}