<?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 2014, 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.ibm.urbancode.air.plugin.source.artifactory" name="Artifactory" version="24"/>
    <description>
        The Artifactory source configuration plug-in creates component versions with artifacts from Artifactory. For additional documentation, see the artifactory_plugin_v1.pdf file included in the plug-in archive file.
    </description>
    <tag>Source and Repositories/Artifactory</tag>
    <server:plugin-type>Source</server:plugin-type>
  </header>

  <step-type name="Import Version">
    <description>Creates a new component version and imports artifacts from Artifactory.</description>
    <properties>
    </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/httpclient.jar:lib/httpcore.jar:lib/HttpComponents-Util.jar:lib/commons-codec.jar:lib/CommonsUtil.jar:lib/CommonsFileUtils.jar:lib/commons-io.jar:lib/log4j.jar:lib/commons-lang.jar:classes:lib/udclient.jar:lib/uDeployRestClient.jar:lib/securedata.jar:lib/jettison-1.1.jar"/>
      <arg file="artifactory_import_version.groovy"/>
      <arg file="${PLUGIN_INPUT_PROPS}"/>
      <arg file="${PLUGIN_OUTPUT_PROPS}"/>
    </command>
  </step-type>

    <!-- ==================================== -->
    <!--   Properties                         -->
    <!-- ==================================== -->
    <server:property-group type="Component" name="ArtifactoryComponentProperties">
      <server:property name="repoUrl" required="true">
        <server:property-ui type="textBox"
                            label="Artifactory URL"
                            description="Base URL for the Artifactory server."
                            placeholder="https://artifactoryrepo.example.com" />
      </server:property>
      <server:property name="repoName" required="true">
        <server:property-ui type="textBox"
                            label="Repository"
                            description="Name of the repository to fetch versions from."
                            placeholder="MyRepository" />
      </server:property>
      <server:property name="user">
        <server:property-ui type="textBox"
                            label="User" />
      </server:property>
      <server:property name="password">
        <server:property-ui type="secureBox"
                            label="Password"/>
      </server:property>
      <server:property name="apiKey">
        <server:property-ui type="secureBox"
                           label="Api Key"
                           description="The api key to authenticate with the Artifactory server. If using api key, username and password will be ignored."/>
      </server:property>
      <server:property name="repoPath">
        <server:property-ui type="textBox"
                            label="Repo Path"
                            description="This value will override 'Group ID' and 'Artifact ID' fields. Path to the versions to be imported. For Maven repositories, format should be 'groupId/artifactId'.  For generic paths, 'path/to/versions'."
                            placeholder="path/to/versions"/>
      </server:property>
      <server:property name="groupId">
        <server:property-ui type="textBox"
                            label="Group ID"
                            description="Artifact group ID."/>
      </server:property>
      <server:property name="artifactId">
        <server:property-ui type="textBox"
                            label="Artifact ID"
                            description="Artifact ID."/>
      </server:property>
      <server:property name="includes" required="false">
        <server:property-ui type="textAreaBox"
                            label="Include Files"
                            description="Files included in the version upload. The default setting
                            of **/* uploads all files. Separate files with commas or newline characters.
                            To specify an extension (ex. zip), use *.zip"
                            placeholder="**/*" />
      </server:property>
      <server:property name="excludes">
        <server:property-ui type="textAreaBox"
                            label="Exclude Files"
                            description="Files excluded in the version upload. Separate files with
                            commas or newline characters." />
      </server:property>
      <server:property name="recursive">
        <server:property-ui type="checkBox"
                            label="Download Recursively"
                            description="Select this box to download files and folders in subfolders of versions. Requires Artifactory Pro edition or higher." />
      </server:property>
      <server:property name="checkHash">
        <server:property-ui type="checkBox" 
                            label="Verify Hash"
                            description="Select to verify hash values after the files are downloaded."/>
      </server:property>
      <server:property name="statuses">
        <server:property-ui type="textBox"
                            label="Add Property as Status"
                            description="Artifactory properties to be set as component version statuses on the imported version.
                            If the property does not exist in Artifactory, or the status does not exist in Deploy, it will be skipped.
                            Multiple properties can be set as statuses with a comma ',' delimited list."/>
      </server:property>
      <server:property name="links">
        <server:property-ui type="textBox"
                            label="Add Property as Link"
                            description="Artifactory properties to be set as component version links on the imported version.
                            If the property does not exist in Artifactory, it will be skipped.
                            Multiple properties can be set as links with a comma ',' delimited list."/>
      </server:property>
      <server:property name="unzipArchive">
        <server:property-ui type="checkBox"
                            label="Unzip Archived Files"
                            description="Select this box to unzip archived files before upload as component version files." />
      </server:property>
      <server:property name="importCount">
        <server:property-ui type="textBox"
                            label="Latest Version Count"
                            description="The number of most recent versions of the component in Artifactory to import."/>
      </server:property>
      <server:property name="versionPattern">
        <server:property-ui type="textBox"
                            label="Version Name Pattern"
                            description="If set, only the versions with names matching this regular expression will be imported.
                            For each group matching the first capturing group, the requested number of latest builds
                            are loaded into IBM UrbanCode Deploy. Use this property only when tracking older branches
                            that contain new builds.
                            Example: To return n versions of each 1.0.*, 1.1.*, 1.2.*, and so on, use the following regular expression: (1.[0-9]+).*"
                            default-value=".*"/>
      </server:property>
      <server:property name="saveFileExecuteBits">
        <server:property-ui type="checkBox"
                            label="Preserve Execute Permissions"
                            description="Select to save file execute permissions with files."/>
      </server:property>
      <server:property name="extensions">
        <server:property-ui type="textBox"
                            label="Extensions of Files to Convert"
                            description="A list, separated by commas, of extensions that specify files which must be
                            converted to a new Character set when downloaded."
                            placeholder=".txt,.log,.properties"/>
      </server:property>
      <server:property name="allowInsecure">
        <server:property-ui type="checkBox"
                            label="Allow Insecure Connection"
                            default-value="false"
                            description="Select this option to allow insecure connections to the Artifactory repository."/>
      </server:property>
      <server:property name="proxyHost">
        <server:property-ui type="textBox"
                            label="HTTP Proxy Host"
                            description="Provide the hostname of the HTTP proxy to use to connect to Artifactory. Eg proxy.domain.com"/>
      </server:property>
      <server:property name="proxyPort">
        <server:property-ui type="textBox"
                            label="HTTP Proxy Port"
                            description="Provide the port number of the HTTP proxy to use to connect to Artifactory."/>
      </server:property>
      <server:property name="proxyUser">
        <server:property-ui type="textBox"
                            label="HTTP Proxy User name"
                            description="Provide the user name to authenticate with HTTP proxy."/>
      </server:property>
      <server:property name="proxyPass">
        <server:property-ui type="secureBox"
                            label="HTTP Proxy Password"
                            description="Provide the password to authenticate with HTTP proxy."/>
      </server:property>
    </server:property-group>

    <server:property-group type="Import" name="ArtifactoryImportProperties">
      <server:property name="version" >
        <server:property-ui type="textBox"
                            label="Specific version"
                            description="If set, only the versions with names matching this regular expression are imported.
                            For each group matching the first capturing group, the desired number of latest builds
                            are loaded into IBM UrbanCode Deploy. If Version Name Pattern is set in the plug-in configuration, versions specified
                            by the version name pattern are filtered out before this regular expression is used as a filter.
                            Example: To return n versions of each 1.0.*, 1.1.*, 1.2.*, and so on, use the following regular expression: (1.[0-9]+).*" />
      </server:property>
    </server:property-group>
</plugin>
