FishEye Event Listener Plugin Module 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:

$ 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:

    <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)

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:

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

Was this page helpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport