-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
247 lines (210 loc) · 10 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?xml version="1.0" encoding="UTF-8"?>
<project name="Dataloader" default="start_export">
<property file="config.properties" />
<property environment="env" />
<property name="dataloader.jar" location="${user.home}/jar" />
<property name="default_api_version" value="${sfdc.version}" />
<property name="dataloader_key_file" value="dataloader.key" />
<property name="soql_filter" value="LAST_YEAR" />
<tstamp>
<format property="timestamp" pattern="yyyy-MM-dd" />
</tstamp>
<!-- export -->
<macrodef name="dataloader">
<attribute name="file" />
<attribute name="object" />
<attribute name="csvFileName" default="All" />
<attribute name="soql" default="" />
<attribute name="operation" />
<attribute name="sdl" default="" />
<attribute name="csv" default="" />
<attribute name="extid" default="" />
<attribute name="apiversion" default="${default_api_version}" />
<attribute name="userName" />
<attribute name="password" />
<attribute name="endpoint" />
<attribute name="log.folder" default="log/@{operation}" />
<attribute name="log.file" default="@{log.folder}/@{object}_@{csvFileName}_${timestamp}.log" />
<sequential>
<mkdir dir="export/export_${timestamp}" />
<mkdir dir="@{log.folder}" />
<record name="@{log.file}" append="true" action="start" />
<echo message="" />
<echo message=">>>>>>>>>>>>>>>>>>>>>>Start @{operation} @{object}>>>>>>>>>>>>>>>>>>>>>>" />
<echo
message=">>>>>>>>>>>>>>>>>>>>>>Current Api Version @{apiversion}>>>>>>>>>>>>>>>>>>>>>>" />
<echo message="" />
<echo
message=">>>>>>>>>>>>>>>>>>>>>>Current Operation User: [@{userName}] >>>>>>>>>>>>>>>>>>>>>>" />
<echo message="" />
<echo message="Exporting @{object}" />
<copy
file="template-process-conf.xml"
tofile="process-conf.xml"
overwrite="true"
failonerror="true" />
<replace file="process-conf.xml">
<replacefilter token="_object_" value="@{object}" />
<replacefilter token="_soql_" value="@{soql} " />
<replacefilter token="_sdl_" value="@{sdl}" />
<replacefilter token="_csv_" value="@{csv}" />
<replacefilter token="_externalId_" value="@{extid}" />
<replacefilter token="_endpoint_" value="@{endpoint}" />
<replacefilter token="_userName_" value="@{username}" />
<replacefilter token="_password_" value="@{password}" />
<replacefilter token="_folder_" value="export_${timestamp}/@{object}_@{csvFileName}" />
<replacefilter token="_file_" value="@{file}_@{csvFileName}_${timestamp}.csv" />
</replace>
<java
classname="com.salesforce.dataloader.process.ProcessRunner"
classpath="dataloader-@{apiversion}-uber.jar"
failonerror="true">
<sysproperty key="salesforce.config.dir" value="." />
<arg line="process.name=@{object}@{operation}" />
</java>
<copy
file="export/export_${timestamp}/@{object}_@{csvFileName}/@{file}_@{csvFileName}_${timestamp}.csv"
tofile="./upsert/csv/@{file}_@{csvFileName}.csv" overwrite="true" failonerror="true" />
<echo message=">>>>>>>>>>>>>>>>>>>>>>@{operation} @{object} Done!>>>>>>>>>>>>>>>>>>>>>>" />
<echo message="log file : @{log.file}" />
<record name="@{log.file}" action="stop" />
</sequential>
</macrodef>
<!-- upsert -->
<macrodef name="upsert">
<attribute name="file" />
<attribute name="object" />
<attribute name="soql" default="" />
<attribute name="operation" />
<attribute name="sdl" default="" />
<attribute name="csv" default="" />
<attribute name="extid" default="" />
<attribute name="apiversion" default="${default_api_version}" />
<attribute name="userName" />
<attribute name="password" />
<attribute name="endpoint" />
<attribute name="log.folder" default="log/@{operation}" />
<attribute name="log.file" default="@{log.folder}/@{object}_${timestamp}.log" />
<sequential>
<mkdir dir="upsert/upsert_${timestamp}" />
<mkdir dir="@{log.folder}" />
<record name="@{log.file}" append="true" action="start" />
<echo message="" />
<echo message=">>>>>>>>>>>>>>>>>>>>>>Start @{operation} @{object}>>>>>>>>>>>>>>>>>>>>>>" />
<echo message="" />
<echo
message=">>>>>>>>>>>>>>>>>>>>>>Current Operation User: [@{userName}] >>>>>>>>>>>>>>>>>>>>>>" />
<echo message="" />
<echo message="Exporting @{object}" />
<copy
file="template-process-conf.xml"
tofile="process-conf.xml"
overwrite="true"
failonerror="true" />
<replace file="process-conf.xml">
<replacefilter token="_object_" value="@{object}" />
<replacefilter token="_soql_" value="@{soql}" />
<replacefilter token="_sdl_" value="@{sdl}" />
<replacefilter token="_csv_" value="@{csv}" />
<replacefilter token="_externalId_" value="@{extid}" />
<replacefilter token="_endpoint_" value="@{endpoint}" />
<replacefilter token="_userName_" value="@{username}" />
<replacefilter token="_password_" value="@{password}" />
<replacefilter token="_folder_" value="upsert_${timestamp}/@{object}_${timestamp}" />
<replacefilter token="_file_" value="@{file}_${timestamp}.csv" />
</replace>
<java
classname="com.salesforce.dataloader.process.ProcessRunner"
classpath="dataloader-@{apiversion}-uber.jar"
failonerror="true">
<sysproperty key="salesforce.config.dir" value="." />
<arg line="process.name=@{object}@{operation}" />
</java>
<echo message=">>>>>>>>>>>>>>>>>>>>>>@{operation} @{object} Done!>>>>>>>>>>>>>>>>>>>>>>" />
<echo message="log file : @{log.file}" />
<record name="@{log.file}" action="stop" />
</sequential>
</macrodef>
<macrodef name="set-property">
<attribute name="name" />
<attribute name="if-property-isset" />
<attribute name="value" default="${@{if-property-isset}}" />
<sequential>
<condition property="@{name}" value="@{value}">
<and>
<isset property="@{if-property-isset}" />
<not>
<equals arg1="${@{if-property-isset}}" arg2="" />
</not>
</and>
</condition>
</sequential>
</macrodef>
<target name="init">
<set-property name="api_version" if-property-isset="apiversion" />
<property name="api_version" value="${default_api_version}" />
<property name="dataloader.fullpath"
location="${dataloader.jar}/dataloader-${api_version}-uber.jar" />
<mkdir dir="${dataloader.jar}" />
<get
src="https://github.com/dyncan/dataloader-jar/raw/main/dataloader-${api_version}-uber.jar"
dest="${dataloader.fullpath}" verbose="true" usetimestamp="true" />
<copy file="${dataloader.jar}/dataloader-${api_version}-uber.jar"
tofile="dataloader-${api_version}-uber.jar" overwrite="true" failonerror="true" />
</target>
<target name="finish">
<echo
message="Copy the generated encrypted password and set sfdc.password in config.properties." />
</target>
<target name="encrypt" depends="generate_key">
<!-- ant encrypt -Dpassword=your_password -Dapiversion=50-->
<sequential>
<java fork="true" classname="com.salesforce.dataloader.security.EncryptionUtil"
classpath="${dataloader.fullpath}">
<arg line="-e ${password} ${dataloader_key_file}" />
</java>
<antcall target="finish" />
</sequential>
</target>
<target name="check_key_file_exist">
<available file="${dataloader_key_file}" property="dataloader_key_file_exist" />
</target>
<!-- Generate keyfile with optional keyfile path -->
<target name="generate_key" depends="init, check_key_file_exist"
unless="dataloader_key_file_exist">
<sequential>
<java fork="true" classname="com.salesforce.dataloader.security.EncryptionUtil"
classpath="${dataloader.fullpath}">
<arg line="-k ${dataloader_key_file}" />
</java>
</sequential>
</target>
<target name="start_export">
<!-- ant start_export -Dsobject_name=User -Dsoql="select id,name from user limit 100"
-Dapiversion=50 -->
<dataloader file="${sobject_name}"
object="${sobject_name}"
csvFileName="${csv_file_name}"
soql="${soql}"
operation="Export"
apiversion="${apiversion}"
userName="${sf.from.username}"
password="${sfdc.from.password}"
endpoint="${sf.from.endpoint}"
/>
</target>
<target name="upsert">
<!-- ant upsert -Dsobject_name=you_test_object__c -Dsdl="./upsert/upsert.sdl"
-Dcsv="./upsert/upsert.csv" -Dextid="Id or yourExtId" -Dapiversion=50 -->
<upsert file="${sobject_name}"
object="${sobject_name}"
sdl="${sdl}" csv="${csv}"
extid="${extid}"
operation="Upsert"
apiversion="${apiversion}"
userName="${sf.to.username}"
password="${sfdc.to.password}"
endpoint="${sf.to.endpoint}"
/>
</target>
</project>