-
Notifications
You must be signed in to change notification settings - Fork 55
/
GeneratePackage_xml.xml
255 lines (219 loc) · 11.7 KB
/
GeneratePackage_xml.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
248
249
250
251
252
253
254
255
<!--
Author : Jitendra Zaa
Date : 12/31/2014
Address : http://JitendraZaa.com
Version : 1.2 Pawel Wozniak 13Feb2017
-->
<project name="Generate Package.xml" default="testPackageXML" basedir="." xmlns:sf="antlib:com.salesforce">
<!-- Use this proxy when in Proxy required network -->
<target name="proxy">
<setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" />
</target>
<!-- Use this empty proxy setting outside Proxy Required network -->
<target name="noproxy">
</target>
<!--
Import AntContrib. It is needed to add For loop support
Download it from - http://mvnrepository.com/artifact/ant-contrib/ant-contrib/1.0b3
-->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${basedir}/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<property file="GeneratePackage_xml.properties"/>
<property environment="env"/>
<property name="tab" value=" "/>
<!-- Get folders content -->
<macrodef name="Package_fetchFolderContents">
<attribute name="folderName"/>
<attribute name="componentType"/>
<attribute name="orgName"/>
<attribute name="sfUserName"/>
<attribute name="sfPassword"/>
<attribute name="sfServerURL"/>
<sequential>
<sf:listMetadata
username="@{sfUserName}"
password="@{sfPassword}"
serverurl="@{sfServerURL}"
metadataType="@{componentType}"
folder="@{folderName}"
resultFilePath="tmp/@{orgName}-@{componentType}-@{folderName}.log"/>
<if>
<!-- Execute only if file created -->
<available file="tmp/@{orgName}-@{componentType}-@{folderName}.log"/>
<then>
<loadfile srcfile="tmp/@{orgName}-@{componentType}-@{folderName}.log" property="@{orgName}.@{componentType}.@{folderName}" >
<filterchain>
<ignoreblank/>
<trim/>
<linecontains>
<contains value="FileName:"/>
</linecontains>
<prefixlines prefix="<members>"/>
<suffixlines suffix="</members>"/>
<tokenfilter>
<replacestring from="FileName: reports/" to=""/>
<replacestring from="FileName: documents/" to=""/>
<replacestring from="FileName: email/" to=""/>
<replacestring from="FileName: dashboards/" to=""/>
<replacestring from="FileName: unfiled$public" to="unfiled$public"/>
<replacestring from=".report" to=""/>
<replacestring from=".email" to=""/>
<replacestring from=".dashboard" to=""/>
</tokenfilter>
</filterchain>
</loadfile>
<!-- Write filtered content to snippet file -->
<for param="line" list="${@{orgName}.@{componentType}.@{folderName}}" delimiter="${line.separator}">
<sequential>
<concat destfile="tmp/@{orgName}.Package.xml.Snnipet.@{componentType}" append="true" >${tab}${tab}@{line}${line.separator}</concat>
</sequential>
</for>
<!-- <echo> Extracted Report Names - ${@{orgName}.@{componentType}.@{folderName}} </echo> -->
</then>
</if>
</sequential>
</macrodef>
<!-- Get the folder name -->
<macrodef name="Package_computeFolderName">
<attribute name="sfUserName"/>
<attribute name="sfPassword"/>
<attribute name="sfServerURL"/>
<attribute name="metadataType"/>
<attribute name="tmpFolderPath"/>
<attribute name="componentType"/>
<attribute name="orgName"/>
<sequential>
<sf:listMetadata
username="@{sfUserName}"
password="@{sfPassword}"
serverurl="@{sfServerURL}"
metadataType="@{metadataType}"
resultFilePath="@{tmpFolderPath}"/>
<echo>Output file for sf:listMetadata - @{tmpFolderPath}</echo>
<loadfile srcfile="@{tmpFolderPath}" property="@{orgName}.@{metadataType}.onlyFolderName" >
<filterchain>
<trim/>
<ignoreblank/>
<linecontains negate="false">
<contains value="FileName"/>
</linecontains>
<tokenfilter>
<replacestring from="FileName: reports/" to=""/>
<replacestring from="FileName: documents/" to=""/>
<replacestring from="FileName: email/" to=""/>
<replacestring from="FileName: dashboards/" to=""/>
<replacestring from="FileName: unfiled$public" to="unfiled$public"/>
<replacestring from=" " to=""/>
</tokenfilter>
</filterchain>
</loadfile>
<for param="line" list="${@{orgName}.@{metadataType}.onlyFolderName}" delimiter="${line.separator}">
<sequential>
<echo>Folder - @{line}</echo>
<concat destfile="tmp/@{orgName}.Package.xml.Snnipet.@{componentType}" append="true">${tab}${tab}<members>@{line}</members>${line.separator}</concat>
<Package_fetchFolderContents
folderName="@{line}"
componentType="@{componentType}"
orgName="@{orgName}"
sfusername="@{sfUserName}"
sfPassword="@{sfPassword}"
sfServerURL="@{sfServerURL}" />
</sequential>
</for>
</sequential>
</macrodef>
<macrodef name="GeneratePackage_xml">
<attribute name="sfUserName"/>
<attribute name="sfPassword"/>
<attribute name="sfServerURL"/>
<!-- This attribute decides where to copy Package.xml -->
<attribute name="packageXMLPath"/>
<attribute name="orgName"/>
<sequential>
<!-- Delete All files first else it will append to existing old file -->
<delete file="tmp/@{orgName}.Package.xml.Snnipet.Dashboard"/>
<delete file="tmp/@{orgName}.Package.xml.Snnipet.Report"/>
<delete file="tmp/@{orgName}.Package.xml.Snnipet.EmailTemplate"/>
<delete file="tmp/@{orgName}.Package.xml.Snnipet.Document"/>
<!-- Create Fresh Files -->
<touch file="tmp/@{orgName}.Package.xml.Snnipet.Dashboard"/>
<touch file="tmp/@{orgName}.Package.xml.Snnipet.Report"/>
<touch file="tmp/@{orgName}.Package.xml.Snnipet.EmailTemplate"/>
<touch file="tmp/@{orgName}.Package.xml.Snnipet.Document"/>
<!-- Empty Content in each file -->
<property name="blankVal" value=""/>
<concat destfile="tmp/@{orgName}.Package.xml.Snnipet.Dashboard" append="true">${blankVal}</concat>
<concat destfile="tmp/@{orgName}.Package.xml.Snnipet.Report" append="true">${blankVal}</concat>
<concat destfile="tmp/@{orgName}.Package.xml.Snnipet.EmailTemplate" append="true">${blankVal}</concat>
<concat destfile="tmp/@{orgName}.Package.xml.Snnipet.Document" append="true">${blankVal}</concat>
<!--
Imp Step :
1. We must assign Password to property and then pass to other Macro else it will ignore
all occurrences of '$' in password
2. Property Name must be unique so safer to add Org Name also
-->
<property name="sfPassword.prop.@{orgName}" value="@{sfPassword}"/>
<Package_computeFolderName
sfUserName="@{sfUserName}"
sfPassword="$${sfPassword.prop.@{orgName}}"
sfServerURL="@{sfServerURL}"
metadataType="DashboardFolder"
componentType = "Dashboard"
tmpFolderPath = "tmp/@{orgName}.DashboardFolders.log"
orgName="@{orgName}"
/>
<Package_computeFolderName
sfUserName="@{sfUserName}"
sfPassword="$${sfPassword.prop.@{orgName}}"
sfServerURL="@{sfServerURL}"
metadataType="ReportFolder"
componentType="Report"
tmpFolderPath = "tmp/@{orgName}.ReportFolders.log"
orgName="@{orgName}"
/>
<Package_computeFolderName
sfUserName="@{sfUserName}"
sfPassword="$${sfPassword.prop.@{orgName}}"
sfServerURL="@{sfServerURL}"
metadataType="EmailFolder"
componentType="EmailTemplate"
tmpFolderPath = "tmp/@{orgName}.EmailFolders.log"
orgName="@{orgName}"
/>
<Package_computeFolderName
sfUserName="@{sfUserName}"
sfPassword="$${sfPassword.prop.@{orgName}}"
sfServerURL="@{sfServerURL}"
metadataType="DocumentFolder"
componentType = "Document"
tmpFolderPath = "tmp/@{orgName}.DocumentFolders.log"
orgName="@{orgName}"
/>
<!-- Load Generated File content which has Snippet of Package.xml in Property -->
<loadfile property="@{orgName}.DashboardFolder.log.edit" srcFile="tmp/@{orgName}.Package.xml.Snnipet.Dashboard" failonerror="false"/>
<loadfile property="@{orgName}.ReportFolder.log.edit" srcFile="tmp/@{orgName}.Package.xml.Snnipet.Report" failonerror="false"/>
<loadfile property="@{orgName}.EmailFolder.log.edit" srcFile="tmp/@{orgName}.Package.xml.Snnipet.EmailTemplate" failonerror="false"/>
<loadfile property="@{orgName}.DocumentFolder.log.edit" srcFile="tmp/@{orgName}.Package.xml.Snnipet.Document" failonerror="false"/>
<copy file="${package.xml.template}" tofile="@{packageXMLPath}" overwrite="true" failonerror="true"/>
<replace file="@{packageXMLPath}">
<replacefilter token="_replaceReportMembersTag_" value="${@{orgName}.ReportFolder.log.edit}"/>
<replacefilter token="_replaceEmailTemplateMembersTag_" value="${@{orgName}.EmailFolder.log.edit}"/>
<replacefilter token="_replaceDashboardMembersTag_" value="${@{orgName}.DashboardFolder.log.edit}"/>
<replacefilter token="_replaceDocumentMembersTag_" value="${@{orgName}.DocumentFolder.log.edit}"/>
</replace>
</sequential>
</macrodef>
<target name="testPackageXML" depends="noproxy"> <!-- Change to proxy if do not want to use proxy -->
<!-- Create tmp folder if missing -->
<mkdir dir="tmp"/>
<GeneratePackage_xml
sfUserName = "${sf.username}"
sfPassword = "$${sf.password}"
sfServerURL = "${sf.serverurl}"
packageXMLPath = "${basedir}/${sf.xmlPath}/Package.xml"
orgName="${sf.Name}" />
</target>
</project>