-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.xml
286 lines (270 loc) · 9.6 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
<?xml version="1.0" encoding="UTF-8"?>
<project default="xar" name="dracor" xmlns:if="ant:if">
<property environment="env"/>
<property name="build.dir" value="build"/>
<property file="local.build.properties"/>
<property file="build.properties"/>
<xmlproperty file="expath-pkg.xml.tmpl"/>
<tstamp>
<format property="timestamp" pattern="hhmmss" />
</tstamp>
<!--
inspired by
https://stackoverflow.com/questions/2974106/how-to-lookup-the-latest-git-commit-hash-from-an-ant-build-script
-->
<available file=".git" type="dir" property="git.present"/>
<target
name="git.revision"
description="Store git revision in ${package.version}"
if="git.present"
>
<exec
executable="git"
outputproperty="git.revision"
failifexecutionfails="false"
errorproperty=""
>
<arg value="describe"/>
<arg value="--tags"/>
<arg value="--always"/>
<arg value="--dirty"/>
</exec>
<!-- strip the leading 'v' from git.revision -->
<exec executable="bash" outputproperty="git.version">
<arg value="-c"/>
<arg value="echo -n ${git.revision} | sed -e 's/^v//'"/>
</exec>
<condition property="package.version" value="${git.version}" else="unknown">
<and>
<isset property="git.version"/>
<length string="${git.version}" trim="yes" length="0" when="greater"/>
</and>
</condition>
</target>
<target name="print.version" depends="git.revision">
<echo level="info" message="${package.version}"/>
</target>
<target name="create.dirs">
<mkdir dir="${build.dir}"/>
<mkdir dir="${dependencies.dir}"/>
</target>
<target name="download.dependencies" depends="create.dirs">
<!-- get exist -->
<!-- this path may be and is subject to change! -->
<get
src="https://github.com/eXist-db/exist/releases/download/eXist-${project.processorversion}/exist-distribution-${project.processorversion}-unix.tar.bz2"
dest="${dependencies.dir}/eXist-db-${project.processorversion}.tar.bz2"
skipexisting="true" />
<!-- clean up old dependencies -->
<delete>
<fileset dir="${dependencies.dir}" includes="*.xar"/>
</delete>
<!-- get dependencies -->
<get
src="https://github.com/eXist-db/expath-crypto-module/releases/download/6.0.1/expath-crypto-module-6.0.1.xar"
dest="${dependencies.dir}/expath-crypto-module-6.0.1.xar"
skipexisting="true"
ignoreerrors="true"/>
<get
src="https://ci.de.dariah.eu/exist-repo/public/openapi-1.7.0.xar"
dest="${dependencies.dir}/openapi-1.7.0.xar"
skipexisting="true"
ignoreerrors="true"/>
</target>
<target
name="xar"
depends="create.dirs, git.revision"
description="build an expath package">
<property
name="xarfile"
value="${build.dir}/${project.abbrev}-${package.version}.xar"
/>
<property name="symlink" value="${project.abbrev}-latest.xar"/>
<delete file="${symlink}"/>
<copy
file="expath-pkg.xml.tmpl"
tofile="expath-pkg.xml"
filtering="true"
overwrite="true"
>
<filterset>
<filter token="package.version" value="${package.version}"/>
<filter token="project.title" value="${project.title}"/>
<filter token="project.abbrev" value="${project.abbrev}"/>
<filter token="project.name" value="${project.name}"/>
<filter
token="project.processorversion"
value="${project.processorversion}"/>
</filterset>
</copy>
<zip basedir="." destfile="${xarfile}"
excludes="${build.dir}/ ${devel.dir}/ test/ .* *build.properties expath-pkg.xml.tmpl"/>
<symlink
resource="${build.dir}/${project.abbrev}-${package.version}.xar"
link="${symlink}"
overwrite="true"
/>
</target>
<target name="clean" description="remove builds, cache and prepared instances">
<delete dir="${devel.dir}"/>
<delete dir="${build.dir}"/>
</target>
<target
name="devel"
depends="check.install, xar, prepare.exist, init"
description="create a development environment with dependencies included">
<!-- now eXist is set up, we can start importing DraCors. -->
<echo message="Start the database with `ant devel.startup`."/>
<echo message="Use `ant load.corpus` to populate the database."/>
</target>
<target name="init">
<exec executable="bash">
<arg value="resources/ant/init.sh"/>
<arg value="${jetty.http.port}"/>
<arg value="${basedir}/${install.dir}"/>
</exec>
<copy file="${xarfile}" todir="${install.dir}/autodeploy" />
</target>
<target name="set.ports">
<!-- HTTP port -->
<property name="xsl" value="resources/ant/jetty-port-update.xslt"/>
<xslt
in="${install.dir}/etc/jetty/jetty-http.xml"
out="${install.dir}/etc/jetty/jetty-http-tmp.xml"
style="${xsl}">
<param name="customPort" expression="${jetty.http.port}"/>
</xslt>
<move
file="${install.dir}/etc/jetty/jetty-http-tmp.xml"
tofile="${install.dir}/etc/jetty/jetty-http.xml"/>
<!-- HTTPS port -->
<xslt
in="${install.dir}/etc/jetty/jetty-ssl.xml"
out="${install.dir}/etc/jetty/jetty-ssl-tmp.xml"
style="${xsl}">
<param name="customPort" expression="${jetty.https.port}"/>
</xslt>
<move
file="${install.dir}/etc/jetty/jetty-ssl-tmp.xml"
tofile="${install.dir}/etc/jetty/jetty-ssl.xml"/>
<xslt
in="${install.dir}/etc/jetty/jetty.xml"
out="${install.dir}/etc/jetty/jetty-tmp.xml"
style="${xsl}">
<param name="customPort" expression="${jetty.https.port}"/>
</xslt>
<move
file="${install.dir}/etc/jetty/jetty-tmp.xml"
tofile="${install.dir}/etc/jetty/jetty.xml"/>
</target>
<target name="prepare.exist" depends="download.dependencies">
<echo message="install eXist to ${install.dir}"/>
<!-- extract eXist -->
<untar
src="${dependencies.dir}/eXist-db-${project.processorversion}.tar.bz2"
dest="${devel.dir}"
compression="bzip2" />
<move todir="${devel.dir}/eXist-db-${project.processorversion}">
<fileset dir="${devel.dir}/exist-distribution-${project.processorversion}" />
</move>
<!-- task setpermissions requires at least ant 1.10.0 -->
<setpermissions mode="755">
<file file="${devel.dir}/eXist-db-${project.processorversion}/bin/startup.sh"/>
</setpermissions>
<!-- move xar dependencies to autodeploy -->
<copy todir="${install.dir}/autodeploy">
<fileset dir="${dependencies.dir}">
<include name="*.xar"/>
</fileset>
</copy>
<antcall target="set.ports"/>
</target>
<target name="check.install">
<condition property="install.available">
<available file="${install.dir}" type="dir" />
</condition>
<fail if="install.available">...
The directory '${install.dir}' already exists. Delete it before setting up a new one!
</fail>
</target>
<target name="devel.startup">
<condition property="devel.available">
<available file="${devel.dir}/eXist-db-${project.processorversion}/bin/startup.sh" />
</condition>
<fail if="!devel.available">
Startup script not available. Run `ant devel` first.
</fail>
<exec executable="bash">
<env key="DRACOR_API_BASE" value="${devel.api.base}"/>
<env key="FUSEKI_SECRET" value="${devel.fuseki.secret}"/>
<env key="GITHUB_WEBHOOK_SECRET" value="${devel.webhook.secret}"/>
<arg value="${devel.dir}/eXist-db-${project.processorversion}/bin/startup.sh"/>
</exec>
</target>
<target name="devel.shutdown">
<property
name="shutdown.script"
value="${devel.dir}/eXist-db-${project.processorversion}/bin/shutdown.sh"
/>
<condition property="devel.available">
<available file="${shutdown.script}"/>
</condition>
<fail if="!devel.available">
Shutdown script not available. Run `ant devel` first.
</fail>
<exec executable="bash">
<arg value="${shutdown.script}"/>
</exec>
</target>
<target name="load.corpus">
<echo level="info" message="Adding corpus '${corpus}' to database..." />
<exec executable="curl">
<arg value="-s"/>
<arg value="-XPOST"/>
<arg value="-uadmin:"/>
<arg value="http://localhost:${jetty.http.port}/exist/restxq/corpora"/>
<arg value="-H"/>
<arg value="Content-Type: application/json"/>
<arg value="-d@corpora/${corpus}.json"/>
</exec>
<echo level="info" message="Loading data for corpus '${corpus}'..." />
<exec executable="curl">
<arg value="-s"/>
<arg value="-XPOST"/>
<arg value="-uadmin:"/>
<arg value="http://localhost:${jetty.http.port}/exist/restxq/corpora/${corpus}"/>
<arg value="-H"/>
<arg value="Content-Type: application/json"/>
<arg value="-d"/>
<arg value="{"load":true}"/>
</exec>
</target>
<target
name="atom.config"
description="create .existdb.json for integration with Atom editor"
>
<property name="atom.config.target" value=".existdb.json"/>
<condition property="existdb.json.available">
<available file="${atom.config.target}"/>
</condition>
<input
message="Overwrite existing ${atom.config.target}?"
validargs="y,n"
addproperty="yes.or.no"
if:true="${existdb.json.available}"
/>
<condition property="overwrite" else="false">
<equals arg1="${yes.or.no}" arg2="y"/>
</condition>
<copy
file=".existdb.json.tmpl"
tofile="${atom.config.target}"
filtering="true"
overwrite="${overwrite}"
>
<filterset>
<filter token="jetty.http.port" value="${jetty.http.port}"/>
</filterset>
</copy>
</target>
</project>