Merge changes from topic 'events'

* changes:
  Update replication plugin revision
  Add more abstract events to the event hierarchy.
This commit is contained in:
David Pursehouse 2015-01-27 00:48:59 +00:00 committed by Gerrit Code Review
commit daf0c20030
27 changed files with 220 additions and 376 deletions

View File

@ -379,9 +379,9 @@ Certain operations in Gerrit trigger events. Plugins may receive
notifications of these events by implementing the corresponding
listeners.
* `com.google.gerrit.common.ChangeListener`:
* `com.google.gerrit.common.EventListener`:
+
Allows to listen to change events. These are the same
Allows to listen to events. These are the same
link:cmd-stream-events.html#events[events] that are also streamed by
the link:cmd-stream-events.html[gerrit stream-events] command.
@ -413,7 +413,8 @@ Gerrit's `stream-events` ssh command will receive them.
To send an event, the plugin must invoke one of the `postEvent`
methods in the `ChangeHookRunner` class, passing an instance of
its own custom event class derived from `ChangeEvent`.
its own custom event class derived from
`com.google.gerrit.server.events.Event`.
[[validation]]
== Validation Listeners

View File

@ -29,7 +29,7 @@ import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.acceptance.SshSession;
import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.common.ChangeListener;
import com.google.gerrit.common.EventListener;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.changes.SubmitInput;
import com.google.gerrit.extensions.client.ChangeStatus;
@ -46,8 +46,8 @@ import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.events.ChangeEvent;
import com.google.gerrit.server.events.ChangeMergedEvent;
import com.google.gerrit.server.events.Event;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.ListBranches.BranchInfo;
import com.google.gerrit.server.project.PutConfig;
@ -102,13 +102,14 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
public void setUp() throws Exception {
mergeResults = Maps.newHashMap();
CurrentUser listenerUser = factory.create(user.id);
hooks.addChangeListener(new ChangeListener() {
hooks.addEventListener(new EventListener() {
@Override
public void onChangeEvent(ChangeEvent event) {
public void onEvent(Event event) {
if (event instanceof ChangeMergedEvent) {
ChangeMergedEvent cMEvent = (ChangeMergedEvent) event;
mergeResults.put(cMEvent.change.number, cMEvent.newRev);
ChangeMergedEvent changeMergedEvent = (ChangeMergedEvent) event;
mergeResults.put(changeMergedEvent.change.number,
changeMergedEvent.newRev);
}
}

View File

@ -36,11 +36,11 @@ import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.data.ApprovalAttribute;
import com.google.gerrit.server.events.ChangeAbandonedEvent;
import com.google.gerrit.server.events.ChangeEvent;
import com.google.gerrit.server.events.ChangeMergedEvent;
import com.google.gerrit.server.events.ChangeRestoredEvent;
import com.google.gerrit.server.events.CommentAddedEvent;
import com.google.gerrit.server.events.DraftPublishedEvent;
import com.google.gerrit.server.events.Event;
import com.google.gerrit.server.events.EventFactory;
import com.google.gerrit.server.events.HashtagsChangedEvent;
import com.google.gerrit.server.events.MergeFailedEvent;
@ -99,11 +99,11 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
}
}
private static class ChangeListenerHolder {
final ChangeListener listener;
private static class EventListenerHolder {
final EventListener listener;
final CurrentUser user;
ChangeListenerHolder(ChangeListener l, CurrentUser u) {
EventListenerHolder(EventListener l, CurrentUser u) {
listener = l;
user = u;
}
@ -159,11 +159,11 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
/** Listeners to receive changes as they happen (limited by visibility
* of holder's user). */
private final Map<ChangeListener, ChangeListenerHolder> listeners =
private final Map<EventListener, EventListenerHolder> listeners =
new ConcurrentHashMap<>();
/** Listeners to receive all changes as they happen. */
private final DynamicSet<ChangeListener> unrestrictedListeners;
private final DynamicSet<EventListener> unrestrictedListeners;
/** Filename of the new patchset hook. */
private final File patchsetCreatedHook;
@ -244,7 +244,7 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
final ProjectCache projectCache,
final AccountCache accountCache,
final EventFactory eventFactory,
final DynamicSet<ChangeListener> unrestrictedListeners) {
final DynamicSet<EventListener> unrestrictedListeners) {
this.anonymousCowardName = anonymousCowardName;
this.repoManager = repoManager;
this.hookQueue = queue.createQueue(1, "hook");
@ -277,12 +277,12 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
}
@Override
public void addChangeListener(ChangeListener listener, CurrentUser user) {
listeners.put(listener, new ChangeListenerHolder(listener, user));
public void addEventListener(EventListener listener, CurrentUser user) {
listeners.put(listener, new EventListenerHolder(listener, user));
}
@Override
public void removeChangeListener(ChangeListener listener) {
public void removeEventListener(EventListener listener) {
listeners.remove(listener);
}
@ -686,37 +686,38 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
}
@Override
public void postEvent(final Change change, final ChangeEvent event,
public void postEvent(final Change change, final Event event,
final ReviewDb db) throws OrmException {
fireEvent(change, event, db);
}
@Override
public void postEvent(final Branch.NameKey branchName,
final ChangeEvent event) {
final Event event) {
fireEvent(branchName, event);
}
private void fireEventForUnrestrictedListeners(final ChangeEvent event) {
for (ChangeListener listener : unrestrictedListeners) {
listener.onChangeEvent(event);
private void fireEventForUnrestrictedListeners(final Event event) {
for (EventListener listener : unrestrictedListeners) {
listener.onEvent(event);
}
}
private void fireEvent(final Change change, final ChangeEvent event, final ReviewDb db) throws OrmException {
for (ChangeListenerHolder holder : listeners.values()) {
private void fireEvent(final Change change, final Event event,
final ReviewDb db) throws OrmException {
for (EventListenerHolder holder : listeners.values()) {
if (isVisibleTo(change, holder.user, db)) {
holder.listener.onChangeEvent(event);
holder.listener.onEvent(event);
}
}
fireEventForUnrestrictedListeners( event );
}
private void fireEvent(Branch.NameKey branchName, final ChangeEvent event) {
for (ChangeListenerHolder holder : listeners.values()) {
private void fireEvent(Branch.NameKey branchName, final Event event) {
for (EventListenerHolder holder : listeners.values()) {
if (isVisibleTo(branchName, holder.user)) {
holder.listener.onChangeEvent(event);
holder.listener.onEvent(event);
}
}

View File

@ -23,7 +23,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.events.ChangeEvent;
import com.google.gerrit.server.events.Event;
import com.google.gwtorm.server.OrmException;
import org.eclipse.jgit.lib.ObjectId;
@ -34,9 +34,9 @@ import java.util.Set;
/** Invokes hooks on server actions. */
public interface ChangeHooks {
public void addChangeListener(ChangeListener listener, CurrentUser user);
public void addEventListener(EventListener listener, CurrentUser user);
public void removeChangeListener(ChangeListener listener);
public void removeEventListener(EventListener listener);
/**
* Fire the Patchset Created Hook.
@ -196,7 +196,7 @@ public interface ChangeHooks {
* @param db The database
* @throws OrmException
*/
public void postEvent(Change change, ChangeEvent event, ReviewDb db)
public void postEvent(Change change, Event event, ReviewDb db)
throws OrmException;
/**
@ -205,5 +205,5 @@ public interface ChangeHooks {
* @param branchName The branch that the event is related to
* @param event The event to post
*/
public void postEvent(Branch.NameKey branchName, ChangeEvent event);
public void postEvent(Branch.NameKey branchName, Event event);
}

View File

@ -23,7 +23,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.events.ChangeEvent;
import com.google.gerrit.server.events.Event;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RefUpdate;
@ -34,7 +34,7 @@ import java.util.Set;
/** Does not invoke hooks. */
public final class DisabledChangeHooks implements ChangeHooks {
@Override
public void addChangeListener(ChangeListener listener, CurrentUser user) {
public void addEventListener(EventListener listener, CurrentUser user) {
}
@Override
@ -103,7 +103,7 @@ public final class DisabledChangeHooks implements ChangeHooks {
}
@Override
public void removeChangeListener(ChangeListener listener) {
public void removeEventListener(EventListener listener) {
}
@Override
@ -113,10 +113,10 @@ public final class DisabledChangeHooks implements ChangeHooks {
}
@Override
public void postEvent(Change change, ChangeEvent event, ReviewDb db) {
public void postEvent(Change change, Event event, ReviewDb db) {
}
@Override
public void postEvent(Branch.NameKey branchName, ChangeEvent event) {
public void postEvent(Branch.NameKey branchName, Event event) {
}
}

View File

@ -15,9 +15,9 @@
package com.google.gerrit.common;
import com.google.gerrit.extensions.annotations.ExtensionPoint;
import com.google.gerrit.server.events.ChangeEvent;
import com.google.gerrit.server.events.Event;
@ExtensionPoint
public interface ChangeListener {
public void onChangeEvent(ChangeEvent event);
public interface EventListener {
public void onEvent(Event event);
}

View File

@ -18,7 +18,7 @@ import static com.google.inject.Scopes.SINGLETON;
import com.google.common.cache.Cache;
import com.google.gerrit.audit.AuditModule;
import com.google.gerrit.common.ChangeListener;
import com.google.gerrit.common.EventListener;
import com.google.gerrit.extensions.config.CapabilityDefinition;
import com.google.gerrit.extensions.config.DownloadCommand;
import com.google.gerrit.extensions.config.DownloadScheme;
@ -271,7 +271,7 @@ public class GerritGlobalModule extends FactoryModule {
DynamicSet.bind(binder(), GitReferenceUpdatedListener.class).to(ReindexAfterUpdate.class);
DynamicSet.bind(binder(), GitReferenceUpdatedListener.class)
.to(ProjectConfigEntry.UpdateChecker.class);
DynamicSet.setOf(binder(), ChangeListener.class);
DynamicSet.setOf(binder(), EventListener.class);
DynamicSet.setOf(binder(), CommitValidationListener.class);
DynamicSet.setOf(binder(), RefOperationValidationListener.class);
DynamicSet.setOf(binder(), MergeValidationListener.class);

View File

@ -14,38 +14,13 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
import com.google.gerrit.server.data.PatchSetAttribute;
public class ChangeAbandonedEvent extends ChangeEvent {
public final String type = "change-abandoned";
public ChangeAttribute change;
public PatchSetAttribute patchSet;
public class ChangeAbandonedEvent extends PatchSetEvent {
public AccountAttribute abandoner;
public String reason;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public ChangeAbandonedEvent() {
super("change-abandoned");
}
}

View File

@ -14,19 +14,30 @@
package com.google.gerrit.server.events;
import com.google.gerrit.common.TimeUtil;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.ChangeAttribute;
public abstract class ChangeEvent {
public abstract class ChangeEvent extends RefEvent {
public ChangeAttribute change;
public long eventCreatedOn = TimeUtil.nowMs() / 1000L;
protected ChangeEvent(String type) {
super(type);
}
public abstract String getType();
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
public abstract Project.NameKey getProjectNameKey();
@Override
public String getRefName() {
return R_HEADS + change.branch;
}
public abstract Change.Key getChangeKey();
public abstract String getRefName();
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
}

View File

@ -14,38 +14,13 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
import com.google.gerrit.server.data.PatchSetAttribute;
public class ChangeMergedEvent extends ChangeEvent {
public final String type = "change-merged";
public ChangeAttribute change;
public PatchSetAttribute patchSet;
public class ChangeMergedEvent extends PatchSetEvent {
public AccountAttribute submitter;
public String newRev;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public ChangeMergedEvent() {
super("change-merged");
}
}

View File

@ -14,38 +14,13 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
import com.google.gerrit.server.data.PatchSetAttribute;
public class ChangeRestoredEvent extends ChangeEvent {
public final String type = "change-restored";
public ChangeAttribute change;
public PatchSetAttribute patchSet;
public class ChangeRestoredEvent extends PatchSetEvent {
public AccountAttribute restorer;
public String reason;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public ChangeRestoredEvent () {
super("change-restored");
}
}

View File

@ -14,40 +14,15 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ApprovalAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
import com.google.gerrit.server.data.PatchSetAttribute;
public class CommentAddedEvent extends ChangeEvent {
public final String type = "comment-added";
public ChangeAttribute change;
public PatchSetAttribute patchSet;
public class CommentAddedEvent extends PatchSetEvent {
public AccountAttribute author;
public ApprovalAttribute[] approvals;
public String comment;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public CommentAddedEvent() {
super("comment-added");
}
}

View File

@ -14,15 +14,13 @@
package com.google.gerrit.server.events;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.IdentifiedUser;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.ReceiveCommand;
public class CommitReceivedEvent extends ChangeEvent {
public final String type = "commit-received";
public class CommitReceivedEvent extends RefEvent {
public final ReceiveCommand command;
public final Project project;
public final String refName;
@ -31,6 +29,7 @@ public class CommitReceivedEvent extends ChangeEvent {
public CommitReceivedEvent(ReceiveCommand command, Project project,
String refName, RevCommit commit, IdentifiedUser user) {
super("commit-received");
this.command = command;
this.project = project;
this.refName = refName;
@ -38,21 +37,11 @@ public class CommitReceivedEvent extends ChangeEvent {
this.user = user;
}
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return project.getNameKey();
}
@Override
public Change.Key getChangeKey() {
return null;
}
@Override
public String getRefName() {
return refName;

View File

@ -14,37 +14,12 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
import com.google.gerrit.server.data.PatchSetAttribute;
public class DraftPublishedEvent extends ChangeEvent {
public final String type = "draft-published";
public ChangeAttribute change;
public PatchSetAttribute patchSet;
public class DraftPublishedEvent extends PatchSetEvent {
public AccountAttribute uploader;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public DraftPublishedEvent() {
super("draft-published");
}
}

View File

@ -0,0 +1,30 @@
// 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.gerrit.common.TimeUtil;
public abstract class Event {
public final String type;
public long eventCreatedOn = TimeUtil.nowMs() / 1000L;
protected Event(String type) {
this.type = type;
}
public String getType() {
return type;
}
}

View File

@ -14,38 +14,15 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
public class HashtagsChangedEvent extends ChangeEvent {
public final String type = "hashtags-changed";
public ChangeAttribute change;
public AccountAttribute editor;
public String[] added;
public String[] removed;
public String[] hashtags;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public HashtagsChangedEvent () {
super("hashtags-changed");
}
}

View File

@ -14,38 +14,13 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
import com.google.gerrit.server.data.PatchSetAttribute;
public class MergeFailedEvent extends ChangeEvent {
public final String type = "merge-failed";
public ChangeAttribute change;
public PatchSetAttribute patchSet;
public class MergeFailedEvent extends PatchSetEvent {
public AccountAttribute submitter;
public String reason;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public MergeFailedEvent() {
super("merge-failed");
}
}

View File

@ -14,37 +14,12 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
import com.google.gerrit.server.data.PatchSetAttribute;
public class PatchSetCreatedEvent extends ChangeEvent {
public final String type = "patchset-created";
public ChangeAttribute change;
public PatchSetAttribute patchSet;
public class PatchSetCreatedEvent extends PatchSetEvent {
public AccountAttribute uploader;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public PatchSetCreatedEvent() {
super("patchset-created");
}
}

View File

@ -0,0 +1,25 @@
// 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.gerrit.server.data.PatchSetAttribute;
public class PatchSetEvent extends ChangeEvent {
public PatchSetAttribute patchSet;
protected PatchSetEvent(String type) {
super(type);
}
}

View File

@ -0,0 +1,25 @@
// 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.gerrit.reviewdb.client.Project;
public abstract class ProjectEvent extends Event {
protected ProjectEvent(String type) {
super(type);
}
public abstract Project.NameKey getProjectNameKey();
}

View File

@ -0,0 +1,23 @@
// 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;
public abstract class RefEvent extends ProjectEvent {
protected RefEvent(String type) {
super(type);
}
public abstract String getRefName();
}

View File

@ -13,21 +13,18 @@
// limitations under the License.
package com.google.gerrit.server.events;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.IdentifiedUser;
import org.eclipse.jgit.transport.ReceiveCommand;
public class RefReceivedEvent extends ChangeEvent {
public final String type = "ref-received";
public class RefReceivedEvent extends RefEvent {
public ReceiveCommand command;
public Project project;
public IdentifiedUser user;
@Override
public String getType() {
return type;
public RefReceivedEvent() {
super("ref-received");
}
@Override
@ -35,11 +32,6 @@ public class RefReceivedEvent extends ChangeEvent {
return project.getNameKey();
}
@Override
public Change.Key getChangeKey() {
return null;
}
@Override
public String getRefName() {
return command.getRefName();

View File

@ -14,19 +14,16 @@
package com.google.gerrit.server.events;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.RefUpdateAttribute;
public class RefUpdatedEvent extends ChangeEvent {
public final String type = "ref-updated";
public class RefUpdatedEvent extends RefEvent {
public AccountAttribute submitter;
public RefUpdateAttribute refUpdate;
@Override
public String getType() {
return type;
public RefUpdatedEvent() {
super("ref-updated");
}
@Override
@ -34,11 +31,6 @@ public class RefUpdatedEvent extends ChangeEvent {
return new Project.NameKey(refUpdate.project);
}
@Override
public Change.Key getChangeKey() {
return null;
}
@Override
public String getRefName() {
return refUpdate.refName;

View File

@ -14,37 +14,12 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
import com.google.gerrit.server.data.PatchSetAttribute;
public class ReviewerAddedEvent extends ChangeEvent {
public final String type = "reviewer-added";
public ChangeAttribute change;
public PatchSetAttribute patchSet;
public class ReviewerAddedEvent extends PatchSetEvent {
public AccountAttribute reviewer;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public ReviewerAddedEvent() {
super("reviewer-added");
}
}

View File

@ -14,36 +14,13 @@
package com.google.gerrit.server.events;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
public class TopicChangedEvent extends ChangeEvent {
public final String type = "topic-changed";
public ChangeAttribute change;
public AccountAttribute changer;
public String oldTopic;
@Override
public String getType() {
return type;
}
@Override
public Project.NameKey getProjectNameKey() {
return new Project.NameKey(change.project);
}
@Override
public Change.Key getChangeKey() {
return new Change.Key(change.id);
}
@Override
public String getRefName() {
return R_HEADS + change.branch;
public TopicChangedEvent() {
super("topic-changed");
}
}

View File

@ -17,11 +17,11 @@ package com.google.gerrit.sshd.commands;
import static com.google.gerrit.sshd.CommandMetaData.Mode.MASTER_OR_SLAVE;
import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.common.ChangeListener;
import com.google.gerrit.common.EventListener;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.events.ChangeEvent;
import com.google.gerrit.server.events.Event;
import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.git.WorkQueue.CancelableRunnable;
import com.google.gerrit.sshd.BaseCommand;
@ -58,7 +58,7 @@ final class StreamEvents extends BaseCommand {
private WorkQueue.Executor pool;
/** Queue of events to stream to the connected user. */
private final LinkedBlockingQueue<ChangeEvent> queue =
private final LinkedBlockingQueue<Event> queue =
new LinkedBlockingQueue<>(MAX_EVENTS);
private final Gson gson = new Gson();
@ -69,9 +69,9 @@ final class StreamEvents extends BaseCommand {
final String type = "dropped-output";
};
private final ChangeListener listener = new ChangeListener() {
private final EventListener listener = new EventListener() {
@Override
public void onChangeEvent(final ChangeEvent event) {
public void onEvent(final Event event) {
offer(event);
}
};
@ -124,12 +124,12 @@ final class StreamEvents extends BaseCommand {
}
stdout = toPrintWriter(out);
hooks.addChangeListener(listener, currentUser);
hooks.addEventListener(listener, currentUser);
}
@Override
protected void onExit(final int rc) {
hooks.removeChangeListener(listener);
hooks.removeEventListener(listener);
synchronized (taskLock) {
done = true;
@ -140,7 +140,7 @@ final class StreamEvents extends BaseCommand {
@Override
public void destroy() {
hooks.removeChangeListener(listener);
hooks.removeEventListener(listener);
final boolean exit;
synchronized (taskLock) {
@ -157,7 +157,7 @@ final class StreamEvents extends BaseCommand {
}
}
private void offer(final ChangeEvent event) {
private void offer(final Event event) {
synchronized (taskLock) {
if (!queue.offer(event)) {
dropped = true;
@ -169,9 +169,9 @@ final class StreamEvents extends BaseCommand {
}
}
private ChangeEvent poll() {
private Event poll() {
synchronized (taskLock) {
ChangeEvent event = queue.poll();
Event event = queue.poll();
if (event == null) {
task = null;
}
@ -188,7 +188,7 @@ final class StreamEvents extends BaseCommand {
// destroy() above, or it closed the stream and is no longer
// accepting output. Either way terminate this instance.
//
hooks.removeChangeListener(listener);
hooks.removeEventListener(listener);
flush();
onExit(0);
return;
@ -199,7 +199,7 @@ final class StreamEvents extends BaseCommand {
dropped = false;
}
final ChangeEvent event = poll();
final Event event = poll();
if (event == null) {
break;
}

@ -1 +1 @@
Subproject commit 225c088073252d5dce48e5cb73cc12e38ed319b8
Subproject commit 10fbbcecedc3f85289f8b164a0c7e2968d61a5c6