Project: [fleXive]
Code Location: http://svn.flexive.org/repository/flexive/trunk/trunk
Browse
/
Download File
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
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="flexive" default="all" basedir="." xmlns:artifact="urn:maven-artifact-ant" xmlns:antlr="urn:antlr-ant">

	<!-- ========================== properties ========================== -->

	<property name="product" value="flexive3"/>

	<property file="build.properties"/>
	<property file="flexive.properties"/>

    <property name="flexive.basedir" value="${basedir}"/>
    <import file="build.shared-properties.xml"/>
    <import file="build.global-properties.xml"/>

	<property name="resources.ui.jsf.dir" value="${flexive.base.ui.jsf.dir}/resources"/>
	<property name="resources.ui.shared.dir" value="${flexive.base.ui.shared.dir}/resources"/>
	<property name="build.framework.classes.dir" value="${flexive.base.build.dir}/framework/classes"/>
	<property name="build.ui.classes.dir" value="${flexive.base.build.dir}/ui/classes"/>
    <property name="build.ui.shared.classes.dir" value="${flexive.base.build.dir}/ui/sharedclasses"/>
    <property name="build.ui.components.dir" value="${flexive.base.build.dir}/ui-components"/>
    <property name="build.ui.jar.dir" value="${flexive.base.build.dir}/ui/jar"/>
	<property name="build.ui.meta.dir" value="${flexive.base.build.dir}/ui/jar/WEB-INF"/>
    <property name="build.ui.components.meta.dir" value="${flexive.base.build.dir}/ui/jar/components/WEB-INF"/>
    <property name="build.ui.jar.libs.dir" value="${flexive.base.build.dir}/ui/libs"/>
    <property name="build.ear.libs.dir" value="${flexive.base.build.dir}/lib"/>
    <property name="build.war.standalone.libs.dir" value="${flexive.base.build.dir}/ui/backend-standalone/lib"/>
    <property name="build.storages.dir" value="${flexive.base.build.dir}/storages"/>
    <property name="build.onlylocal.src.dir" value="${flexive.build.framework.dir}/onlylocal-src"/>
    <property name="build.onlylocal.classes.dir" value="${flexive.build.framework.dir}/onlylocal-classes"/>
    <property name="shared.meta.dir" value="${flexive.build.framework.jar.dir}/shared.meta"/>
    <property name="database.src.dir" value="${flexive.build.framework.sqlResources.dir}"/>
    <property name="database.classpathref" value="classpath.build.framework"/>

    <property name="web.ui.dojo.baseName" value="dojo-flexive"/>
    <property name="web.ui.yui.version" value="2.9.0"/>
    <property name="flexive.dist" value="flexive-${flexive.version}"/>

	<property name="invalid.path" value="${flexive.base.build.dir}/temp"/>

    <property name="merge.ui.jsf.dir" value="${flexive.base.ui.jsf.dir}/resources/merge"/>

	<property name="sqlparser.jar" value="flexive-sqlParser.jar"/>
	<property name="extractor.jar" value="flexive-extractor.jar"/>
    <property name="extractor-audio.jar" value="flexive-extractor-audio.jar"/>
	<property name="extractor-documents.jar" value="flexive-extractor-documents.jar"/>
    <property name="extractor-video.jar" value="flexive-extractor-video.jar"/>
    <property name="flatstorage.jar" value="flexive-flatstorage.jar"/>
    <property name="ejb-interfaces-onlylocal.jar" value="flexive-ejb-interfaces-local.jar"/>
    <property name="ejb-interfaces-all.jar" value="flexive-ejb-interfaces-all.jar"/>


    <!-- check if sqlParser has been run -->
	<available file="${flexive.lib.dir}/${sqlparser.jar}" property="missing.parsers"/>

	<!-- javac options -->
	<property name="compiler.deprecation" value="on"/>
	<property name="compiler.optimize" value="on"/>
	<property name="compiler.debug" value="on"/>
	<property name="compiler.source" value="1.6"/>
	<property name="compiler.target" value="1.6"/>
    <property name="compiler.fork" value="false"/>


	<!-- ========================== paths =============================== -->

	<!-- classpath needed to compile the core framework -->
	<path id="classpath.build.framework">
        <fileset dir="${flexive.lib.dir}/jsf" includes="jsonrpc-1.0.jar"/>
		<fileset dir="${flexive.lib.dir}" includes="*.jar" excludes="qdox.jar"/>
		<fileset dir="${flexive.lib.dir}/text_extraction" includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/xstream" includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/groovy" includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/mail" includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/antlr" includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/openejb-3.1/lib" includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/audio" includes="*.jar"/>
    </path>

    <path id="classpath.build.jsf">
        <fileset dir="${flexive.lib.dir}/jsf" includes="*.jar"/>
        <fileset refid="flexive.lib.ui.ajax4jsf"/>
    </path>

    <path id="classpath.build.jsf2">
        <fileset dir="${flexive.lib.dir}/jsf2" includes="*.jar"/>
    </path>

    <path id="classpath.build.plugin">
        <path path="${build.framework.classes.dir}"/>
        <path path="${build.ui.shared.classes.dir}"/>
        <path path="${build.ui.components.dir}/jsf-shared/classes"/>
        <path path="${build.ui.components.dir}/jsf-core/classes"/>
        <path refid="classpath.build.framework"/>
        <path refid="classpath.build.jsf"/>
        <!-- Include TestNG for test runner plugin -->
        <fileset dir="${flexive.lib.dir}/testNG" includes="*.jar"/>
    </path>

    <path id="classpath.build.plugin.jsf2">
        <path path="${build.framework.classes.dir}"/>
        <path path="${build.ui.shared.classes.dir}"/>
        <path path="${build.ui.components.dir}/jsf-shared/classes"/>
        <path path="${build.ui.components.dir}/jsf2-components/classes"/>
        <path refid="classpath.build.jsf2"/>
        <path refid="classpath.build.framework"/>
        <!-- Include TestNG for test runner plugin -->
        <fileset dir="${flexive.lib.dir}/testNG" includes="*.jar"/>
    </path>

    <fileset id="jar.ejb.classes" dir="${build.framework.classes.dir}">
		<include name="com/flexive/ejb/**"/>
		<include name="*.properties"/>
        <include name="**/*.flexive"/>
        <include name="**/*.sql"/>
    </fileset>
    <fileset id="jar.ejb.resources" dir="${flexive.resources.framework.dir}">
		<include name="embeddedJBossCacheConfig.xml"/>
        <include name="fxresources/**"/>
    </fileset>

    <fileset id="jar.core.classes" dir="${build.framework.classes.dir}">
        <include name="com/flexive/core/**"/>
    </fileset>
    <fileset id="jar.core.resources" dir="${flexive.resources.framework.dir}">
        <exclude name="**/*"/>  <!-- no inclusions right now -->
    </fileset>

    <path id="jar.ear.libs">
        <fileset dir="${flexive.lib.dir}" includes="${sqlparser.jar},${extractor.jar},${extractor-documents.jar},${extractor-audio.jar},${extractor-video.jar},${flatstorage.jar},cglib*.jar,fxStream.jar,commons-io-1.1.jar,sanselan.jar,quartz*.jar,PDFRenderer.jar,commons-*.jar,jbosscache-core.jar,jgroups.jar,jboss-common-core-42-compat.jar,urlrewrite-*.jar,guava*.jar,jsr173_1.0_api.jar,jtidy.jar,mime-util*,slf4j*,icepdf-core.jar"/>
        <fileset dir="${flexive.lib.dir}/groovy" includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/audio" includes="*.jar"/>
        <fileset dir="${build.ui.jar.dir}" includes="*.jar" excludes="flexive-plugin-jsf-testrunner.jar,flexive-plugin-jsf-*,flexive-plugin-jsf2-*,flexive-backend.jar,flexive-plugin-jsf-newsletter.jar"/>
        <fileset dir="${flexive.lib.dir}/antlr" includes="antlr-runtime-*.jar"/>

        <fileset dir="${build.ui.jar.dir}">
            <!-- only include the testrunner plugin if target test.package.ear was invoked -->
            <include name="flexive-plugin-jsf-testrunner.jar" if="package.testNG"/>
        </fileset>
        <fileset dir="${flexive.lib.dir}/xstream" includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/mail" includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/text_extraction"  includes="*.jar"/>
        <fileset dir="${flexive.lib.dir}/jsf" includes="jsonrpc-1.0.jar"/>
    </path>

	<!-- ========================== tasks / macros ====================== -->
    <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="classpath.build.framework"/>
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="classpath.build.framework"/>
    <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
               uri="urn:maven-artifact-ant"
               classpathref="classpath.build.framework" />
    <typedef resource="org/apache/tools/ant/antlr/antlib.xml"
             uri="urn:antlr-ant" classpathref="classpath.build.framework"/>

    <!-- ========================== imports ============================= -->
	<import file="build.tests.xml"/>
    <import file="build.javadoc.xml"/>
    <import file="build.macros.xml"/>
    <import file="${flexive.base.framework.dir}/storages/H2/build.xml"/>

    <!-- ========================== targets ============================= -->

    <target name="init" unless="init.done">
        <echo>Java version: ${ant.java.version}</echo>
        <groovy src="buildTasks.groovy"/>
        <groovy>
            void setParam(String name) {
                try {
                    properties['database.'+name] = properties['database.'+properties['database.vendor']+'.'+name]
                } catch(Exception e) {
                    if(!properties['database.vendor'])
                        println "Please specify a database vendor in build.properties! Missing entry: [database.vendor]!"
                    else
                        println "Failed to set parameter [database.$name]: Missing entry [database.${properties['database.vendor']}.$name] in build.properties?"
                    ant.fail("Could not configure database settings!")
                }
            }
            //setup database properties based on the selected database vendor
            setParam('host')
            setParam('port')
            setParam('username')
            setParam('password')
            setParam('database.division')
            setParam('database.config')
            setParam('database.test')
            setParam('schema.division')
            setParam('schema.config')
            setParam('schema.test')
            setParam('url.base')
            setParam('url.parameters')
        </groovy>
        <!-- Ensure init is called only once because the groovy task cannot be redefined -->
        <property name="init.done" value="true"/>
    </target>

    <target name="clean" description="Clean everything but parsers">
		<delete dir="${flexive.base.build.dir}"/>
		<delete dir="${base.reports.dir}"/>
		<delete dir="${flexive.dist.dir}"/>
	</target>

	<target name="clean.all" depends="clean.parsers" description="Clean everything">
		<delete dir="${flexive.base.build.dir}"/>
		<delete dir="${base.reports.dir}"/>
	</target>

    <target name="jsf.no.shared" description="Disables the sharing of JSF libraries in the EAR lib folder (useful for mixing JSF1 and JSF2 applications).">
        <echo>Disabled sharing of JSF libs</echo>
        <property name="jsf.noshared" value="1"/>
    </target>

    <target name="preinit.filesets">
        <path id="__jsflibs">
            <fileset dir="${flexive.lib.dir}/jsf" includes="*.jar" excludes="jsf-api.jar, jsf-impl.jar,el-*.jar,*-src.jar,jstl*, portlet.jar, jsonrpc*"/>
            <fileset refid="flexive.lib.ui.ajax4jsf"/>
            <fileset dir="${build.ui.jar.dir}" includes="flexive-plugin-jsf-*,flexive-backend.jar" excludes="flexive-plugin-jsf2-core.jar,flexive-plugin-jsf-shared.jar,flexive-plugin-jsf-testrunner.jar,flexive-plugin-jsf-newsletter.jar"/>
        </path>
        <path id="__jsflibs.shared">
            <fileset dir="${build.ui.jar.dir}" includes="flexive-plugin-jsf-shared.jar"/>
        </path>
    </target>

    <target name="init.filesets.jsfshared" depends="preinit.filesets" unless="jsf.noshared">
        <!-- Include JSF1 dependencies in EAR lib folder -->
        <path id="jar.ear.jsflibs">
            <path refid="__jsflibs"/>
            <path refid="__jsflibs.shared"/>
        </path>
        <!-- Don't include JSF1 dependencies in WAR lib folder -->
        <path id="jar.war.jsflibs"/>
    </target>

    <target name="init.filesets.jsfstandalone" if="jsf.noshared">
        <!-- Don't include JSF1 libraries in EAR lib folder -->
        <path id="jar.ear.jsflibs">
            <path refid="__jsflibs.shared"/>
        </path>

        <!-- Include JSF1 dependencies in WAR lib folder -->
        <path id="jar.war.jsflibs" refid="__jsflibs"/>
    </target>

    <target name="init.filesets.jsf" depends="init.filesets.jsfshared, init.filesets.jsfstandalone"/>


    <target name="redeploy.web.jboss" depends="init" description="Redeploy web files to JBoss">
        <groovy>
             File jbossDir = null
             boolean isJBoss5 = false;
             new File(properties['deploy.ear.path']+"/../tmp/deploy").eachFileMatch(~/.*flexive.ear-contents.*/) { dir ->
                if( jbossDir == null ) {
                    jbossDir = dir
                }
             }
             if( jbossDir == null ) {
                //search in JBoss 5.x deployments
                new File(properties['deploy.ear.path']+"/../tmp").eachFile() { dir ->
                    if(!dir.isDirectory())
                        return
                    File war = new File(dir.getAbsolutePath()+File.separatorChar+"flexive.war")
                    if( war.exists() ) {
                      if( jbossDir == null ) {
                        jbossDir = war
                        isJBoss5 = true
                      } else
                        if( war.lastModified() > jbossDir.lastModified() )
                            jbossDir = war
                    }
                }
             }
             if( jbossDir == null )
                ant.fail(message:"No JBoss webdeployment found!")
             println "Redeploying web files to [$jbossDir] ..."
             properties['dir.deploy.jboss'] = jbossDir
             if( isJBoss5 ) {
                ant.copy(todir:(jbossDir.absolutePath+"/adm"), verbose:true) {
                    fileset(dir:properties['basedir']+"/src/ui/jsf-backend/web/adm")
                }
                ant.copy(todir:(jbossDir.absolutePath+"/pub"), verbose:true) {
                    fileset(dir:properties['basedir']+"/src/ui/jsf-backend/web/pub")
                }
                ant.copy(todir:(jbossDir.absolutePath+"/WEB-INF"), verbose:true) {
                    fileset(dir:properties['basedir']+"/src/ui/jsf-backend/resources/WEB-INF")
                }
             } else {
                ant.copy(todir:(jbossDir.absolutePath+"/flexive-exp.war/adm"), verbose:true) {
                    fileset(dir:properties['basedir']+"/src/ui/jsf-backend/web/adm")
                }
                ant.copy(todir:(jbossDir.absolutePath+"/flexive-exp.war/pub"), verbose:true) {
                    fileset(dir:properties['basedir']+"/src/ui/jsf-backend/web/pub")
                }
                ant.copy(todir:(jbossDir.absolutePath+"/flexive-exp.war/WEB-INF"), verbose:true) {
                    fileset(dir:properties['basedir']+"/src/ui/jsf-backend/resources/WEB-INF")
                }
             }
        </groovy>
    </target>

    <target name="prepare" description="Prepare build directory structures" depends="init,init.filesets.jsf">
        <groovy>
            def file = properties.basedir+File.separatorChar+"build.properties"
            if( !new File(file).exists() ) {
                ant.fail(message:"Please create a customized ${file} file from build.properties.sample.")
            }
            rawVersion = org.apache.tools.ant.Main.class.getPackage().getImplementationVersion()
            if( rawVersion != null ) {
                antVersion = rawVersion.split("\\.")
                int major = Integer.valueOf(antVersion[0])
                int minor = Integer.valueOf(antVersion[1])
                if( major == 1 &amp;&amp; minor >= 7 ) {
                   //version 1.7+ is ok
                } else if( major > 1 ) {
                    //v2+ should be ok as well
                } else {
                    ant.fail(message:"Ant version 1.7 or higher is required! You are using version ${org.apache.tools.ant.Main.class.getPackage().getImplementationVersion()}!")
                }
            }
        </groovy>
		<mkdir dir="${build.framework.classes.dir}"/>
		<mkdir dir="${build.ui.classes.dir}"/>
        <mkdir dir="${build.ui.shared.classes.dir}"/>
        <mkdir dir="${flexive.build.framework.jar.dir}"/>
		<mkdir dir="${build.ui.jar.dir}"/>
        <mkdir dir="${build.storages.dir}"/>
		<mkdir dir="${invalid.path}"/>
        <javac-call srcdir="${flexive.src.framework.dir}"
                    destdir="${build.framework.classes.dir}"
                    includes="com/flexive/tools/**/*.java"
                    excludes="com/flexive/tools/db/**">
            <classpath refid="classpath.build.framework"/>
        </javac-call>
        <jar jarfile="${flexive.build.framework.jar.dir}/flexive-ant.jar">
            <fileset dir="${build.framework.classes.dir}">
                <include name="com/flexive/tools/ant/**/*"/>
                <include name="com/flexive/tools/*"/>
            </fileset>
        </jar>
        <jar jarfile="${flexive.build.framework.jar.dir}/openUrl.jar">
            <fileset dir="${build.framework.classes.dir}">
                <include name="com/flexive/tools/OpenUrl*"/>
            </fileset>
            <manifest>
                <attribute name="Class-Path" value="extlib/h2.jar"/>
                <attribute name="Main-Class" value="com.flexive.tools.OpenUrl"/>
            </manifest>
        </jar>
        <taskdef name="applicationDescriptorBuilder"
                 classname="com.flexive.tools.ant.ApplicationDescriptorBuilderTask"
                 classpath="${flexive.build.framework.jar.dir}/flexive-ant.jar"/>
        <taskdef name="scriptIndexBuilder"
                 classname="com.flexive.tools.ant.ScriptIndexBuilderTask"
                 classpath="${flexive.build.framework.jar.dir}/flexive-ant.jar"/>
        <taskdef name="makeMessages"
                 classname="com.flexive.tools.ant.MakeMessagesTask"
                 classpath="${flexive.build.framework.jar.dir}/flexive-ant.jar"/>
        <taskdef name="svnVersion"
                 classname="com.flexive.tools.ant.SubversionVersionTask"
                 classpath="${flexive.build.framework.jar.dir}/flexive-ant.jar"/>
    </target>


	<target name="all" description="Clean and rebuild everything" depends="jar.all,jar.ear">
	</target>

	<!-- safety fallback that generates the parsers if they are missing -->
	<target name="check.parsers" unless="missing.parsers" description="Check if SQL and HTML parsers have been built yet">
		<echo message="Compiling and packaging SQL/HTML parser..."/>
		<antcall target="gen.parsers"/>
	</target>

	<target name="clean.parsers" depends="init">
		<delete dir="${build.framework.classes.dir}/com/flexive/sqlParser"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/sqlParser/ParseException.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/sqlParser/SimpleCharStream.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/sqlParser/SQL.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/sqlParser/SQLConstants.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/sqlParser/SQLTokenManager.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/sqlParser/Token.java"/>

		<delete file="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor/HtmlExtractorParser.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor/HtmlExtractorParserConstants.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor/HtmlExtractorParserTokenManager.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor/ParseException.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor/SimpleCharStream.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor/Token.java"/>
		<delete file="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor/TokenMgrError.java"/>

		<safeDelete file="${flexive.lib.dir}/${sqlparser.jar}"/>
		<safeDelete file="${flexive.lib.dir}/${extractor.jar}"/>
		<safeDelete file="${flexive.lib.dir}/${extractor-documents.jar}"/>
        <safeDelete file="${flexive.lib.dir}/${extractor-audio.jar}"/>
        <safeDelete file="${flexive.lib.dir}/${extractor-video.jar}"/>
	</target>

	<target name="gen.parsers" depends="clean.parsers, prepare" description="Generate SQL and HTML parsers">
		<javacc
                target="${flexive.src.framework.dir}/com/flexive/sqlParser/Parser.jj"
                javacchome="${flexive.lib.dir}"
                outputdirectory="${flexive.src.framework.dir}/com/flexive/sqlParser"
        />
		<javacc
                target="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor/htmlParser.jj"
                javacchome="${flexive.lib.dir}"
                outputdirectory="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor"
        />
		<javac-call srcdir="${flexive.src.framework.dir}" includes="com/flexive/shared/**,com/flexive/sqlParser/**,com/flexive/extractor/**" destdir="${build.framework.classes.dir}">
			<classpath refid="classpath.build.framework"/>
		</javac-call>
		<jar jarfile="${flexive.lib.dir}/${sqlparser.jar}">
			<fileset dir="${build.framework.classes.dir}">
				<include name="com/flexive/sqlParser/**"/>
			</fileset>
			<manifest>
				<attribute name="Main-Class" value="com.flexive.sqlParser.consoleTest"/>
			</manifest>
		</jar>
		<jar jarfile="${flexive.lib.dir}/${extractor.jar}">
            <fileset dir="${build.framework.classes.dir}">
				<include name="com/flexive/extractor/DocumentParser*"/>
                <include name="com/flexive/extractor/HtmlExtractor*"/>
                <include name="com/flexive/extractor/htmlExtractor/**"/>
			</fileset>
        </jar>
        <jar jarfile="${flexive.lib.dir}/${extractor-documents.jar}">
            <fileset  dir="${flexive.resources.framework.dir}/extractor-documents-resources" includes="**/*"/>
            <fileset dir="${build.framework.classes.dir}">
				<include name="com/flexive/extractor/**"/>
                <exclude name="com/flexive/extractor/HtmlExtractor*"/>
                <exclude name="com/flexive/extractor/htmlExtractor/***"/>
                <exclude name="com/flexive/extractor/audio/**"/>
			</fileset>
        </jar>
        <jar jarfile="${flexive.lib.dir}/${extractor-audio.jar}">
            <fileset  dir="${flexive.resources.framework.dir}/extractor-audio-resources" includes="**/*"/>
            <fileset dir="${build.framework.classes.dir}">
				<include name="com/flexive/extractor/audio/**"/>
            </fileset>
        </jar>
        <jar jarfile="${flexive.lib.dir}/${extractor-video.jar}">
            <fileset dir="${flexive.resources.framework.dir}/extractor-video-resources" includes="**/*"/>
            <fileset dir="${build.framework.classes.dir}">
                <include name="com/flexive/extractor/video/**"/>
            </fileset>
        </jar>
    </target>


    <target name="htmlParserStandalone" depends="clean.parsers, prepare">
		<javacc
                target="${flexive.src.framework.dir}/com/flexive/extractor/htmlExtractor/htmlParser.jj"
                javacchome="${flexive.lib.dir}"
                outputdirectory="flexive.src.framework.dirwork.dir}/com/flexive/extractor/htmlExtractor"
        />
		<javac-call
                srcdir="${flexive.src.framework.dir}"
                includes="**/htmlExtractor/**"
                destdir="${build.framework.classes.dir}">
			<classpath refid="classpath.build.framework"/>
        </javac-call>
		<jar jarfile="${flexive.lib.dir}/${extractor.jar}">
			<fileset dir="${build.framework.classes.dir}">
				<include name="com/flexive/extractor/htmlExtractor/**"/>
			</fileset>
			<manifest>
				<attribute name="Main-Class" value="com.flexive.extractor.htmlExtractor.consoleTest"/>
			</manifest>
		</jar>
	</target>

    <target name="compile.framework"
            depends="prepare, check.parsers, compile.framework.parsers, compile.framework.main"
            description="Compile the complete core framework"/>

    <target name="compile.framework.main">
        <javac-call
                srcdir="${flexive.src.framework.dir}"
                destdir="${build.framework.classes.dir}"
                excludes="**/sqlParser/**,**/extractor/**">
            <classpath refid="classpath.build.framework"/>
        </javac-call>
    </target>

    <target name="compile.framework.parsers" description="Compiles the parsers embedded in the core framework">
        <antlr:antlr3 target="${flexive.src.framework.cmisparser.dir}/CmisSql.g">
            <classpath refid="classpath.build.framework"/>
        </antlr:antlr3>
    </target>

    <target name="jar.framework" depends="jar.framework.shared, jar.ejb, jar.storages" description="Package the complete core framework"/>

	<target name="jar.framework.shared.prepare">
		<uptodate property="jar.framework.shared.skip" targetfile="${flexive.build.framework.jar.dir}/flexive-shared.jar">
			<srcfiles dir="${shared.meta.dir}" includes="**/*"/>
			<srcfiles dir="${basedir}" includes="flexive.properties"/>
			<srcfiles dir="${build.framework.classes.dir}" includes="com/flexive/shared/**"/>
		</uptodate>
	</target>

	<target name="jar.framework.shared" depends="compile.framework,jar.framework.shared.prepare" unless="jar.framework.shared.skip" description="Package the shared part of the framework">
		<tstamp>
			<format property="build.time" pattern="yyyy/MM/dd HH:mm" unit="hour"/>
		</tstamp>
        <svnVersion property="build.number"/>

        <delete dir="${shared.meta.dir}"/>
		<mkdir dir="${shared.meta.dir}"/>

		<copy file="${basedir}/flexive.properties" tofile="${shared.meta.dir}/flexive.properties" overwrite="true"/>
        <replaceBuildProperties file="${shared.meta.dir}/flexive.properties" buildNumber="${build.number}" buildTime="${build.time}"/>
        <makeMessages srcDir="${flexive.resources.framework.dir}/messages" dest="${shared.meta.dir}/FxExceptionMessages" srcPrefix="Ex"/>
        <makeMessages srcDir="${flexive.resources.framework.dir}/messages" dest="${shared.meta.dir}/FxSharedMessages" srcPrefix="FxSharedMessages"/>
        <makeMessages srcDir="${flexive.resources.framework.dir}/messages" dest="${shared.meta.dir}/Enum" srcPrefix="Enum"/>
        <makeMessages srcDir="${flexive.resources.framework.dir}/messages" dest="${shared.meta.dir}/History" srcPrefix="History"/>

		<emma enabled="${emma.enabled}">
			<instr instrpath="${build.framework.classes.dir}"
                   mode="overwrite"
                   merge="false"
                   metadatafile="${coverage.dir}/coverage.em">
				<filter value="+com.flexive.shared.*"/>
			</instr>
		</emma>
		<jar jarfile="${flexive.build.framework.jar.dir}/flexive-shared.jar" keepcompression="true">
			<fileset dir="${build.framework.classes.dir}">
				<include name="com/flexive/shared/**"/>
                <exclude name="com/flexive/shared/interfaces/**"/>
			</fileset>
			<zipfileset dir="${shared.meta.dir}" includes="FxExceptionMessages*.properties, FxSharedMessages*.properties, Enum*.properties, History*.properties, flexive.properties"/>
        </jar>
        <!-- Create default interfaces file -->
        <jar jarfile="${flexive.build.framework.jar.dir}/${ejb-interfaces-all.jar}" keepcompression="true">
			<fileset dir="${build.framework.classes.dir}">
                <include name="com/flexive/shared/interfaces/**"/>
			</fileset>
        </jar>
	</target>

	<target name="compile.ui.shared" depends="jar.framework.shared" description="Compile the shared UI classes">
		<javac-call
                srcdir="${flexive.src.ui.shared.dir}"
                destdir="${build.ui.shared.classes.dir}"
                >
			<classpath refid="classpath.build.framework"/>
			<classpath>
				<path path="${build.framework.classes.dir}"/>
			</classpath>
		</javac-call>
        <makeMessages srcDir="${resources.ui.jsf.dir}/messages" dest="${build.ui.meta.dir}/ApplicationMessages"/>
	</target>

    <target name="compile.ui" depends="compile.ui.shared,jar.jsf.components" description="Compiles the flexive backend UI">
        <property name="merge.ui.dir" value="${build.ui.jar.dir}/merge"/>
		<delete dir="${merge.ui.dir}"/>

        <echo message="Compiling JSF"/>
        <javac-call
                srcdir="${flexive.src.ui.jsf.dir}"
                destdir="${build.ui.classes.dir}"
                >
            <classpath>
                <path path="${build.framework.classes.dir}"/>
                <path path="${build.ui.shared.classes.dir}"/>
                <fileset dir="${build.ui.jar.dir}" includes="*.jar"/>
            </classpath>
            <classpath refid="classpath.build.framework"/>
            <classpath refid="classpath.build.jsf"/>
        </javac-call>
    </target>

	<target name="jar.ui" depends="compile.ui,jar.jsf.components">
		<jar jarfile="${build.ui.jar.dir}/flexive-backend.jar">
			<fileset dir="${build.ui.classes.dir}">
                <include name="com/flexive/war/**/*"/>
                <include name="org/apache/myfaces/webapp/filter/**/*"/>
			</fileset>
            <fileset dir="${build.ui.meta.dir}">
                <include name="ApplicationMessages*.properties"/>
            </fileset>
        </jar>
        <jar jarfile="${build.ui.jar.dir}/flexive-web-shared.jar">
			<fileset dir="${build.ui.shared.classes.dir}">
			</fileset>
		</jar>
        <!--emma enabled="${emma.enabled}">
			<instr
				instrpath="${build.ui.jar.dir}/flexive-backend.jar"
				mode="overwrite"
				merge="true"
				metadatafile="${coverage.dir}/coverage.em">
				<filter value="+com.flexive.war.*" />
			</instr>
		</emma>
        <emma enabled="${emma.enabled}">
			<instr
				instrpath="${build.ui.jar.dir}/flexive-web-shared.jar"
				mode="overwrite"
				merge="true"
				metadatafile="${coverage.dir}/coverage.em">
				<filter value="+com.flexive.war.*" />
			</instr>
		</emma-->
        <mkdir dir="${build.ui.jar.libs.dir}"/>
        <copy todir="${build.ui.jar.libs.dir}">
            <path refid="jar.war.jsflibs"/>
        </copy>

		<war warfile="${flexive.base.build.dir}/ui/flexive.war" webxml="${resources.ui.jsf.dir}/web.xml" keepcompression="yes">
			<!-- jsp,html,.. files -->
			<fileset dir="${flexive.web.ui.shared.dir}">
				<include name="**/*"/>
			</fileset>
            <fileset dir="${flexive.web.ui.jsf.dir}">
                <include name="**/*"/>
            </fileset>

			<!-- JSF resources -->
			<zipfileset dir="${resources.ui.jsf.dir}/WEB-INF" prefix="WEB-INF">
	            <include name="faces-config.xml"/>
	            <include name="flexive-admin.taglib.xml"/>
                <include name="flexive_jsf.tld"/>
	            <include name="templates/**/*"/>
            </zipfileset>
            <!-- richfaces skins -->
			<zipfileset dir="${resources.ui.jsf.dir}/WEB-INF" prefix="WEB-INF/classes">
	            <include name="flexive.skin.properties"/>
            </zipfileset>

            <!-- include dojo from ZIP file, install in /pub/js/dojo -->
            <zipfileset src="${flexive.base.ui.shared.dir}/resources/lib/dojo/${web.ui.dojo.baseName}Navigation.zip" prefix="pub/js/dojoNavigation">
                <include name="*"/>
                <include name="src/**/*"/>
            </zipfileset>

            <!-- include EditArea from ZIP file, install in /adm/js/edit_area  -->
            <zipfileset src="${resources.ui.jsf.dir}/lib/edit_area.zip" prefix="adm/js/"
                        includes="**/*">
            </zipfileset>

            <!-- include beans.xml -->
            <zipfileset prefix="WEB-INF" dir="${flexive.resources.framework.dir}" includes="beans.xml"/>

            <lib dir="${build.ui.jar.libs.dir}" includes="**/*"/>
        </war>
	</target>

    <target name="jar.ui.standalone" depends="jar.interfaces.onlylocal,jar.ui"
            description="Packages the backend for standalone deployment in a JavaEE Web Profile Container">

        <mkdir dir="${build.war.standalone.libs.dir}"/>
        <copy todir="${build.war.standalone.libs.dir}">
            <path refid="jar.ear.libs"/>
            <path refid="jar.ear.jsflibs"/>
        </copy>

        <copy file="${flexive.base.build.dir}/ui/flexive.war" tofile="${flexive.base.build.dir}/ui/flexive-standalone.war"/>
        
        <jar jarfile="${flexive.base.build.dir}/ui/flexive-standalone.war" update="true">
            <zipfileset prefix="WEB-INF/lib" dir="${flexive.build.framework.jar.dir}" includes="*.jar" 
                excludes="${sqlparser.jar},${htmlparser.jar},richfaces*.jar,${ejb-interfaces-all.jar}"/>
            <zipfileset prefix="WEB-INF/lib" dir="${build.war.standalone.libs.dir}" includes="*.jar"/>
        </jar>
    </target>

    <target name="jar.core.prepare">
        <uptodate targetfile="${flexive.build.framework.jar.dir}/flexive-core.jar" property="jar.core.skip">
            <srcfiles refid="jar.core.classes"/>
            <srcfiles refid="jar.core.resources"/>
        </uptodate>
    </target>

    <target name="jar.core" depends="compile.framework, jar.core.prepare" unless="jar.core.skip">
        <jar jarfile="${flexive.build.framework.jar.dir}/flexive-core.jar">
			<fileset refid="jar.core.classes"/>
			<fileset refid="jar.core.resources"/>
        </jar>
        <emma enabled="${emma.enabled}">
            <instr
                instrpath="${flexive.build.framework.jar.dir}/flexive-core.jar"
                mode="overwrite"
                merge="true"
                metadatafile="${coverage.dir}/coverage.em">
                <filter excludes="*Test*" />
                <filter value="+com.flexive.core.*" />
            </instr>
        </emma> 
    </target>

	<target name="jar.ejb.prepare">
		<uptodate targetfile="${flexive.build.framework.jar.dir}/flexive-ejb.jar" property="jar.ejb.skip">
			<srcfiles refid="jar.ejb.classes"/>
			<srcfiles refid="jar.ejb.resources"/>
        </uptodate>
	</target>

	<target name="jar.ejb" depends="compile.framework, jar.ejb.prepare, jar.core" unless="jar.ejb.skip">
        <scriptIndexBuilder indexFile="${build.framework.classes.dir}/fxresources/scripts/runonce/scriptindex.flexive"
                            scriptDir="${flexive.resources.framework.dir}/fxresources/scripts/runonce"/>
        <scriptIndexBuilder indexFile="${build.framework.classes.dir}/fxresources/scripts/startup/scriptindex.flexive"
                            scriptDir="${flexive.resources.framework.dir}/fxresources/scripts/startup"/>
        <scriptIndexBuilder indexFile="${build.framework.classes.dir}/fxresources/scripts/library/scriptindex.flexive"
                            scriptDir="${flexive.resources.framework.dir}/fxresources/scripts/library"/>
        <scriptIndexBuilder indexFile="${build.framework.classes.dir}/fxresources/binaries/thumbs/resourceindex.flexive"
                            scriptDir="${flexive.resources.framework.dir}/fxresources/binaries/thumbs"/>
        <jar jarfile="${flexive.build.framework.jar.dir}/flexive-ejb.jar">
			<fileset refid="jar.ejb.classes"/>
			<fileset refid="jar.ejb.resources"/>
            <zipfileset prefix="META-INF" dir="${flexive.resources.framework.dir}" includes="beans.xml"/>
        </jar>
		<emma enabled="${emma.enabled}">
			<instr
				instrpath="${flexive.build.framework.jar.dir}/flexive-ejb.jar"
				mode="overwrite"
				merge="true"
				metadatafile="${coverage.dir}/coverage.em">
				<filter excludes="*Test*" />
				<filter value="+com.flexive.ejb.beans.*" />
			</instr>
		</emma>
	</target>

    <target name="jar.interfaces.onlylocal" depends="jar.ejb.prepare, jar.framework">
        <!-- Create dummy interfaces that disable the remote ones for EJB Lite deployment -->
        <copy todir="${build.onlylocal.src.dir}">
            <fileset dir="${flexive.src.framework.dir}" includes="com/flexive/shared/interfaces/**"/>
        </copy>

        <replace dir="${build.onlylocal.src.dir}" token="@Remote" value=""/>

        <javac-call srcdir="${build.onlylocal.src.dir}" destdir="${build.onlylocal.classes.dir}">
            <classpath refid="classpath.build.framework"/>
            <classpath>
                <fileset dir="${flexive.build.framework.jar.dir}" includes="*.jar"/>
            </classpath>
        </javac-call>

        <!-- Create marker file to indicate that only local interfaces are packaged -->
        <echo file="${build.onlylocal.classes.dir}/flexive-ejb-interfaces-onlylocal.properties">
        </echo>

        <jar file="${flexive.build.framework.jar.dir}/${ejb-interfaces-onlylocal.jar}">
            <fileset dir="${build.onlylocal.classes.dir}" includes="**"/>
        </jar>
        
    </target>

    <target  name="jar.dbsetup" depends="jar.framework.shared">
        <javac-call srcdir="${flexive.src.framework.dir}"
                    destdir="${build.framework.classes.dir}"
                    includes="com/flexive/tools/db/**/*.java">
            <classpath refid="classpath.build.framework"/>
        </javac-call>
        <jar jarfile="${flexive.build.framework.jar.dir}/flexive-dbsetup.jar">
            <manifest>
                <attribute name="Class-Path" value="flexive-shared.jar flexive-ejb.jar flexive-core.jar"/>
                <attribute name="Main-Class" value="com.flexive.tools.db.DBSetup"/>
            </manifest>
            <fileset dir="${build.framework.classes.dir}">
                <include name="com/flexive/tools/db/**/*"/>
            </fileset>
        </jar>
    </target>

    <target name="jar.storages" depends="jar.ejb,jar.dbsetup,jar.h2.storedprocedures">
        <groovy>
            new File(properties['flexive.base.framework.dir']+"/storages").eachDir() { File dir ->
                if(dir.name.startsWith(".")) //skip .svn
                    return
                m = project.createTask("buildStorage")
                m.setDynamicAttribute("vendor", dir.name)
                m.setDynamicAttribute("srcdir", dir.absolutePath)
                m.setDynamicAttribute("builddir", properties['build.storages.dir']+"/"+dir.name)
                m.setDynamicAttribute("classpathref", "classpath.build.plugin")
                m.setDynamicAttribute("jarfile", properties['flexive.build.framework.jar.dir']+"/flexive-storage-"+dir.name+".jar")
                m.perform()
            }
        </groovy>
    </target>

    <target name="jar.tests" depends="tests.compile.all">
        <jar file="${flexive.build.framework.jar.dir}/flexive-tests.jar">
            <fileset dir="${tests.classes.dir}" includes="com/flexive/tests/**/*"/>
        </jar>
    </target>

    <!--<target name="jar.all" depends="jar.framework, jar.ui, jar.tests"/>-->
    <target name="jar.all" depends="jar.framework, jar.storages, jar.ui"/>

    <target name="jar.ear" depends="prepare" description="Assemble flexive.ear">
        <mkdir dir="${flexive.drop.dir}"/>
        <applicationDescriptorBuilder dropDir="${flexive.drop.dir}" destFile="${flexive.base.build.dir}/application.xml" srcFile="${resources.ui.shared.dir}/application.xml"/>
        <jar jarfile="${flexive.build.framework.jar.dir}/flexive-drop-resources.jar">
            <fileset file="${flexive.drop.dir}/drops.archives"/>
        </jar>
        <copy todir="${build.ear.libs.dir}">
            <fileset dir="${flexive.build.framework.jar.dir}" includes="*.jar" excludes="${sqlparser.jar},${htmlparser.jar},*-ejb.jar,${ejb-interfaces-onlylocal.jar},richfaces*.jar"/>
            <fileset dir="${flexive.drop.dir}" includes="*.jar" excludes="*-ejb.jar,*.war,*.par"/>

            <path refid="jar.ear.libs"/>
            
            <!-- Shared libraries -->
            <path refid="jar.ear.jsflibs"/>

            <fileset dir="${flexive.lib.dir}/testNG">
                <!-- include testNG only if target test.package.ear was invoked -->
                <include name="testng*jar" if="package.testNG"/>
            </fileset>

        </copy>
        <!-- Create manifest classpath -->
        <manifestclasspath property="ear.classpath" jarfile="${flexive.base.build.dir}/flexive.ear">
            <classpath>
                <fileset dir="${build.ear.libs.dir}" includes="**/*"/>
            </classpath>
        </manifestclasspath>
        <jar jarfile="${flexive.base.build.dir}/flexive.ear" keepcompression="true">
            <manifest >
                <attribute name="Class-Path" value="${ear.classpath}"/>
                <!-- JBoss 7 module dependencies -->
                <attribute name="Dependencies" value="javax.faces.api, com.h2database.h2, org.jboss.common-core"/>
            </manifest>
			<metainf dir="${flexive.base.build.dir}">
				<include name="application.xml"/>
			</metainf>
            <metainf dir="${flexive.base.framework.dir}/resources/jboss">
                <include name="jboss-app.xml"/>
            </metainf>
            <metainf dir="${flexive.base.framework.dir}/resources/glassfish">
                <include name="sun-application.xml"/>
            </metainf>
            <metainf dir="${resources.ui.shared.dir}">
                <include name="geronimo-application.xml"/>
                <include name="weblogic-application.xml"/>
            </metainf>
            <fileset dir="${flexive.build.framework.jar.dir}" includes="*-ejb.jar"/>
            <fileset dir="${flexive.base.build.dir}/ui" includes="*.war"/>
            <fileset dir="${flexive.drop.dir}" includes="*.war,*-ejb.jar,*.par"/>

            <zipfileset prefix="lib" dir="${build.ear.libs.dir}" includes="**/*"/>
        </jar>
	</target>

    <target name="build-deploy" depends="jar.all,jar.ear,deploy" description="Build the application and deploy flexive to an application server"/>

	<target name="deploy" depends="jar.ear" description="Build a current EAR and deploy flexive to an application server">
		<echo message="Deploying ${flexive.edition} ${flexive.version} ..."/>
		<echo message="Warning: if you did run tests previously, call target 'clean' first or the applicationserver will fail due to EMMA dependencies!"/>
		<copy file="${flexive.base.build.dir}/flexive.ear" toDir="${deploy.ear.path}" overwrite="true" failonerror="true"/>
	</target>

    <target name="db.noupdate" description="Skip db updates">
        <property name="db.noupdate" value="1"/>
        <echo message="Skipping database update!"/>
    </target>

    <target name="db.defaults" depends="init" description="Use default schema/database values for db.update and db.update.config">
        <property name="db.config" value="${database.database.config}"/>
        <property name="schema.config" value="${database.schema.config}"/>
        <property name="db.division" value="${database.database.division}"/>
        <property name="schema.division" value="${database.schema.division}"/>
    </target>

    <target name="db.update.config" description="Update config database" depends="init, jar.dbsetup, jar.storages" unless="db.noupdate">
        <echo taskname="flexive">Setting up configuration database for vendor ${database.vendor} ... (this can be changed in build.properties)</echo>
        <input taskname="flexive" addproperty="db.config" defaultvalue="${database.database.config}"
               message="Please enter the configuration database (will be created if it does not exist):"/>
        <input taskname="flexive" addproperty="schema.config" defaultvalue="${database.schema.config}"
               message="Please enter the configuration schema you want to create or reset:"/>
        <java fork="true" classname="com.flexive.tools.db.DBSetup" failonerror="true">
            <classpath>
                <path path="${flexive.build.framework.dir}/classes"/>
                <fileset dir="${flexive.build.framework.jar.dir}" includes="*.jar"/>
                <fileset dir="${flexive.lib.dir}" includes="*.jar, groovy/*.jar"/>
            </classpath>
            <arg value="${database.vendor}"/>
            <arg value="${db.config}"/>
            <arg value="${schema.config}"/>
            <arg value="config"/>
            <arg value="true"/>
            <arg value="true"/>
            <arg value="false"/>
            <arg value="${database.username}"/>
            <arg value="${database.password}"/>
            <arg value="${database.url.base}"/>
            <arg value="${database.url.parameters}"/>
        </java>
    </target>

    <target name="db.update.division" description="Update division database" depends="init, jar.dbsetup, jar.storages" unless="db.noupdate">
        <echo taskname="flexive">Setting up division database for vendor ${database.vendor} ... (this can be changed in build.properties)</echo>
        <input taskname="flexive" addproperty="db.division" defaultvalue="${database.database.division}"
               message="Please enter the division database (will be created if it does not exist):"/>
        <input taskname="flexive" addproperty="schema.division" defaultvalue="${database.schema.division}"
               message="Please enter the division schema you want to create or reset:"/>
        <java fork="true" classname="com.flexive.tools.db.DBSetup" failonerror="true">
            <classpath>
                <path path="${flexive.build.framework.dir}/classes"/>
                <fileset dir="${flexive.build.framework.jar.dir}" includes="*.jar"/>
                <fileset dir="${flexive.lib.dir}" includes="*.jar, groovy/*.jar"/>
            </classpath>
            <arg value="${database.vendor}"/>
            <arg value="${db.division}"/>
            <arg value="${schema.division}"/>
            <arg value="division"/>
            <arg value="true"/>
            <arg value="true"/>
            <arg value="false"/>
            <arg value="${database.username}"/>
            <arg value="${database.password}"/>
            <arg value="${database.url.base}"/>
            <arg value="${database.url.parameters}"/>
        </java>
    </target>

    <target name="db.update" description="Update config and division database" depends="db.update.config, db.update.division" unless="db.noupdate"/>

    <target name="db.update.test" description="Update test database (configuration database has to exist!)" depends="init, jar.dbsetup, jar.storages" unless="db.noupdate">
        <echo taskname="flexive">[fleXive] is using ${database.vendor} database settings... (this can be changed in build.properties)</echo>
        <java fork="true" classname="com.flexive.tools.db.DBSetup" failonerror="true">
            <classpath>
                <path refid="build.classpath.testng"/>
                <path path="${flexive.build.framework.dir}/classes"/>
                <fileset dir="${flexive.build.framework.jar.dir}" includes="*.jar"/>
                <fileset dir="${flexive.lib.dir}" includes="*.jar, groovy/*.jar"/>
            </classpath>
            <!--jvmarg value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"/-->
            <arg value="${database.vendor}"/>
            <arg value="${database.database.test}"/>
            <arg value="${database.schema.test}"/>
            <arg value="division"/>
            <arg value="true"/>
            <arg value="true"/>
            <arg value="false"/>
            <arg value="${database.username}"/>
            <arg value="${database.password}"/>
            <arg value="${database.url.base}"/>
            <arg value="${database.url.parameters}"/>
        </java>
    </target>

    <target name="db.flatstorage.create" depends="init">
        <input taskname="flexive" addproperty="flatstorage.url" defaultValue="${database.url.base}flexive"
                message="Connection URL:"/>
        <input taskname="flexive" addproperty="flatstorage.schema" defaultValue="${database.schema.division}"
               message="Database schema:"/>
        <input taskname="flexive" addproperty="flatstorage.tableName" defaultValue="FX_FLAT_STORAGE"
               message="Table name:"/>
        <input taskname="flexive" addproperty="flatstorage.nstring" defaultValue="20"
               message="STRING columns:"/>
        <input taskname="flexive" addproperty="flatstorage.ntext" defaultValue="10"
               message="TEXT columns:"/>
        <input taskname="flexive" addproperty="flatstorage.nbigint" defaultValue="10"
               message="BIGINT columns:"/>
        <input taskname="flexive" addproperty="flatstorage.ndouble" defaultValue="10"
               message="DOUBLE columns:"/>
        <input taskname="flexive" addproperty="flatstorage.nselect" defaultValue="10"
               message="SELECT/BOOLEAN columns:"/>
        <createFlatStorage jar="${flexive.lib.dir}/flexive-flatstorage.jar"
                           lib="${flexive.build.framework.jar.dir}"
                           extlib="lib"
                           connectionurl="${flatstorage.url}"
                           schema="${flatstorage.schema}"
                           tablename="${flatstorage.tableName}"
                           user="${database.username}"
                           password="${database.password}"
                           nstring="${flatstorage.nstring}"
                           ntext="${flatstorage.ntext}"
                           nbigint="${flatstorage.nbigint}"
                           ndouble="${flatstorage.ndouble}"
                           nselect="${flatstorage.nselect}"
                />
    </target>

    <target name="examples">
        <ant antfile="${basedir}/src/examples/helloworld/build.xml" inheritAll="false"/>
        <ant antfile="${basedir}/src/examples/products/build.xml" inheritAll="false"/>
        <ant antfile="${basedir}/src/examples/tutorial01-documentstore/build.xml" inheritAll="false"/>
        <ant antfile="${basedir}/src/examples/announcement-submission/build.xml" inheritAll="false"/>
    </target>

    <target name="dist.prepare">
        <delete dir="${flexive.dist.dir}"/>
        <mkdir dir="${flexive.dist.dir}"/>
        <mkdir dir="${flexive.dist.apps.dir}"/>
        <mkdir dir="${flexive.dist.apps.disabled.dir}"/>
        <echo file="${flexive.dist.apps.disabled.dir}/README.txt">Use this directory for flexive applications that should not be included in flexive.ear.</echo>
    </target>

    <target name="dist" depends="jar.all,jar.interfaces.onlylocal,jar.jsf2.components,dist.prepare,tests.package.dist,dist.srcOnly,dist.assemble,examples,dist.package" description="Build a distribution of all jars, wars and ears">
    </target>

    <target name="dist.assemble">
        <svnVersion property="dist.build.number"/>
        <groovy>
            properties['dist.bin.file'] = properties['flexive.dist'].replaceAll("@@build.number@@", properties['dist.build.number'])+"-bin.zip"
            properties['dist.bin-all.file'] = properties['flexive.dist'].replaceAll("@@build.number@@", properties['dist.build.number'])+"-bin-all.zip"
        </groovy>
        <!-- Create flexive distribution -->
        <copy file="${flexive.lib.dir}/${sqlparser.jar}" tofile="${flexive.dist.lib.dir}/${sqlparser.jar}"/>
		<copy file="${flexive.lib.dir}/${extractor.jar}" tofile="${flexive.dist.lib.dir}/${extractor.jar}"/>
        <copy file="${flexive.lib.dir}/${flatstorage.jar}" tofile="${flexive.dist.lib.dir}/${flatstorage.jar}"/>
		<copy file="${flexive.lib.dir}/${extractor-documents.jar}" tofile="${flexive.dist.lib.dir}/${extractor-documents.jar}"/>
        <copy file="${flexive.lib.dir}/${extractor-audio.jar}" tofile="${flexive.dist.lib.dir}/${extractor-audio.jar}"/>
        <copy file="${flexive.lib.dir}/${extractor-video.jar}" tofile="${flexive.dist.lib.dir}/${extractor-video.jar}"/>
		<copy file="${flexive.build.framework.jar.dir}/flexive-ant.jar" tofile="${flexive.dist.lib.dir}/flexive-ant.jar"/>
        <copy file="${flexive.build.framework.jar.dir}/flexive-shared.jar" tofile="${flexive.dist.lib.dir}/flexive-shared.jar"/>
        <copy file="${flexive.build.framework.jar.dir}/${ejb-interfaces-all.jar}" tofile="${flexive.dist.lib.dir}/${ejb-interfaces-all.jar}"/>
        <copy file="${flexive.build.framework.jar.dir}/${ejb-interfaces-onlylocal.jar}" tofile="${flexive.dist.lib.dir}/${ejb-interfaces-onlylocal.jar}"/>
        <copy todir="${flexive.dist.lib.dir}">
            <fileset dir="${build.ui.jar.dir}" includes="*.jar" excludes="flexive-backend.jar,flexive-plugin-*.jar"/>
        </copy>
        <copy file="${flexive.build.framework.jar.dir}/flexive-ejb.jar" tofile="${flexive.dist.lib.dir}/flexive-ejb.jar"/>
        <copy file="${flexive.build.framework.jar.dir}/flexive-core.jar" tofile="${flexive.dist.lib.dir}/flexive-core.jar"/>
        <copy todir="${flexive.dist.lib.dir}">
            <fileset dir="${flexive.build.framework.jar.dir}" includes="flexive-storage-*.jar"/>
        </copy>
        <copy file="${flexive.build.framework.jar.dir}/flexive-dbsetup.jar" tofile="${flexive.dist.lib.dir}/flexive-dbsetup.jar"/>
        <copy file="${flexive.lib.dir}/flexive-flatstorage.jar" tofile="${flexive.dist.lib.dir}/flexive-flatstorage.jar"/>

        <!-- Copy backend administration to applications folder -->
        <copy file="${flexive.base.build.dir}/ui/flexive.war" todir="${flexive.dist.apps.dir}/flexive-backend"/>
        <copy file="${build.ui.jar.dir}/flexive-backend.jar" todir="${flexive.dist.apps.dir}/flexive-backend"/>
        <!-- Include standard plugin setup -->
        <copy todir="${flexive.dist.apps.dir}">
            <fileset dir="${build.ui.jar.dir}" includes="flexive-plugin-*.jar" excludes="flexive-plugin-jsf-testrunner.jar,flexive-plugin-jsf-newsletter.jar,flexive-plugin-jsf2-core.jar"/>
        </copy>
        <copy todir="${flexive.dist.apps.disabled.dir}">
            <fileset dir="${build.ui.jar.dir}" includes="flexive-plugin-jsf-testrunner.jar,flexive-plugin-jsf2-core.jar,flexive-plugin-jsf-newsletter.jar"/>
        </copy>

        <!-- Copy build environment to root dist folder -->
        <copy todir="${flexive.dist.dir}">
            <fileset dir="${basedir}/disttools" includes="**/*"/>
            <fileset file="${basedir}/build.macros.xml"/>
            <fileset file="${basedir}/build.global-properties.xml"/>
        </copy>

        <!-- Copy template projects to templates/ -->
        <copy todir="${flexive.dist.templates.dir}/template-component">
            <fileset dir="${flexive.base.ui.dir}/template-component" includes="**/*" excludes=".svn,.SVN"/>
        </copy>
        <copy todir="${flexive.dist.templates.dir}/template-project">
            <fileset dir="${flexive.basedir}/src/template-project" includes="**/*" excludes=".svn,.SVN"/>
        </copy>

        <!-- Copy third-party libraries to extlib/ -->
        <copy todir="${flexive.dist.extlib.dir}" >
            <path refid="flexive.shared-libs.path"/>
            <mapper type="flatten"/>
        </copy>
        <delete dir="${flexive.dist.extlib.dir}" includes="jsf-facelets-src.jar"/>

        <!-- Copy openURL helper application (com.flexive.tools.OpenUrl) -->
        <copy todir="${flexive.dist.dir}" file="${flexive.build.framework.jar.dir}/openUrl.jar"/>

        <!-- Copy global deployment descriptors -->
        <copy todir="${flexive.dist.meta.dir}">
            <fileset file="${flexive.base.framework.dir}/resources/jboss/jboss-app.xml"/>
            <fileset file="${flexive.base.framework.dir}/resources/glassfish/sun-application.xml"/>
        </copy>
        <!--<copy file="${flexive.base.build.dir}/flexive.ear" tofile="${flexive.dist.dir}/flexive.ear" overwrite="true"/>-->

        <!-- Create a sample database.properties file -->
        <echo file="${flexive.dist.dir}/database.properties">
