リスナー
リスナーはJIRAで固有であり、拡張するのにとても強力な方法です。
JIRA has a complete event subsystem which fires events whenever anything happens inside the application. For example an ISSUE_CREATED
event is fired whenever an issue is created.
A Listener is a class that implements one of the Listener interfaces. It is then called whenever events occur in JIRA. Using those events, you can then perform any action you want. For example the email sent by JIRA is driven by the MailListener.
リスナーは、JIRA内で発生するイベントから外部システムに影響を与えたいときに最も便利です。
Listener Interfaces
JIRA には次のような(基本の JiraListener を拡張した)具体的なリスナーがあります。
com.atlassian.jira.event.JiraListener | すべての JIRA リスナー インタフェースが拡張している基本のインタフェース。一意性、説明、パラメータなどの主要なリスナー プロパティをカバーしています。 |
com.atlassian.jira.event.issue.IssueEventListener | 課題でイベントが発生するたびに使用される、Jira のメイン リスナー。 |
com.atlassian.jira.event.user.UserEventListener | このリスナーは JIRA 内でユーザーに対して何かが起こるたびに呼びだされます。 |
Example Listeners
The examples provided may be freely used and modified for use in your own environment. The source of all examples is available and should give you good overview of how simple it is to write your own listeners. Both example listeners are included with JIRA 2.1, and both implement UserEventListener
and IssueEventListener
.
- DebugListener (source) — This is a very simple listener that prints events and their content to System.out whenever they are received. To test this listener, add a listener with the class
com.atlassian.jira.event.listeners.DebugListener
. - MailListener (source) — This listener is how mail notifications are currently sent from within JIRA, and a good example of a more complex listener. It basically listens for events, and turns them into email notifications using Velocity templates to generate the mail bodies.
This listener is usually always turned on in JIRA — see Email Notifications for more details. If you want to write more complex or more specific notifications, you can disable the internal MailListener and add your own.
リスナーで実現できるその他の便利なタスクの例:
- SMS または IM 通知を送信する — リスナーは SMS または インスタント メッセンジャー(例、ICQ または AIM)、メッセージを送信する Java ライブラリを介して様々なイベントの通知を容易に送ることができます。
- グループ通知 — リスナーは課題の内容によって、信頼できるグループに課題の変更を通知することができます。例えば、環境に "windows" が含まれている課題は "windows-開発者" グループに通知することができます。
Registering a Listener
For custom-written listener classes, make sure your listener class is in the classpath where JIRA can see it — the best locations are usually the
<jira-application-dir>/WEB-INF/classes
or <jira-application-dir>/WEB-INF/lib
subdirectories within of your JIRA Installation Directory (as JAR files).
リスナーを登録するには、次の手順に従います。
- Log in as a user with the 'JIRA System Administrators' global permission.
- Choose > System. Select Advanced > Listeners to open the Listeners page.
Keyboard shortcut: 'g' + 'g' + type 'lis'
- ページの下部にある 「リスナーの追加」 フォームで、次のフィールドの入力を完了します。
- 名前 — リスナーを適切に説明する名前
- 'Class' — the fully-qualified class name of your listener.
To use one of JIRA's built-in listener classes, first click the 'Built-in Listeners' link to expand the list of listener classes and then click the name of the specific class in the list. The fully-qualified class name of the built-in listener will be added to the 'Class' field.
- 追加ボタンをクリックすると、リスナーが上部のリスナー一覧に追加されます。
Editing Listener Properties
リスナーがパラメータまたはプロパティを受け入れる場合、JIRA の管理エリアのリスナー ページにある、対象のリスナーに関連する編集リンクをクリックすることで変更することができます。
独自のリスナーを定義する場合、String オブジェクトの配列として渡されるパラメータ名の定義をオーバーロードするメソッド getAcceptedParams
があります。init
メソッドは、設定値を含む Map
を受け取ります (JavaDoc は現在は使用されていません)。com.atlassian.jira.event.listeners.DebugParamListener
クラスは 2 つのパラメータでのこれの実行例です。
Removing a Listener
リスナーを削除するには、JIRA の管理エリアのリスナー ページにある、対象のリスナーに関連する削除リンクをクリックします。
Custom Events
With the ability to add custom events to JIRA, the Listener must be updated to deal with the event as appropriate. This is possible by providing an implementation for the method customEvent(IssueEvent event)
in the Listener. For example, the MailListener implementation passes the custom event on for notification processing. The DebugListener logs that the custom event has been fired.
参考情報
- Plugin Tutorial - Writing event listeners with the atlassian-event library — this describes how to write listeners using the Atlassian Events library (see JIRA-specific Atlassian Events), rather than the JIRA Listener Events described above.