-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.xml
979 lines (881 loc) · 45 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
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
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="HsgProject" default="all" xmlns:if="ant:if" xmlns:unless="ant:unless" xmlns:xdb="http://exist-db.org/ant">
<property file="build/local.build.properties"/>
<property file="build/build.properties"/>
<property name="repos" value="repos"/>
<property name="libs" value="lib"/>
<property name="build" value="build"/>
<property name="build-env" value=""/>
<!-- use "xars" unless called with a "repo-name" property -->
<condition property="xars" value="${repo-name}" else="xars">
<isset property="repo-name"/>
</condition>
<property name="instance.tempColl" value="hsg-temp"/>
<property name="instance.tempPath" value="/db/${instance.tempColl}"/>
<property name="local.instance.temp" value="${local.instance.uri}${instance.tempPath}"/>
<property name="production.instance.temp" value="${production.instance.uri}${instance.tempPath}"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="build/lib/ant-contrib-1.0b3.jar"/>
<target name="all" depends="ping-localhost,ping-public-repo,clean,update,build,deploy"
description="Clean, update, build, and deploy all packages (assumes 'setup' has already been run)"/>
<condition property="git.private.include">
<istrue value="${git.private.include}"/>
</condition>
<target name="clone-private-repos" if="${git.private.include}"
description="Clone private packages">
<echo message="Cloning private packages into ${repos}..."/>
<foreach list="${git.private.repo-names}" delimiter="," parallel="false" target="git.clone.private" param="repo-name"/>
</target>
<target name="check-if-repo-exists">
<condition property="repo-exists" value="true" else="false">
<available file="${repos}/${repo-name}" type="dir"/>
</condition>
<echo if:true="${repo-exists}" message="If you need to re-clone this repo, please delete ${repos}/${repo-name} and try again."/>
<!-- let the command git.clone only fail on error, if the to-be-cloned repo is not yet existing, e.g. on an initial setup -->
<condition property="fail-on-error" value="false" else="true">
<istrue value="${repo-exists}"/>
</condition>
</target>
<target name="git.clone.private" depends="check-if-repo-exists">
<antcall target="git.clone">
<param name="local-repo-name" value="${repo-name}"/>
<param name="origin" value="${git.private.remotes.origin.org}/${repo-name}.git"/>
<param name="upstream" value="${git.private.remotes.upstream.org}/${repo-name}.git"/>
</antcall>
</target>
<target name="clone-public-repos">
<echo message="Cloning required packages into ${repos}..."
description="Clone public packages"/>
<foreach list="${git.public.repo-names}" delimiter="," parallel="false" target="git.clone.public" param="repo-name"/>
<!-- TODO(AR) these should likely move to HistoryAtState -->
<foreach list="${git.joewiz.repo-names}" delimiter="," parallel="false" target="git.clone.joewiz" param="repo-name"/>
</target>
<target name="git.clone.public" depends="check-if-repo-exists">
<antcall target="git.clone">
<param name="local-repo-name" value="${repo-name}"/>
<param name="origin" value="${git.public.remotes.origin.org}/${repo-name}.git"/>
<param name="upstream" value="${git.public.remotes.upstream.org}/${repo-name}.git"/>
</antcall>
</target>
<!-- TODO(AR) these should likely move to HistoryAtState -->
<target name="git.clone.joewiz" depends="check-if-repo-exists">
<antcall target="git.clone">
<param name="local-repo-name" value="${repo-name}"/>
<param name="origin" value="${git.joewiz.remotes.origin.org}/${repo-name}.git"/>
<param name="upstream" value="${git.joewiz.remotes.upstream.org}/${repo-name}.git"/>
</antcall>
</target>
<target name="setup" depends="prepare,upgrade-local-build-properties,mvn-copy-dependencies,clone-public-repos,clone-private-repos"
description="Clone required repositories">
<echo message="Completed cloning of repositories..."/>
</target>
<target name="build" depends="prepare" description="Build all packages">
<iterate target="build-xar"/>
</target>
<target name="deploy" description="Deploy all packages"
depends="ping-localhost,ping-public-repo,deploy.init,deploy.install-packages-from-public-repo,deploy.upload,deploy.deploy,deploy.cleanup"/>
<target name="deploy-one" description="Deploy one package"
depends="ping-localhost,ping-public-repo,deploy.init,deploy.upload-one,deploy.deploy-xar,deploy.cleanup"/>
<target name="prepare">
<mkdir dir="${libs}"/>
<mkdir dir="${xars}"/>
<mkdir dir="${repos}"/>
</target>
<target name="mvn-copy-dependencies" depends="prepare">
<delete>
<fileset dir="${libs}">
<include name="*.jar"/>
</fileset>
</delete>
<exec executable="${mvn}" dir=".">
<arg line="dependency:copy-dependencies -DoutputDirectory=${libs}" />
</exec>
</target>
<target name="update">
<echo message="-------------------------------------"/>
<echo message="Pulling updates for all repositories"/>
<echo message="-------------------------------------"/>
<antcall target="update-public-repos"/>
<antcall target="update-private-repos"/>
</target>
<target name="update-private-repos" if="${git.private.include}"
description="Update private packages">
<echo message="Cloning private packages into ${repos}..."/>
<foreach list="${git.private.repo-names}" delimiter="," parallel="false" target="git.pull-path" param="repo-name"/>
</target>
<target name="update-public-repos">
<echo message="Updating required packages into ${repos}..."
description="Update public packages"/>
<foreach list="${git.public.repo-names}" delimiter="," parallel="false" target="git.pull-path" param="repo-name"/>
<!-- TODO(AR) these should likely move to HistoryAtState -->
<foreach list="${git.joewiz.repo-names}" delimiter="," parallel="false" target="git.pull-path" param="repo-name"/>
</target>
<target name="git.pull-path">
<antcall target="git.pull">
<param name="local-repo-path" value="${repos}/${repo-name}"/>
</antcall>
</target>
<target name="update-one">
<antcall target="git.pull">
<param name="local-repo-path" value="${repos}/${repo-name}"/>
</antcall>
</target>
<target name="deploy.init">
<path id="exist.classpath">
<fileset dir="${libs}">
<include name="*.jar"/>
</fileset>
</path>
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="exist.classpath"/>
</typedef>
<typedef resource="net/sf/antcontrib/antlib.xml">
<classpath refid="exist.classpath"/>
</typedef>
</target>
<target name="deploy.upload">
<echo message="Uploading packages ..."/>
<xdb:store uri="${local.instance.temp}" user="${local.instance.user}"
password="${local.instance.password}" createcollection="true">
<fileset dir="${xars}">
<include name="*.xar"/>
</fileset>
</xdb:store>
</target>
<target name="deploy.upload-to-production">
<echo message="Uploading packages ..."/>
<xdb:store uri="${production.instance.temp}" user="${production.instance.user}"
password="${production.instance.password}" createcollection="true">
<fileset dir="${xars}">
<include name="*.xar"/>
</fileset>
</xdb:store>
</target>
<target name="deploy.upload-one" depends="deploy.get-xar-filename">
<echo message="Uploading package ${repo-name} ..."/>
<xdb:store uri="${local.instance.temp}" user="${local.instance.user}"
password="${local.instance.password}" createcollection="true"
srcfile="${repos}/${repo-name}/${build}/${xar}"/>
</target>
<target name="deploy.deploy">
<echo message="Installing packages ..."/>
<iterate-xars target="deploy.deploy-xar"/>
</target>
<target name="deploy.install-packages-from-public-repo">
<echo message="Installing packages from public repo..."/>
<xdb:create uri="${local.instance.uri}/db" user="${local.instance.user}"
password="${local.instance.password}" collection="${instance.tempColl}"/>
<echo message="Installing Shared Resources..."/>
<xdb:xquery uri="${local.instance.temp}" user="${local.instance.user}"
password="${local.instance.password}"
query="repo:install-and-deploy('http://exist-db.org/apps/shared', '${eXist.public-repo.lookup}')"/>
<echo message="Installing TEI Publisher Libraries..."/>
<xdb:xquery uri="${local.instance.temp}" user="${local.instance.user}"
password="${local.instance.password}"
query="repo:install-and-deploy('http://existsolutions.com/apps/tei-publisher-lib', '${eXist.public-repo.lookup}')"
/>
<echo message="Installing Crypto Module..."/>
<xdb:xquery uri="${local.instance.temp}" user="${local.instance.user}"
password="${local.instance.password}"
query="repo:install-and-deploy('http://expath.org/ns/crypto', '${eXist.public-repo.lookup}')"/>
<echo message="Installing SAML Module..."/>
<xdb:xquery uri="${local.instance.temp}" user="${local.instance.user}"
password="${local.instance.password}"
query="repo:install-and-deploy('http://exist-db.org/xquery/exsaml', '${eXist.public-repo.lookup}')"/>
<!-- NOTE: Messaging and Replication app is needed on production system in ApacheMQ environment,
but without ApacheMQ listening, deploying an app that registers the replication trigger will fail. -->
<!--
<echo message="Installing Messaging and Replication..."/>
<xdb:xquery uri="${local.instance.temp}" user="${local.instance.user}" password="${local.instance.password}"
query="repo:install-and-deploy('http://exist-db.org/messaging-replication', '${eXist.public-repo.lookup}')"/>
-->
</target>
<target name="deploy.get-xar-filename" unless="xar">
<path id="xar-path-ref">
<fileset dir="${repos}/${repo-name}/${build}">
<include name="*.xar"/>
</fileset>
</path>
<property name="xar-path" refid="xar-path-ref"/>
<basename property="xar" file="${xar-path}"/>
</target>
<target name="deploy.deploy-xar" depends="deploy.get-xar-filename">
<echo message="Deploying xar ${xar}"/>
<xdb:xquery uri="${local.instance.temp}" user="${local.instance.user}"
password="${local.instance.password}" queryFile="${build}/deploy.xql"
outputproperty="deploy.output">
<variable name="temp" value="${instance.tempPath}"/>
<variable name="xar" value="${xar}"/>
<variable name="repo" value="${eXist.public-repo.lookup}"/>
</xdb:xquery>
<echo message="${deploy.output}"/>
</target>
<target name="deploy.cleanup">
<echo message="Removing temporary collection ..."/>
<xdb:remove uri="${local.instance.temp}" user="${local.instance.user}"
password="${local.instance.password}" collection="${instance.tempPath}"/>
</target>
<target name="clean" description="Call clean on all package dirs; remove built xars">
<delete>
<fileset dir="${xars}">
<include name="*.xar"/>
</fileset>
</delete>
<subant target="clean" failonerror="false">
<fileset dir=".">
<include name="${repos}/*/build.xml"/>
</fileset>
</subant>
</target>
<target name="clean-all" depends="clean"
description="Clean everything, including checked out repos, downloaded libs, and built xars">
<delete dir="${libs}" failonerror="false"/>
<delete dir="${repos}" failonerror="false"/>
<delete dir="${xars}" failonerror="false"/>
</target>
<!-- Called on each directory in repos to build it -->
<target name="build-xar">
<echo message="Building ${dir}"/>
<echo message="Validating well-formedness of XML files in ${dir}"/>
<xmlvalidate lenient="true">
<fileset dir="${dir}" includes="**/**.xml,**/**.xconf" excludes="node_modules/**"/>
</xmlvalidate>
<subant target="xar${build-env}">
<!-- set version for repos deployed to localhost during development, since CI sets versions at time of release -->
<property name="app.version" value="0.0.0-development"/>
<fileset dir="${dir}">
<include name="build.xml"/>
</fileset>
</subant>
<copy todir="xars/" failonerror="false">
<fileset dir="${dir}/build">
<include name="*.xar"/>
</fileset>
</copy>
<delete dir="${dir}" includes="*.xar"/>
</target>
<target name="git.pull">
<echo message="Updating ${local-repo-path}..."/>
<exec executable="${git}" dir="${local-repo-path}" failonerror="true">
<arg line="pull"/>
<arg line="--recurse-submodules"/>
</exec>
<exec executable="${git}" dir="${local-repo-path}" failonerror="true">
<arg line="submodule"/>
<arg line="update"/>
<arg line="--recursive"/>
</exec>
</target>
<!-- Iterate through directory of repos and call target for each -->
<scriptdef name="iterate" language="javascript">
<attribute name="target"/>
<![CDATA[
repos = project.getProperty("repos");
fs = project.createDataType("fileset");
fs.setDir(new java.io.File(repos));
fs.setIncludes("*/build.xml");
ds = fs.getDirectoryScanner(project);
descriptors = ds.getIncludedFiles();
var basedir = fs.getDir(project);
for (i=0; i < descriptors.length; i++) {
var descriptor = new java.io.File(basedir, descriptors[i]);
var dir = descriptor.getParent();
// create and use a Task via Ant API
antc = project.createTask("antcall");
var prop = antc.createParam();
prop.setName("dir");
prop.setValue(dir);
antc.setTarget(attributes.get("target"));
antc.perform();
}
]]>
</scriptdef>
<!-- Iterate through directory of xars and call target for each xar -->
<scriptdef name="iterate-xars" language="javascript">
<attribute name="target"/>
<![CDATA[
xarsDir = project.getProperty("xars");
fs = project.createDataType("fileset");
fs.setDir(new java.io.File(xarsDir));
fs.setIncludes("*.xar");
ds = fs.getDirectoryScanner(project);
xars = ds.getIncludedFiles();
var basedir = fs.getDir(project);
for (i=0; i < xars.length; i++) {
// create and use a Task via Ant API
antc = project.createTask("antcall");
var prop = antc.createParam();
prop.setName("xar");
prop.setValue(xars[i]);
antc.setTarget(attributes.get("target"));
antc.perform();
}
]]>
</scriptdef>
<target name="git.clone">
<echo message="Cloning ${origin}..."/>
<exec executable="${git}" outputproperty="git.output" dir="${repos}" failonerror="${fail-on-error}">
<arg line="clone"/>
<arg line="--depth 1"/>
<arg line="${origin}"/>
<arg line="${local-repo-name}"/>
</exec>
<echo message="${git.output}"/>
<condition property="set-upstream">
<not>
<equals arg1="${origin}" arg2="${upstream}"/>
</not>
</condition>
<echo if:true="${set-upstream}" message="Configuring upstream: ${upstream}..."/>
<exec if:true="${set-upstream}" executable="${git}" dir="${repos}/${local-repo-name}" failonerror="${fail-on-error}">
<arg line="remote"/>
<arg line="add"/>
<arg line="upstream"/>
<arg line="${upstream}"/>
</exec>
<exec if:true="${set-upstream}" executable="${git}" dir="${repos}/${local-repo-name}" failonerror="${fail-on-error}">
<arg line="fetch"/>
<arg line="upstream"/>
</exec>
</target>
<target name="test">
<ant antfile="${repos}/hsg-test/build.xml" target="test" useNativeBasedir="true"/>
</target>
<!-- ================================================= -->
<!-- Targets for uploading files from oXygen to the db -->
<!-- ================================================= -->
<condition property="is-xml">
<contains string="${file-name}" substring=".xml"/>
</condition>
<target name="validate-if-xml" if="${is-xml}">
<xmlvalidate file="${directory}/${file-name}" lenient="true" failonerror="true"/>
</target>
<target name="upload-file-to-localhost"
description="Upload a file from an hsg-project repo to eXist-db on localhost"
depends="deploy.init,validate-if-xml,ping-localhost">
<property name="directory" value="${directory}"/>
<property name="file-name" value="${file-name}"/>
<property name="file-path" value="${directory}/${file-name}"/>
<echo message="Uploading ${file-name} from ${directory} to eXist-db localhost"/>
<path id="parent-dir">
<pathelement path="${directory}"/>
</path>
<fileset file="${file-path}" id="file"/>
<pathconvert targetos="unix" property="file-path.unix" refid="parent-dir">
<map from="c:" to=""/>
</pathconvert>
<condition property="is-hsg-project-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/"/>
</condition>
<fail message="ERROR: The directory ${directory} is not an hsg-project repo"
unless="${is-hsg-project-repo}"/>
<condition property="is-hsg-staging-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/hsg-staging"/>
</condition>
<propertyregex property="target-collection" input="${file-path.unix}"
regexp=".*?/hsg-project/${repos}/(hsg-staging/)?(.*)" select="/db/apps/\2"
defaultvalue="Error" override="true"/>
<property name="target-xmldb-collection-uri"
value="${local.instance.uri}${target-collection}"/>
<xdb:store user="${local.instance.user}" password="${local.instance.password}"
uri="${target-xmldb-collection-uri}" createcollection="true" createsubcollections="true">
<fileset refid="file"/>
</xdb:store>
</target>
<target name="upload-file-to-production"
description="Upload a file from an hsg-project repo to eXist-db on history.state.gov"
depends="deploy.init,validate-if-xml,ping-production">
<property name="directory" value="${directory}"/>
<property name="file-name" value="${file-name}"/>
<property name="file-path" value="${directory}/${file-name}"/>
<echo
message="Uploading ${file-name} from ${directory} to eXist-db on history.state.gov"/>
<path id="parent-dir">
<pathelement path="${directory}"/>
</path>
<fileset file="${file-path}" id="file"/>
<pathconvert targetos="unix" property="file-path.unix" refid="parent-dir">
<map from="c:" to=""/>
</pathconvert>
<condition property="is-hsg-project-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/"/>
</condition>
<fail message="ERROR: The directory ${directory} is not an hsg-project repo"
unless="${is-hsg-project-repo}"/>
<condition property="is-hsg-staging-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/hsg-staging"/>
</condition>
<fail
message="ERROR: The directory ${directory} is part of the hsg-staging repo and cannot be uploaded to the production server"
if="${is-hsg-staging-repo}"/>
<propertyregex property="target-collection" input="${file-path.unix}"
regexp=".*?/hsg-project/${repos}/(.*)" select="/db/apps/\1" defaultvalue="Error"
override="true"/>
<property name="target-xmldb-collection-uri"
value="${production.instance.uri}${target-collection}"/>
<xdb:store user="${production.instance.user}" password="${production.instance.password}"
uri="${target-xmldb-collection-uri}" ssl="true" createcollection="true"
createsubcollections="true">
<fileset refid="file"/>
</xdb:store>
</target>
<target name="delete-file-from-localhost"
description="Delete a file from an hsg-project repo from eXist-db on localhost"
depends="deploy.init">
<property name="directory" value="${directory}"/>
<property name="file-name" value="${file-name}"/>
<property name="file-path" value="${directory}/${file-name}"/>
<echo message="Deleting ${file-name} from ${directory} on eXist-db localhost"/>
<path id="parent-dir">
<pathelement path="${directory}"/>
</path>
<fileset file="${file-path}" id="file"/>
<pathconvert targetos="unix" property="file-path.unix" refid="parent-dir">
<map from="c:" to=""/>
</pathconvert>
<condition property="is-hsg-project-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/"/>
</condition>
<fail message="ERROR: The directory ${directory} is not an hsg-project repo"
unless="${is-hsg-project-repo}"/>
<propertyregex property="target-collection" input="${file-path.unix}"
regexp=".*?/hsg-project/${repos}/(hsg-staging/)?(.*)" select="/db/apps/\2"
defaultvalue="Error" override="true"/>
<property name="target-xmldb-collection-uri"
value="${local.instance.uri}${target-collection}"/>
<xdb:remove user="${local.instance.user}" password="${local.instance.password}"
uri="${target-xmldb-collection-uri}" resource="${file-name}"/>
</target>
<target name="delete-file-from-production"
description="Delete a file from an hsg-project repo from eXist-db on history.state.gov"
depends="deploy.init">
<property name="directory" value="${directory}"/>
<property name="file-name" value="${file-name}"/>
<property name="file-path" value="${directory}/${file-name}"/>
<echo message="Deleting ${file-name} from ${directory} on eXist-db localhost"/>
<path id="parent-dir">
<pathelement path="${directory}"/>
</path>
<fileset file="${file-path}" id="file"/>
<pathconvert targetos="unix" property="file-path.unix" refid="parent-dir">
<map from="c:" to=""/>
</pathconvert>
<condition property="is-hsg-project-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/"/>
</condition>
<fail message="ERROR: The directory ${directory} is not an hsg-project repo"
unless="${is-hsg-project-repo}"/>
<condition property="is-hsg-staging-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/hsg-staging"/>
</condition>
<fail
message="ERROR: The directory ${directory} is part of the hsg-staging repo and cannot be uploaded to the production server"
if="${is-hsg-staging-repo}"/>
<propertyregex property="target-collection" input="${file-path.unix}"
regexp=".*?/hsg-project/repos/(.*)" select="/db/apps/\1" defaultvalue="Error"
override="true"/>
<property name="target-xmldb-collection-uri"
value="${production.instance.uri}${target-collection}"/>
<xdb:remove user="${production.instance.user}" password="${production.instance.password}"
uri="${target-xmldb-collection-uri}" resource="${file-name}" ssl="true"/>
</target>
<target name="update-repo"
description="Pull updates for the parent repo of a file (from an hsg-project repo)"
depends="deploy.init">
<property name="directory" value="${directory}"/>
<path id="parent-dir">
<pathelement path="${directory}"/>
</path>
<pathconvert targetos="unix" property="file-path.unix" refid="parent-dir">
<map from="c:" to=""/>
</pathconvert>
<condition property="is-hsg-project-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/"/>
</condition>
<fail message="ERROR: The directory ${directory} is not an hsg-project repo"
unless="${is-hsg-project-repo}"/>
<propertyregex property="repo-name" input="${file-path.unix}"
regexp=".*/hsg-project/${repos}/([^/]+)" select="\1" defaultvalue="Error" override="true"/>
<antcall target="git.pull">
<param name="local-repo-path" value="${repos}/${repo-name}"/>
</antcall>
</target>
<target name="update-hsg-project" description="Updates the hsg-project repo">
<echo message="------------------------------------"/>
<echo message="Pulling updates for hsg-project repo"/>
<echo message="------------------------------------"/>
<exec executable="${git}" dir=".">
<arg line="checkout"/>
<arg line="HEAD"/>
<arg line="hsg-project.xpr"/>
</exec>
<exec executable="${git}" dir=".">
<arg line="pull"/>
</exec>
</target>
<target name="deploy-repo-to-localhost"
description="Packages and deploys the parent repo of a file (from an hsg-project repo) to eXist-db on localhost"
depends="deploy.init">
<path id="parent-dir">
<pathelement path="${directory}"/>
</path>
<pathconvert targetos="unix" property="file-path.unix" refid="parent-dir">
<map from="c:" to=""/>
</pathconvert>
<condition property="is-hsg-project-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/"/>
</condition>
<fail message="ERROR: The directory ${directory} is not an hsg-project repo"
unless="${is-hsg-project-repo}"/>
<condition property="is-hsg-staging-repo">
<contains string="${file-path.unix}" substring="/hsg-project/${repos}/hsg-staging"/>
</condition>
<fail
message="ERROR: The directory ${directory} is part of the hsg-staging repo and cannot be deployed"
if="${is-hsg-staging-repo}"/>
<propertyregex property="repo-name" input="${file-path.unix}"
regexp=".*/hsg-project/${repos}/([^/]+)" select="\1" defaultvalue="Error"
override="true"/>
<echo>Validating well-formedness of XML files in ${repo-name}</echo>
<xmlvalidate lenient="true">
<fileset dir="${repos}/${repo-name}" includes="**/**.xml,**/**.xconf" excludes="node_modules/**"/>
</xmlvalidate>
<subant>
<!-- set version for repos deployed to localhost during development, since CI sets versions at time of release -->
<property name="app.version" value="0.0.0-development"/>
<fileset dir="${repos}/${repo-name}">
<include name="build.xml"/>
</fileset>
</subant>
<antcall target="deploy.upload-one"/>
<antcall target="deploy.deploy-xar"/>
<antcall target="deploy.cleanup"/>
</target>
<target name="open-repo-in-github-desktop"
description="Opens an hsg-project repo in oXygen XML Editor" depends="deploy.init">
<property name="directory" value="${directory}"/>
<path id="parent-dir">
<pathelement path="${directory}"/>
</path>
<pathconvert targetos="unix" property="file-path.unix" refid="parent-dir">
<map from="c:" to=""/>
</pathconvert>
<propertyregex property="repo-basepath" input="${file-path.unix}"
regexp="(.*?/hsg-project/${repos}/[^/]*)" select="\1" defaultvalue="ERROR" override=""/>
<fail message="ERROR: The directory ${file-path.unix} is not an hsg-project repo">
<condition>
<equals arg1="${repo-basepath}" arg2="ERROR"/>
</condition>
</fail>
<exec executable="${github}" dir="${repo-basepath}">
<arg line="."/>
</exec>
</target>
<target name="open-repo-in-vscode" description="Opens an hsg-project repo in Visual Studio Code"
depends="deploy.init">
<property name="directory" value="${directory}"/>
<path id="parent-dir">
<pathelement path="${directory}"/>
</path>
<pathconvert targetos="unix" property="file-path.unix" refid="parent-dir">
<map from="c:" to=""/>
</pathconvert>
<propertyregex property="repo-basepath" input="${file-path.unix}"
regexp="(.*?/hsg-project/${repos}/[^/]*)" select="\1" defaultvalue="ERROR" override=""/>
<fail message="ERROR: The directory ${file-path.unix} is not an hsg-project repo">
<condition>
<equals arg1="${repo-basepath}" arg2="ERROR"/>
</condition>
</fail>
<propertyregex property="repo" input="${file-path.unix}"
regexp=".*?/hsg-project/${repos}/([^/]*)" select="\1" override=""/>
<copy file="${build}/vscode-existdb_tmpl.json" tofile="${repo-basepath}/.existdb.json"
overwrite="yes"/>
<replace file="${repo-basepath}/.existdb.json" token="@@@" value="${repo}"/>
<exec executable="${vscode}" dir="${repo-basepath}">
<arg line="."/>
</exec>
</target>
<target name="ping-localhost">
<condition property="exist-running">
<http requestmethod="HEAD" url="http://localhost:8080/exist/apps/dashboard/index.html"/>
</condition>
<fail unless="${exist-running}" message="eXist is not running. Please start eXist and try again."/>
</target>
<target name="ping-production">
<condition property="exist-running">
<http requestmethod="GET" url="${production.instance.http}/test"/>
</condition>
<fail unless="${exist-running}" message="The production server cannot be reached. Please confirm you are connected to the internet and try again."/>
</target>
<target name="ping-public-repo">
<condition property="public-repo-accessible">
<http requestmethod="GET" url="${eXist.public-repo}" />
</condition>
<fail unless="${public-repo-accessible}" message="The package repository at ${eXist.public-repo} cannot be reached. Please confirm you are connected to the internet and try again."/>
</target>
<!-- =================================================================== -->
<!-- Wipe eXist-db database; perform only with eXist-db shut down -->
<!-- =================================================================== -->
<target name="wipe-exist-data" description="Wipe eXist data">
<condition property="exist-running">
<http requestmethod="GET" url="http://localhost:8080/exist"/>
</condition>
<fail if="${exist-running}"
message="eXist is still running. Please shut down eXist and try again."/>
<condition property="eXist.data-exists">
<available file="${eXist.data}"/>
</condition>
<fail unless="${eXist.data-exists}" message="No eXist data was found in ${eXist.data}. This probably indicates you have just installed eXist. It could also indicate you have not run the steps required to prepare hsg-project's settings to find your eXist installation, so please consult the hsg-project setup documentation."/>
<echo message="-------------------------"/>
<echo message="Wiping eXist data"/>
<echo message="-------------------------"/>
<delete dir="${eXist.data}"/>
</target>
<target name="wipe-exist-data-with-confirmation" description="Wipe eXist data">
<property name="are-you-sure" value="${are-you-sure}"/>
<condition property="proceed">
<equals arg1="${are-you-sure}" arg2="true"/>
</condition>
<fail unless="${proceed}"
message="Halted 'Wipe eXist database' thanks to your selection of 'No'."/>
<antcall target="wipe-exist-data"/>
</target>
<target name="create-new-local-build-properties"
description="Create a new local copy of build.properties, overwriting any existing copy">
<copy file="${build}/build.properties" tofile="${build}/local.build.properties" overwrite="yes"/>
</target>
<target name="check-local-build-properties"
description="Check to make sure a local copy of build.properties is available" unless="exists-local-build-properties">
<copy file="${build}/build.properties" tofile="${build}/local.build.properties"/>
</target>
<condition property="exists-local-build-properties">
<available file="${build}/local.build.properties"/>
</condition>
<!--
Set properties for the macOS-based hsg development environment, which uses Homebrew to install dependencies
According to Homebrew's documentation, Homebrew's pre-built binary packages are installed in the following locations:
- /usr/local for macOS Intel
- /opt/homebrew for Apple Silicon
@see https://docs.brew.sh/FAQ#why-should-i-install-homebrew-in-the-default-location
For macOS, we set the $homebrew-prefix property to the appropriate location.
For other platforms, we will assume that the binaries are on the PATH and set $homebrew-prefix to an empty string.
-->
<condition property="homebrew-prefix" value="/usr/local/bin/">
<os family="mac" arch="x86_64"/>
</condition>
<condition property="homebrew-prefix" value="/opt/homebrew/bin/">
<os family="mac" arch="aarch64"/>
</condition>
<condition property="homebrew-prefix" value="">
<not>
<os family="mac"/>
</not>
</condition>
<condition property="exist-home" value="/Applications/eXist-db.app">
<os family="mac"/>
</condition>
<condition property="exist-data" value="${user.home}/Library/Application Support/org.exist">
<os family="mac"/>
</condition>
<target name="upgrade-local-build-properties"
description="Upgrade local.build.properties file to latest build.properties while preserving passwords" depends="check-local-build-properties">
<echo message="------------------------------------------------------------"/>
<echo message="Upgrading local.build.properties file (preserving passwords)"/>
<echo message="------------------------------------------------------------"/>
<propertyfile file="${build}/local.build.properties" comment="Updated with latest hsg-project settings">
<entry key="eXist.data" value="${exist-data}"/>
<entry key="eXist.home" value="${exist-home}"/>
<entry key="git" value="${homebrew-prefix}git"/>
<entry key="github" value="${homebrew-prefix}github"/>
<entry key="mvn" value="${homebrew-prefix}mvn"/>
<entry key="vscode" value="${homebrew-prefix}code"/>
<entry key="local.instance.password" value="${local.instance.password}"/>
<entry key="production.instance.user" value="${production.instance.user}"/>
<entry key="production.instance.password" value="${production.instance.password}"/>
<entry key="git.private.include" value="${git.private.include}"/>
</propertyfile>
</target>
<target name="store-production-password"
description="Store production password in local.build.properties" depends="check-local-build-properties">
<property name="password" value="${password}"/>
<propertyfile file="${build}/local.build.properties" comment="Updated with production.instance.password">
<entry key="production.instance.password" value="${password}"/>
</propertyfile>
</target>
<target name="apply-hsg-project-customizations-to-exist"
description="Apply hsg-project customizations to eXist"
depends="upgrade-local-build-properties,prepare-exist-configuration"/>
<target name="prepare-exist-configuration" depends="back-up-exist-configuration-file">
<echo message="-------------------------------------------------------"/>
<echo message="Applying hsg customizations to eXist configuration file"/>
<echo message="-------------------------------------------------------"/>
<xslt in="${eXist.home}/Contents/Resources/etc/conf-orig.xml" style="${build}/configure-exist.xsl" out="${eXist.home}/Contents/Resources/etc/conf.xml" processor="trax">
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
<classpath>
<fileset dir="${eXist.home}/Contents/Java">
<include name="Saxon*.jar"/>
</fileset>
</classpath>
<param name="target" type="STRING" expression="development"/>
</xslt>
<copy file="${build}/webdav.properties" todir="${eXist.home}/Contents/Resources/etc/" overwrite="true"/>
</target>
<target name="back-up-exist-configuration-file" unless="exist-configuration-backup-exists">
<copy file="${eXist.home}/Contents/Resources/etc/conf.xml" tofile="${eXist.home}/Contents/Resources/etc/conf-orig.xml"/>
</target>
<condition property="exist-configuration-backup-exists">
<available file="${eXist.home}/Contents/Resources/etc/conf-orig.xml"/>
</condition>
<target name="update-homebrew">
<property environment="env"/>
<echo message="-----------------"/>
<echo message="Updating Homebrew"/>
<echo message="-----------------"/>
<echo message="--------"/>
<echo message="brew tap"/>
<echo message="--------"/>
<exec executable="/usr/local/bin/brew" dir=".">
<arg line="tap"/>
</exec>
<echo message="-----------"/>
<echo message="brew update"/>
<echo message="-----------"/>
<exec executable="/usr/local/bin/brew" dir=".">
<arg line="update"/>
</exec>
<echo message="------------"/>
<echo message="brew upgrade"/>
<echo message="------------"/>
<exec executable="/usr/local/bin/brew" dir=".">
<arg line="upgrade"/>
</exec>
<echo message="------------"/>
<echo message="brew cleanup"/>
<echo message="------------"/>
<exec executable="/usr/local/bin/brew" dir=".">
<arg line="cleanup"/>
</exec>
<echo message="-----------"/>
<echo message="brew doctor"/>
<echo message="-----------"/>
<exec executable="/usr/local/bin/brew" dir="." searchpath="true">
<!-- assume path is set correctly, since our hsg-project setup directions will have us set this up correctly; see https://docs.brew.sh/FAQ.html#my-mac-apps-dont-find-usrlocalbin-utilities -->
<env key="PATH" value="/usr/local/bin:${env.PATH}"/>
<arg line="doctor"/>
</exec>
<echo message="--------------------"/>
<echo message="brew list --versions"/>
<echo message="--------------------"/>
<exec executable="/usr/local/bin/brew" dir=".">
<arg line="list"/>
<arg line="--versions"/>
</exec>
<echo message="----------------------------"/>
<echo message="brew list --casks --versions"/>
<echo message="----------------------------"/>
<exec executable="/usr/local/bin/brew" dir=".">
<arg line="list"/>
<arg line="--casks"/>
<arg line="--versions"/>
</exec>
</target>
<target name="troubleshoot" description="Generate a troubleshooting report">
<condition property="local.build.properties.exists">
<available file="build/local.build.properties" />
</condition>
<echo message="----------------------"/>
<echo message="Troubleshooting report"/>
<echo message="----------------------"/>
<echo message="Username: ${user.name}"/>
<echo message="Operating system: ${os.name} ${os.version}"/>
<antcall target="hardware-info"/>
<antcall target="disk-free-space-check"/>
<antcall target="software-update-check"/>
<antcall target="update-hsg-project"/>
<antcall target="update"/>
<antcall target="repo-status"/>
<antcall target="update-homebrew"/>
<antcall target="show-app-versions"/>
<antcall target="exist-environment"/>
<echo message="----------------------------------------------------------------------------------------------"/>
<echo message="Please copy and paste the entire report (starting with 'Troubleshooting report') into an email"/>
<echo message="----------------------------------------------------------------------------------------------"/>
</target>
<target name="exist-environment">
<echo message="-----------------"/>
<echo message="eXist environment"/>
<echo message="-----------------"/>
<echo message="Java: ${java.version}"/>
<echo message="Java home: ${java.home}"/>
<echo message="local.build.properties file found: ${local.build.properties.exists}"/>
<echo message="eXist.data: ${eXist.data}"/>
<echo message="eXist.home: ${eXist.home}"/>
</target>
<target name="hardware-info">
<echo message="--------------------"/>
<echo message="Hardware information"/>
<echo message="--------------------"/>
<exec executable="system_profiler">
<arg line="SPHardwareDataType"/>
</exec>
</target>
<target name="show-app-versions">
<echo message="--------------------------"/>
<echo message="Versions of installed apps"/>
<echo message="--------------------------"/>
<exec executable="mdls" dir="." outputproperty="exist.version">
<arg line="-raw"/>
<arg line="-name"/>
<arg line="kMDItemVersion"/>
<arg line="'/Applications/eXist-db.app'"/>
</exec>
<exec executable="mdls" dir="." outputproperty="github.version">
<arg line="-raw"/>
<arg line="-name"/>
<arg line="kMDItemVersion"/>
<arg line="'/Applications/GitHub Desktop.app'"/>
</exec>
<exec executable="mdls" dir="." outputproperty="oxygen.version">
<arg line="-raw"/>
<arg line="-name"/>
<arg line="kMDItemVersion"/>
<arg line="'/Applications/Oxygen XML Editor/Oxygen XML Editor.app'"/>
</exec>
<echo message="eXist v${exist.version}"/>
<echo message="GitHub Desktop v${github.version}"/>
<echo message="oXygen XML Editor v${oxygen.version}"/>
</target>
<target name="repo-status">
<iterate target="git.rev-parse"/>
</target>
<target name="git.rev-parse">
<echo message="${dir}"/>
<exec executable="${git}" dir="${dir}" outputproperty="git.current-commit">
<arg line="rev-parse"/>
<arg line="--short"/>
<arg line="HEAD"/>
</exec>
<echo message="Head: ${git.current-commit}"/>
<echo message="Status"/>
<exec executable="${git}" dir="${dir}">
<arg line="status"/>
</exec>
</target>
<target name="software-update-check">
<echo message="---------------------------"/>
<echo message="Checking for system updates"/>
<echo message="---------------------------"/>
<echo message="(This may take several minutes.)"/>
<exec executable="softwareupdate">
<arg line="-l"/>
</exec>
</target>
<target name="disk-free-space-check">
<echo message="---------------------------"/>
<echo message="Checking free space on disk"/>
<echo message="---------------------------"/>
<exec executable="df">
<arg line="-h"/>
</exec>
</target>
</project>