Skip to content

Commit 84e0885

Browse files
committed
Added Ant build script and config for Travis
1 parent 2896df1 commit 84e0885

13 files changed

+1193
-4
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8
4+
sudo: false
5+
branches:
6+
only:
7+
- master
8+
env:
9+
global:
10+
- secure: "EL+cB87KI7FTCTt8nLDYu1Quvl8qsQRjBl3OsD+/DTb846OGXreuwv77nd/pd3inabIIcZIe5HQpae67Nfyxgdl2/+qVOCCZf980I+pG4W7qpYc9epyGZI/BgPzLFPknm0cKweu0mB0/t6ubTb0knFGJE+D9ny4926x3d5H94/4="
11+
- secure: "BA8Q3I1HiI0Tr0wEqWBpi5kXeOxE2OtDtNZUiIG3inJTedFAKTQ3d/g9au2mSqKiMIkPScQkO+mA4Fd16hFFtzFnec2AfoIhbTRwLgfC+/OjrNJK8AXw6XLorJiSV8yNI8qZYEHRyJtQ/W+09+UO7vtftUBPnNvf7fUmIqvwAzk="
12+
script:
13+
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && ant -lib lib/ant-salesforce.jar -Dsf.username=${SFUSER} -Dsf.password=${SFPWD} deploy || [ "${TRAVIS_PULL_REQUEST}" != "false" ]'
14+
- '[ "${TRAVIS_PULL_REQUEST}" != "false" ] && ant -lib lib/ant-salesforce.jar -Dsf.username=${SFUSER} -Dsf.password=${SFPWD} deploy || [ "${TRAVIS_PULL_REQUEST}" = "false" ]'

build.xml

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,66 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<project name="Apex Commons Sample Application" default="generate.mocks" basedir=".">
1+
<project xmlns:sf="antlib:com.salesforce" basedir="." xmlns:git="antlib:com.rimerosolutions.ant.git" default="deploy">
2+
3+
<property name="sf.server" value="https://login.salesforce.com"/>
4+
<import file="${basedir}/lib/exec_anon.xml"/>
5+
<import file="${basedir}/lib/undeploy.xml"/>
36

7+
<!-- Downloaded from Salesforce Tools page under Setup -->
8+
<typedef
9+
uri="antlib:com.salesforce"
10+
resource="com/salesforce/antlib.xml"
11+
classpath="${basedir}/lib/ant-salesforce.jar"/>
12+
13+
<!-- See https://github.com/rimerosolutions/ant-git-tasks -->
14+
<taskdef uri="antlib:com.rimerosolutions.ant.git"
15+
resource="com/rimerosolutions/ant/git/jgit-ant-lib.xml">
16+
<classpath>
17+
<pathelement location="${basedir}/lib/org.eclipse.jgit.ant-3.0.0.201306101825-r.jar"/>
18+
<pathelement location="${basedir}/lib/org.eclipse.jgit-3.0.0.201306101825-r.jar"/>
19+
<pathelement location="${basedir}/lib/jsch-0.1.50.jar"/>
20+
<pathelement location="${basedir}/lib/ant-git-tasks-0.0.1.jar"/>
21+
</classpath>
22+
</taskdef>
23+
24+
<!-- Deploy -->
25+
<target name="deploy" depends="undeploy">
26+
27+
<!-- Download and deploy ApexMocks -->
28+
<delete dir="${basedir}/lib/apexmocks"/>
29+
<echo message="Cloning fflib-apex-mocks..."/>
30+
<git:git directory="${basedir}/lib/apexmocks" verbose="false">
31+
<git:clone uri="https://github.com/financialforcedev/fflib-apex-mocks.git"/>
32+
</git:git>
33+
<sf:deploy
34+
username="${sf.username}"
35+
password="${sf.password}"
36+
serverurl="${sf.server}"
37+
testLevel="RunLocalTests"
38+
deployRoot="${basedir}/lib/apexmocks/src"/>
39+
40+
<!-- Download and deploy ApexCommons -->
41+
<delete dir="${basedir}/lib/apexcommon"/>
42+
<echo message="Cloning fflib-apex-common..."/>
43+
<git:git directory="${basedir}/lib/apexcommon" verbose="false">
44+
<git:clone uri="https://github.com/financialforcedev/fflib-apex-common.git"/>
45+
</git:git>
46+
<sf:deploy
47+
username="${sf.username}"
48+
password="${sf.password}"
49+
serverurl="${sf.server}"
50+
testLevel="RunLocalTests"
51+
deployRoot="${basedir}/lib/apexcommon/fflib/src"/>
52+
53+
<!-- Deploy Apex Commons Sample -->
54+
<sf:deploy
55+
username="${sf.username}"
56+
password="${sf.password}"
57+
serverurl="${sf.server}"
58+
testLevel="RunLocalTests"
59+
deployRoot="${basedir}/fflib-sample-code/src"/>
60+
61+
</target>
62+
63+
<!-- Generate Mocks -->
464
<target name="generate.mocks">
565
<java classname="com.financialforce.apexmocks.ApexMockGenerator">
666
<classpath>
@@ -12,5 +72,5 @@
1272
<arg value="${basedir}/fflib-sample-code/src/classes"/>
1373
</java>
1474
</target>
15-
16-
</project>
75+
76+
</project>

