Skip to content

Commit

Permalink
Added Ant build script and config for Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
afawcettffdc committed Dec 9, 2016
1 parent 2896df1 commit 84e0885
Show file tree
Hide file tree
Showing 13 changed files with 1,193 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: java
jdk:
- oraclejdk8
sudo: false
branches:
only:
- master
env:
global:
- secure: "EL+cB87KI7FTCTt8nLDYu1Quvl8qsQRjBl3OsD+/DTb846OGXreuwv77nd/pd3inabIIcZIe5HQpae67Nfyxgdl2/+qVOCCZf980I+pG4W7qpYc9epyGZI/BgPzLFPknm0cKweu0mB0/t6ubTb0knFGJE+D9ny4926x3d5H94/4="
- secure: "BA8Q3I1HiI0Tr0wEqWBpi5kXeOxE2OtDtNZUiIG3inJTedFAKTQ3d/g9au2mSqKiMIkPScQkO+mA4Fd16hFFtzFnec2AfoIhbTRwLgfC+/OjrNJK8AXw6XLorJiSV8yNI8qZYEHRyJtQ/W+09+UO7vtftUBPnNvf7fUmIqvwAzk="
script:
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && ant -lib lib/ant-salesforce.jar -Dsf.username=${SFUSER} -Dsf.password=${SFPWD} deploy || [ "${TRAVIS_PULL_REQUEST}" != "false" ]'
- '[ "${TRAVIS_PULL_REQUEST}" != "false" ] && ant -lib lib/ant-salesforce.jar -Dsf.username=${SFUSER} -Dsf.password=${SFPWD} deploy || [ "${TRAVIS_PULL_REQUEST}" = "false" ]'
68 changes: 64 additions & 4 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Apex Commons Sample Application" default="generate.mocks" basedir=".">
<project xmlns:sf="antlib:com.salesforce" basedir="." xmlns:git="antlib:com.rimerosolutions.ant.git" default="deploy">

<property name="sf.server" value="https://login.salesforce.com"/>
<import file="${basedir}/lib/exec_anon.xml"/>
<import file="${basedir}/lib/undeploy.xml"/>

<!-- Downloaded from Salesforce Tools page under Setup -->
<typedef
uri="antlib:com.salesforce"
resource="com/salesforce/antlib.xml"
classpath="${basedir}/lib/ant-salesforce.jar"/>

<!-- See https://github.com/rimerosolutions/ant-git-tasks -->
<taskdef uri="antlib:com.rimerosolutions.ant.git"
resource="com/rimerosolutions/ant/git/jgit-ant-lib.xml">
<classpath>
<pathelement location="${basedir}/lib/org.eclipse.jgit.ant-3.0.0.201306101825-r.jar"/>
<pathelement location="${basedir}/lib/org.eclipse.jgit-3.0.0.201306101825-r.jar"/>
<pathelement location="${basedir}/lib/jsch-0.1.50.jar"/>
<pathelement location="${basedir}/lib/ant-git-tasks-0.0.1.jar"/>
</classpath>
</taskdef>

<!-- Deploy -->
<target name="deploy" depends="undeploy">

<!-- Download and deploy ApexMocks -->
<delete dir="${basedir}/lib/apexmocks"/>
<echo message="Cloning fflib-apex-mocks..."/>
<git:git directory="${basedir}/lib/apexmocks" verbose="false">
<git:clone uri="https://github.com/financialforcedev/fflib-apex-mocks.git"/>
</git:git>
<sf:deploy
username="${sf.username}"
password="${sf.password}"
serverurl="${sf.server}"
testLevel="RunLocalTests"
deployRoot="${basedir}/lib/apexmocks/src"/>

<!-- Download and deploy ApexCommons -->
<delete dir="${basedir}/lib/apexcommon"/>
<echo message="Cloning fflib-apex-common..."/>
<git:git directory="${basedir}/lib/apexcommon" verbose="false">
<git:clone uri="https://github.com/financialforcedev/fflib-apex-common.git"/>
</git:git>
<sf:deploy
username="${sf.username}"
password="${sf.password}"
serverurl="${sf.server}"
testLevel="RunLocalTests"
deployRoot="${basedir}/lib/apexcommon/fflib/src"/>

<!-- Deploy Apex Commons Sample -->
<sf:deploy
username="${sf.username}"
password="${sf.password}"
serverurl="${sf.server}"
testLevel="RunLocalTests"
deployRoot="${basedir}/fflib-sample-code/src"/>

</target>

<!-- Generate Mocks -->
<target name="generate.mocks">
<java classname="com.financialforce.apexmocks.ApexMockGenerator">
<classpath>
Expand All @@ -12,5 +72,5 @@
<arg value="${basedir}/fflib-sample-code/src/classes"/>
</java>
</target>

</project>
</project>
Binary file added lib/ant-contrib-1.0b3.jar
Binary file not shown.
Binary file added lib/ant-git-tasks-0.0.1.jar
Binary file not shown.
Binary file added lib/ant-salesforce.jar
Binary file not shown.
50 changes: 50 additions & 0 deletions lib/ant-salesforce.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<project xmlns:sf="antlib:com.salesforce">

<!-- Downloaded from http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ -->
<taskdef
resource="net/sf/antcontrib/antlib.xml"
classpath="${basedir}/lib/ant-contrib-1.0b3.jar"/>

<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="Salesforce 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>28.0</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}"/>
<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>28.0</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>28.0</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}"/>
<delete dir="${basedir}/installdeploy"/>
</sequential>
</macrodef>

</project>
158 changes: 158 additions & 0 deletions lib/exec_anon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?xml version="1.0"?>
<!--
* Copyright (c) 2012, FinancialForce.com, inc
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the FinancialForce.com, inc nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<project name="ExecAnon">