# This is the database configuration file used by the flexive setup tasks.
#
# Enter the settings for your database server connection to be used for development.
# Please use the database.vendor property at the bottom of this file to select
# the database vendor to use.

# MySQL database settings

# The server host or IP
database.MySQL.host=localhost
# The server port
database.MySQL.port=3306
# The user name and password to be used for creating flexive database structures
database.MySQL.username=root
# if the password is not set, use "()" to set it to empty
database.MySQL.password=a
# division database to use
database.MySQL.database.division=flexive
# configuration database to use
database.MySQL.database.config=flexive
# test database to use
database.MySQL.database.test=flexive
# division schema
database.MySQL.schema.division=flexive
# configuration schema
database.MySQL.schema.config=flexiveConfiguration
# test schema
database.MySQL.schema.test=flexiveTest
# JDBC base URL, will be appended by the database name and the url parameters
database.MySQL.url.base=jdbc:mysql://${database.MySQL.host}:${database.MySQL.port}/
# Optional URL parameters to append to the JDBC connect string
database.MySQL.url.parameters=?useUnicode=true&amp;characterEncoding=UTF-8

# H2 database settings

# The server host or IP
database.H2.host=localhost
# The server port
database.H2.port=9092
# The user name and password to be used for creating flexive database structures
database.H2.username=sa
# if the password is not set, use "()" to set it to empty
database.H2.password=()
# division database to use
database.H2.database.division=~/flexive
# configuration database to use
database.H2.database.config=~/flexive
# test database to use
database.H2.database.test=~/flexive
# division schema
database.H2.schema.division=flexive
# configuration schema
database.H2.schema.config=flexiveConfiguration
# test schema
database.H2.schema.test=flexiveTest            
# JDBC base URL, will be appended by the database name and the url parameters
database.H2.url.base=jdbc:h2:tcp://${database.H2.host}:${database.H2.port}/
# Optional URL parameters to append to the JDBC connect string
database.H2.url.parameters=;MVCC=TRUE

