<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed Materials - Property of IBM* and/or HCL**
- UrbanCode Deploy
- UrbanCode Build
- UrbanCode Release
- AnthillPro
- (c) Copyright IBM Corporation 2011, 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:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <header>
    <identifier id="com.urbancode.air.plugin.Shell" version="10" name="Shell"/>
    <description>The Shell plugin allows users to run custom shell scripts during the deployment process.</description>
    <tag>Scripting/Shell</tag>
  </header>
  <step-type name="Shell">
    <description>Execute a shell or batch script.</description>
    <properties>
      <property name="directoryOffset" required="true">
        <property-ui type="textBox" description="The working directory to use when executing this command. This is relative to current working directory." label="Directory Offset" default-value="."/>
      </property>
      <property name="shellInterpreter">
        <property-ui type="textBox" label="Interpreter" 
                       description="Optionally specify the interpreter to use to evaluate the command.
                       If left blank the following platform-specific behavior will be used:
                       Command Line will use .bat file interpreter on Windows and .com file interpreter on VMS. On other
                       systems it will use the shell specified by 'air/shell' agent variable if present. *nix systems
                       may override this by having the Command Line starts with a #! sequence."/>
      </property>
      <property name="scriptBody" required="true">
        <property-ui type="textAreaBox" label="Shell Script" description="Enter the script code to execute."/>
      </property>
      <property name="runAsDaemon">
        <property-ui type="checkBox" label="Daemon" description="Check this option to run the command in the background while permitting the step to
                complete immediately. The output will not be captured if running as a daemon."/>
      </property>
      <property name="outputFile">
        <property-ui type="textBox" label="Output File" description="Only set this value if Daemon is checked. Enter the 
              path of the file to which the command output is directed. Leave blank to discard the output. The output 
              will not be captured if an output file is specified."/>
      </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/shell.jar:lib/CommonsUtil.jar:lib/log4j.jar:lib/NativeProcess.jar:lib/WinAPI.jar:lib/securedata.jar:lib/jettison-1.1.jar:lib/commons-codec.jar"/>
      <arg file="shell.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>
  <step-type name="Shell (with xargs)">
    <description>Execute a shell or batch script a number of times equal to a multi-valued input.</description>
    <properties>
      <property name="directoryOffset" required="true">
        <property-ui type="textBox" description="The working directory to use when executing this command. This is relative to current working directory." label="Directory Offset" default-value="."/>
      </property>
      <property name="shellInterpreter">
        <property-ui type="textBox" label="Interpreter" 
                       description="Optionally specify the interpreter to use to evaluate the command.
                       If left blank the following platform-specific behavior will be used:
                       Command Line will use .bat file interpreter on Windows and .com file interpreter on VMS. On other
                       systems it will use the shell specified by 'air/shell' agent variable if present. *nix systems
                       may override this by having the Command Line starts with a #! sequence."/>
      </property>
	  <property name="xargs" required="true">
        <property-ui type="textBox" label="xargs" 
                       description="The delimiter-separated values to use as input to the script. The delimiter can be specified below."/>
	  </property>
	  <property name="xargsDelimiter" required="true">
        <property-ui type="textBox" label="xargs delimiter" 
                       description="The delimiter used to seperate the values to use as input to the script. The default delimiter used is comma" default-value=","/>
	  </property>
	  <property name="runOncePerArg">
        <property-ui type="checkBox" label="Once Per Arg" 
                       description="Run the script once per argument in xargs."/>
	  </property>
      <property name="scriptBody" required="true">
        <property-ui type="textAreaBox" label="Shell Script" description="Enter the script code to execute."/>
      </property>
      <property name="runAsDaemon">
        <property-ui type="checkBox" label="Daemon" description="Check this option to run the command in the background while permitting the step to
                complete immediately. The output will not be captured if running as a daemon."/>
      </property>
      <property name="outputFile">
        <property-ui type="textBox" label="Output File" description="Enter the path of the file to which the command output is directed. Leave blank to discard
              the output. The output will not be captured if a output file is specified."/>
      </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/shell.jar:lib/CommonsUtil.jar:lib/log4j.jar:lib/NativeProcess.jar:lib/WinAPI.jar:lib/securedata.jar:lib/jettison-1.1.jar:lib/commons-codec.jar"/>
      <arg file="xargs.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>
</plugin>
