Dissolve gerrit-server top-level directory

Change-Id: I538512dfe0f1bea774c01fdd45fa410a45634011
This commit is contained in:
David Ostrovsky
2017-09-21 08:37:42 +02:00
committed by Dave Borowitz
parent 472396c797
commit 376a7bbb64
1549 changed files with 342 additions and 335 deletions

View File

@@ -0,0 +1,56 @@
// 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.events.ChangeEvent;
import java.sql.Timestamp;
public abstract class AbstractChangeEvent implements ChangeEvent {
private final ChangeInfo changeInfo;
private final AccountInfo who;
private final Timestamp when;
private final NotifyHandling notify;
protected AbstractChangeEvent(
ChangeInfo change, AccountInfo who, Timestamp when, NotifyHandling notify) {
this.changeInfo = change;
this.who = who;
this.when = when;
this.notify = notify;
}
@Override
public ChangeInfo getChange() {
return changeInfo;
}
@Override
public AccountInfo getWho() {
return who;
}
@Override
public Timestamp getWhen() {
return when;
}
@Override
public NotifyHandling getNotify() {
return notify;
}
}

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2016 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.events.GerritEvent;
/** Intermediate class for events that do not support notification type. */
public abstract class AbstractNoNotifyEvent implements GerritEvent {
@Override
public NotifyHandling getNotify() {
return NotifyHandling.NONE;
}
}

View File

@@ -0,0 +1,42 @@
// 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.RevisionEvent;
import java.sql.Timestamp;
public abstract class AbstractRevisionEvent extends AbstractChangeEvent implements RevisionEvent {
private final RevisionInfo revisionInfo;
protected AbstractRevisionEvent(
ChangeInfo change,
RevisionInfo revision,
AccountInfo who,
Timestamp when,
NotifyHandling notify) {
super(change, who, when, notify);
revisionInfo = revision;
}
@Override
public RevisionInfo getRevision() {
return revisionInfo;
}
}

View File

