<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
- Licensed Materials - Property of IBM* and/or HCL**
- UrbanCode Build
- (c) Copyright IBM Corporation 2013, 2017. All Rights Reserved.
- (c) Copyright HCL Technologies Ltd. 2018. All Rights Reserved.
-
- U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by
- GSA ADP Schedule Contract with IBM Corp.
-
- * Trademark of International Business Machines
- ** Trademark of HCL Technologies Limited
-->

<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.UCBUtils" name="UCB Utils" version="1"/>
    <description>
      The UCB Utils plug-in provides steps to facilitate various tasks.
    </description>
    <tag>Utilities/UCBUtils</tag>
  </header>

  <!-- ==================================== -->
  <!--   STEPS                              -->
  <!-- ==================================== -->

  <!-- ==================================== -->
  <!--   Generate a json file               -->
  <!-- ==================================== -->
  <step-type name="Create a json file">
    <description>Create a json file.</description>
    <properties>
      <property name="jsonTextArea" required="true">
        <property-ui type="textAreaBox"
                     label="JSON Content"
                     description="The json content. Enter json content string." />
      </property>
      <property name="beautifyJSON">
        <property-ui type="checkBox"
                     label="Beautify Content"
                     description="Beautify the content when writing to file."/>
      </property>
      <property name="overwrite">
        <property-ui type="checkBox"
                     label="Overwrite"
                     description="Overwrite the output file if it already exists."/>
      </property>
      <property name="file" required="true">
        <property-ui type="textBox"
                     label="JSON File"
                     description="The name of the json file to create."/>
      </property>
      <property name="customEncoding">
        <property-ui type="textBox"
                     label="Custom Encoding"
                     description="Specify a character encoding to use when writing to file. If blank, 
                                 the default character encoding of the agent will be used. Examples: 
                                 US-ASCII, UCS-2,JIS X 0201, UTF-16, UTF-16LE, EUC."/>
      </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/securedata.jar"/>
      <arg file="writeJson.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>

  <!-- ==================================== -->
  <!--   Add Properties                     -->
  <!-- ==================================== -->
  <step-type name="Add Properties">
    <description>Add scoped properties.</description>
    <properties>
      <property name="propertiesTextArea" required="true">
        <property-ui type="textAreaBox"
                     label="Properties"
                     description="The properties to add. Enter each property on a new line. Separate the property name and value with '='." />
      </property>
      <property name="propertiesScope" required="true">
        <property-ui type="selectBox"
                     label="Scope"
                     description="The scope of the properties"
                     default-value="buildlife" />
        <server:value label="buildlife">buildlife</server:value>
        <server:value label="job">job</server:value>
        <server:value label="buildrequest">buildrequest</server:value>
        <server:value label="system">system</server:value>
      </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/securedata.jar:lib/httpcore.jar:lib/httpclient.jar:lib/httpclient-cache.jar:lib/httpmime.jar:lib/HttpComponents-Util.jar:lib/CommonsUtil.jar:lib/commons-logging.jar:lib/commons-codec.jar:lib/log4j.jar:lib/jettison-1.1.jar" />
      <arg file="addProperties.groovy" />
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>
</plugin>