# PostgreSQL database settings

# The server host or IP
database.PostgreSQL.host=localhost
# The server port
database.PostgreSQL.port=5432
# The user name and password to be used for creating flexive database structures
database.PostgreSQL.username=postgres
# if the password is not set, use "()" to set it to empty
database.PostgreSQL.password=a
# division database to use
database.PostgreSQL.database.division=flexive
# configuration database to use
database.PostgreSQL.database.config=flexiveConfiguration
# test database to use
database.PostgreSQL.database.test=flexiveTest
# division schema
database.PostgreSQL.schema.division=public
# configuration schema
database.PostgreSQL.schema.config=public
# test division schema
database.PostgreSQL.schema.test=public
# JDBC base URL, will be appended by the database name and the url parameters
database.PostgreSQL.url.base=jdbc:postgresql://${database.PostgreSQL.host}:${database.PostgreSQL.port}/
# Optional URL parameters to append to the JDBC connect string
database.PostgreSQL.url.parameters=

#select the database vendor to use
#database.vendor=H2
#database.vendor=PostgreSQL
database.vendor=MySQL
        </echo>

        <!-- Copy the raw sources created by dist.srcOnly -->
        <copy todir="${flexive.dist.dir}">
            <fileset file="${flexive.base.build.dir}/flexive-srcOnly.zip"/>
        </copy>
    </target>

    <target name="jar.maven.sources" description="Creates the source JAR files" unless="maven.sources.skip">
        <mkdir dir="${flexive.build.repo.dir}"/>

        <parallel>
            <maven-build-sources artifactId="flexive-ejb"
                                 label="[fleXive] EJB classes"
                                 srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/ejb/" packagenames="com.flexive.ejb.*"/>
            <maven-build-sources artifactId="flexive-core"
                                 label="[fleXive] core classes"
                                 srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/core/" packagenames="com.flexive.core.*"/>

            <maven-build-sources artifactId="flexive-shared"
                                 label="[fleXive] shared classes"
                                 srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/shared/" packagenames="com.flexive.shared.*"/>

            <maven-build-sources artifactId="flexive-ejb-interfaces-all"
                                 label="[fleXive] EJB interfaces"
                                 srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/shared/interfaces" packagenames="com.flexive.shared.interfaces.*"/>

            <maven-build-sources artifactId="flexive-ejb-interfaces-local"
                                 label="[fleXive] local EJB interfaces"
                                 srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/shared/interfaces" packagenames="com.flexive.shared.interfaces.*"/>

            <maven-build-sources artifactId="flexive-web-shared" label="[fleXive] shared web classes" srcdir="${flexive.src.ui.shared.dir}"/>
            <maven-build-sources artifactId="flexive-plugin-jsf-core" label="[fleXive] JSF components" srcdir="${flexive.src.ui.components.dir}"/>
            <maven-build-sources artifactId="flexive-plugin-jsf2-core" label="[fleXive] JSF 2 components" srcdir="${flexive.src.ui.jsf2-components.dir}"/>
            <maven-build-sources artifactId="flexive-plugin-jsf-shared" label="[fleXive] shared JSF classes for JSF 1 and 2" srcdir="${flexive.src.ui.jsf-shared.dir}"/>
            <maven-build-sources artifactId="flexive-plugin-globalconfig" label="[fleXive] global (division) configuration plugin" srcdir="${flexive.base.ui.dir}/jsf-globalconfig/src/java"/>
            <maven-build-sources artifactId="flexive-plugin-jsf-feedbackPlugin" label="[fleXive] backend feedback plugin" srcdir="${flexive.base.ui.dir}/jsf-feedbackPlugin/src/java"/>
            <maven-build-sources artifactId="flexive-plugin-jsf-newsletter" label="[fleXive] backend newsletter plugin" srcdir="${flexive.base.ui.dir}/jsf-newsletter/src/java"/>
            <maven-build-sources artifactId="flexive-backend" label="[fleXive] backend application" srcdir="${flexive.src.ui.jsf.dir}"/>

            <maven-build-sources artifactId="flexive-extractor" label="[fleXive] extractors base module" srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/extractor/" packagenames="com.flexive.extractor"/>
            <maven-build-sources artifactId="flexive-extractor-documents" label="[fleXive] document extractors module" srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/extractor/" packagenames="com.flexive.extractor.*"/>
            <maven-build-sources artifactId="flexive-extractor-audio" label="[fleXive] audio extractors module" srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/extractor/audio/" packagenames="com.flexive.extractor.audio.*"/>
            <maven-build-sources artifactId="flexive-extractor-video" label="[fleXive] video extractors module" srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/extractor/video/" packagenames="com.flexive.extractor.video.*"/>

            <maven-build-sources artifactId="flexive-sqlParser" label="[fleXive] FxSQL parser" srcdir="${flexive.src.framework.dir}"
                                 prefix="com/flexive/sqlParser/" packagenames="com.flexive.sqlParser.*"/>
            <maven-build-sources artifactId="flexive-h2" label="[fleXive] H2 database support" srcdir="${flexive.base.framework.dir}/storages/H2/java"/>
            <maven-build-sources artifactId="flexive-mysql" label="[fleXive] MySQL database support" srcdir="${flexive.base.framework.dir}/storages/MySQL/java"/>
            <maven-build-sources artifactId="flexive-postgresql" label="[fleXive] PostgreSQL database support" srcdir="${flexive.base.framework.dir}/storages/PostgreSQL/java"/>
        </parallel>
    </target>

    <macrodef name="maven-build-sources">
        <attribute name="artifactId" description="The artifact name"/>
        <attribute name="label" description="The artifact label (displayed in the JavaDoc documentation)"/>
        <attribute name="srcdir"/>
        <attribute name="prefix" default="" description="Path prefix to limit include filter"/>
        <attribute name="packagenames" default="*" description="Packages to include for JavaDoc (see jdoc-call macro)"/>
        <element name="args" implicit="true" optional="true"/>

        <sequential>
            <!-- Create source JAR -->
            <jar file="${flexive.build.repo.dir}/@{artifactId}-sources.jar">
                <fileset dir="@{srcdir}">
                    <include name="@{prefix}**/*.java"/>
                    <include name="@{prefix}**/*.groovy"/>
                    <include name="@{prefix}**/*.gy"/>
                    <include name="@{prefix}**/*.jj"/>
                </fileset>
                <args/>
            </jar>

            <!-- Create JavaDocs -->
            <jdoc-call srcdir="@{srcdir}"
                       destdir="${flexive.build.repo.dir}/javadoc/@{artifactId}"
                       name="@{artifactId}"
                       packagenames="@{packagenames}"
                       doctitle="@{label}"/>
            <jar file="${flexive.build.repo.dir}/@{artifactId}-javadoc.jar">
                <fileset dir="${flexive.build.repo.dir}/javadoc/@{artifactId}" includes="**/*"/>
            </jar>
        </sequential>
    </macrodef>

    <target name="maven.deploy" description="Publish to Maven repository set in maven.dist.repo" depends="jar.all,jar.jsf2.components,jar.interfaces.onlylocal,jar.maven.sources">
        <maven-deploy-with-sources path="${flexive.build.framework.jar.dir}" name="flexive-ejb"/>
        <maven-deploy-with-sources path="${flexive.build.framework.jar.dir}" name="flexive-core"/>

        <maven-deploy-with-sources path="${flexive.build.framework.jar.dir}" name="flexive-shared"/>
        <maven-deploy-with-sources path="${flexive.build.framework.jar.dir}" name="flexive-ejb-interfaces-all"/>
        <maven-deploy-with-sources path="${flexive.build.framework.jar.dir}" name="flexive-ejb-interfaces-local"/>

        <maven-deploy-with-sources path="${build.ui.jar.dir}" name="flexive-web-shared"/>
        <maven-deploy-with-sources path="${build.ui.jar.dir}" name="flexive-plugin-jsf-core"/>
        <maven-deploy-with-sources path="${build.ui.jar.dir}" name="flexive-plugin-jsf2-core"/>
        <maven-deploy-with-sources path="${build.ui.jar.dir}" name="flexive-plugin-jsf-shared"/>
        <maven-deploy-with-sources path="${build.ui.jar.dir}" name="flexive-plugin-globalconfig"/>
        <maven-deploy-with-sources path="${build.ui.jar.dir}" name="flexive-plugin-jsf-feedbackPlugin"/>
        <maven-deploy-with-sources path="${build.ui.jar.dir}" name="flexive-plugin-jsf-newsletter"/>
        <maven-deploy-with-sources path="${build.ui.jar.dir}" name="flexive-backend"/>

        <maven-deploy-with-sources path="${flexive.lib.dir}" name="flexive-extractor"/>
        <maven-deploy-with-sources path="${flexive.lib.dir}" name="flexive-extractor-documents"/>
        <maven-deploy-with-sources path="${flexive.lib.dir}" name="flexive-extractor-audio"/>
        <maven-deploy-with-sources path="${flexive.lib.dir}" name="flexive-extractor-video"/>
        <maven-deploy-with-sources path="${flexive.lib.dir}" name="flexive-sqlParser"/>
        <maven-deploy file="${flexive.lib.dir}/fxStream.jar" pom="fxStream.pom"/>
        <maven-deploy file="${flexive.lib.dir}/flexive-flatstorage.jar" pom="flexive-flatstorage.pom"/>

        <copy file="${flexive.build.framework.jar.dir}/flexive-storage-H2.jar" tofile="${flexive.build.repo.dir}/flexive-h2.jar"/>
        <copy file="${flexive.build.framework.jar.dir}/flexive-storage-MySQL.jar" tofile="${flexive.build.repo.dir}/flexive-mysql.jar"/>
        <copy file="${flexive.build.framework.jar.dir}/flexive-storage-PostgreSQL.jar" tofile="${flexive.build.repo.dir}/flexive-postgresql.jar"/>

        <maven-deploy-with-sources path="${flexive.build.repo.dir}" name="flexive-h2"/>
        <maven-deploy-with-sources path="${flexive.build.repo.dir}" name="flexive-mysql"/>
        <maven-deploy-with-sources path="${flexive.build.repo.dir}" name="flexive-postgresql"/>

        <maven-deploy file="${flexive.base.build.dir}/ui/flexive.war" pom="flexive-backend-war.pom"/>

        <!-- Also package libraries that are not available on common public servers -->
        <maven-deploy file="${flexive.lib.dir}/sanselan.jar" pom="sanselan.pom"/>
        <maven-deploy file="${flexive.lib.dir}/icepdf-core.jar" pom="icepdf-core.pom"/>
        <maven-deploy file="${flexive.lib.dir}/jsf/jsf-facelets.jar" pom="jsf-facelets.pom">
            <attach file="${flexive.lib.dir}/jsf/jsf-facelets-src.jar" classifier="sources"/>
        </maven-deploy>
        <maven-deploy file="${flexive.lib.dir}/jboss-common-core-42-compat.jar" pom="jboss-common-core-42-compat.pom"/>
        <maven-deploy file="${flexive.lib.dir}/PDFRenderer.jar" pom="pdf-renderer.pom"/>
        <maven-deploy file="${flexive.lib.dir}/audio/jflac-1.3.jar" pom="jflac.pom"/>

        <!-- ZIP SQL Schemas - TODO: legacy package, remove after next release (schemas are also contained in flexive-h2 and flexive-mysql) -->
        <jar file="${flexive.base.build.dir}/flexive-sql-schemas.jar">
            <zipfileset prefix="com/flexive/schemas/MySQL" dir="${flexive.base.framework.dir}/storages/MySQL/resources" includes="**/*"/>
            <zipfileset prefix="com/flexive/schemas/H2" dir="${flexive.base.framework.dir}/storages/H2/resources" includes="**/*"/>
        </jar>
        <maven-deploy file="${flexive.base.build.dir}/flexive-sql-schemas.jar" pom="flexive-sql-schemas.pom"/>


        <!-- Deploy archetypes -->