<!-- Download from http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ -->
<taskdef
resource="net/sf/antcontrib/antlib.xml"
classpath="${basedir}/lib/ant-contrib-1.0b3.jar"/>

<!-- Download from https://code.google.com/p/missing-link/ -->
<taskdef
name="http"
classname="org.missinglink.ant.task.http.HttpClientTask"
classpath="${basedir}/lib/ml-ant-http-1.1.3.jar"/>

<!-- Download from http://www.oopsconsultancy.com/software/xmltask/ -->
<taskdef
name="xmltask"
classname="com.oopsconsultancy.xmltask.ant.XmlTask"
classpath="${basedir}/lib/xmltask.jar"/>

<target name="ExecAnon">
<executeApex username="${sf.username}" password="${sf.password}">${what}</executeApex>
</target>

<!-- Provides access to the Salesforce Tooling REST API ExecuteAnnoynmous resource -->
<macrodef name="executeApex" description="Provides access to the Salesforce Tooling REST API ExecuteAnnoynmous resource">
<attribute name="username" description="Salesforce user name."/>
<attribute name="password" description="Salesforce password."/>
<attribute name="resultprefix" description="Property name prefix used for properties containing response data" default="executeAnonymousResponse"/>
<attribute name="failonerror" description="If the execute fails then fail the Ant script" default="true"/>
<text name="apexcode"/>
<sequential>
<!-- Login -->
<login username="@{username}" password="@{password}" serverurl="serverUrl" sessionId="sessionId"/>
<!-- Extract host/instance name from the serverUrl returned from the login response -->
<propertyregex property="host"
input="${serverUrl}"
regexp="^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$"
select="\3"
casesensitive="false" />
<!-- Execute Apex via Tooling API /executeAnonymous resource -->
<http url="https://${host}/services/data/v30.0/tooling/executeAnonymous" method="GET" entityProperty="executeAnonymousResponse" statusProperty="loginResponseStatus" printrequestheaders="false" printresponseheaders="false">
<headers>
<header name="Authorization" value="Bearer ${sessionId}"/>
</headers>
<query>
<parameter name="anonymousBody" value="@{apexcode}"/>
</query>
</http>
<!-- Parse JSON response and set properites -->
<script language="javascript">
var response = eval('('+project.getProperty('executeAnonymousResponse')+')');
for(field in response)
project.setProperty('@{resultprefix}.' + field, response[field]);
</script>
<!-- Fail on error?-->
<if>
<and>
<equals arg1="@{failonerror}" arg2="true"/>
<equals arg1="${@{resultprefix}.success}" arg2="false"/>
</and>
<then>
<if>
<equals arg1="${@{resultprefix}.compiled}" arg2="false"/>
<then>
<fail message="${@{resultprefix}.line}:${@{resultprefix}.column} ${@{resultprefix}.compileProblem}"/>
</then>
<else>
<fail message="${@{resultprefix}.exceptionMessage} ${@{resultprefix}.exceptionStackTrace}"/>
</else>
</if>
</then>
</if>
</sequential>
</macrodef>

<!-- Login into Salesforce and return the session Id and serverUrl -->
<macrodef name="login">
<attribute name="username" description="Salesforce user name."/>
<attribute name="password" description="Salesforce password."/>
<attribute name="serverurl" description="Server Url property."/>
<attribute name="sessionId" description="Session Id property."/>
<sequential>
<!-- Obtain Session Id via Login SOAP service -->
<http url="https://login.salesforce.com/services/Soap/c/30.0" method="POST" failonunexpected="false" entityProperty="loginResponse" statusProperty="loginResponseStatus">
<headers>
<header name="Content-Type" value="text/xml"/>
<header name="SOAPAction" value="login"/>
</headers>
<entity>
<![CDATA[
<env:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Body>
<sf:login xmlns:sf='urn:enterprise.soap.sforce.com'>
<sf:username>@{username}</sf:username>
<sf:password>@{password}</sf:password>
</sf:login>
</env:Body>
</env:Envelope>
]]>
</entity>
</http>
<!-- Parse response -->
<xmltask destbuffer="loginResponseBuffer">
<insert path="/">${loginResponse}</insert>
</xmltask>
<if>
<!-- Success? -->
<equals arg1="${loginResponseStatus}" arg2="200"/>
<then>
<!-- Parse sessionId and serverUrl -->
<xmltask sourcebuffer="loginResponseBuffer" failWithoutMatch="true">
<copy path="/*[local-name()='Envelope']/*[local-name()='Body']/:loginResponse/:result/:sessionId/text()" property="@{sessionId}"/>
<copy path="/*[local-name()='Envelope']/*[local-name()='Body']/:loginResponse/:result/:serverUrl/text()" property="@{serverUrl}"/>
</xmltask>
</then>
<else>
<!-- Parse login error message and fail build -->
<xmltask sourcebuffer="loginResponseBuffer" failWithoutMatch="true">
<copy path="/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Fault']/*[local-name()='faultstring']/text()" property="faultString"/>
</xmltask>
<fail message="${faultString}"/>
</else>
</if>
</sequential>
</macrodef>

<target name="ExecAnonScript">
<loadfile property="script" srcFile="${what}"/>
<executeApex username="${sf.username}" password="${sf.password}">${script}</executeApex>
</target>

</project>
Binary file added lib/jsch-0.1.50.jar
Binary file not shown.
Binary file added lib/ml-ant-http-1.1.3.jar
Binary file not shown.
Binary file added lib/org.eclipse.jgit-3.0.0.201306101825-r.jar
Binary file not shown.
Binary file added lib/org.eclipse.jgit.ant-3.0.0.201306101825-r.jar
Binary file not shown.
Loading

0 comments on commit 84e0885

Please sign in to comment.