Last updated Feb 19, 2024

Fisheye event listener plugin tutorial

This is a brief tutorial which teaches you how to write a trivial event listener plugin.The Fisheye Twitter Integration Plugin Tutorial contains an event listener plugin module as part of a more complex plugin.

Plugin Source

We encourage you to work through this tutorial. If you want to skip ahead or check your work when you are done, you can find the plugin source code on Atlassian Bitbucket. Bitbucket serves a public Git repository containing the tutorial's code. To clone the repository, issue the following command:

1
2
$ git clone https://atlassian_tutorial@bitbucket.org/atlassian_tutorial/fecru-review-creator.git

Alternatively, you can download the source using the Downloads page here: https://bitbucket.org/atlassian_tutorial/fecru-review-creator

Work through the Tutorial

An Event Listener must implement com.atlassian.event.EventListener.

Your implementation is added to atlassian-plugin.xml:

1
2
<listener key="trivial-listener" class="com.example.eventlistener.MyTrivialListener"/>

Your implementation's getHandledEventClasses method must return an array of the event classes you wish to be notified of, in our example, comment creation and update events. (here are other event types)

1
2
public class MyTrivialListener implements EventListener {
...
    public Class[] getHandledEventClasses() {
        return new Class[] {CommentCreatedEvent.class, CommentUpdatedEvent.class};
    }
}

When a commit occurs our handleEvent method will be called:

1
2
public class MyTrivialListener implements EventListener {
...
    public void handleEvent(Event event) {
        ReviewCommentEvent commentEvent = (ReviewCommentEvent)event;
        System.out.println("Changed comment " + commentEvent.getCommentId());
    }
...
}

Rate this page: