amguerrero / sfdc_ant_tasks

Salesforce.com ANT Deployment Helper Tasks
14 stars 5 forks source link

Salesforce.com Helper ANT Tasks

Salesforce.com Helper ANT Tasks project is a lib where I'm compiling some ant tasks I think are useful to keep a Salesforce.com metadata git clean while keeping the deployment as hassle free as possible. These are the tasks you can find in the project:

Quick Usage Guide

Ok, enough is enough, you just want to use this ANT tasks, so let's go for the prerequisites, before doing anything be aware that these ant tasks need for Delta Deployment Task and Negative Permissions Adder Task:

Being happy with these prerequisites we need to add these tasks so we can use them in our ANT build.xml file. First we need to copy the jar file lib/SalesforceAntTasks-with-dependencies.jar somewhere so we can reference it from build.xml file like the dir libs/ for instance:

<taskdef name="deltaDeployment"
    classpath="libs/SalesforceAntTasks-with-dependencies.jar"
    classname="sfanttasks.sfdeltadeployment.SFDeltaDeploymentTask" />
<taskdef name="addNegativePermisions"
    classpath="libs/SalesforceAntTasks-with-dependencies.jar"
    classname="sfanttasks.sfpermissionadjustments.SFNegativePermissionAdderTask" />
<taskdef name="metadataCleanup"
    classpath="libs/SalesforceAntTasks-with-dependencies.jar"
    classname="sfanttasks.sfmetadatacleanup.SFMetadataCleanupTask" />
<taskdef name="nodeSubstitution"
    classpath="libs/SalesforceAntTasks-with-dependencies.jar"
    classname="sfanttasks.sfnodesubstitution.SFNodeSubstitutionTask" />

Once we have the task defined in the build.xml, we can begin using them like this:

<target name="deploy">
    <deltaDeployment deltaFolder="delta"
        destructiveFolder="destructiveChanges"
        gitBaseDir="git_repository/sfdc_project"
        previousDeployment="v.1.0.1" />
    <addNegativePermisions srcFolder="delta"
        gitBaseDir="git_repository/sfdc_project"
        previousDeployment="v.1.0.1" />
    <metadataCleanup srcFolder="delta" />
    <nodeSubstitution srcFolder="delta">
        <always fileType="profile" value="false">
            <node>objectPermissions.allowCreate</node>
            <node>objectPermissions.allowDelete</node>
            <node name="fieldPermissions.editable" />
        </always>
    </nodeSubstitution>
    <sf:deploy deployRoot="delta/src" ... />
    <sf:deploy deployRoot="destructiveChanges" ... />
</target>

In this example, the target deploy:

Configuration files

In config/ directory you can find an example of the config files for the Salesforce.com Helper ANT Tasks. These configuration files are actually the configuration by default if the files are not provided.

Update for v.0.1

From the version tagged v.0.1 there is a change in how to configure the Metadata Cleanup, it will use matching operations instead of regular expressions, i.e.:

{
  "object": {
    "fields": [
      { "fullName": { "isManagedPackage" : "true" } }
    ],
    "validationRules": [
      { "fullName": { "startsWith" : "REMOVE_ME" } }
    ],
    "webLinks": [
      { "fullName": { "endsWith" : "Delete__c" } }
    ],
    "listViews": [
      { "fullName": { "always" : "" } }
    ]
  },
  "profile": {
    "applicationVisibilities": [
      { "application": { "matches" : ".+(XXX|999).+" } },
      {
        "default": { "equalTo" : "false" },
        "visible": { "equalTo" : "false" }
      } ],
    "objectPermissions": [
      { "object": { "doesNotContain" : "My_Object" } }
    ]
  }
}

In the example above we're configuring the metadata cleanup task to:

There are now the following matching operations:

Building the jar files

In order to build the jar files after modifying the project's classes there are a couple of options: With gradle:

# Gradle
$ gradle fatJar

It will create the following jar file:

build/libs/sfdc_ant_tasks-all.jar

With maven:

# Maven
$ mvn package

It will create the following jar files:

target/SalesforceAntTasks-1.0-SNAPSHOT-jar-with-dependencies.jar
target/SalesforceAntTasks-1.0-SNAPSHOT.jar