Events: Add GerritEvent and ProjectEvent interfaces

In the current implementation the event interfaces don't share a common
base interface, which means it's not possible for users to refer to them
in a generic way.

Add a GerritEvent interface from which all events now inherit. This makes
it possible to define, for example, a list:

  List<GerritEvent> events

and add any of the derived event types.

Also add a new intermediate interface, ProjectEvent, and modify all the
existing project-related events to derive from it.

Change-Id: I62ccd8f0b172e1d1e432d84ca3e20d088480be20
This commit is contained in:
David Pursehouse
2016-07-01 14:26:03 +09:00
parent b7e1c70b15
commit 9a090100a2
10 changed files with 47 additions and 16 deletions

View File

@@ -20,7 +20,7 @@ import com.google.gerrit.extensions.common.AccountInfo;
/** Notified whenever a user signed up for a Contributor License Agreement. */
@ExtensionPoint
public interface AgreementSignupListener {
interface Event {
interface Event extends GerritEvent {
AccountInfo getAccount();
String getAgreementName();
}

View File

@@ -17,7 +17,7 @@ package com.google.gerrit.extensions.events;
import com.google.gerrit.extensions.common.ChangeInfo;
/** Interface to be extended by Events with a Change. */
public interface ChangeEvent {
public interface ChangeEvent extends GerritEvent {
ChangeInfo getChange();
}

View File

@@ -23,10 +23,7 @@ import java.util.Properties;
*/
@ExtensionPoint
public interface GarbageCollectorListener {
interface Event {
/** @return The name of the project that has been garbage collected. */
String getProjectName();
interface Event extends ProjectEvent {
/**
* @return Properties describing the result of the garbage collection
* performed by JGit.

View File

@@ -0,0 +1,19 @@
// 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.extensions.events;
/** Base interface to be extended by Events. */
public interface GerritEvent {
}

View File

@@ -21,9 +21,7 @@ import com.google.gerrit.extensions.common.AccountInfo;
/** Notified when one or more references are modified. */
@ExtensionPoint
public interface GitReferenceUpdatedListener {
interface Event {
String getProjectName();
interface Event extends ProjectEvent {
String getRefName();
String getOldObjectId();
String getNewObjectId();

View File

@@ -19,8 +19,7 @@ import com.google.gerrit.extensions.annotations.ExtensionPoint;
/** Notified whenever the HEAD of a project is updated. */
@ExtensionPoint
public interface HeadUpdatedListener {
interface Event {
String getProjectName();
interface Event extends ProjectEvent {
String getOldHeadName();
String getNewHeadName();
}

View File

@@ -20,8 +20,7 @@ import com.google.gerrit.extensions.annotations.ExtensionPoint;
/** Notified whenever a project is created on the master. */
@ExtensionPoint
public interface NewProjectCreatedListener {
interface Event {
String getProjectName();
interface Event extends ProjectEvent {
String getHeadName();
}

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.extensions.events;
/** Notified when a plugin fires an event. */
public interface PluginEventListener {
interface Event {
interface Event extends GerritEvent {
String pluginName();
String getType();
String getData();

View File

@@ -19,8 +19,7 @@ import com.google.gerrit.extensions.annotations.ExtensionPoint;
/** Notified whenever a project is deleted on the master. */
@ExtensionPoint
public interface ProjectDeletedListener {
interface Event {
String getProjectName();
interface Event extends ProjectEvent {
}
void onProjectDeleted(Event event);

View File

@@ -0,0 +1,20 @@
// 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.extensions.events;
/** Interface to be extended by Events with a Project. */
public interface ProjectEvent extends GerritEvent {
String getProjectName();
}