-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
460 lines (418 loc) · 17.5 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<project name="hybris-performance-management" default="dist" basedir=".">
<description>
A script to generate a Dynatrace fastpack for SAP Hybris environments.
It creates a fastpack with profiles and dashboards that are ready to use
</description>
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath>
<pathelement location="lib/xmltask.jar"/>
</classpath>
</taskdef>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${basedir}/lib/ant-contrib"/>
</classpath>
</taskdef>
<taskdef name="http" classname="org.missinglink.ant.task.http.HttpClientTask">
<classpath>
<pathelement location="lib/ant-http/ml-ant-http-1.1.3.jar"/>
</classpath>
</taskdef>
<scriptdef language="javascript" name="lower">
<attribute name="string" />
<attribute name="to" />
project.setProperty( attributes.get( "to" ),
attributes.get( "string" ).toLowerCase() );
</scriptdef>
<scriptdef language="javascript" name="upper">
<attribute name="string" />
<attribute name="to" />
project.setProperty( attributes.get( "to" ),
attributes.get( "string" ).toUpperCase() );
</scriptdef>
<!-- set global properties for this build -->
<loadproperties srcFile="fastpack.properties"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="fastpack-template" location="fastpack-template"/>
<property name="prod" value="Production"/>
<property name="stag" value="Staging"/>
<property name="prod.short" value="p"/>
<property name="stag.short" value="s"/>
<property name="prod-profile-postfix" value="_${prod}.profile.xml"/>
<property name="stag-profile-postfix" value="_${stag}.profile.xml"/>
<target name="init">
<tstamp>
<format property="build.time" pattern="MM/dd/yyyy hh:mm"/>
</tstamp>
<mkdir dir="${build}"/>
<copy todir="${build}">
<fileset dir="${fastpack-template}"/>
</copy>
</target>
<target name="get-uem-config" unless="config.uem">
<!-- if UEM configuration is not set in fastpack.properties ask for it -->
<input message="Enable UEM (y/n):" validargs="yes,no" addproperty="config.uem"/>
<condition property="enable.uem">
<istrue value="${config.uem}"/>
</condition>
<condition property="disable.uem">
<isfalse value="${config.uem}"/>
</condition>
</target>
<target name="config-uem" depends="get-customer-prefix, get-uem-config">
<echo>Building with UEM: ${config.uem}</echo>
<if>
<istrue value="${config.uem}"/>
<then>
<if>
<istrue value="${build.production}"/>
<then>
<xmltask source="${build}/profiles/${customer.prefix}${prod-profile-postfix}" dest="${build}/profiles/${customer.prefix}${prod-profile-postfix}">
<replace path="//application[@name='B2C']/uemappconfig/uemsensorconfig/@uemmode" withText="CAPTURE_SERVER_AND_ENDUSER_SIDE"/>
</xmltask>
</then>
</if>
<if>
<istrue value="${build.staging}"/>
<then>
<xmltask source="${build}/profiles/${customer.prefix}${stag-profile-postfix}" dest="${build}/profiles/${customer.prefix}${stag-profile-postfix}">
<replace path="//application[@name='B2C']/uemappconfig/uemsensorconfig/@uemmode" withText="CAPTURE_SERVER_AND_ENDUSER_SIDE"/>
</xmltask>
</then>
</if>
</then>
<else>
<if>
<istrue value="${build.production}"/>
<then>
<xmltask source="${build}/profiles/${customer.prefix}${prod-profile-postfix}" dest="${build}/profiles/${customer.prefix}${prod-profile-postfix}">
<replace path="//uemsensorconfig/@uemmode" withText="CAPTURE_SERVER_SIDE"/>
</xmltask>
</then>
</if>
<if>
<istrue value="${build.staging}"/>
<then>
<xmltask source="${build}/profiles/${customer.prefix}${stag-profile-postfix}" dest="${build}/profiles/${customer.prefix}${stag-profile-postfix}">
<replace path="//uemsensorconfig/@uemmode" withText="CAPTURE_SERVER_SIDE"/>
</xmltask>
</then>
</if>
</else>
</if>
</target>
<target name="get-customer-prefix" unless="customer.prefix">
<!-- if customer prefix is not set in fastpack.properties ask for it -->
<input message="Enter Customer Prefix:" addproperty="customer.prefix"/>
</target>
<target name="config-customer" depends="get-customer-prefix">
<echo>Building with Customer/Profile Prefix: ${customer.prefix}</echo>
<if>
<istrue value="${build.production}"/>
<then>
<copy file="${build}/profiles/Production.profile.xml" tofile="${build}/profiles/${customer.prefix}${prod-profile-postfix}"/>
</then>
</if>
<if>
<istrue value="${build.staging}"/>
<then>
<copy file="${build}/profiles/Production.profile.xml" tofile="${build}/profiles/${customer.prefix}${stag-profile-postfix}"/>
</then>
</if>
</target>
<target name="build" depends="init, config-customer, config-uem">
<echo>SAP Hybris Fastpack Version: ${build.version}</echo>
<lower string="${customer.prefix}" to="customer.prefix.lower" />
<if>
<istrue value="${build.production}"/>
<then>
<!-- production profile -->
<var name="mapping.env" value="${prod.short}" />
<var name="mapping.idx" value="${mapping.productionidx}" />
<var name="pattern" value="${mapping.pattern}" />
<lower string="${pattern}" to="pattern.lower" />
<echo>Mapping: ${pattern.lower}-web|app|adm|dth|srch.*</echo>
<xmltask source="${build}/profiles/${customer.prefix}${prod-profile-postfix}" dest="${build}/profiles/${customer.prefix}${prod-profile-postfix}">
<replace path="//agentmapping[@id='applicationserver']/@namepattern" withText="${pattern.lower}-app.*"/>
<replace path="//agentmapping[@id='adminserver']/@namepattern" withText="${pattern.lower}-adm.*"/>
<replace path="//agentmapping[@id='datahub']/@namepattern" withText="${pattern.lower}-dth.*"/>
<replace path="//agentmapping[@id='webserver']/@namepattern" withText="${pattern.lower}-web.*"/>
<replace path="//agentmapping[@id='searchengine']/@namepattern" withText="${pattern.lower}-srch.*"/>
</xmltask>
<!-- adding a version tag as description -->
<xmltask source="${build}/profiles/${customer.prefix}${prod-profile-postfix}" dest="${build}/profiles/${customer.prefix}${prod-profile-postfix}">
<replace path="//systemprofile/@description" withText="Version ${build.version} created ${build.time}"/>
<replace path="//dynatrace/@version" withText="${dashboard.version}"/>
<replace path="//configuration[@active='true']/@id" withText="${build.version}"/>
<replace path="//configuration[@active='true']/@description" withText="Version ${build.version} created ${build.time}"/>
</xmltask>
</then>
</if>
<if>
<istrue value="${build.staging}"/>
<then>
<!-- staging profile -->
<var name="mapping.env" value="${stag.short}" />
<var name="mapping.idx" value="${mapping.stagingidx}" />
<var name="pattern" value="${mapping.pattern}" />
<lower string="${pattern}" to="pattern.lower" />
<echo>Mapping: ${pattern.lower}-web|app|adm|dth|srch.*</echo>
<xmltask source="${build}/profiles/${customer.prefix}${stag-profile-postfix}" dest="${build}/profiles/${customer.prefix}${stag-profile-postfix}">
<replace path="//agentmapping[@id='applicationserver']/@namepattern" withText="${pattern.lower}-app.*"/>
<replace path="//agentmapping[@id='adminserver']/@namepattern" withText="${pattern.lower}-adm.*"/>
<replace path="//agentmapping[@id='datahub']/@namepattern" withText="${pattern.lower}-dth.*"/>
<replace path="//agentmapping[@id='webserver']/@namepattern" withText="${pattern.lower}-web.*"/>
<replace path="//agentmapping[@id='searchengine']/@namepattern" withText="${pattern.lower}-srch.*"/>
</xmltask>
<!-- adding a version tag as description -->
<xmltask source="${build}/profiles/${customer.prefix}${stag-profile-postfix}" dest="${build}/profiles/${customer.prefix}${stag-profile-postfix}">
<replace path="//systemprofile/@description" withText="Version ${build.version} created ${build.time}"/>
<replace path="//dynatrace/@version" withText="${dashboard.version}"/>
<replace path="//configuration[@active='true']/@id" withText="${build.version}"/>
<replace path="//configuration[@active='true']/@description" withText="Version ${build.version} created ${build.time}"/>
</xmltask>
</then>
</if>
<!-- creating dashboards -->
<if>
<istrue value="${build.production}"/>
<then>
<!-- production dashboards -->
<copy todir="${build}/dashboards">
<fileset dir="${build}/dashboards"/>
<globmapper from="[y]*.dashboard.xml" to="${customer.prefix}_${prod} - [y]*.dashboard.xml"/>
</copy>
<foreach target="set-dashboard-source" param="dashboard">
<param name="environment" value="${customer.prefix}_${prod}"/>
<fileset dir="${build}/dashboards">
<include name="${customer.prefix}_${prod} - [y]*.dashboard.xml"/>
</fileset>
</foreach>
</then>
</if>
<if>
<istrue value="${build.staging}"/>
<then>
<!-- staging dashboards -->
<copy todir="${build}/dashboards">
<fileset dir="${build}/dashboards"/>
<globmapper from="[y]*.dashboard.xml" to="${customer.prefix}_${stag} - [y]*.dashboard.xml"/>
</copy>
<foreach target="set-dashboard-source" param="dashboard">
<param name="environment" value="${customer.prefix}_${stag}"/>
<fileset dir="${build}/dashboards">
<include name="${customer.prefix}_${stag} - [y]*.dashboard.xml"/>
</fileset>
</foreach>
</then>
</if>
<!-- clean templates -->
<delete>
<fileset dir="${build}/dashboards" includes="[y]*.dashboard.xml"/>
<fileset dir="${build}/profiles" includes="Production.profile.xml"/>
</delete>
</target>
<target name="set-dashboard-source">
<echo>${dashboard}</echo>
<xmltask source="${dashboard}" dest="${dashboard}">
<replace path="//dashboardconfig/@sessionid" withText="${environment}"/>
<replace path="//dashboardconfig/@locationassource" withText="true" />
</xmltask>
<xmltask source="${dashboard}" dest="${dashboard}">
<replace path="//dashboardconfig/@authorname" withText="${dashboard.author}"/>
</xmltask>
<xmltask source="${dashboard}" dest="${dashboard}">
<replace path="//dashboardconfig/@memento.version" withText="${dashboard.version}"/>
</xmltask>
<xmltask source="${dashboard}" dest="${dashboard}">
<replace path="//dynatrace/@version" withText="${dashboard.version}"/>
</xmltask>
<!-- add a help-link to community -->
<var name="dashboard.name" unset="true"/>
<var name="dashboard.anchor" unset="true"/>
<basename file="${dashboard}" property="dashboard.name"/>
<propertyregex property="dashboard.anchor.tmp"
input="${dashboard.name}"
regexp="[^\]]*\] (.*)\.dashboard.xml"
select="\1"
casesensitive="false" />
<propertyregex property="dashboard.anchor"
input="${dashboard.anchor.tmp}"
regexp=" "
replace="_"
casesensitive="false" />
<lower string="${dashboard.anchor}" to="dashboard.anchor.lower" />
<echo>Help Link: https://community.dynatrace.com/community/display/EVAL/hybris_fastpack_dashboards#hybris_fastpack_dashboards-${dashboard.anchor.lower}</echo>
<property name="dashlet-id" value="id"/>
<var name="dashlet-id" unset="true"/>
<xmltask source="${dashboard}" dest="${dashboard}">
<!-- using the image length as identifier to find the header image dashlets -->
<replace path="//image[contains(@length,'9008')]/../@description" withText="[Help for this Dashboard|https://community.dynatrace.com/community/display/EVAL/hybris_fastpack_dashboards#hybris_fastpack_dashboards-${dashboard.anchor.lower}]"/>
<copy path="//image[contains(@length,'9008')]/../@id" property="dashlet-id"/>
</xmltask>
<!-- set sub-header dashlet style (blue bar headers) -->
<xmltask source="${dashboard}">
<call path="//image[contains(@length,'1448')]/..">
<param name="id" path="@id"/>
<actions>
<!--echo>id = @{id}</echo-->
<xmltask source="${dashboard}" dest="${dashboard}">
<!--print path="//portletfolder[@portletconfigorder='@{id}']/designconfig"/-->
<replace path="//portletfolder[@portletconfigorder='@{id}']/designconfig" withFile="subheaderdesign.xml"/>
</xmltask>
</actions>
</call>
</xmltask>
<var name="dashlet-id" unset="true"/>
<!-- set default dashlet header style -->
<xmltask source="${dashboard}">
<call path="//portletconfig[not(.//image)]">
<param name="id" path="@id"/>
<actions>
<!--echo>id = @{id}</echo-->
<xmltask source="${dashboard}" dest="${dashboard}">
<!--print path="//portletfolder[@portletconfigorder='@{id}']/designconfig"/-->
<replace path="//portletfolder[@portletconfigorder='@{id}']/designconfig" withFile="dashletdesign.xml"/>
</xmltask>
</actions>
</call>
</xmltask>
<var name="dashlet-id" unset="true"/>
<!-- set default dashlet header image -->
<xmltask source="${dashboard}">
<call path="//image">
<actions>
<!--echo>id = @{id}</echo-->
<xmltask source="${dashboard}" dest="${dashboard}">
<replace path="//image[contains(@length,'8132')]" withFile="headerimage.xml"/>
</xmltask>
</actions>
</call>
</xmltask>
<!-- set default dashlet header image -->
<xmltask source="${dashboard}">
<call path="//image">
<actions>
<!--echo>id = @{id}</echo-->
<xmltask source="${dashboard}" dest="${dashboard}">
<replace path="//image[contains(@length,'1448')]" withFile="separatorimage.xml"/>
</xmltask>
</actions>
</call>
</xmltask>
</target>
<target name="add-dashboard-config">
<var name="dashboard.name" unset="true"/>
<basename file="${dashboard}" property="dashboard.name"/>
<xmltask source="${build}/plugin.xml" dest="${build}/plugin.xml">
<insert path="/plugin/extension/metainfo">
<![CDATA[
<resource resource="dashboards/${dashboard.name}" resource_type="dashboard">
<instance instance="server"/>
</resource>
]]>
</insert>
</xmltask>
</target>
<target name="add-web-dashboard-config">
<var name="dashboard.name" unset="true"/>
<basename file="${dashboard}" property="dashboard.name"/>
<xmltask source="${build}/plugin.xml" dest="${build}/plugin.xml">
<insert path="/plugin/extension/metainfo">
<![CDATA[
<resource resource="web-dashboards/${dashboard.name}" resource_type="resource" target_dir="conf/dashboards/web">
<instance instance="server"/>
</resource>
]]>
</insert>
</xmltask>
</target>
<target name="add-profile-config">
<var name="profile.name" unset="true"/>
<basename file="${profile}" property="profile.name"/>
<xmltask source="${build}/plugin.xml" dest="${build}/plugin.xml">
<insert path="/plugin/extension/metainfo">
<![CDATA[
<resource resource="profiles/${profile.name}" resource_type="systemProfile">
<instance instance="server"/>
</resource>
]]>
</insert>
</xmltask>
</target>
<target name="build-fastpack" depends="build">
<echo>Bulding new fastpack</echo>
<echo>${build.time}</echo>
<!-- update plugin configuration -->
<foreach target="add-dashboard-config" param="dashboard">
<fileset dir="${build}/dashboards">
<include name="*.dashboard.xml"/>
</fileset>
</foreach>
<foreach target="add-web-dashboard-config" param="dashboard">
<fileset dir="${build}/web-dashboards">
<include name="*.xml"/>
<include name="*.json"/>
</fileset>
</foreach>
<foreach target="add-profile-config" param="profile">
<fileset dir="${build}/profiles">
<include name="*.profile.xml"/>
</fileset>
</foreach>
<zip destfile="${dist}/${customer.prefix}-fastpack-${build.version}.dtp">
<fileset dir="${build}">
<exclude name="**/[y]*"/>
<exclude name="**/Production*"/>
</fileset>
</zip>
<copy file="${dist}/${customer.prefix}-fastpack-${build.version}.dtp" tofile="${dist}/hybris-fastpack-latest.dtp"/>
</target>
<target name="deploy">
<exec executable="curl" dir="${dist}">
<arg value="-s"/>
<arg value="-v"/>
<arg value="-X POST"/>
<arg value="-F"/>
<arg value="file=@${customer.prefix}-fastpack-${build.version}.dtp"/>
<arg value="-k" />
<arg value="-u"/>
<arg value="${deploy.user}:${deploy.passwd}"/>
<arg value="https://${deploy.server}:8021/rest/management/installjobs"/>
</exec>
</target>
<target name="clean" description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
<target name="build.multiple">
<echo>Prefix: ${prefix}</echo>
<antcall target="build-fastpack">
<param name="customer.prefix" value="${prefix}"/>
</antcall>
<if>
<istrue value="${deploy.enable}"/>
<then>
<antcall target="deploy">
<param name="customer.prefix" value="${prefix}"/>
</antcall>
</then>
</if>
</target>
<target name="dist" depends="clean" if="profiles.list" description="create a new fastpack" >
<propertyregex property="profiles.list.trimmed"
input="${profiles.list}"
regexp=" "
replace=""
global="true"
casesensitive="false"
defaultValue="${profiles.list}" />
<echo>Build configurations for: ${profiles.list.trimmed}</echo>
<echo>Build production: ${build.production}</echo>
<echo>Build staging: ${build.staging}</echo>
<echo>Enable UEM: ${config.uem}</echo>
<foreach target="build.multiple" param="prefix" list="${profiles.list.trimmed}"/>
</target>
</project>