atlassian JIRA 插件開發(六) — JIRA系統的插件體系,總體一瞥

【原文地址:http://blog.sina.com.cn/s/blog_3e7397cf0100k395.html,原作者博客:Rocky的博客http://blog.sina.com.cn/yuzhenxin


JIRA系統是一個非常優秀的項目管理系統,在JIRA系統上可以進行流程定義、表單定義、豐富的權限管理等等。但其最有特色的,我認爲還是其高可配置、靈活的插件體系。在JIRA所提供的插件體系下,我們可以進行二次開發,通過功能擴展以滿足差異化的需求。如:自定義菜單、擴展自定義屬性、擴展流程的驗證規則、擴展流程的流轉條件、擴展流程的PostFunction等等。

 

JIRA的插件體系是基於OSGI可插拔式的,每一個插件實際上就是一個jar包。這個插件jar包放到%JIRA_HOME%\atlassian-jira\WEB-INF\lib目錄下,重啓JIRA系統,即可實現插件的動態部署。(轉者注:插件version2,可以採用UPM方式,具體可見:http://blog.csdn.net/yieryi_/article/details/47955167

 

那麼JIRA是怎麼能識別出插件的呢?  所有的JIRA插件jar包中,都必須要包含一個以atlassian-plugin.xml 命名的配置文件。下面是一個 atlassian-plugin.xml樣例。(以jira-suite-utilities插件的配置文件爲例子,紅色部分是註釋說明)

 

<atlassian-pluginkey="com.googlecode.jira-suite-utilities"

                  name="JIRA Suite Utilities"  plugin-version="2">

      <plugin-info>

           <description>Many objects to extendJIRA</description>

           <version>0.7.7</version>

           <application-version min="3.5"max="4.1"/>

           <vendor name="Quadratica SRL" url=""/>

      </plugin-info>  

 

      <!—在JIRA中增加自定義屬性,如這裏定義了一個“Location Text Field” 類型的自定義字段 -->

      <customfield-type key="locationtextfield" name="Location Text Field"

                     class="com.atlassian.jira.issue.customfields.impl.TextCFType"

                     i18n-name-key="custom.field.type.text_field.name">

          <resource type="i18n" name="i18n"location="com.googlecode.jsu.maps.resources" /><!—國際化資源文件-->

          <descriptionkey="custom.field.type.text_field.description">Saving locations and showing it atmaps.</description>

          <!—自定義字段的查看、編輯的顯示模板-->

          <resource type="velocity" name="view"location="templates/jira/fields/view/view-location.vm"/>

          <resource type="velocity"name="edit"location="templates/plugins/fields/edit/edit-basictext.vm"/>

          <resource type="velocity" name="xml"location="templates/plugins/fields/xml/xml-basictext.vm"/>

      </customfield-type>

 

      <!—流程流轉的條件規則定義,如這裏定義了一個“用戶是否屬於某個羣組”的判斷條件定義-->

      <workflow-conditionkey="userIsInAnyGroups-condition" name="User Is In Any Groups"

                   class="com.googlecode.jsu.workflow.WorkflowUserIsInAnyGroupsConditionPluginFactory">

          <description>It allows only users inany given groups to execute thetransition.</description>

          <!—條件定義的具體實現類-->

          <condition-class>com.googlecode.jsu.workflow.condition.UserIsInAnyGroupsCondition</condition-class>

          <resource type="velocity" name="view"location="templates/jira/workflow/userIsInAnyGroups-condition-view.vm"/>

          <resource type="velocity" name="input-parameters"location="templates/jira/workflow/userIsInAnyGroups-condition-edit.vm"/>

          <resource type="velocity" name="edit-parameters"location="templates/jira/workflow/userIsInAnyGroups-condition-edit.vm"/>

      </workflow-condition>

   

     <!—流程處理方式在提交時的校驗定義,下面的例子是定義了一個時間比較的驗證類 -->

     <workflow-validator key="dateCompare-validator"name="Date Compare"

                    class="com.googlecode.jsu.workflow.WorkflowDateCompareValidatorPluginFactory">

         <description>Compare two datefields during a workflowtransition.</description>

         <validator-class>

              com.googlecode.jsu.workflow.validator.DateCompareValidator

         </validator-class>

         <resource type="velocity" name="view"location="templates/jira/workflow/validator/datecompare-validator-view.vm"/>

         <resource type="velocity" name="input-parameters"location="templates/jira/workflow/validator/datecompare-validator-input.vm"/>

         <resource type="velocity" name="edit-parameters"location="templates/jira/workflow/validator/datecompare-validator-edit.vm"/>

     </workflow-validator> 

 

     <!—流程在提交後的處理函數定義,下面的例子是一個從其他字段中拷貝值的方法定義 -->

     <workflow-functionkey="copyValueFromOtherField-function" name="Copy Value From OtherField"

                class="com.googlecode.jsu.workflow.WorkflowCopyValueFromOtherFieldPostFunctionPluginFactory">

        <description>It copies the value ofone field toanother.</description>

        <function-class>

               com.googlecode.jsu.workflow.function.CopyValueFromOtherFieldPostFunction

        </function-class>

        <orderable>true</orderable>

        <unique>false</unique>

        <deletable>true</deletable>       

        <default>false</default>

        <resource type="velocity" name="view"location="templates/jira/workflow/copyvaluefromfield-function-view.vm"/>

        <resource type="velocity" name="input-parameters"location="templates/jira/function/copyvaluefromfield-function-input.vm"/>

        <resource type="velocity" name="edit-parameters"location="templates/jira/workflow/copyvaluefromfield-function-edit.vm"/>

    </workflow-function>

   

    <!—下面的XML是定義了Dashboard上可顯示的Portlet -->

    <issue-tabpanelkey="transitions-summary-tabpanel"

                                   name="TransitionsSummary Tab Panel"

                                   class="com.googlecode.jsu.transitionssummary.issuetabpanel.TransitionsSummaryTabPanel">

        <description key="transition.summary.description"/>

        <label key="transition.summary.transitions"/>

        <resourcetype="i18n"  name="i18n"  location="com.googlecode.jsu.transitionssummary.transitionssummary"/>

       <resource type="velocity"  name="view"  location="templates/jira/issuetabpanel/transitionssummary/transitions-summary-view.vm"/>

    </issue-tabpanel>

</atlassian-plugin>

 

當然,在這個JIRA插件配置文件中,定義的自定義屬性、流程驗證器、流程流轉條件以及流程流轉後處理方法等,也是需要按照JIRA的規範實現相關的接口的。這裏,暫時先不展開描述。在後續的連載中,儘量詳細介紹(因爲我很懶,不知道什麼時候會更新Blog)。

 

還是以剛剛的jira-suite-utilities插件爲例。將jira-suite-utilities-0.7.7.jar拷貝到 %JIRA_HOME%\atlassian-jira\WEB-INF\lib目錄下,重啓JIRA系統。 登陸JIRA系統,我們在自定義屬性中,就可以看見在原有的自定義屬性類型中新增加了一種“LocationText Field”類型的字段。(轉者注:可以清晰的看到,作者定義的這個插件atlassian-plugin.xml文件中有version=2的字樣,所以採用UPM也是可以的。)如下所示:


同樣,我們在流程的驗證器中,也能發現系統中多了一些原來所沒有的驗證器,如“User Is In AnyGroups”驗證器。

 

選中該驗證器後點擊下一步:

 

以上的這些功能,都是通過插件方式提供的,而沒有對JIRA系統做任何破壞性、侵入式的修改!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章