<commit_before><project xmlns:sf="antlib:com.salesforce">

  <!-- Following typedefs and macro definitions are from https://gist.github.com/afawcett/5843110 -->
  <!--   Download from Salesforce Tools page under Setup -->
  <typedef 
      uri="antlib:com.salesforce" 
      resource="com/salesforce/antlib.xml" 
      classpath="${cumulus_ci.basedir}/lib/ant-salesforce.jar"/>
      
  <!--   Download from http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ -->
  <taskdef 
      resource="net/sf/antcontrib/antlib.xml" 
      classpath="${cumulus_ci.basedir}/lib/ant-contrib-1.0b2.jar"
      />  

  <!-- load whitelists -->
  <loadproperties srcFile="${cumulus_ci.basedir}/whitelists/object_subtype.properties"/>
  <loadfile property="metadata_whitelist" srcfile="${cumulus_ci.basedir}/whitelists/metadata.txt" />

  <!-- Ant doesn't like < in replace tokens or values so set a property with < via cdata for reuse later -->
  <property name="lt"><![CDATA[<]]></property>
  <property name="downgradePackage" value="false" />

  <scriptdef name="downgradeCheck" language="javascript">
    <attribute name="installedversion" />
    <attribute name="buildversion" />
    <!-- Taken from here: http://stackoverflow.com/questions/6701948/efficient-way-to-compare-version-strings-in-java -->
    <![CDATA[var installedVersion;
var buildVersion;
var result;

function versionCompare(installedVersion, buildVersion) {
    var installedVersionString = String(installedVersion);
    var buildVersionString = String(buildVersion);
    var installedVals = installedVersionString.split('.');
    var buildVals = buildVersionString.split('.');
    var diff;
    // var signum;

    var i = 0;
    while (i < installedVals.length && i < buildVals.length && installedVals[i] == buildVals[i]) {
        i++;
    }

    if (i < installedVals.length && i < buildVals.length) {
        diff = installedVals[i] < buildVals[i] ? installedVals[i] - buildVals[i] : (installedVals[i] > buildVals[i] ? installedVals[i] - buildVals[i] : 0)
        // signum = diff ? (diff < 0 ? -1 : 1) : 0;
    } else {
        diff = installedVals.length - buildVals.length
        // signum = diff ? (diff < 0 ? -1 : 1) : 0;
    }
    return diff ? (diff < 0 ? -1 : 1) : 0;
}

result           = false;
installedVersion = attributes.get('installedversion')+'';
buildVersion     = attributes.get('buildversion')+'';

if (installedVersion == 'Not Installed') {
    installedVersion = '0.0';
}

if (buildVersion != 'Not Installed') {
    result = versionCompare(installedVersion, buildVersion) <= 0 ? false : true;
}
project.setProperty("downgradePackage", result);
]]>
  </scriptdef>


  <macrodef name="installPackage" description="Installs the given managed package">
      <attribute name="namespace" description="Namespace of managed package to install."/>
      <attribute name="version" description="Version of managed package to install."/>
      <attribute name="packagePassword" description="Password used to install the pacakge. Optional." default=""/>
      <attribute name="username" description="Salesforce user name."/>
      <attribute name="password" description="<PASSWORD>."/>
      <sequential>
          <!-- Generate optional <password> element? -->
          <if><equals arg1="@{packagePassword}" arg2=""/>
              <then><property name="passwordElement" value=""/></then>
              <else><property name="passwordElement" value="&lt;password&gt;@{packagePassword}&lt;/password&gt;"/></else>
          </if>
          <!-- Generate working folder and metadata files representing the package to install -->
          <delete dir="${basedir}/installdeploy"/>
          <mkdir dir="${basedir}/installdeploy"/>
          <mkdir dir="${basedir}/installdeploy"/>         
          <mkdir dir="${basedir}/installdeploy/installedPackages"/>
          <echo file="${basedir}/installdeploy/package.xml"><![CDATA[<Package xmlns="http://soap.sforce.com/2006/04/metadata"><types><members>@{namespace}</members><name>InstalledPackage</name></types><version>${cumulusci.package.apiVersion}</version></Package>]]></echo>
          <echo file="${basedir}/installdeploy/installedPackages/@{namespace}.installedPackage"><![CDATA[<InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata"><versionNumber>@{version}</versionNumber>${passwordElement}</InstalledPackage>]]></echo>
          <sf:deploy deployRoot="${basedir}/installdeploy" username="@{username}" password="<PASSWORD>}" maxPoll="${cumulusci.maxPoll.managed}" />
          <delete dir="${basedir}/installdeploy"/>
      </sequential>
  </macrodef>


  <macrodef name="uninstallPackage" description="Uninstalls the given managed package">
      <attribute name="namespace" description="Namespace of managed package to install."/>
      <attribute name="username" description="Salesforce user name."/>
      <attribute name="password" description="Salesforce password."/>
      <sequential>
          <!-- Generate working folder and metadata files representing the package to uninstall -->       
          <delete dir="${basedir}/installdeploy"/>
          <mkdir dir="${basedir}/installdeploy"/>
          <mkdir dir="${basedir}/installdeploy"/>         
          <mkdir dir="${basedir}/installdeploy/installedPackages"/>
          <echo file="${basedir}/installdeploy/package.xml"><![CDATA[<Package xmlns="http://soap.sforce.com/2006/04/metadata"><version>${cumulusci.package.apiVersion}</version></Package>]]></echo>
          <echo file="${basedir}/installdeploy/destructiveChanges.xml"><![CDATA[<Package xmlns="http://soap.sforce.com/2006/04/metadata"><types><members>@{namespace}</members><name>InstalledPackage</name></types><version>${cumulusci.package.apiVersion}</version></Package>]]></echo>
          <echo file="${basedir}/installdeploy/installedPackages/@{namespace}.installedPackage"><![CDATA[<InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata"><versionNumber>@{version}</versionNumber></InstalledPackage>]]></echo>
          <sf:deploy deployRoot="${basedir}/installdeploy" username="@{username}" password="<PASSWORD>}" maxPoll="${cumulusci.maxPoll.managed}" />
      </sequential>
  </macrodef>


  <macrodef name="getPackageVersion" description="Sets the InstalledPackage.NAMESPACE.versionNumber property to the version number of the package">
    <attribute name="namespace" description="Package's name to fetch version number for" />
    <attribute name="refresh" default="true" description="Should installedPackages be refreshed from the target org and deleted at the end of execution?" />
    <sequential>
      <!-- If we should refresh the installed packages, refresh them -->
      <if><istrue value="@{refresh}" />
        <then>
          <sf:bulkRetrieve
            username="${sf.username}"
            password="${<PASSWORD>}"
            metadataType="InstalledPackage"
            retrieveTarget="${basedir}/installedPackages"/>
        </then>
      </if>

      <if>
        <available file="${basedir}/installedPackages/installedPackages/@{namespace}.installedPackage" />
        <then>
          <!-- replace the string versionNumber with @{namespace}.versionNumber so the property is namespaced when loaded -->
          <replace file="${basedir}/installedPackages/installedPackages/@{namespace}.installedPackage" token="versionNumber" value="@{namespace}.versionNumber" />

          <!-- load the installedPackage file as properties -->
          <xmlproperty file="${basedir}/installedPackages/installedPackages/@{namespace}.installedPackage" />
        </then>
        <else>
          <!-- The package does not exist in the target org -->
          <property name="InstalledPackage.@{namespace}.versionNumber" value="Not Installed" />
        </else>
      </if>

      <!-- If refresh is true, delete the directory created to fetch the installedPackage metadata since it was created in the context of this macro execution-->
      <if>
        <istrue value="@{refresh}"/>
        <then>
          <delete dir="${basedir}/installedPackages"/>
        </then>
      </if>

    </sequential>
  </macrodef>

  <macrodef name="updatePackageVersion" description="Installs a specific version of a package.  If the package needs to be downgraded, first uninstalls the package.">
    <attribute name="namespace" description="Package's name to be installed" />
    <attribute name="version" description="The version to install (ex. 1.3).  Passing Not Installed will ensure the package is uninstalled" />
    <sequential>
      <downgradeCheck installedVersion="${InstalledPackage.@{namespace}.versionNumber}" buildVersion="@{version}" />
      <if>
        <!-- NOTE: This assumes getPackageVersions was already run -->
        <not><equals arg1="${InstalledPackage.@{namespace}.versionNumber}" arg2="@{version}" /></not>
        <then>
          <!-- decide if uninstall is needed -->
          <if>
            <and>
              <!-- package is installed in org -->
              <not><equals arg1="${InstalledPackage.@{namespace}.versionNumber}" arg2="Not Installed" /></not>
            
              <!-- package needs downgrade or should be Not Installed -->
              <or>
                <bool><equals arg1="${downgradePackage}" arg2="true" /></bool>
                <equals arg1="@{version}" arg2="Not Installed" />
              </or>
            </and>
            <then>
              <echo>Uninstalling @{namespace} ${InstalledPackage.@{namespace}.versionNumber} to downgrade to @{version}</echo>
              <uninstallPackage namespace="@{namespace}" username="${sf.username}" password="${<PASSWORD>}"/>
            </then>
            <else>
              <!-- just an upgrade, no need to uninstall first -->
              <echo>Upgrading @{namespace} from ${InstalledPackage.@{namespace}.versionNumber} to @{version}</echo>
            </else>
          </if>
          <if>
            <not><equals arg1="@{version}" arg2="Not Installed" /></not>
            <then>
              <installPackage namespace="@{namespace}" version="@{version}" username="${sf.username}" password="${<PASSWORD>}"/>
            </then>
          </if>
        </then>
      </if>
    </sequential>
  </macrodef>

  <macrodef name="retrieveUnpackaged" description="Retrieves all unpackaged metadata from the target org into the specified dir">
    <attribute name="dir" description="The local directory to store the metadata files" />
    <sequential>

      <!-- Create a clean output directory structure -->
      <delete dir="@{dir}" />
      <mkdir dir="@{dir}"/>
      <mkdir dir="@{dir}/unpackaged"/>
      <mkdir dir="@{dir}/standard"/>

      <!-- Retrieve standard objects (uses /build/standard_objects.xml as the manifest) -->
      <sf:retrieve 
        username="${sf.username}" 
        password="${sf.password}" 
        serverurl="${sf.serverurl}" 
        retrieveTarget="@{dir}/standard" 
        unpackaged="${cumulus_ci.basedir}/standard_objects.xml"/>

      <!-- Retrieve unpackaged metadata (uses /build/all_metadata_types.xml as the manifest) -->
      <sf:retrieve 
        username="${sf.username}" 
        password="${<PASSWORD>}" 
        serverurl="${sf.serverurl}" 
        retrieveTarget="@{dir}/unpackaged" 
        unpackaged="${cumulus_ci.basedir}/all_meta_types.xml"/>

    </sequential>
  </macrodef>

  <macrodef name="retrieveAdminProfile" description="Retrieves the Admin.profile from the target org into the specified dir">
    <attribute name="dir" description="The local directory to store the metadata files" />
    <sequential>

      <!-- Create a clean output directory structure -->
      <delete dir="@{dir}" />
      <mkdir dir="@{dir}"/>

      <!-- Retrieve unpackaged metadata (uses /build/all_metadata_types.xml as the manifest) -->
      <sf:retrieve 
        username="${sf.username}" 
        password="${<PASSWORD>}" 
        serverurl="${sf.serverurl}" 
        retrieveTarget="@{dir}" 
        unpackaged="${cumulus_ci.basedir}/admin_profile.xml"/>

    </sequential>
  </macrodef>

  <macrodef name="updateAdminProfileGrantFLS" description="Updates the Admin.profile to grant all FLS">
    <attribute name="dir" description="The local directory where the Admin.profile was retrieved to" />
    <sequential>
      <replaceregexp file="@{dir}/profiles/Admin.profile" match="${lt}editable>false${lt}" replace="${lt}editable>true${lt}" flags="g" />
      <replaceregexp file="@{dir}/profiles/Admin.profile" match="${lt}readable>false${lt}" replace="${lt}readable>true${lt}" flags="g" />
    </sequential>
  </macrodef>

  <macrodef name="deleteWhitelistedMetadata" description="Deletes any metadata files from a given directory which are listed in /build/whitelists/metadata.txt">
    <attribute name="dir" description="The directory to delete metadata from" />
    <sequential>
      <!-- Delete whitelisted files which are added to the org by Salesforce.  This includes both components which are always in an org and components which are automatically created by enabling Sites -->
      <for param="filename" list="${metadata_whitelist}" delimiter="${line.separator}" >
        <sequential>
          <echo>Deleting whitelisted metadata file @{filename}</echo>
          <delete>
            <fileset dir="@{dir}" includes="**/*/@{filename}" /><commit_msg>Added ability to configure the manifest used for retrieveAdminProfile. This allows projects to include additional metadata in the retrieve call without having to retrieve the metadata a second time<commit_after><project xmlns:sf="antlib:com.salesforce">

  <!-- Following typedefs and macro definitions are from https://gist.github.com/afawcett/5843110 -->
  <!--   Download from Salesforce Tools page under Setup -->
  <typedef 
      uri="antlib:com.salesforce" 
      resource="com/salesforce/antlib.xml" 
      classpath="${cumulus_ci.basedir}/lib/ant-salesforce.jar"/>
      
  <!--   Download from http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ -->
  <taskdef 
      resource="net/sf/antcontrib/antlib.xml" 
      classpath="${cumulus_ci.basedir}/lib/ant-contrib-1.0b2.jar"
      />  

  <!-- load whitelists -->
  <loadproperties srcFile="${cumulus_ci.basedir}/whitelists/object_subtype.properties"/>
  <loadfile property="metadata_whitelist" srcfile="${cumulus_ci.basedir}/whitelists/metadata.txt" />

  <!-- Ant doesn't like < in replace tokens or values so set a property with < via cdata for reuse later -->
  <property name="lt"><![CDATA[<]]></property>
  <property name="downgradePackage" value="false" />

  <scriptdef name="downgradeCheck" language="javascript">
    <attribute name="installedversion" />
    <attribute name="buildversion" />
    <!-- Taken from here: http://stackoverflow.com/questions/6701948/efficient-way-to-compare-version-strings-in-java -->
    <![CDATA[var installedVersion;
var buildVersion;
var result;

function versionCompare(installedVersion, buildVersion) {
    var installedVersionString = String(installedVersion);
    var buildVersionString = String(buildVersion);
    var installedVals = installedVersionString.split('.');
    var buildVals = buildVersionString.split('.');
    var diff;
    // var signum;

    var i = 0;
    while (i < installedVals.length && i < buildVals.length && installedVals[i] == buildVals[i]) {
        i++;
    }

    if (i < installedVals.length && i < buildVals.length) {
        diff = installedVals[i] < buildVals[i] ? installedVals[i] - buildVals[i] : (installedVals[i] > buildVals[i] ? installedVals[i] - buildVals[i] : 0)
        // signum = diff ? (diff < 0 ? -1 : 1) : 0;
    } else {
        diff = installedVals.length - buildVals.length
        // signum = diff ? (diff < 0 ? -1 : 1) : 0;
    }
    return diff ? (diff < 0 ? -1 : 1) : 0;
}

result           = false;
installedVersion = attributes.get('installedversion')+'';
buildVersion     = attributes.get('buildversion')+'';

if (installedVersion == 'Not Installed') {
    installedVersion = '0.0';
}

if (buildVersion != 'Not Installed') {
    result = versionCompare(installedVersion, buildVersion) <= 0 ? false : true;
}
project.setProperty("downgradePackage", result);
]]>
  </scriptdef>


  <macrodef name="installPackage" description="Installs the given managed package">
      <attribute name="namespace" description="Namespace of managed package to install."/>
      <attribute name="version" description="Version of managed package to install."/>
      <attribute name="packagePassword" description="Password used to install the pacakge. Optional." default=""/>
      <attribute name="username" description="Salesforce user name."/>
      <attribute name="password" description="<PASSWORD>."/>
      <sequential>
          <!-- Generate optional <password> element? -->
          <if><equals arg1="@{packagePassword}" arg2=""/>
              <then><property name="passwordElement" value=""/></then>
              <else><property name="passwordElement" value="&lt;password&gt;@{packagePassword}&lt;/password&gt;"/></else>
          </if>
          <!-- Generate working folder and metadata files representing the package to install -->
          <delete dir="${basedir}/installdeploy"/>
          <mkdir dir="${basedir}/installdeploy"/>
          <mkdir dir="${basedir}/installdeploy"/>         
          <mkdir dir="${basedir}/installdeploy/installedPackages"/>
          <echo file="${basedir}/installdeploy/package.xml"><![CDATA[<Package xmlns="http://soap.sforce.com/2006/04/metadata"><types><members>@{namespace}</members><name>InstalledPackage</name></types><version>${cumulusci.package.apiVersion}</version></Package>]]></echo>
          <echo file="${basedir}/installdeploy/installedPackages/@{namespace}.installedPackage"><![CDATA[<InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata"><versionNumber>@{version}</versionNumber>${passwordElement}</InstalledPackage>]]></echo>
          <sf:deploy deployRoot="${basedir}/installdeploy" username="@{username}" password="<PASSWORD>}" maxPoll="${cumulusci.maxPoll.managed}" />
          <delete dir="${basedir}/installdeploy"/>
      </sequential>
  </macrodef>


  <macrodef name="uninstallPackage" description="Uninstalls the given managed package">
      <attribute name="namespace" description="Namespace of managed package to install."/>
      <attribute name="username" description="Salesforce user name."/>
      <attribute name="password" description="<PASSWORD>."/>
      <sequential>
          <!-- Generate working folder and metadata files representing the package to uninstall -->       
          <delete dir="${basedir}/installdeploy"/>
          <mkdir dir="${basedir}/installdeploy"/>
          <mkdir dir="${basedir}/installdeploy"/>         
          <mkdir dir="${basedir}/installdeploy/installedPackages"/>
          <echo file="${basedir}/installdeploy/package.xml"><![CDATA[<Package xmlns="http://soap.sforce.com/2006/04/metadata"><version>${cumulusci.package.apiVersion}</version></Package>]]></echo>
          <echo file="${basedir}/installdeploy/destructiveChanges.xml"><![CDATA[<Package xmlns="http://soap.sforce.com/2006/04/metadata"><types><members>@{namespace}</members><name>InstalledPackage</name></types><version>${cumulusci.package.apiVersion}</version></Package>]]></echo>
          <echo file="${basedir}/installdeploy/installedPackages/@{namespace}.installedPackage"><![CDATA[<InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata"><versionNumber>@{version}</versionNumber></InstalledPackage>]]></echo>
          <sf:deploy deployRoot="${basedir}/installdeploy" username="@{username}" password="<PASSWORD>}" maxPoll="${cumulusci.maxPoll.managed}" />
      </sequential>
  </macrodef>


  <macrodef name="getPackageVersion" description="Sets the InstalledPackage.NAMESPACE.versionNumber property to the version number of the package">
    <attribute name="namespace" description="Package's name to fetch version number for" />
    <attribute name="refresh" default="true" description="Should installedPackages be refreshed from the target org and deleted at the end of execution?" />
    <sequential>
      <!-- If we should refresh the installed packages, refresh them -->
      <if><istrue value="@{refresh}" />
        <then>
          <sf:bulkRetrieve
            username="${sf.username}"
            password="${<PASSWORD>}"
            metadataType="InstalledPackage"
            retrieveTarget="${basedir}/installedPackages"/>
        </then>
      </if>

      <if>
        <available file="${basedir}/installedPackages/installedPackages/@{namespace}.installedPackage" />
        <then>
          <!-- replace the string versionNumber with @{namespace}.versionNumber so the property is namespaced when loaded -->
          <replace file="${basedir}/installedPackages/installedPackages/@{namespace}.installedPackage" token="versionNumber" value="@{namespace}.versionNumber" />

          <!-- load the installedPackage file as properties -->
          <xmlproperty file="${basedir}/installedPackages/installedPackages/@{namespace}.installedPackage" />
        </then>
        <else>
          <!-- The package does not exist in the target org -->
          <property name="InstalledPackage.@{namespace}.versionNumber" value="Not Installed" />
        </else>
      </if>

      <!-- If refresh is true, delete the directory created to fetch the installedPackage metadata since it was created in the context of this macro execution-->
      <if>
        <istrue value="@{refresh}"/>
        <then>
          <delete dir="${basedir}/installedPackages"/>
        </then>
      </if>

    </sequential>
  </macrodef>

  <macrodef name="updatePackageVersion" description="Installs a specific version of a package.  If the package needs to be downgraded, first uninstalls the package.">
    <attribute name="namespace" description="Package's name to be installed" />
    <attribute name="version" description="The version to install (ex. 1.3).  Passing Not Installed will ensure the package is uninstalled" />
    <sequential>
      <downgradeCheck installedVersion="${InstalledPackage.@{namespace}.versionNumber}" buildVersion="@{version}" />
      <if>
        <!-- NOTE: This assumes getPackageVersions was already run -->
        <not><equals arg1="${InstalledPackage.@{namespace}.versionNumber}" arg2="@{version}" /></not>
        <then>
          <!-- decide if uninstall is needed -->
          <if>
            <and>
              <!-- package is installed in org -->
              <not><equals arg1="${InstalledPackage.@{namespace}.versionNumber}" arg2="Not Installed" /></not>
            
              <!-- package needs downgrade or should be Not Installed -->
              <or>
                <bool><equals arg1="${downgradePackage}" arg2="true" /></bool>
                <equals arg1="@{version}" arg2="Not Installed" />
              </or>
            </and>
            <then>
              <echo>Uninstalling @{namespace} ${InstalledPackage.@{namespace}.versionNumber} to downgrade to @{version}</echo>
              <uninstallPackage namespace="@{namespace}" username="${sf.username}" password="${<PASSWORD>}"/>
            </then>
            <else>
              <!-- just an upgrade, no need to uninstall first -->
              <echo>Upgrading @{namespace} from ${InstalledPackage.@{namespace}.versionNumber} to @{version}</echo>
            </else>
          </if>
          <if>
            <not><equals arg1="@{version}" arg2="Not Installed" /></not>
            <then>
              <installPackage namespace="@{namespace}" version="@{version}" username="${sf.username}" password="${<PASSWORD>}"/>
            </then>
          </if>
        </then>
      </if>
    </sequential>
  </macrodef>

  <macrodef name="retrieveUnpackaged" description="Retrieves all unpackaged metadata from the target org into the specified dir">
    <attribute name="dir" description="The local directory to store the metadata files" />
    <sequential>

      <!-- Create a clean output directory structure -->
      <delete dir="@{dir}" />
      <mkdir dir="@{dir}"/>
      <mkdir dir="@{dir}/unpackaged"/>
      <mkdir dir="@{dir}/standard"/>

      <!-- Retrieve standard objects (uses /build/standard_objects.xml as the manifest) -->
      <sf:retrieve 
        username="${sf.username}" 
        password="${<PASSWORD>}" 
        serverurl="${sf.serverurl}" 
        retrieveTarget="@{dir}/standard" 
        unpackaged="${cumulus_ci.basedir}/standard_objects.xml"/>

      <!-- Retrieve unpackaged metadata (uses /build/all_metadata_types.xml as the manifest) -->
      <sf:retrieve 
        username="${sf.username}" 
        password="${<PASSWORD>}" 
        serverurl="${sf.serverurl}" 
        retrieveTarget="@{dir}/unpackaged" 
        unpackaged="${cumulus_ci.basedir}/all_meta_types.xml"/>

    </sequential>
  </macrodef>

  <macrodef name="retrieveAdminProfile" description="Retrieves the Admin.profile from the target org into the specified dir">
    <attribute name="dir" description="The local directory to store the metadata files" />
    <attribute name="manifest" description="The package.xml manifest to use when retrieving the Admin.profile.  Override this to retrieve additional metadata with the profile if needed" default="DEFAULT" />
    <sequential>

      <!-- Create a clean output directory structure -->
      <delete dir="@{dir}" />
      <mkdir dir="@{dir}"/>

      <!-- Retrieve unpackaged metadata (uses /build/all_metadata_types.xml as the manifest) -->
      <if>
        <equals arg1="@{manifest}" arg2="DEFAULT" />
        <then>
          <property name="manifest" value="${cumulus_ci.basedir}/admin_profile.xml" />
        </then>
        <else>
          <property name="manifest" value="@{manifest}" />
        </else>
      </if>
      <sf:retrieve 
        username="${sf.username}" 
        password="${<PASSWORD>}" 
        serverurl="${sf.serverurl}" 
        retrieveTarget="@{dir}" 
        unpackaged="${manifest}"/>

    </sequential>
  </macrodef>

  <macrodef name="updateAdminProfileGrantFLS" description="Updates the Admin.profile to grant all FLS">
    <attribute name="dir" description="The local directory where the Admin.profile was retrieved to" />
    <sequential>
      <replaceregexp file="@{dir}/profiles/Admin.profile" match="${lt}editable>false${lt}" replace="${lt}editable>true${lt}" flags="g" />
      <replaceregexp file="@{dir}/profiles/Admin.profile" match="${lt}readable>false${lt}" replace="${lt}readable>true${lt}" flags="g" />
    </sequential>
  </macrodef>

  <macrodef name="deleteWhitelistedMetadata" description="Deletes any metadata files from a given directory which are listed in /build/whitelists/metadata.txt">
    <attribute name="dir" description="The directory to delete metadata from" />
    <sequential>
      <!-- Delete whitelisted files which are added to the org by Salesforce.  This includes both components which are always in an org and components which are automatically created by enabling Sites -->
      <for param="filename" list="${metadata_whitelist}" delimiter="${line.separator}" >
        <sequential>
          <echo>Deleting whitelisted metadata file @{filename}</echo>
          <delete>
            <fileset dir="@{dir}" includes="**/*/@{filename}" />
{'fraction_non_alphanumeric': 0.15521600527646476, 'fraction_numerical': 0.006009307097577956, 'mean_word_length': 3.3341273622359853, 'pattern_counts': {'":': 0, '<': 515, '<?xml version=': 0, '>': 501, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 37}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4967955', 'n_tokens_mistral': 7661, 'n_tokens_neox': 7274, 'n_words': 1713}