This repository has been archived by the owner on Aug 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
build_common.xml
512 lines (425 loc) · 19.7 KB
/
build_common.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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<!-- this is a 'superclass' ant script with all stuff in common.
It should be used via 'import' plus passing of properties
'app_properties' (reference properties file) and
'app_src' (listing of the src folders to be included) -->
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="build_common">
<mkdir dir="WebContent/WEB-INF/lib" />
<!-- requires app_name, app_properties properties and app_src path -->
<fail unless="app_properties">app_properties is not set. Did you use the right build_xyz.xml?</fail>
<available file="${app_properties}" property="isFileAvail" />
<fail unless="isFileAvail" message="app_properties file not found: ${app_properties}" />
<fail unless="app_name">app_name is not set. Did you use the right build_xyz.xml?</fail>
<echo>Running Ant for MOLGENIS App "${app_name}" using basedir ${basedir}</echo>
<!-- static properties shared between all apps-->
<property file="${app_properties}" />
<property name="molgenis.dir" value="../molgenis-legacy" />
<property name="build.molgenis.dir" value="../molgenis-legacy/bin" />
<property name="build.molgenis_apps.dir" value="build/classes" />
<property name="testng.report.dir" value="dist/test-output" />
<property name="war.dir" value="dist/war" />
<property name="war.name" value="${app_name}.war" />
<property name="webxml.dir" value="WebContent/WEB-INF/web.xml" />
<property name="lib.dir" value="WebContent/WEB-INF/lib" />
<!-- path to MOLGENIS toolkit -->
<path id="molgenis.classpath">
<pathelement location="${build.molgenis.dir}" />
<pathelement location="${build.molgenis_apps.dir}" />
<fileset dir="../molgenis-legacy/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="WebContent/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
</path>
<!-- path to app src -->
<taskdef resource="testngtasks" classpathref="molgenis.classpath" />
<taskdef name="xmltask" classpathref="molgenis.classpath" classname="com.oopsconsultancy.xmltask.ant.XmlTask" />
<!-- clean out generated and build folders -->
<target name="clean">
<!-- remove and create generated folder -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${build.molgenis.dir}" />
<fileset dir="${build.molgenis_apps.dir}" />
<fileset dir="${testng.report.dir}" />
<fileset dir="${war.dir}" />
</delete>
<mkdir dir="${build.molgenis.dir}" />
<mkdir dir="${build.molgenis_apps.dir}" />
<mkdir dir="${output_src}" />
<mkdir dir="${output_sql}" />
<mkdir dir="${testng.report.dir}" />
<mkdir dir="${war.dir}" />
</target>
<!-- generate based on properties file for this app_properties-->
<target name="generate" depends="update-eclipse">
<!-- clean generated folders -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${output_src}" excludes=".gitignore" />
<fileset dir="${output_sql}" excludes=".gitignore" />
<fileset dir="${output_ccp}" excludes=".gitignore" />
</delete>
<mkdir dir="${output_src}" />
<mkdir dir="${output_sql}" />
<!-- check if the molgenis project is where it is to be expected, in ../molgenis/ -->
<condition property="dir.exists">
<available file="${molgenis.dir}" type="dir" />
</condition>
<!-- check if molgenis is compiled into ${build.dir}, otherwise compile now -->
<javac srcdir="${molgenis.dir}/src" destdir="${build.molgenis.dir}" nowarn="on" debug="true" includeantruntime="false">
<classpath refid="molgenis.classpath" />
</javac>
<!-- copy resources to build dir -->
<copy todir="${build.molgenis.dir}">
<fileset dir="${molgenis.dir}/src" includes="**/*.xml,**/*.properties,**/*.txt,**/*.ico,**/*.js,**/*.css,**/*.jpg,**/*.png,**/*.gif,**/*.ftl" />
</copy>
<!-- call the generator -->
<java maxmemory="512m" classname="org.molgenis.Molgenis" fork="yes" failonerror="true">
<classpath refid="molgenis.classpath" />
<classpath refid="app.class.path" />
<arg value="${app_properties}" />
</java>
<!-- copy all ftl files from module folders-->
<!-- concat all elements of app_path together separated by /**/*, -->
<pathconvert property="app_path" refid="app.class.path" pathsep="/**/*," dirsep="/">
<map from="${basedir}/" to="" />
</pathconvert>
<echo message="copying ftl files from ${app_path} to ${build.dir}" />
<fail unless="app_path">app.class.path is not set</fail>
<copy todir="${build.molgenis_apps.dir}">
<!-- watch the trailing /**/*.ftl"-->
<fileset dir="." includes="${app_path}/**/*" excludes="**/*.java" />
<!-- cut the two leading directories from path -->
<mapper type="regexp" from="^[-_a-zA-Z0-9]*[/\\][-_a-zA-Z0-9]*[/\\](.*)" to="\1" />
<!--cutdirsmapper dirs="2"/-->
</copy>
<!-- copy sql and other resources from generate sql -->
<copy todir="${build.molgenis_apps.dir}" verbose="true">
<fileset dir="${output_sql}" includes="**/*.sql" erroronmissingdir="false" />
<fileset dir="${output_src}" includes="**/*.xml,**/*.properties,**/*.txt,**/*.ico" />
</copy>
<!-- copy source.R from generated to build -->
<copy todir="${build.molgenis_apps.dir}" verbose="true">
<fileset dir="${output_src}" includes="**/*.R" />
</copy>
<!-- Copy persistence.xml to rigth location if it's specified in *.properties as persistence_xml_location-->
<antcall target="copy-persistence.xml" />
</target>
<target name="check_persistence_xml_locaton">
<echo>${persistence_xml_location}</echo>
<condition property="condition">
<isset property="persistence_xml_location" />
</condition>
</target>
<target name="updatedb">
<java classname="org.molgenis.Molgenis" fork="yes" failonerror="true">
<classpath refid="molgenis.classpath" />
<classpath refid="app.class.path" />
<arg value="${app_properties}" />
<arg value="--updatedb" />
</java>
</target>
<target name="updatedbfillmeta">
<java classname="org.molgenis.Molgenis" fork="yes" failonerror="true">
<classpath refid="molgenis.classpath" />
<classpath refid="app.class.path" />
<arg value="${app_properties}" />
<arg value="--updatedbfillmeta" />
</java>
</target>
<target name="copy-persistence.xml" depends="check_persistence_xml_locaton" if="condition">
<copy file="${persistence_xml_location}" todir="${build.molgenis_apps.dir}/META-INF/" overwrite="true" />
<echo>persistence.xml copied from ${persistence_xml_location} to ${build.molgenis_apps.dir}/META-INF/</echo>
</target>
<target name="compile">
<pathconvert property="app_src" refid="app.class.path" pathsep=":">
<map from="${basedir}/" to="" />
</pathconvert>
<fail unless="app_src">app.class.path is not set. Did you use the right build_xyz.xml?</fail>
<echo message="compile :${output_src}:${app_src}" />
<!-- compile the generated results, use fork to run it with its own memory settings -->
<!-- NB: under Windows, forking works only if the javac path is in your PATH variable -->
<javac fork="true" srcdir="${output_src}:${app_src}" destdir="${build.molgenis_apps.dir}" nowarn="on" memoryinitialsize="256m" memorymaximumsize="512m" debug="true" includeantruntime="false">
<classpath refid="molgenis.classpath" />
</javac>
</target>
<target name="test" depends="cb,findbugs" />
<target name="testng">
<!-- combine classpaths -->
<path id="combined.class.path">
<path refid="molgenis.classpath" />
<path refid="app.class.path" />
<path location="${output_src}" />
</path>
<!-- run the tests -->
<testng outputDir="${testng.report.dir}" haltOnFailure="true">
<xmlfileset dir="${build.molgenis_apps.dir}" includes="**/*testng.xml" />
<classpath location="${cb.instrument.dir}" />
<classpath refid="combined.class.path"/>
<classfileset dir="${build.molgenis.dir}" includes="**/*Test*.class" />
<sysproperty key="net.sourceforge.cobertura.datafile" value="${cb.file}" />
<jvmarg value="-noverify" />
<jvmarg value="-ea" />
<jvmarg value="-Xmx2048m" />
</testng>
<!--junitreport todir="${testng.report.dir}">
<fileset dir="${testng.report.dir}">
<include name="**/*.xml" />
</fileset>
<report format="noframes" todir="${testng.report.dir}" />
</junitreport-->
</target>
<!-- add robots.txt to webcontent folder, blocking all non-malicious webcrawlers - you can add this optionally to your build script! -->
<target name="add_robotstxt">
<echo>Adding WebContent/robots.txt to block webcrawlers..</echo>
<echo file="WebContent/robots.txt" append="false">User-agent: *${line.separator}Disallow: /${line.separator}</echo>
</target>
<!-- findbugs -->
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="molgenis.classpath"/>
<property name="findbugs.home" value="${molgenis.dir}/lib/findbugs-2.0.1" />
<target name="findbugs">
<pathconvert property="app_src" refid="app.class.path" pathsep=":">
<map from="${basedir}/" to="" />
</pathconvert>
<findbugs home="${findbugs.home}"
output="xml" outputFile="${basedir}/dist/findbugs.xml"
jvmargs="-Xms1024M -Xmx1024M ">
<!--
<sourcePath path="${molgenis.dir}/src" />
-->
<sourcePath path="${app_src}" />
<class location="${build.molgenis.dir}" />
<class location="${build.molgenis_apps.dir}" />
<auxclasspath>
<path refid="molgenis.classpath" />
</auxclasspath>
</findbugs>
</target>
<target name="findbugs.html">
<pathconvert property="app_src" refid="app.class.path" pathsep=":">
<map from="${basedir}/" to="" />
</pathconvert>
<findbugs home="${findbugs.home}"
output="html" outputFile="${basedir}/dist/findbugs.html"
jvmargs="-Xms1024M -Xmx1024M ">
<!--
<sourcePath path="${molgenis.dir}/src" />
-->
<sourcePath path="${app_src}" />
<class location="${build.molgenis.dir}" />
<class location="${build.molgenis_apps.dir}" />
<auxclasspath>
<path refid="molgenis.classpath" />
</auxclasspath>
</findbugs>
</target>
<!-- cobertura -->
<property name="cb.file" location="${basedir}/dist/cobertura.ser" />
<path id="cb.classpath">
<fileset dir="${molgenis.dir}/lib/cobertura">
<include name="*.jar" />
</fileset>
</path>
<target name="cb.init">
<!-- output directory -->
<property name="cb.report.dir" value="${basedir}/dist/cobertura" />
<!-- instrumentation directory -->
<property name="cb.instrument.dir" value="${cb.report.dir}/cobertura-instrumented-classes" />
<property name="cb.src.dir" value="${molgenis.dir}/src" />
<property name="cb.classes.dir" value="${build.molgenis.dir}" />
<taskdef classpathref="cb.classpath" resource="tasks.properties" />
</target>
<target name="cb" depends="cb.gen, cb.xml, cb.html">
<delete file="${cb.file}" />
<delete dir="${cb.instrument.dir}" />
</target>
<target name="cb.instrument">
<mkdir dir="${cb.report.dir}" />
<cobertura-instrument todir="${cb.instrument.dir}/"
datafile="${cb.file}">
<fileset dir="${cb.classes.dir}">
<include name="**/*.class" />
<exclude name="**/*Test.class" />
</fileset>
</cobertura-instrument>
</target>
<target name="init.cb.path">
<property name="test.cp" value="cb.test.cp" />
<path id="cb.test.cp">
<pathelement path="${cb.instrument.dir}" />
<pathelement path="${cb.classes.dir}" />
<path refid="molgenis.classpath" />
<path refid="app.class.path" />
<path refid="cb.classpath" />
</path>
</target>
<target name="cb.run" depends="init.cb.path, testng" />
<target name="cb.gen" depends="cb.init, cb.instrument, cb.run" />
<target name="cb.html">
<cobertura-report format="html"
destdir="${cb.report.dir}"
datafile="${cb.file}">
<fileset dir="${cb.src.dir}">
<include name="**/*.java" />
</fileset>
</cobertura-report>
</target>
<target name="cb.xml">
<cobertura-report format="xml"
destdir="${cb.report.dir}"
datafile="${cb.file}">
<fileset dir="${cb.src.dir}">
<include name="**/*.java" />
</fileset>
</cobertura-report>
</target>
<!--
<target name="javadoc">
<javadoc access="public" destdir="${dir.javadoc}" author="true" version="true" noindex="false" use="true" classpathref="classpath">
<fileset dir="handwritten/java" defaultexcludes="yes">
<include name="**/*.java" />
<exclude name="org/test/**/*.java" />
</fileset>
<fileset dir="generated/java" defaultexcludes="yes">
<include name="**/*.java" />
<exclude name="org/test/**/*.java" />
</fileset>
</javadoc>
</target>
<target name="makeWar" depends="compile">
the ant war task. with all resources in place, create the war file
<war destfile="${war.dir}/${war.name}" webxml="${webxml.dir}">
<classes dir="${build.dir}">
<include name="**/*" />
</classes>
<lib dir="../molgenis/lib">
<include name="**/*.jar" />
</lib>
<lib dir="WebContent/WEB-INF/lib">
<include name="**/*.jar" />
</lib>
<metainf dir="WebContent/META-INF">
</metainf>
</war>
</target>
-->
<target name="update-eclipse">
<echo>Restoring .classpath from template file ${basedir}/.classpath.template.xml</echo>
<copy file="${basedir}/.classpath.template.xml" tofile="${basedir}/.classpath" overwrite="true" />
<echo>Customizing .classpath for ${app_name} ...</echo>
<pathconvert property="app_xml" refid="app.class.path" pathsep=""/><classpathentry kind="src" path="">
<!--<map from="${user.dir}/" to="" />-->
<map from="${basedir}/" to="" />
</pathconvert>
<!-- add generated src as well -->
<property name="app_xml2" value="<classpathentry kind="src" path="${app_xml}"/>" />
<property name="app_xml3" value="${app_xml2}<classpathentry kind="src" path="${output_sql}"/><classpathentry kind="src" path="${output_src}"/>" />
<echo message="eclipse .classpath xml: ${app_xml3}" />
<xmltask source=".classpath" dest=".classpath" outputter="simple">
<remove path="classpath/classpathentry[@kind='src' and not(@exported)]" />
<insert path="classpath" position="under" xml="${app_xml3}" />
</xmltask>
<echo>Restoring .setting/sorg.eclipse.wst.common.component from template file ${basedir}/.settings/template.org.eclipse.wst.common.component</echo>
<copy file="${basedir}/.settings/template.org.eclipse.wst.common.component" tofile="${basedir}/.settings/org.eclipse.wst.common.component" overwrite="true" />
<copy file="${basedir}/.settings/template.jsdtscope" tofile="${basedir}/.settings/jsdtscope" overwrite="yes" />
<copy file="${basedir}/.settings/template.org.eclipse.jdt.core.prefs" tofile="${basedir}/.settings/org.eclipse.jdt.core.prefs" overwrite="yes" />
<copy file="${basedir}/.settings/template.org.eclipse.wst.common.project.facet.core.xml" tofile="${basedir}/.settings/org.eclipse.wst.common.project.facet.core.xml" overwrite="yes" />
<copy file="${basedir}/.project.template" tofile="${basedir}/.project" overwrite="yes" />
<!-- <wb-resource deploy-path="/WEB-INF/classes" source-path="/generated/src"/> -->
<pathconvert property="app_xml4" refid="app.class.path" pathsep=""/><wb-resource deploy-path="/WEB-INF/classes" source-path="">
<!--<map from="${user.dir}/" to="" />-->
<map from="${basedir}/" to="" />
</pathconvert>
<!-- add generated src as well -->
<property name="app_xml5" value="<wb-resource deploy-path="/WEB-INF/classes" source-path="${app_xml4}"/>" />
<property name="app_xml6" value="<wb-resource deploy-path="/WEB-INF/classes" source-path="${output_src}"/>${app_xml5}" />
<property name="app_xml7" value="<wb-resource deploy-path="/WEB-INF/classes" source-path="${output_sql}"/>${app_xml6}" />
<echo message="eclipse .classpath xml: ${app_xml5}" />
<xmltask source=".settings/template.org.eclipse.wst.common.component" dest=".settings/org.eclipse.wst.common.component" outputter="simple">
<insert path="project-modules/wb-module" position="under" xml="${app_xml7}" />
</xmltask>
<antcall target="download-jars"/>
</target>
<target name="generate-compile" depends="generate,compile" />
<target name="clean-generate-compile" depends="clean,generate,compile" />
<target name="clean-generate-compile-run" depends="clean,generate,compile,run" />
<target name="clean-generate-compile-test" depends="clean,generate,compile,test" />
<target name="clean-generate-compile-webtest" depends="clean,generate,compile,webtest" />
<target name="testcopy">
<pathconvert property="app_path" refid="app.class.path" pathsep="/**/*," dirsep="/">
<map from="${basedir}/" to="" />
</pathconvert>
<copy todir="${build.molgenis_apps.dir}">
<!-- watch the trailing /**/*.ftl"-->
<fileset dir="." includes="${app_path}/**/*" excludes="**/*.java" />
<fileset dir="${app_path}/handwritten/java/META-INF" />
<!-- cut the two leading directories from path -->
<mapper type="regexp" from="^[-_a-zA-Z0-9]*/[-_a-zA-Z0-9]*/(.*)" to="\1" />
<!--cutdirsmapper dirs="2"/-->
</copy>
<!-- copy sql and other resources from generate sql -->
<copy todir="${build.dir}" verbose="true">
<fileset dir="${output_sql}" includes="**/*.sql" />
<fileset dir="${output_src}" includes="**/*.xml,**/*.properties,**/*.txt,**/*.ico" />
</copy>
</target>
<target name="run" description="Start the application on port 8080">
<java maxmemory="512m" classname="boot.RunStandalone" fork="yes" failonerror="true">
<classpath>
<path refid="molgenis.classpath" />
<path location="${build.molgenis.dir}" />
<path location="${build.molgenis_apps.dir}" />
</classpath>
</java>
</target>
<target name="runOn" description="Start the application on a specified port, e.g. ant -f build_myapp.xml runOn -Dport=9000">
<java maxmemory="512m" classname="boot.RunStandalone" fork="yes" failonerror="true">
<arg value="${port}" />
<classpath>
<path refid="molgenis.classpath" />
<path location="${build.molgenis.dir}" />
<path location="${build.molgenis_apps.dir}" />
</classpath>
</java>
</target>
<target name="makeWar">
<war destfile="${war.dir}/${war.name}" webxml="${webxml.dir}">
<classes dir="${build.molgenis.dir}">
<include name="**/*" />
</classes>
<classes dir="${build.molgenis_apps.dir}">
<include name="**/*" />
</classes>
<fileset dir="WebContent">
<exclude name="WebContent/META-INF/*" />
<exclude name="WebContent/WEB-INF/*" />
<include name="**/*.*" />
</fileset>
<lib dir="../molgenis/lib">
<include name="**/*.jar" />
</lib>
<lib dir="WebContent/WEB-INF/lib">
<include name="**/*.jar" />
</lib>
<metainf dir="WebContent/META-INF">
</metainf>
</war>
</target>
<target name="webtest" description="Start the Selenium test">
<testng classpathref="molgenis.classpath" haltOnFailure="true">
<classfileset dir="${build.molgenis_apps.dir}" includes="**/${selenium_test_class}.class" />
</testng>
</target>
<target name="clean-generate-compile-war" depends="clean,generate,compile,makeWar" />
<target name="clean-generate-compile-updatedbfillmeta-run" depends="clean,generate,compile,updatedbfillmeta,run" />
<target name="download-jars">
<echo message="installing ivy.." />
<mkdir dir="WebContent/WEB-INF/lib" />
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.0.0/ivy-2.0.0.jar" dest="WebContent/WEB-INF/lib/ivy.jar" usetimestamp="true" />
<path id="ivy.lib.path">
<fileset dir="${lib.dir}" includes="ivy.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
<echo message="resolving dependecies ..." />
<ivy:retrieve pattern="${lib.dir}/[artifact].[ext]" type="jar,bundle" sync="true" />
</target>
</project>