@@ -0,0 +1,67 @@
// 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.extensions.events;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.events.AgreementSignupListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.inject.Inject;
public class AgreementSignup {
private final DynamicSet<AgreementSignupListener> listeners;
private final EventUtil util;
@Inject
AgreementSignup(DynamicSet<AgreementSignupListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(Account account, String agreementName) {
if (!listeners.iterator().hasNext()) {
return;
}
Event event = new Event(util.accountInfo(account), agreementName);
for (AgreementSignupListener l : listeners) {
try {
l.onAgreementSignup(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
}
private static class Event extends AbstractNoNotifyEvent
implements AgreementSignupListener.Event {
private final AccountInfo account;
private final String agreementName;
Event(AccountInfo account, String agreementName) {
this.account = account;
this.agreementName = agreementName;
}
@Override
public AccountInfo getAccount() {
return account;
}
@Override
public String getAgreementName() {
return agreementName;
}
}
}

View File

@@ -0,0 +1,78 @@
// Copyright (C) 2016 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.events.AssigneeChangedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.sql.Timestamp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AssigneeChanged {
private static final Logger log = LoggerFactory.getLogger(AssigneeChanged.class);
private final DynamicSet<AssigneeChangedListener> listeners;
private final EventUtil util;
@Inject
AssigneeChanged(DynamicSet<AssigneeChangedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(Change change, Account account, Account oldAssignee, Timestamp when) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change),
util.accountInfo(account),
util.accountInfo(oldAssignee),
when);
for (AssigneeChangedListener l : listeners) {
try {
l.onAssigneeChanged(event);
} catch (Exception e) {
util.logEventListenerError(event, l, e);
}
}
} catch (OrmException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractChangeEvent implements AssigneeChangedListener.Event {
private final AccountInfo oldAssignee;
Event(ChangeInfo change, AccountInfo editor, AccountInfo oldAssignee, Timestamp when) {
super(change, editor, when, NotifyHandling.ALL);
this.oldAssignee = oldAssignee;
}
@Override
public AccountInfo getOldAssignee() {
return oldAssignee;
}
}
}

View File

@@ -0,0 +1,106 @@
// 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.ChangeAbandonedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.IOException;
import java.sql.Timestamp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChangeAbandoned {
private static final Logger log = LoggerFactory.getLogger(ChangeAbandoned.class);
private final DynamicSet<ChangeAbandonedListener> listeners;
private final EventUtil util;
@Inject
ChangeAbandoned(DynamicSet<ChangeAbandonedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(
Change change,
PatchSet ps,
Account abandoner,
String reason,
Timestamp when,
NotifyHandling notifyHandling) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change),
util.revisionInfo(change.getProject(), ps),
util.accountInfo(abandoner),
reason,
when,
notifyHandling);
for (ChangeAbandonedListener l : listeners) {
try {
l.onChangeAbandoned(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (PatchListObjectTooLargeException e) {
log.warn("Couldn't fire event: " + e.getMessage());
} catch (PatchListNotAvailableException
| GpgException
| IOException
| OrmException
| PermissionBackendException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractRevisionEvent
implements ChangeAbandonedListener.Event {
private final String reason;
Event(
ChangeInfo change,
RevisionInfo revision,
AccountInfo abandoner,
String reason,
Timestamp when,
NotifyHandling notifyHandling) {
super(change, revision, abandoner, when, notifyHandling);
this.reason = reason;
}
@Override
public String getReason() {
return reason;
}
}
}

View File

@@ -0,0 +1,98 @@
// 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.ChangeMergedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.IOException;
import java.sql.Timestamp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChangeMerged {
private static final Logger log = LoggerFactory.getLogger(ChangeMerged.class);
private final DynamicSet<ChangeMergedListener> listeners;
private final EventUtil util;
@Inject
ChangeMerged(DynamicSet<ChangeMergedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(
Change change, PatchSet ps, Account merger, String newRevisionId, Timestamp when) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change),
util.revisionInfo(change.getProject(), ps),
util.accountInfo(merger),
newRevisionId,
when);
for (ChangeMergedListener l : listeners) {
try {
l.onChangeMerged(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (PatchListObjectTooLargeException e) {
log.warn("Couldn't fire event: " + e.getMessage());
} catch (PatchListNotAvailableException
| GpgException
| IOException
| OrmException
| PermissionBackendException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractRevisionEvent implements ChangeMergedListener.Event {
private final String newRevisionId;
Event(
ChangeInfo change,
RevisionInfo revision,
AccountInfo merger,
String newRevisionId,
Timestamp when) {
super(change, revision, merger, when, NotifyHandling.ALL);
this.newRevisionId = newRevisionId;
}
@Override
public String getNewRevisionId() {
return newRevisionId;
}
}
}

View File

@@ -0,0 +1,98 @@
// 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.ChangeRestoredListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.IOException;
import java.sql.Timestamp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChangeRestored {
private static final Logger log = LoggerFactory.getLogger(ChangeRestored.class);
private final DynamicSet<ChangeRestoredListener> listeners;
private final EventUtil util;
@Inject
ChangeRestored(DynamicSet<ChangeRestoredListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(Change change, PatchSet ps, Account restorer, String reason, Timestamp when) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change),
util.revisionInfo(change.getProject(), ps),
util.accountInfo(restorer),
reason,
when);
for (ChangeRestoredListener l : listeners) {
try {
l.onChangeRestored(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (PatchListObjectTooLargeException e) {
log.warn("Couldn't fire event: " + e.getMessage());
} catch (PatchListNotAvailableException
| GpgException
| IOException
| OrmException
| PermissionBackendException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractRevisionEvent implements ChangeRestoredListener.Event {
private String reason;
Event(
ChangeInfo change,
RevisionInfo revision,
AccountInfo restorer,
String reason,
Timestamp when) {
super(change, revision, restorer, when, NotifyHandling.ALL);
this.reason = reason;
}
@Override
public String getReason() {
return reason;
}
}
}

View File

@@ -0,0 +1,71 @@
// Copyright (C) 2016 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.events.ChangeRevertedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.sql.Timestamp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChangeReverted {
private static final Logger log = LoggerFactory.getLogger(ChangeReverted.class);
private final DynamicSet<ChangeRevertedListener> listeners;
private final EventUtil util;
@Inject
ChangeReverted(DynamicSet<ChangeRevertedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(Change change, Change revertChange, Timestamp when) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event = new Event(util.changeInfo(change), util.changeInfo(revertChange), when);
for (ChangeRevertedListener l : listeners) {
try {
l.onChangeReverted(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (OrmException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractChangeEvent implements ChangeRevertedListener.Event {
private final ChangeInfo revertChange;
Event(ChangeInfo change, ChangeInfo revertChange, Timestamp when) {
super(change, revertChange.owner, when, NotifyHandling.ALL);
this.revertChange = revertChange;
}
@Override
public ChangeInfo getRevertChange() {
return revertChange;
}
}
}

View File

@@ -0,0 +1,125 @@
// 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.CommentAddedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CommentAdded {
private static final Logger log = LoggerFactory.getLogger(CommentAdded.class);
private final DynamicSet<CommentAddedListener> listeners;
private final EventUtil util;
@Inject
CommentAdded(DynamicSet<CommentAddedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(
Change change,
PatchSet ps,
Account author,
String comment,
Map<String, Short> approvals,
Map<String, Short> oldApprovals,
Timestamp when) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change),
util.revisionInfo(change.getProject(), ps),
util.accountInfo(author),
comment,
util.approvals(author, approvals, when),
util.approvals(author, oldApprovals, when),
when);
for (CommentAddedListener l : listeners) {
try {
l.onCommentAdded(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (PatchListObjectTooLargeException e) {
log.warn("Couldn't fire event: " + e.getMessage());
} catch (PatchListNotAvailableException
| GpgException
| IOException
| OrmException
| PermissionBackendException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractRevisionEvent implements CommentAddedListener.Event {
private final String comment;
private final Map<String, ApprovalInfo> approvals;
private final Map<String, ApprovalInfo> oldApprovals;
Event(
ChangeInfo change,
RevisionInfo revision,
AccountInfo author,
String comment,
Map<String, ApprovalInfo> approvals,
Map<String, ApprovalInfo> oldApprovals,
Timestamp when) {
super(change, revision, author, when, NotifyHandling.ALL);
this.comment = comment;
this.approvals = approvals;
this.oldApprovals = oldApprovals;
}
@Override
public String getComment() {
return comment;
}
@Override
public Map<String, ApprovalInfo> getApprovals() {
return approvals;
}
@Override
public Map<String, ApprovalInfo> getOldApprovals() {
return oldApprovals;
}
}
}

View File

@@ -0,0 +1,140 @@
// 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.extensions.events;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
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.GpgException;
import com.google.gerrit.server.change.ChangeJson;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EventUtil {
private static final Logger log = LoggerFactory.getLogger(EventUtil.class);
private static final ImmutableSet<ListChangesOption> CHANGE_OPTIONS;
static {
EnumSet<ListChangesOption> opts = EnumSet.allOf(ListChangesOption.class);
// Some options, like actions, are expensive to compute because they potentially have to walk
// lots of history and inspect lots of other changes.
opts.remove(ListChangesOption.CHANGE_ACTIONS);
opts.remove(ListChangesOption.CURRENT_ACTIONS);
// CHECK suppresses some exceptions on corrupt changes, which is not appropriate for passing
// through the event system as we would rather let them propagate.
opts.remove(ListChangesOption.CHECK);
CHANGE_OPTIONS = Sets.immutableEnumSet(opts);
}
private final ChangeData.Factory changeDataFactory;
private final Provider<ReviewDb> db;
private final ChangeJson changeJson;
@Inject
EventUtil(
ChangeJson.Factory changeJsonFactory,
ChangeData.Factory changeDataFactory,
Provider<ReviewDb> db) {
this.changeDataFactory = changeDataFactory;
this.db = db;
this.changeJson = changeJsonFactory.create(CHANGE_OPTIONS);
}
public ChangeInfo changeInfo(Change change) throws OrmException {
return changeJson.format(change);
}
public RevisionInfo revisionInfo(Project project, PatchSet ps)
throws OrmException, PatchListNotAvailableException, GpgException, IOException,
PermissionBackendException {
return revisionInfo(project.getNameKey(), ps);
}
public RevisionInfo revisionInfo(Project.NameKey project, PatchSet ps)
throws OrmException, PatchListNotAvailableException, GpgException, IOException,
PermissionBackendException {
ChangeData cd = changeDataFactory.create(db.get(), project, ps.getId().getParentKey());
return changeJson.getRevisionInfo(cd, ps);
}
public AccountInfo accountInfo(Account a) {
if (a == null || a.getId() == null) {
return null;
}
AccountInfo accountInfo = new AccountInfo(a.getId().get());
accountInfo.email = a.getPreferredEmail();
accountInfo.name = a.getFullName();
accountInfo.username = a.getUserName();
return accountInfo;
}
public Map<String, ApprovalInfo> approvals(
Account a, Map<String, Short> approvals, Timestamp ts) {
Map<String, ApprovalInfo> result = new HashMap<>();
for (Map.Entry<String, Short> e : approvals.entrySet()) {
Integer value = e.getValue() != null ? Integer.valueOf(e.getValue()) : null;
result.put(e.getKey(), ChangeJson.getApprovalInfo(a.getId(), value, null, null, ts));
}
return result;
}
public void logEventListenerError(Object event, Object listener, Exception error) {
if (log.isDebugEnabled()) {
log.debug(
String.format(
"Error in event listener %s for event %s",
listener.getClass().getName(), event.getClass().getName()),
error);
} else {
log.warn(
"Error in listener {} for event {}: {}",
listener.getClass().getName(),
event.getClass().getName(),
error.getMessage());
}
}
public static void logEventListenerError(Object listener, Exception error) {
if (log.isDebugEnabled()) {
log.debug(String.format("Error in event listener %s", listener.getClass().getName()), error);
} else {
log.warn("Error in listener {}: {}", listener.getClass().getName(), error.getMessage());
}
}
}

View File

@@ -0,0 +1,231 @@
// Copyright (C) 2012 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Project;
import com.google.inject.Inject;
import org.eclipse.jgit.lib.BatchRefUpdate;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.transport.ReceiveCommand;
public class GitReferenceUpdated {
public static final GitReferenceUpdated DISABLED =
new GitReferenceUpdated() {
@Override
public void fire(
Project.NameKey project,
RefUpdate refUpdate,
ReceiveCommand.Type type,
Account updater) {}
@Override
public void fire(Project.NameKey project, RefUpdate refUpdate, Account updater) {}
@Override
public void fire(
Project.NameKey project,
String ref,
ObjectId oldObjectId,
ObjectId newObjectId,
Account updater) {}
@Override
public void fire(Project.NameKey project, ReceiveCommand cmd, Account updater) {}
@Override
public void fire(Project.NameKey project, BatchRefUpdate batchRefUpdate, Account updater) {}
};
private final DynamicSet<GitReferenceUpdatedListener> listeners;
private final EventUtil util;
@Inject
GitReferenceUpdated(DynamicSet<GitReferenceUpdatedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
private GitReferenceUpdated() {
this.listeners = null;
this.util = null;
}
public void fire(
Project.NameKey project, RefUpdate refUpdate, ReceiveCommand.Type type, Account updater) {
fire(
project,
refUpdate.getName(),
refUpdate.getOldObjectId(),
refUpdate.getNewObjectId(),
type,
util.accountInfo(updater));
}
public void fire(Project.NameKey project, RefUpdate refUpdate, Account updater) {
fire(
project,
refUpdate.getName(),
refUpdate.getOldObjectId(),
refUpdate.getNewObjectId(),
ReceiveCommand.Type.UPDATE,
util.accountInfo(updater));
}
public void fire(
Project.NameKey project,
String ref,
ObjectId oldObjectId,
ObjectId newObjectId,
Account updater) {
fire(
project,
ref,
oldObjectId,
newObjectId,
ReceiveCommand.Type.UPDATE,
util.accountInfo(updater));
}
public void fire(Project.NameKey project, ReceiveCommand cmd, Account updater) {
fire(
project,
cmd.getRefName(),
cmd.getOldId(),
cmd.getNewId(),
cmd.getType(),
util.accountInfo(updater));
}
public void fire(Project.NameKey project, BatchRefUpdate batchRefUpdate, Account updater) {
if (!listeners.iterator().hasNext()) {
return;
}
for (ReceiveCommand cmd : batchRefUpdate.getCommands()) {
if (cmd.getResult() == ReceiveCommand.Result.OK) {
fire(
project,
cmd.getRefName(),
cmd.getOldId(),
cmd.getNewId(),
cmd.getType(),
util.accountInfo(updater));
}
}
}
private void fire(
Project.NameKey project,
String ref,
ObjectId oldObjectId,
ObjectId newObjectId,
ReceiveCommand.Type type,
AccountInfo updater) {
if (!listeners.iterator().hasNext()) {
return;
}
ObjectId o = oldObjectId != null ? oldObjectId : ObjectId.zeroId();
ObjectId n = newObjectId != null ? newObjectId : ObjectId.zeroId();
Event event = new Event(project, ref, o.name(), n.name(), type, updater);
for (GitReferenceUpdatedListener l : listeners) {
try {
l.onGitReferenceUpdated(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
}
private static class Event implements GitReferenceUpdatedListener.Event {
private final String projectName;
private final String ref;
private final String oldObjectId;
private final String newObjectId;
private final ReceiveCommand.Type type;
private final AccountInfo updater;
Event(
Project.NameKey project,
String ref,
String oldObjectId,
String newObjectId,
ReceiveCommand.Type type,
AccountInfo updater) {
this.projectName = project.get();
this.ref = ref;
this.oldObjectId = oldObjectId;
this.newObjectId = newObjectId;
this.type = type;
this.updater = updater;
}
@Override
public String getProjectName() {
return projectName;
}
@Override
public String getRefName() {
return ref;
}
@Override
public String getOldObjectId() {
return oldObjectId;
}
@Override
public String getNewObjectId() {
return newObjectId;
}
@Override
public boolean isCreate() {
return type == ReceiveCommand.Type.CREATE;
}
@Override
public boolean isDelete() {
return type == ReceiveCommand.Type.DELETE;
}
@Override
public boolean isNonFastForward() {
return type == ReceiveCommand.Type.UPDATE_NONFASTFORWARD;
}
@Override
public AccountInfo getUpdater() {
return updater;
}
@Override
public String toString() {
return String.format(
"%s[%s,%s: %s -> %s]",
getClass().getSimpleName(), projectName, ref, oldObjectId, newObjectId);
}
@Override
public NotifyHandling getNotify() {
return NotifyHandling.ALL;
}
}
}

View File

@@ -0,0 +1,105 @@
// 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.extensions.events;
import com.google.common.collect.ImmutableSortedSet;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.events.HashtagsEditedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HashtagsEdited {
private static final Logger log = LoggerFactory.getLogger(HashtagsEdited.class);
private final DynamicSet<HashtagsEditedListener> listeners;
private final EventUtil util;
@Inject
public HashtagsEdited(DynamicSet<HashtagsEditedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(
Change change,
Account editor,
ImmutableSortedSet<String> hashtags,
Set<String> added,
Set<String> removed,
Timestamp when) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change), util.accountInfo(editor), hashtags, added, removed, when);
for (HashtagsEditedListener l : listeners) {
try {
l.onHashtagsEdited(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (OrmException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractChangeEvent implements HashtagsEditedListener.Event {
private Collection<String> updatedHashtags;
private Collection<String> addedHashtags;
private Collection<String> removedHashtags;
Event(
ChangeInfo change,
AccountInfo editor,
Collection<String> updated,
Collection<String> added,
Collection<String> removed,
Timestamp when) {
super(change, editor, when, NotifyHandling.ALL);
this.updatedHashtags = updated;
this.addedHashtags = added;
this.removedHashtags = removed;
}
@Override
public Collection<String> getHashtags() {
return updatedHashtags;
}
@Override
public Collection<String> getAddedHashtags() {
return addedHashtags;
}
@Override
public Collection<String> getRemovedHashtags() {
return removedHashtags;
}
}
}

View File

@@ -0,0 +1,65 @@
// 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.extensions.events;
import com.google.gerrit.extensions.events.PluginEventListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.inject.Inject;
public class PluginEvent {
private final DynamicSet<PluginEventListener> listeners;
@Inject
PluginEvent(DynamicSet<PluginEventListener> listeners) {
this.listeners = listeners;
}
public void fire(String pluginName, String type, String data) {
if (!listeners.iterator().hasNext()) {
return;
}
Event e = new Event(pluginName, type, data);
for (PluginEventListener l : listeners) {
l.onPluginEvent(e);
}
}
private static class Event extends AbstractNoNotifyEvent implements PluginEventListener.Event {
private final String pluginName;
private final String type;
private final String data;
Event(String pluginName, String type, String data) {
this.pluginName = pluginName;
this.type = type;
this.data = data;
}
@Override
public String pluginName() {
return pluginName;
}
@Override
public String getType() {
return type;
}
@Override
public String getData() {
return data;
}
}
}

View File

@@ -0,0 +1,101 @@
// 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.extensions.events;
import com.google.common.collect.Lists;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.ReviewerAddedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ReviewerAdded {
private static final Logger log = LoggerFactory.getLogger(ReviewerAdded.class);
private final DynamicSet<ReviewerAddedListener> listeners;
private final EventUtil util;
@Inject
ReviewerAdded(DynamicSet<ReviewerAddedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(
Change change, PatchSet patchSet, List<Account> reviewers, Account adder, Timestamp when) {
if (!listeners.iterator().hasNext() || reviewers.isEmpty()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change),
util.revisionInfo(change.getProject(), patchSet),
Lists.transform(reviewers, util::accountInfo),
util.accountInfo(adder),
when);
for (ReviewerAddedListener l : listeners) {
try {
l.onReviewersAdded(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (PatchListObjectTooLargeException e) {
log.warn("Couldn't fire event: " + e.getMessage());
} catch (PatchListNotAvailableException
| GpgException
| IOException
| OrmException
| PermissionBackendException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractRevisionEvent implements ReviewerAddedListener.Event {
private final List<AccountInfo> reviewers;
Event(
ChangeInfo change,
RevisionInfo revision,
List<AccountInfo> reviewers,
AccountInfo adder,
Timestamp when) {
super(change, revision, adder, when, NotifyHandling.ALL);
this.reviewers = reviewers;
}
@Override
public List<AccountInfo> getReviewers() {
return reviewers;
}
}
}

View File

@@ -0,0 +1,138 @@
// Copyright (C) 2016 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.ReviewerDeletedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ReviewerDeleted {
private static final Logger log = LoggerFactory.getLogger(ReviewerDeleted.class);
private final DynamicSet<ReviewerDeletedListener> listeners;
private final EventUtil util;
@Inject
ReviewerDeleted(DynamicSet<ReviewerDeletedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(
Change change,
PatchSet patchSet,
Account reviewer,
Account remover,
String message,
Map<String, Short> newApprovals,
Map<String, Short> oldApprovals,
NotifyHandling notify,
Timestamp when) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change),
util.revisionInfo(change.getProject(), patchSet),
util.accountInfo(reviewer),
util.accountInfo(remover),
message,
util.approvals(reviewer, newApprovals, when),
util.approvals(reviewer, oldApprovals, when),
notify,
when);
for (ReviewerDeletedListener listener : listeners) {
try {
listener.onReviewerDeleted(event);
} catch (Exception e) {
util.logEventListenerError(this, listener, e);
}
}
} catch (PatchListObjectTooLargeException e) {
log.warn("Couldn't fire event: " + e.getMessage());
} catch (PatchListNotAvailableException
| GpgException
| IOException
| OrmException
| PermissionBackendException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractRevisionEvent
implements ReviewerDeletedListener.Event {
private final AccountInfo reviewer;
private final String comment;
private final Map<String, ApprovalInfo> newApprovals;
private final Map<String, ApprovalInfo> oldApprovals;
Event(
ChangeInfo change,
RevisionInfo revision,
AccountInfo reviewer,
AccountInfo remover,
String comment,
Map<String, ApprovalInfo> newApprovals,
Map<String, ApprovalInfo> oldApprovals,
NotifyHandling notify,
Timestamp when) {
super(change, revision, remover, when, notify);
this.reviewer = reviewer;
this.comment = comment;
this.newApprovals = newApprovals;
this.oldApprovals = oldApprovals;
}
@Override
public AccountInfo getReviewer() {
return reviewer;
}
@Override
public String getComment() {
return comment;
}
@Override
public Map<String, ApprovalInfo> getNewApprovals() {
return newApprovals;
}
@Override
public Map<String, ApprovalInfo> getOldApprovals() {
return oldApprovals;
}
}
}

View File

@@ -0,0 +1,92 @@
// 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.RevisionCreatedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.IOException;
import java.sql.Timestamp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RevisionCreated {
private static final Logger log = LoggerFactory.getLogger(RevisionCreated.class);
private final DynamicSet<RevisionCreatedListener> listeners;
private final EventUtil util;
@Inject
RevisionCreated(DynamicSet<RevisionCreatedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(
Change change, PatchSet patchSet, Account uploader, Timestamp when, NotifyHandling notify) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change),
util.revisionInfo(change.getProject(), patchSet),
util.accountInfo(uploader),
when,
notify);
for (RevisionCreatedListener l : listeners) {
try {
l.onRevisionCreated(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (PatchListObjectTooLargeException e) {
log.warn("Couldn't fire event: " + e.getMessage());
} catch (PatchListNotAvailableException
| GpgException
| IOException
| OrmException
| PermissionBackendException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractRevisionEvent
implements RevisionCreatedListener.Event {
Event(
ChangeInfo change,
RevisionInfo revision,
AccountInfo uploader,
Timestamp when,
NotifyHandling notify) {
super(change, revision, uploader, when, notify);
}
}
}

View File

@@ -0,0 +1,74 @@
// 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.events.TopicEditedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.sql.Timestamp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TopicEdited {
private static final Logger log = LoggerFactory.getLogger(TopicEdited.class);
private final DynamicSet<TopicEditedListener> listeners;
private final EventUtil util;
@Inject
TopicEdited(DynamicSet<TopicEditedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(Change change, Account account, String oldTopicName, Timestamp when) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(util.changeInfo(change), util.accountInfo(account), oldTopicName, when);
for (TopicEditedListener l : listeners) {
try {
l.onTopicEdited(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (OrmException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractChangeEvent implements TopicEditedListener.Event {
private final String oldTopic;
Event(ChangeInfo change, AccountInfo editor, String oldTopic, Timestamp when) {
super(change, editor, when, NotifyHandling.ALL);
this.oldTopic = oldTopic;
}
@Override
public String getOldTopic() {
return oldTopic;
}
}
}

View File

@@ -0,0 +1,137 @@
// Copyright (C) 2016 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.extensions.events;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.VoteDeletedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class VoteDeleted {
private static final Logger log = LoggerFactory.getLogger(VoteDeleted.class);
private final DynamicSet<VoteDeletedListener> listeners;
private final EventUtil util;
@Inject
VoteDeleted(DynamicSet<VoteDeletedListener> listeners, EventUtil util) {
this.listeners = listeners;
this.util = util;
}
public void fire(
Change change,
PatchSet ps,
Account reviewer,
Map<String, Short> approvals,
Map<String, Short> oldApprovals,
NotifyHandling notify,
String message,
Account remover,
Timestamp when) {
if (!listeners.iterator().hasNext()) {
return;
}
try {
Event event =
new Event(
util.changeInfo(change),
util.revisionInfo(change.getProject(), ps),
util.accountInfo(reviewer),
util.approvals(remover, approvals, when),
util.approvals(remover, oldApprovals, when),
notify,
message,
util.accountInfo(remover),
when);
for (VoteDeletedListener l : listeners) {
try {
l.onVoteDeleted(event);
} catch (Exception e) {
util.logEventListenerError(this, l, e);
}
}
} catch (PatchListObjectTooLargeException e) {
log.warn("Couldn't fire event: " + e.getMessage());
} catch (PatchListNotAvailableException
| GpgException
| IOException
| OrmException
| PermissionBackendException e) {
log.error("Couldn't fire event", e);
}
}
private static class Event extends AbstractRevisionEvent implements VoteDeletedListener.Event {
private final AccountInfo reviewer;
private final Map<String, ApprovalInfo> approvals;
private final Map<String, ApprovalInfo> oldApprovals;
private final String message;
Event(
ChangeInfo change,
RevisionInfo revision,
AccountInfo reviewer,
Map<String, ApprovalInfo> approvals,
Map<String, ApprovalInfo> oldApprovals,
NotifyHandling notify,
String message,
AccountInfo remover,
Timestamp when) {
super(change, revision, remover, when, notify);
this.reviewer = reviewer;
this.approvals = approvals;
this.oldApprovals = oldApprovals;
this.message = message;
}
@Override
public Map<String, ApprovalInfo> getApprovals() {
return approvals;
}
@Override
public Map<String, ApprovalInfo> getOldApprovals() {
return oldApprovals;
}
@Override
public String getMessage() {
return message;
}
@Override
public AccountInfo getReviewer() {
return reviewer;
}
}
}