<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.urbancode.com/PluginXMLSchema_v1" 
   xmlns:server="http://www.urbancode.com/PluginServerXMLSchema_v1"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <header>
    <identifier id="com.urbancode.air.plugin.jira" name="JIRA" version="3"/>
    <description>
This plugin provides a integrations with JIRA. Issues can be reported on, commented on, updated and created. This integration requires that the SOAP Service be enabled in RPC JIRA Plugin in JIRA.
      </description>
    <tag>Quality/Issue Tracking/JIRA</tag>
    <server:plugin-type>Automation</server:plugin-type>
  </header>
  
  <!-- ==================================== -->
  <!--  Add Comments                         -->
  <!-- ==================================== -->
  <step-type name="Add Comments">
    <description>Add comments to JIRA issues detected by parsing the source change comments of the build life.</description>
    <properties>
      <property name="issueIdPattern" required="true">
        <server:property-ui type="textAreaBox"
                            label="Issue ID Pattern"
                            description="A regular expression that represents the IDs to search for in the build life source change comments.  Eg. TEST-[0-9]+"/>
      </property>
      <property name="commentBody" required="true">
        <server:property-ui type="textAreaBox"
                            label="Comment"
                            description="The template to use for adding a comment to JIRA Issues."/>
      </property>
      <property name="failMode" required="true">
        <server:property-ui type="selectBox"
                            label="Fail Mode"
                            default-value="FAIL_FAST"
                            description="What should be done when an issue can not be commented on."/>
        <server:value label="Warn Only">WARN_ONLY</server:value>
        <server:value label="Fail Fast">FAIL_FAST</server:value>
        <server:value label="Fail on no Updates">FAIL_ON_NO_UPDATES</server:value>
      </property>
      <property name="automation" required="true">
        <server:property-ui type="automationPropSheetRef"
                            label="JIRA Workspace"/>
      </property>
    </properties>
    <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]></post-processing>
    <command program="${GROOVY_HOME}/bin/groovy">
      <arg value="-cp"/>
      <arg path="classes:lib/activation-1.1.1.jar:lib/javamail-1.4.1.jar:lib/httpcore.jar:lib/httpclient.jar:lib/httpclient-cache.jar:lib/httpmime.jar:lib/HttpComponents-Util.jar:lib/commons-codec.jar:lib/CommonsUtil.jar:lib/log4j.jar:lib/axis-1.4.jar:lib/axis-ant-1.4.jar:lib/axis-jaxrpc-1.4.jar:lib/axis-saaj-1.4.jar:lib/axis-wsdl4j-1.5.1.jar:lib/commons-logging.jar:lib/commons-discovery-0.2.jar"/>
      <arg file="add_comments.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>
  
  <!-- ==================================== -->
  <!--  Create Issue                         -->
  <!-- ==================================== -->
  <step-type name="Create Issue">
    <description>Create a new issue in JIRA. The type of issue created is configurable.</description>
    <properties>
      <property name="projectKey" required="true">
        <server:property-ui type="textBox"
                            label="Project Key"
                            description="The project key in JIRA"/>
      </property>
      <property name="issueTypeName" required="true">
        <server:property-ui type="textBox"
                            label="Issue Type"
                            description="The name of the issue type to create. Eg. Bug, Improvement, New Feature, etc"/>
      </property>
      <property name="assignee" required="true">
        <server:property-ui type="textBox"
                            label="Assignee"
                            default-value="-1"
                            description="The JIRA username to assign the issue to. Use -1 to use JIRA's automatic assignment."/>
      </property>
      <property name="summary" required="true">
        <server:property-ui type="textBox"
                            label="Summary"
                            description="The summary for this issue."/>
      </property>
      <property name="environment">
        <server:property-ui type="textBox"
                            label="Environment"
                            description="The environment of this issue."/>
      </property>
      <property name="issueDescription" required="true">
        <server:property-ui type="textAreaBox"
                            label="Issue Description"
                            description="The description of this issue."/>
      </property>
      <property name="automation" required="true">
        <server:property-ui type="automationPropSheetRef"
                            label="JIRA Workspace"/>
      </property>
    </properties>
    <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]></post-processing>
    <command program="${GROOVY_HOME}/bin/groovy">
      <arg value="-cp"/>
      <arg path="classes:lib/activation-1.1.1.jar:lib/javamail-1.4.1.jar:lib/httpcore.jar:lib/httpclient.jar:lib/httpclient-cache.jar:lib/httpmime.jar:lib/HttpComponents-Util.jar:lib/commons-codec.jar:lib/CommonsUtil.jar:lib/log4j.jar:lib/axis-1.4.jar:lib/axis-ant-1.4.jar:lib/axis-jaxrpc-1.4.jar:lib/axis-saaj-1.4.jar:lib/axis-wsdl4j-1.5.1.jar:lib/commons-logging.jar:lib/commons-discovery-0.2.jar"/>
      <arg file="create_issue.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>
  
  <!-- ==================================== -->
  <!--  Update Issue                         -->
  <!-- ==================================== -->
  <step-type name="Update Issue">
    <description>Update JIRA issues detected by parsing the source change comments of the build life.</description>
    <properties>
      <property name="issueIdPattern" required="true">
        <server:property-ui type="textAreaBox"
                            label="Issue ID Pattern"
                            description="A regular expression that represents the IDs to search for in the build life source change comments.  Eg. TEST-[0-9]+"/>
      </property>
      <property name="actionName" required="true">
        <server:property-ui type="textBox"
                            label="Action Name"
                            description="The Action which should be performed upon the issues. (e.g. 'Resolve Issue' or 'Close Issue')"
                            default-value="Resolve Issue" />
      </property>
      <property name="additionalComment">
        <server:property-ui type="textAreaBox"
                            label="Additional Comment"
                            description="Enter any comments that you would like to be added to the issue when it is updated. Leave the field blank if you do not want to add any comments."/>
      </property>
      <property name="automation" required="true">
        <server:property-ui type="automationPropSheetRef"
                            label="JIRA Workspace"/>
      </property>
    </properties>
    <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]></post-processing>
    <command program="${GROOVY_HOME}/bin/groovy">
      <arg value="-cp"/>
      <arg path="classes:lib/activation-1.1.1.jar:lib/javamail-1.4.1.jar:lib/httpcore.jar:lib/httpclient.jar:lib/httpclient-cache.jar:lib/httpmime.jar:lib/HttpComponents-Util.jar:lib/commons-codec.jar:lib/CommonsUtil.jar:lib/log4j.jar:lib/axis-1.4.jar:lib/axis-ant-1.4.jar:lib/axis-jaxrpc-1.4.jar:lib/axis-saaj-1.4.jar:lib/axis-wsdl4j-1.5.1.jar:lib/commons-logging.jar:lib/commons-discovery-0.2.jar"/>
      <arg file="update_issue.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>
  
  <!-- ==================================== -->
  <!--  Check Status                         -->
  <!-- ==================================== -->
  <step-type name="Check Status">
    <description>Validate the status of JIRA issues detected by parsing the source change comments of the build life.</description>
    <properties>
      <property name="issueIdPattern" required="true">
        <server:property-ui type="textAreaBox"
                            label="Issue ID Pattern"
                            description="A regular expression that represents the IDs to search for in the build life source change comments.  Eg. TEST-[0-9]+"/>
      </property>
      <property name="statusName" required="true">
        <server:property-ui type="textBox"
                            label="Status Name"
                            description="The status to that we expect the issue to be in."
                            default-value="Resolved" />
      </property>
      <property name="failMode" required="true">
        <server:property-ui type="selectBox"
                            label="Fail Mode"
                            description="What should be done when an unexpected status is found."/>
        <server:value label="Warn Only">WARN_ONLY</server:value>
        <server:value label="Fail Fast">FAIL_FAST</server:value>
        <server:value label="Fail on All Failure">FAIL_ON_NO_UPDATES</server:value>
        <server:value label="Fail on Any failure">FAIL_ON_ANY_FAILURE</server:value>
      </property>
      <property name="automation" required="true">
        <server:property-ui type="automationPropSheetRef"
                            label="JIRA Workspace"/>
      </property>
    </properties>
    <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]></post-processing>
    <command program="${GROOVY_HOME}/bin/groovy">
      <arg value="-cp"/>
      <arg path="classes:lib/activation-1.1.1.jar:lib/javamail-1.4.1.jar:lib/httpcore.jar:lib/httpclient.jar:lib/httpclient-cache.jar:lib/httpmime.jar:lib/HttpComponents-Util.jar:lib/commons-codec.jar:lib/CommonsUtil.jar:lib/log4j.jar:lib/axis-1.4.jar:lib/axis-ant-1.4.jar:lib/axis-jaxrpc-1.4.jar:lib/axis-saaj-1.4.jar:lib/axis-wsdl4j-1.5.1.jar:lib/commons-logging.jar:lib/commons-discovery-0.2.jar"/>
      <arg file="check_status.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>
  
  <!-- ==================================== -->
  <!--  Publish Issue Report                         -->
  <!-- ==================================== -->
  <!-- TODO doesn't support making a html report -->
  <!-- TODO doesn't support checking dependency changelogs -->
  <step-type name="Publish Issue Report">
    <description>Create a report of JIRA issues detected by parsing the source change comments of the build life.</description>
    <properties>
      <property name="issueIdPattern" required="true">
        <server:property-ui type="textAreaBox"
                            label="Issue ID Pattern"
                            description="A regular expression that represents the IDs to search for in the build life source change comments.  Eg. TEST-[0-9]+"/>
      </property>
      <property name="automation" required="true">
        <server:property-ui type="automationPropSheetRef"
                            label="JIRA Workspace"/>
      </property>
    </properties>
    <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]></post-processing>
    <command program="${GROOVY_HOME}/bin/groovy">
      <arg value="-cp"/>
      <arg path="classes:lib/activation-1.1.1.jar:lib/javamail-1.4.1.jar:lib/httpcore.jar:lib/httpclient.jar:lib/httpclient-cache.jar:lib/httpmime.jar:lib/HttpComponents-Util.jar:lib/commons-codec.jar:lib/CommonsUtil.jar:lib/log4j.jar:lib/axis-1.4.jar:lib/axis-ant-1.4.jar:lib/axis-jaxrpc-1.4.jar:lib/axis-saaj-1.4.jar:lib/axis-wsdl4j-1.5.1.jar:lib/commons-logging.jar:lib/commons-discovery-0.2.jar"/>
      <arg file="issue_report.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>
  
  <!-- ==================================== -->
  <!--  AUTOMATION                          -->
  <!-- ==================================== -->
  <server:property-group type="Automation" name="Automation">
    <server:property name="serverUrl" required="true">
      <server:property-ui type="textBox" 
                          label="JIRA Base URL"
                          description="The JIRA server URL. Eg. https://bugs.company.com" />
    </server:property>
    <server:property name="serverIssueUrl">
      <server:property-ui type="textBox"
                          label="Issue URL"
                          description="This field provides a template which will be used to generate 
                          links from issues directly to the issue page within JIRA. The value '${issueId}' will be replaced 
                          in the template with the issue id of the associated issue. Please provide a url template such 
                          as https://bugs.company.com/browse/${issueId}." />
    </server:property>
    <server:property name="username">
      <server:property-ui type="textBox"
                          label="User Name"
                          description="The user name to be used to connect to the JIRA server."/>
    </server:property>
    <server:property name="password">
      <server:property-ui type="secureBox"
                          label="Password"
                          description="The password to be used to connect to the JIRA server."/>
    </server:property>
    <server:property name="passwordScript">
      <server:property-ui type="textAreaBox"
                          label="Password Script"
                          description="If you wish to use a script or server:property lookups for your password, leave 
                          the Password field blank and enter it here."/>
    </server:property>
    <server:property name="serverVersion" required="true">
      <server:property-ui type="selectBox" 
                          label="Server Version"
                          description="Specify the version of your JIRA server, chose the highest version available 
                          without going over your current version (versions 3.9 and above have been reported to work 
                          with the 3.11 integration)."
                          default-value="3.6.5" />
      <server:value label="3.6.5">3.6.5</server:value>
      <server:value label="3.11">3.11</server:value>
      <server:value label="4.3-rc1">4.3-rc1</server:value>
    </server:property>
  </server:property-group>
</plugin>