lib/ant-contrib-1.0b3.jar

219 KB
Binary file not shown.

lib/ant-git-tasks-0.0.1.jar

55.4 KB
Binary file not shown.

lib/ant-salesforce.jar

18.7 MB
Binary file not shown.

lib/ant-salesforce.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<project xmlns:sf="antlib:com.salesforce">
2+
3+
<!-- Downloaded from http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ -->
4+
<taskdef
5+
resource="net/sf/antcontrib/antlib.xml"
6+
classpath="${basedir}/lib/ant-contrib-1.0b3.jar"/>
7+
8+
<macrodef name="installPackage" description="Installs the given managed package">
9+
<attribute name="namespace" description="Namespace of managed package to install."/>
10+
<attribute name="version" description="Version of managed package to install."/>
11+
<attribute name="packagePassword" description="Password used to install the pacakge. Optional." default=""/>
12+
<attribute name="username" description="Salesforce user name."/>
13+
<attribute name="password" description="Salesforce password."/>
14+
<sequential>
15+
<!-- Generate optional <password> element? -->
16+
<if><equals arg1="@{packagePassword}" arg2=""/>
17+
<then><property name="passwordElement" value=""/></then>
18+
<else><property name="passwordElement" value="&lt;password&gt;@{packagePassword}&lt;/password&gt;"/></else>
19+
</if>
20+
<!-- Generate working folder and metadata files representing the package to install -->
21+
<delete dir="${basedir}/installdeploy"/>
22+
<mkdir dir="${basedir}/installdeploy"/>
23+
<mkdir dir="${basedir}/installdeploy"/>
24+
<mkdir dir="${basedir}/installdeploy/installedPackages"/>
25+
<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>
26+
<echo file="${basedir}/installdeploy/installedPackages/@{namespace}.installedPackage"><![CDATA[<InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata"><versionNumber>@{version}</versionNumber>${passwordElement}</InstalledPackage>]]></echo>
27+
<sf:deploy deployRoot="${basedir}/installdeploy" username="@{username}" password="@{password}"/>
28+
<delete dir="${basedir}/installdeploy"/>
29+
</sequential>
30+
</macrodef>
31+
32+
<macrodef name="uninstallPackage" description="Uninstalls the given managed package">
33+
<attribute name="namespace" description="Namespace of managed package to install."/>
34+
<attribute name="username" description="Salesforce user name."/>
35+
<attribute name="password" description="Salesforce password."/>
36+
<sequential>
37+
<!-- Generate working folder and metadata files representing the package to uninstall -->
38+
<delete dir="${basedir}/installdeploy"/>
39+
<mkdir dir="${basedir}/installdeploy"/>
40+
<mkdir dir="${basedir}/installdeploy"/>
41+
<mkdir dir="${basedir}/installdeploy/installedPackages"/>
42+
<echo file="${basedir}/installdeploy/package.xml"><![CDATA[<Package xmlns="http://soap.sforce.com/2006/04/metadata"><version>28.0</version></Package>]]></echo>
43+
<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>
44+
<echo file="${basedir}/installdeploy/installedPackages/@{namespace}.installedPackage"><![CDATA[<InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata"><versionNumber>@{version}</versionNumber></InstalledPackage>]]></echo>
45+
<sf:deploy deployRoot="${basedir}/installdeploy" username="@{username}" password="@{password}"/>
46+
<delete dir="${basedir}/installdeploy"/>
47+
</sequential>
48+
</macrodef>
49+
50+
</project>

lib/exec_anon.xml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
* Copyright (c) 2012, FinancialForce.com, inc
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without modification,
7+
* are permitted provided that the following conditions are met:
8+
*
9+
* - Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* - Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* - Neither the name of the FinancialForce.com, inc nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21+
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
-->
27+
<project name="ExecAnon">
28+
29+
<!-- Download from http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ -->
30+
<taskdef
31+
resource="net/sf/antcontrib/antlib.xml"
32+
classpath="${basedir}/lib/ant-contrib-1.0b3.jar"/>
33+
34+
<!-- Download from https://code.google.com/p/missing-link/ -->
35+
<taskdef
36+
name="http"
37+
classname="org.missinglink.ant.task.http.HttpClientTask"
38+
classpath="${basedir}/lib/ml-ant-http-1.1.3.jar"/>
39+
40+
<!-- Download from http://www.oopsconsultancy.com/software/xmltask/ -->
41+
<taskdef
42+
name="xmltask"
43+
classname="com.oopsconsultancy.xmltask.ant.XmlTask"
44+
classpath="${basedir}/lib/xmltask.jar"/>
45+
46+
<target name="ExecAnon">
47+
<executeApex username="${sf.username}" password="${sf.password}">${what}</executeApex>
48+
</target>
49+
50+
<!-- Provides access to the Salesforce Tooling REST API ExecuteAnnoynmous resource -->
51+
<macrodef name="executeApex" description="Provides access to the Salesforce Tooling REST API ExecuteAnnoynmous resource">
52+
<attribute name="username" description="Salesforce user name."/>
53+
<attribute name="password" description="Salesforce password."/>
54+
<attribute name="resultprefix" description="Property name prefix used for properties containing response data" default="executeAnonymousResponse"/>
55+
<attribute name="failonerror" description="If the execute fails then fail the Ant script" default="true"/>
56+
<text name="apexcode"/>
57+
<sequential>
58+
<!-- Login -->
59+
<login username="@{username}" password="@{password}" serverurl="serverUrl" sessionId="sessionId"/>
60+
<!-- Extract host/instance name from the serverUrl returned from the login response -->
61+
<propertyregex property="host"
62+
input="${serverUrl}"
63+
regexp="^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$"
64+
select="\3"
65+
casesensitive="false" />
66+
<!-- Execute Apex via Tooling API /executeAnonymous resource -->
67+
<http url="https://${host}/services/data/v30.0/tooling/executeAnonymous" method="GET" entityProperty="executeAnonymousResponse" statusProperty="loginResponseStatus" printrequestheaders="false" printresponseheaders="false">
68+
<headers>
69+
<header name="Authorization" value="Bearer ${sessionId}"/>
70+
</headers>
71+
<query>
72+
<parameter name="anonymousBody" value="@{apexcode}"/>
73+
</query>
74+
</http>
75+
<!-- Parse JSON response and set properites -->
76+
<script language="javascript">
77+
var response = eval('('+project.getProperty('executeAnonymousResponse')+')');
78+
for(field in response)
79+
project.setProperty('@{resultprefix}.' + field, response[field]);
80+
</script>
81+
<!-- Fail on error?-->
82+
<if>
83+
<and>
84+
<equals arg1="@{failonerror}" arg2="true"/>
85+
<equals arg1="${@{resultprefix}.success}" arg2="false"/>
86+
</and>
87+
<then>
88+
<if>
89+
<equals arg1="${@{resultprefix}.compiled}" arg2="false"/>
90+
<then>
91+
<fail message="${@{resultprefix}.line}:${@{resultprefix}.column} ${@{resultprefix}.compileProblem}"/>
92+
</then>
93+
<else>
94+
<fail message="${@{resultprefix}.exceptionMessage} ${@{resultprefix}.exceptionStackTrace}"/>
95+
</else>
96+
</if>
97+
</then>
98+
</if>
99+
</sequential>
100+
</macrodef>
101+
102+
<!-- Login into Salesforce and return the session Id and serverUrl -->
103+
<macrodef name="login">
104+
<attribute name="username" description="Salesforce user name."/>
105+
<attribute name="password" description="Salesforce password."/>
106+
<attribute name="serverurl" description="Server Url property."/>
107+
<attribute name="sessionId" description="Session Id property."/>
108+
<sequential>
109+
<!-- Obtain Session Id via Login SOAP service -->
110+
<http url="https://login.salesforce.com/services/Soap/c/30.0" method="POST" failonunexpected="false" entityProperty="loginResponse" statusProperty="loginResponseStatus">
111+
<headers>
112+
<header name="Content-Type" value="text/xml"/>
113+
<header name="SOAPAction" value="login"/>
114+
</headers>
115+
<entity>
116+
<![CDATA[
117+
<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/'>
118+
<env:Body>
119+
<sf:login xmlns:sf='urn:enterprise.soap.sforce.com'>
120+
<sf:username>@{username}</sf:username>
121+
<sf:password>@{password}</sf:password>
122+
</sf:login>
123+
</env:Body>
124+
</env:Envelope>
125+
]]>
126+
</entity>
127+
</http>
128+
<!-- Parse response -->
129+
<xmltask destbuffer="loginResponseBuffer">
130+
<insert path="/">${loginResponse}</insert>
131+
</xmltask>
132+
<if>
133+
<!-- Success? -->
134+
<equals arg1="${loginResponseStatus}" arg2="200"/>
135+
<then>
136+
<!-- Parse sessionId and serverUrl -->
137+
<xmltask sourcebuffer="loginResponseBuffer" failWithoutMatch="true">
138+
<copy path="/*[local-name()='Envelope']/*[local-name()='Body']/:loginResponse/:result/:sessionId/text()" property="@{sessionId}"/>
139+
<copy path="/*[local-name()='Envelope']/*[local-name()='Body']/:loginResponse/:result/:serverUrl/text()" property="@{serverUrl}"/>
140+
</xmltask>
141+
</then>
142+
<else>
143+
<!-- Parse login error message and fail build -->
144+
<xmltask sourcebuffer="loginResponseBuffer" failWithoutMatch="true">
145+
<copy path="/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Fault']/*[local-name()='faultstring']/text()" property="faultString"/>
146+
</xmltask>
147+
<fail message="${faultString}"/>
148+
</else>
149+
</if>
150+
</sequential>
151+
</macrodef>
152+
153+
<target name="ExecAnonScript">
154+
<loadfile property="script" srcFile="${what}"/>
155+
<executeApex username="${sf.username}" password="${sf.password}">${script}</executeApex>
156+
</target>
157+
158+
</project>

lib/jsch-0.1.50.jar

248 KB
Binary file not shown.

lib/ml-ant-http-1.1.3.jar

45.4 KB
Binary file not shown.
1.66 MB
Binary file not shown.

0 commit comments

Comments
 (0)