-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.xml
252 lines (238 loc) · 13.2 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
<?xml version="1.0" encoding="UTF-8"?>
<!--
A build script for the XQuery Institute's Demo App
Since eXist-db's XQuery is usually edited in the database via eXide, this script
works to keep the eXist-db and Git repository on the local file system in sync.
Workflow:
1) Keep a 'master' Git repository and a local branch (I named mine 'ksclarke')
2) Pull changes down from 'master' and merge them into 'ksclarke'
3) Once file system and upstream Git (i.e. 'master') are like you want them in the
local 'ksclarke' branch, run (on the command line, from that branch):
ant dump-db-files
This will dump the changes (the most recent versions from eXist-db) to the file
system where Git can be used to compare changes from the database with changes
from other the developers upstream.
4) Merge database changes and upstream developer's changes into 'ksclarke' branch
5) Now to push the changes from the file system (which include the changes from the
upstream developer (and the most recent eXist-db changes) back to eXist-db, run:
ant update-db
This will write the contents of the file system into the database, destructively
overwriting the files that live in the eXist-db.
6) Rinse. Wash. Repeat.
Author: Kevin S. Clarke <[email protected]>
Last Updated: 2014/06/11
-->
<project default="xar" name="${project.app}" xmlns:xdb="http://exist-db.org/ant">
<!-- Properties that may vary depending on developer's configuration -->
<property file="build.properties"/>
<!-- Properties that should be consistent across developer builds -->
<property name="project.version" value="0.1"/>
<property name="project.app" value="xq-institute"/>
<property name="build.dir" value="build"/>
<!-- Creates a classpath using ${exist.home} (defined in build.properties) -->
<path id="classpath.core">
<fileset dir="${exist.home}/lib/core">
<include name="*.jar"/>
</fileset>
<pathelement path="${exist.home}/exist.jar"/>
<pathelement path="${exist.home}/exist-optional.jar"/>
</path>
<!-- Pulls in the eXist-db ant extensions from the project's ${classpath.core} -->
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="classpath.core"/>
</typedef>
<!-- Dumps the current state from the database to the Git file system-->
<target name="dump-db-files">
<xdb:extract destdir="." subcollections="true" createdirectories="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}" overwrite="true"
user="${db.username}" password="${db.password}" /> <!-- u/p should be configured in build.properties -->
<!-- We have to rename files because eXist-db's Ant task only expects to output XML files -->
<move todir="." verbose="false">
<fileset dir="." includes="**/*"/>
<globmapper from="*.xsl.xml" to="*.xsl"/>
</move>
<move todir="." verbose="false">
<fileset dir="." includes="**/*"/>
<globmapper from="*.html.xml" to="*.html"/>
</move>
<move todir="." verbose="false">
<fileset dir="." includes="**/*"/>
<globmapper from="*.xconf.xml" to="*.xconf"/>
</move>
<move todir="." verbose="false">
<fileset dir="." includes="**/*"/>
<globmapper from="*.svg.xml" to="*.svg"/>
</move>
</target>
<!-- Updates (destructively) the eXist-db with files from the file system -->
<!-- This has grown out of control... would be better to reimplement with a single executed XQuery -->
<target name="update-db">
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir=".">
<!-- We don't need build script in eXist-db and it would lose its comments on export from there -->
<exclude name="build.xml"/>
<include name="*.xml"/>
<include name="*.xql"/>
<include name="*.html"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/system/config/db/apps/${project.app}"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="system/config/db/apps/${project.app}">
<include name="collection.xconf"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/system/config/db/apps/${project.app}/data/indexed-plays/"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="system/config/db/apps/${project.app}/data/indexed-plays">
<include name="collection.xconf"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/data/plays"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="data/plays">
<include name="*.xml"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/data/indexed-plays"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="data/indexed-plays">
<include name="*.xml"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/modules"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="modules">
<include name="*.xqm"/>
<include name="*.xql"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/templates"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="templates">
<include name="*.html"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/slides"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="slides">
<include name="*.html"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/demos"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="demos">
<include name="*.html"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/resources/css"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="resources/css">
<include name="*.css"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/resources/fonts"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="resources/fonts">
<include name="*.eot"/>
<include name="*.svg"/>
<include name="*.ttf"/>
<include name="*.woff"/>
<include name="*.xml"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/resources/css/theme"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="resources/css/theme">
<include name="*.css"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/resources/css/print"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="resources/css/print">
<include name="*.css"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/resources/xsl"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="resources/xsl">
<include name="*.xsl"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/resources/js"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="resources/js">
<include name="*.js"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/resources/js/highlight"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="resources/js/highlight">
<include name="*.js"/>
</fileset>
</xdb:store>
<xdb:store createcollection="true" createsubcollections="true"
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/resources/js/print-pdf"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
<fileset dir="resources/js/print-pdf">
<include name="*.js"/>
</fileset>
</xdb:store>
<xdb:xquery
uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/apps/${project.app}/"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
xquery version "3.0";
import module namespace sm = "http://exist-db.org/xquery/securitymanager";
import module namespace dbutil = "http://exist-db.org/xquery/dbutil";
dbutil:scan(xs:anyURI("/db/apps/${project.app}"), function($collection, $resource) {
if ($resource and ends-with($resource, '.xql'))
then (sm:chgrp($resource, 'guest'), sm:chmod($resource, 'rwxr-xr-x'))
else if ($resource)
then sm:chgrp($resource, 'guest')
else sm:chgrp($collection, 'guest')
})
</xdb:xquery>
</target>
<target name="reindex-plays">
<property name="server-uri" value="xmldb:exist://localhost:8080/exist/xmlrpc"/>
<property name="collection" value="/db/apps/${project.app}/data"/>
<echo message="Reindexing '${collection}' collection on ${server-uri}"/>
<xdb:xquery uri="${server-uri}/db" outputproperty="result"
user="${db.username}" password="${db.password}"> <!-- u/p should be configured in build.properties -->
xquery version "3.0";
import module namespace xmldb="http://exist-db.org/xquery/xmldb";
let $start-time := util:system-time()
let $reindex := xmldb:reindex('/db/apps/${project.app}/data')
let $end-time := util:system-time()
let $runtime-ms := (($end-time - $start-time) div xs:dayTimeDuration('PT1S')) * 1000
return $runtime-ms
</xdb:xquery>
<echo message="Reindex performed in ${result} milliseconds."/>
</target>
<!-- Builds the XAR package for the XQuery Institute demo application -->
<target name="xar">
<mkdir dir="${build.dir}"/>
<zip basedir="." destfile="${build.dir}/${project.app}-${project.version}.xar" excludes="${build.dir}/*"/>
</target>
<!-- Deletes the build directory, including previously built XAR packages -->
<target name="clean">
<delete dir="${build.dir}"/>
</target>
</project>