<!--
        <maven-deploy file="${flexive.resources.framework.dir}/maven/archetypes/flexive-ear-archetype/target/flexive-ear-archetype-3.1-SNAPSHOT.jar"
                      pomPath="${flexive.resources.framework.dir}/maven/archetypes/flexive-ear-archetype"
                      pom="pom.xml"/>
-->
    </target>

    <macrodef name="maven-deploy-with-sources">
        <attribute name="path" description="Path to the JAR file"/>
        <attribute name="name" description="Base file name without extension. Will be used for the JAR, POM, and sources JAR file."/>
        <sequential>
            <maven-deploy file="@{path}/@{name}.jar" pom="@{name}.pom">
                <attach file="${flexive.build.repo.dir}/@{name}-sources.jar" classifier="sources"/>
                <attach file="${flexive.build.repo.dir}/@{name}-javadoc.jar" classifier="javadoc"/>
            </maven-deploy>
        </sequential>
    </macrodef>

    <macrodef name="maven-deploy">
        <attribute name="file"/>
        <attribute name="pom"/>
        <attribute name="pomPath" default="${flexive.resources.framework.dir}/maven"/>
        <element name="args" optional="true" implicit="true"/>
        <sequential>
            <copy file="@{pomPath}/@{pom}" todir="${flexive.base.build.dir}" overwrite="true">
                <filterset>
                    <filter token="FLEXIVE_VERSION" value="${flexive.maven.version}"/>
                    <filter token="FLEXIVE_BRANCH" value="${flexive.maven.branch}"/>
                </filterset>
            </copy>
            <!--artifact:install-provider groupid="org.apache.maven.wagon" artifactid="wagon-ssh" version="1.0-beta-1"/-->
            <artifact:deploy file="@{file}" uniqueversion="false">
                <remoterepository url="${maven.dist.repo}">
                    <snapshots updatePolicy="always"/>
                    <authentication username="${maven.dist.user}" password="${maven.dist.password}"
                                    privateKey="${maven.dist.privatekey}"/>
                </remoterepository>
                <pom file="${flexive.base.build.dir}/@{pom}"/>

                <args/>
            </artifact:deploy>
        </sequential>
    </macrodef>

    <target name="dist.package">
        <!-- Create flexive distribution w/ backend and examples ZIP file -->
        <zip destfile="${flexive.base.build.dir}/${dist.bin-all.file}">
            <fileset dir="${basedir}" includes="flexive-dist/**"/>
            <zipfileset prefix="flexive-dist" dir="${basedir}/legal" includes="LICENSE.txt,LGPL.txt,GPL.txt"/>

            <!-- Package examples in the applications folder -->
            <zipfileset prefix="flexive-dist/applications/disabled/helloworld" dir="${flexive.drop.dir}" includes="helloworld*"/>
            <zipfileset prefix="flexive-dist/applications/disabled/tutorial01-documentstore" dir="${flexive.drop.dir}" includes="tutorial01-documentstore*"/>
            <zipfileset prefix="flexive-dist/applications/disabled/products" dir="${flexive.drop.dir}" includes="products*"/>
            <zipfileset prefix="flexive-dist/applications/disabled/announcement-submission" dir="${flexive.drop.dir}" includes="announcement-submission*"/>

            <!-- Package optional applications -->
            <zipfileset prefix="flexive-dist/applications/flexive-atompub" dir="${flexive.drop.dir}" includes="flexive-atompub*"/>
            <zipfileset prefix="flexive-dist/applications/flexive-webdav" dir="${flexive.drop.dir}" includes="flexive-webdav*"/>
        </zip>
        <copy file="${flexive.base.build.dir}/${dist.bin-all.file}" toFile="${flexive.base.build.dir}/flexive-dist.zip"/>
        <!-- Create flexive distribution w/o backend and GPL'd files -->
        <zip destfile="${flexive.base.build.dir}/${dist.bin.file}">
            <fileset dir="${basedir}" includes="flexive-dist/**" excludes="**/flexive-backend/, **/extlib/mysql-connector*"/>
            <zipfileset prefix="flexive-dist" dir="${basedir}/legal" includes="LICENSE.txt,LGPL.txt"/>
        </zip>
    </target>

    <target name="dist.srcOnly" depends="prepare" description="Create a ZIP file with all sources of the current flexive installation (excluding build files and libraries)">
        <svnVersion property="dist.build.number"/>
        <groovy>
            properties['dist.srcOnly.file'] = properties['flexive.dist'].replaceAll("@@build.number@@", properties['dist.build.number'])+"-srcOnly.zip"
        </groovy>
        <zip destfile="${flexive.base.build.dir}/${dist.srcOnly.file}">
            <fileset dir="${flexive.src.framework.dir}" includes="**/*"/>
            <fileset dir="${flexive.src.ui.components.dir}" includes="**/*"/>
            <fileset dir="${flexive.src.ui.jsf.dir}" includes="**/*"/>
            <fileset dir="${flexive.src.ui.shared.dir}" includes="**/*"/>
            <fileset dir="${basedir}/legal" includes="LICENSE.txt,GPL.txt"/>
        </zip>
	    <copy file="${flexive.base.build.dir}/${dist.srcOnly.file}" toFile="${flexive.base.build.dir}/flexive-srcOnly.zip"/>
    </target>

    <target name="dist.src" depends="prepare" description="Create a ZIP file with the complete source tree and all libraries and buildfiles needed for building flexive">
        <svnVersion property="dist.build.number"/>
        <groovy>
            properties['dist.src.file'] = properties['flexive.dist'].replaceAll("@@build.number@@", properties['dist.build.number'])+"-src.zip"
        </groovy>

        <zip destfile="${flexive.base.build.dir}/${dist.src.file}">
            <zipfileset prefix="flexive-src"
                    dir="${basedir}" includes="disttools/**/*, legal/**/*, lib/**/*, src/**/*, *.xml, *.sample, flexive.properties, *.groovy"
                    excludes="build.properties, *.iws, *.ipr"/>
            <zipfileset prefix="flexive-src" dir="legal" includes="GPL*.txt, LICENSE.txt"/>
        </zip>

        <copy file="${flexive.base.build.dir}/${dist.src.file}" toFile="${flexive.base.build.dir}/flexive-src.zip"/>
    </target>

    <!-- ============================= Plugin targets ================================ -->

    <target name="jar.jsf.shared" depends="compile.ui.shared">
        <buildPlugin name="jsf-shared" srcdir="${flexive.base.ui.jsf-shared.dir}">
            <plugin-jar-elements>
                <!-- explode YUI and TinyMCE editor files in into jsf core plugins JAR under flexive-faces -->

                <zipfileset src="${flexive.base.ui.shared.dir}/resources/lib/tiny_mce.zip" prefix="META-INF/resources/flexive-faces/js" includes="**/*">
                    <!-- Exclude source javascript files -->
                    <exclude name="**/*_src.js"/>
                </zipfileset>

                <!-- Include the rest of YUI (skins, images, ...) -->
                <zipfileset src="${flexive.base.ui.shared.dir}/resources/lib/yui-${web.ui.yui.version}.zip" prefix="META-INF/resources/flexive-faces/js/yui">
                    <include name="**/*"/>
                    <!-- Exclude debug JS files -->
                    <exclude name="**/*-debug.js"/>
                </zipfileset>
            </plugin-jar-elements>
        </buildPlugin>
    </target>

    <target name="jar.jsf.shared.test" depends="compile.ui.shared" description="Tests if the JSF shared classes can be compiled with both JSF 1.2 and JSF 2">
        <delete dir="${build.ui.components.dir}/jsf-shared" failonerror="false"/>
        <echo>Compiling jsf-shared against JSF 1.2...</echo>
        <buildPlugin name="jsf-shared" srcdir="${flexive.base.ui.jsf-shared.dir}"/>

        <delete dir="${build.ui.components.dir}/jsf-shared"/>
        <echo>Compiling jsf-shared against JSF 2...</echo>
        <buildPlugin name="jsf-shared" srcdir="${flexive.base.ui.jsf-shared.dir}"
                     classpathref="classpath.build.plugin.jsf2"/>
        <delete dir="${build.ui.components.dir}/jsf-shared"/>
    </target>


    <target name="jar.jsf2.components" depends="jar.jsf.shared">
        <buildPlugin name="jsf2-core" srcdir="${flexive.base.ui.jsf2-components.dir}"
                    classpathref="classpath.build.plugin.jsf2"/>
    </target>

    <target name="jar.jsf.components" depends="compile.ui.shared, jar.jsf.shared">
        <buildPlugin name="jsf-core" srcdir="${flexive.base.ui.components.dir}"/>
        
        <buildPlugin name="jsf-testrunner" srcdir="${flexive.base.ui.dir}/jsf-testrunner"/>
        <buildPlugin name="globalconfig" srcdir="${flexive.base.ui.dir}/jsf-globalconfig"/>
        <buildPlugin name="jsf-feedbackPlugin" srcdir="${flexive.base.ui.dir}/jsf-feedbackPlugin"/>
        <buildPlugin name="jsf-newsletter" srcdir="${flexive.base.ui.dir}/jsf-newsletter"/>
        <!--emma enabled="${emma.enabled}">
			<instr
				instrpath="${build.ui.jar.dir}/flexive-jsf-core.jar"
				mode="overwrite"
				merge="true"
				metadatafile="${coverage.dir}/coverage.em">
				<filter value="+com.flexive.*" />
			</instr>
		</emma-->
    </target>

    <macrodef name="buildPlugin">
        <attribute name="name"/>
        <attribute name="srcdir"/>
        <attribute name="classpathref" default="classpath.build.plugin"/>
        <element name="plugin-jar-elements" optional="true"/>
        <sequential>
            <compilePlugin srcdir="@{srcdir}" builddir="${build.ui.components.dir}/@{name}"
                           classpathref="@{classpathref}"/>
            <buildPluginJar name="@{name}" srcdir="@{srcdir}" builddir="${build.ui.components.dir}/@{name}"
                            jarfile="${build.ui.jar.dir}/flexive-plugin-@{name}.jar">
                <jar-elements>
                    <plugin-jar-elements/>
                </jar-elements>
            </buildPluginJar>
        </sequential>
    </macrodef>

</project>