root/main/trunk/greenstone3/build.xml @ 32697

Revision 32697, 188.0 KB (checked in by davidb, 20 months ago)

Updated to work with apache-tomcat-8.x

Line 
1<?xml version="1.0"?>
2<!-- ======================================================================
3     March 2005                                                   
4
5     Greenstone3 build and install script
6                 
7     kjdon                                                               
8     ====================================================================== -->
9<project name="greenstone3" default="usage" basedir=".">
10  <echo>os.name: ${os.name}</echo>
11
12  <!-- ============ classpath =================== -->
13  <path id="project.classpath">
14    <fileset dir="lib/java">
15      <include name="**/*.jar"/>
16    </fileset>
17  </path>
18 
19  <!-- ============ self defined tasks =================== -->
20  <taskdef name="mysetproxy" classname="org.greenstone.anttasks.MySetProxy" classpathref="project.classpath"/>
21  <taskdef name="getuserandpassword" classname="org.greenstone.anttasks.MyGetUserAndPassword" classpathref="project.classpath"/>
22  <taskdef name="rsr" classname="org.greenstone.anttasks.RegexSearchReplace" classpathref="project.classpath"/>
23  <!--<taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="project.classpath"/>-->
24  <taskdef name="if" classname="ise.antelope.tasks.IfTask" classpathref="project.classpath"/>
25  <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpathref="project.classpath"/>
26  <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" classpathref="project.classpath"/>
27
28 
29  <!-- ===================== Property Definitions =========================== -->
30 
31  <!--
32
33  Each of the following properties are used in the build script.
34  Values for these properties are set by the first place they are
35  defined, from the following list:
36
37  * Definitions on the "ant" command line (ant -Dfoo=bar compile).
38
39  * Definitions from a "build.properties" file in the top level
40  source directory of this application.
41
42  * Definitions from a "build.properties" file in the user's
43  home directory.
44
45  * Default definitions in this build.xml file.
46
47  You will note below that property values can be composed based on the
48  contents of previously defined properties.  This is a powerful technique
49  that helps you minimize the number of changes required when your development
50  environment is modified.  Note that property composition is allowed within
51  "build.properties" files as well as in the "build.xml" script.
52
53  -->
54
55  <!-- Developer property. Set value=true if you want test https certificates issued
56       (as there's a limit on how many real certificates you can be issued per week).
57       If not testing can either uncomment this property or set value=false.
58       BEWARE: iff test.mode is true (so https.testing gets set to minus-minus-staging)
59       AND the default protocol is https (server.protocols contains https first), the
60       check-tomcat-running target and any other targets running an ant http condition
61       to test the default GS DL URL (which will be over https) won't work.
62       This is because the testing certificate is not trusted by clients, in this case
63       the ant http condition. (Clients that are browsers can be set to temporarily
64       trust the testing certificate, but don't know how to make ant do that, maybe it
65       needs to be done at Java level.)
66       Ant socket conditions to the URL will work because socket tests don't use
67       the protocol, just the host and port.
68  -->
69  <property name="https.test.mode" value="false"/>
70  <property name="sudo.or.not" value="/bin/bash"/><!-- by default, we don't run even special commands with sudo -->
71
72  <property name="os.linux" value="Linux"/>
73  <property name="os.mac" value="Mac OS X"/>
74  <property name="os.solaris" value="SunOS"/>
75  <property name="os.unix" value="${os.linux},${os.mac},${os.solaris}"/>
76  <property name="os.windows" value="Windows 95,Windows 98,Windows 2000,Windows 2003,Windows XP,Windows NT,Windows ME,Windows Vista,Windows 7,Windows Server 2008,Windows Server 2008 R2"/> <!-- check this!!!-->
77
78  <!-- this is true for linux and macs -->
79  <condition property="current.os.isunix">
80    <os family="unix"/>
81  </condition>
82 
83  <condition property="current.os.isunixnotmac">
84    <and>
85      <os family="unix"/>
86      <not>
87    <os family="mac"/>
88      </not>
89    </and>
90  </condition>
91 
92  <condition property="current.os.ismac">
93    <os family="mac"/>
94  </condition>
95 
96  <condition property="current.os.iswindows">
97    <os family="windows"/>
98  </condition>
99
100  <!-- create build.properties if it has not been created yet -->
101  <if>
102    <bool><not><available file="build.properties"/></not></bool>
103    <copy file="build.properties.svn" tofile="build.properties"/>
104    <property name="first.run" value="true"/>
105  </if>
106
107  <!-- create the packages dir if it has not been created yet -->
108  <mkdir dir="packages"/>
109 
110  <!--the first three properties have to be put on the top to be used by build.properties-->
111  <property name="gs2build.home" value="${basedir}${file.separator}gs2build"/>
112  <property name="src.packages.home" value="${basedir}/src/packages"/>
113  <property name="flax.svn.root" value="http://svn.greenstone.org/flax"/>
114
115  <property name="solr-ext.home" value="${basedir}/ext/solr"/>
116
117  <property file="build.properties"/>
118  <if><bool><available file="${user.home}/build.properties"/></bool>
119    <property file="${user.home}/build.properties"/>
120  </if>
121
122  <if>
123    <bool><not><matches string="${server.protocols}" pattern="^\s*(https?|http\s*,\s*https|https\s*,\s*http)\s*$"/></not></bool>
124    <fail>@@@@
125      In file build.properties: invalid value for server.protocols.
126      It must contain http or https, or both (in order of preference) separated by commas.
127    </fail>
128  </if>
129
130  <!--
131       * "valid ports range from 1024–49151" is probably about user assignable ports.
132       But 80 is a valid port for running web servers including GS
133       and in future the range may become greater, so don't restrict the port range to 1024-49151.
134       https://stackoverflow.com/questions/113224/what-is-the-largest-tcp-ip-network-port-number-allowable-for-ipv4
135  -->
136    <if>
137      <bool>
138    <not><matches string="${localhost.port.http}" pattern="^\d{2,}\s*$"/></not>
139      </bool>
140      <fail>...
141    ********* ERROR: localhost.port.http in file build.properties is set to an invalid port number.
142    If port 80 is not possible, user assignable ports range from 1024–49151.
143    But don't choose any port already in use by another application.
144    Try setting to localhost.port.http=8383
145      </fail>
146    </if>
147
148    <!-- if server.protocols contains https, ensure its port number is valid -->
149    <if>
150      <bool>
151      <and>
152        <matches string="${server.protocols}" pattern="https"/>
153        <not><matches string="${tomcat.port.https}" pattern="^\d{2,}\s*$"/></not>
154      </and>
155      </bool>
156      <fail>...
157    ********* ERROR: in file build.properties, server.protocols includes https but
158    tomcat.port.https is set to an invalid port number.
159    If port 443 is not possible, user assignable ports range from 1024–49151.
160    But don't choose any port already in use by another application.
161    Try setting tomcat.port.https=8443
162      </fail>
163    </if>
164
165    <!--
166     Bail if https is enabled but the keystore password (keystore.pass property) is not set.
167     However, keystore.pass has no default value and is therefore not set as a rule.
168     So don't bail when 'ant' is run for the first time to create build.props from build.props.svn.
169     But do bail if running ant.prepare and https enabled and password not set.
170     (Maybe put this entire section before the first target: so we only bail after all non-targets
171     are executed so that any other first ever initialisation is completed?)
172    -->
173    <if>
174      <bool>
175    <and>
176      <matches string="${server.protocols}" pattern="https"/>
177      <or>
178        <not><isset property="keystore.pass"/></not>
179        <matches string="${keystore.pass}" pattern="^\s*$"/>
180      </or>
181    </and>
182      </bool>
183      <if>
184    <bool><isset property="first.run"/></bool>
185    <echo>IMPORTANT: In file build.properties, when property server.protocols includes https,
186    as now, the keystore.pass property must be set to a non-empty value.
187    Either set server.protocols to http by itself, if you don't want support for https,
188    or set keystore.pass if you do want https support.</echo>
189    <else>
190      <fail>...
191      ********* ERROR: server.protocols contains https in file build.properties, but the keystore.pass
192      property required for obtaining/renewing the https certificate is not set or is set to the empty
193      string. Choose a password for keystore.pass and set it in build.properties before proceeding.
194      </fail>
195    </else>
196      </if>
197    </if>
198
199    <!-- Set the keystore file name for linux versus windows. Ultimately unused/inactive if HTTPS
200     isn't enabled and no certificate obtained. We don't yet have https certification on mac -->
201    <condition property="keystore.file" value="fullchain_and_prvtkey.pfx" else="fullchain_and_prvtkey.p12">
202      <istrue value="${current.os.iswindows}"/>
203    </condition>   
204
205    <!-- Originally, https redirectPort when using regular http port 8383
206     was always fixed at 8443. Now we use redirectPort=tomcat.port.https.
207    -->
208    <property name="https.redirect.port" value="${tomcat.port.https}"/>
209
210    <!-- The default protocol to be used is the FIRST in the comma separated list for server.protocols
211    The default public tomcat port depends on the default server protocol
212    -->
213    <if>
214      <bool><matches string="${server.protocols}" pattern="^https"/></bool>
215      <property name="default.server.protocol" value="https"/>
216      <property name="default.tomcat.port" value="${tomcat.port.https}"/>     
217      <else>
218    <property name="default.server.protocol" value="http"/>
219    <property name="default.tomcat.port" value="${localhost.port.http}"/>   
220      </else>
221    </if>
222   
223
224    <!-- For setting filter tokens.
225     Used to set up server.xml when configuring tomcat -->
226    <property name="comment.start" value="&lt;!--" />
227    <property name="comment.end" value="--&gt;" />
228
229    <!--
230     If https is enabled, regardless of whether it is the default protocol,
231     there's some more work to do:
232     -
233     - if https is not enabled, comment out its Connecter element in server.xml
234    -->   
235    <if>
236      <bool><matches string="${server.protocols}" pattern="https"/></bool>     
237      <property name="https.comment.out.start" value=""/>
238      <property name="https.comment.out.end" value=""/>
239
240      <else>   
241    <property name="https.comment.out.start" value="${comment.start}"/>
242    <property name="https.comment.out.end" value="${comment.end}"/>
243      </else>
244    </if>
245
246    <!-- if server.protocols doesn't contain http, then http is only to be locally available,
247     e.g. for solr servlet on 127.0.0.1
248     In that case, see https://serverfault.com/questions/218666/how-to-configure-tomcat-to-only-listen-to-127-0-0-1
249    -->
250    <condition property="restrict.http.to.local" value="false" else="true">
251      <matches string="${server.protocols}" pattern="http($|\s+|,)"/>
252    </condition>
253   
254    <condition property="http.address.restriction" value="address=&quot;127.0.0.1&quot;" else="">
255      <istrue value="${restrict.http.to.local}"/>
256    </condition>
257
258    <!-- No certificates for localhost: https://letsencrypt.org/docs/certificates-for-localhost/
259    But 'localhost' (or actually, 127.0.0.1) needed for solr: solr servlet not accessible to outside world
260    -->
261    <condition property="local.http.url" value="http://${localhost.server.http}" else="http://${localhost.server.http}:${localhost.port.http}">
262      <equals arg1="${localhost.port.http}" arg2="80" trim="true"/>
263    </condition>
264
265    <!-- On linux, if testing https certification, pass in minus-minus-staging. If not testing on linux, nothing extra to pass in.
266         On windows or mac, if testing https certification, nothing extra to pass in. If not testing on windows or mac, pass in minus-minus-live.
267    -->
268    <if><bool><istrue value="${current.os.isunixnotmac}"/></bool>   
269        <condition property="https.testing" value="" else="--staging">
270            <isfalse value="${https.test.mode}"/>
271        </condition>
272    </if>
273    <if><bool><or><istrue value="${current.os.iswindows}"/><istrue value="${current.os.ismac}"/></or></bool>
274        <condition property="https.testing" value="--live" else="">
275            <isfalse value="${https.test.mode}"/>
276        </condition>
277        <!-- Set bitness of windows OS, so we can use it for the zeroSSL executable.
278            The Java system property os.arch will return x86 for 32 bit and AMD64 (or x64) for 64 bit OS.
279            See https://stackoverflow.com/questions/20856694/how-to-find-the-os-bit-type -->
280        <condition property="os.bitness" value="64" else="32">
281            <matches string="${os.arch}" pattern="64"/>
282        </condition>         
283    </if>
284
285  <!-- now we've read in properties, apply defaults -->
286  <property name="disable.collection.building" value="false"/>
287
288  <!-- get properties from the environment -->
289  <property environment="env"/>
290
291  <!-- get the filesets defining components and executables -->
292  <import file="resources/xml/components.xml"/>
293  <import file="resources/xml/executables.xml"/>
294   
295  <!-- version properties for external packages -->
296  <!-- for Java versions < 1.4, we print out the message that Java is too old.
297    For Java 1.4, we use Tomcat 5.5, for Java5 and higher, we use Tomcat 8.x-->
298  <condition property="tomcat.version" value="apache-tomcat-5.5.25" else="apache-tomcat-8.5.35">
299    <equals arg1="1.4" arg2="${ant.java.version}"/>
300  </condition>
301  <condition property="tomcat.version.major" value="5" else="8">
302    <equals arg1="1.4" arg2="${ant.java.version}"/>
303  </condition>
304  <condition property="privileged.attribute" value="privileged='true'" else="">
305    <equals arg1="8" arg2="${tomcat.version.major}"/>
306  </condition>
307
308  <!-- external access to the GS3 pages or not
309       https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html -->
310  <condition property="allowed.IPs"
311         value=".*"
312         else="(127\.0\.0\.1|::1|0:0:0:0:0:0:0:1)">
313    <matches pattern="^(1|true|yes)$" string="${server.external.access}"/>
314  </condition>
315
316  <property name="axis.zip.version" value="axis-bin-1_4.zip"/>
317  <property name="axis.dir.version" value="axis-1_4"/>
318  <property name="sqlite.targz.version" value="sqlite-autoconf-3070602.tar.gz"/>
319
320  <property name="build.home" value="${basedir}/build"/>
321  <property name="src.home" value="${basedir}/src/java"/>
322
323  <if><bool><istrue value="${gsdl3home.isreadonly}"/></bool>
324    <property name="readonly-packages.home" value="${basedir}/packages"/>
325    <property name="packages.home" value="${gsdl3.writablehome}/packages"/>
326    <!--
327     To run solr from a read-only location (like a DVD-ROM), its locktype needs to be "single",
328     else solr tries to write out a lock file to the collection's index folder which is read-only.
329
330     https://cwiki.apache.org/confluence/display/solr/IndexConfig+in+SolrConfig
331     says that the "single" locktype is "for special situations of a read-only index directory, or ...."
332     
333     See also http://wiki.apache.org/lucene-java/AvailableLockFactories
334     And look for the documentation on "locktype" in solr collection's etc/conf/solrconfig.xml
335     for further information on the different locktypes.
336
337     To set the locktype property from the commandline (it's a property to the server web), pass in
338     "-Dsolr.lock.type=..." to the web server, as explained in
339     http://lucene.472066.n3.nabble.com/Where-can-we-set-the-parameters-in-Solr-Config-td4183706.html
340      -->
341    <property name="readonly.catalina.opts" value="-Dsolr.lock.type=single"/>
342  <else>
343    <property name="packages.home" value="${basedir}/packages"/>
344    <property name="readonly.catalina.opts" value=""/>
345  </else>
346  </if>
347
348  <!-- this may be set in build.properties, e.g. if you move the web dir to
349       tomcats webapps directory -->
350  <property name="web.home" value="${basedir}/web"/>
351  <property name="web.writablehome" value="${gsdl3.writablehome}"/>
352  <!-- If using a dispersed GS3 web folder, then the user web would not contain everything in the
353       default GS3 web (it won't contain a CGI or lib folder inside WEB-INF, for instance) -->
354  <if>
355    <bool><available file="${web.home}/WEB-INF/cgi" type="dir"/></bool>
356    <property name="full.web.dir" value="${web.home}"/>
357    <else>
358        <property name="full.web.dir" value="${basedir}/web"/>
359    </else>
360  </if> 
361 
362  <!-- jar files needed by applets go here -->
363  <property name="web.applet" value="${web.home}/applet"/>
364 
365  <!-- jar files needed by the servlet (and extra ones) go here -->
366  <property name="web.lib" value="${web.home}/WEB-INF/lib"/>
367  <property name="web.writablelib" value="${web.writablehome}/WEB-INF/lib"/>
368  <!-- other files needed by the servlet go here -->
369  <property name="web.classes" value="${web.home}/WEB-INF/classes"/>
370  <property name="web.writableclasses" value="${web.writablehome}/WEB-INF/classes"/>
371
372  <if>
373    <bool><istrue value="${gsdl3home.isreadonly}"/></bool>
374    <echo>Greenstone3 home directory is read-only</echo>
375    <echo>  => Writable area is: ${gsdl3.writablehome}</echo>
376
377    <condition property="gsdl3.writablehome.already-exists">
378      <available file="${gsdl3.writablehome}" type="dir"/>
379    </condition>
380
381    <if>
382      <bool><not><istrue value="${gsdl3.writablehome.already-exists}"/></not></bool>
383
384      <!-- set up writable area -->
385      <echo>No previous Greenstone home writable area detected</echo>
386      <echo>  => Setting up area</echo>
387      <mkdir dir="${gsdl3.writablehome}"/>
388      <mkdir dir="${gsdl3.writablehome}/packages"/>
389      <mkdir dir="${gsdl3.writablehome}/logs"/>
390      <mkdir dir="${gsdl3.writablehome}/ext/solr"/>
391
392      <chmod perm="a+rwx" dir="${gsdl3.writablehome}"/>
393      <chmod perm="a+rwx" dir="${gsdl3.writablehome}/packages"/>
394      <chmod perm="a+rwx" dir="${gsdl3.writablehome}/logs"/>
395      <chmod perm="a+rwx" dir="${gsdl3.writablehome}/ext/solr"/>
396
397      <!-- copy over packages tomcat folder -->
398
399      <if>
400    <bool><istrue value="${current.os.iswindows}"/></bool>
401    <copy todir="${gsdl3.writablehome}/packages/tomcat"
402          preservelastmodified="true"
403          failonerror="true" > 
404      <fileset dir="${readonly-packages.home}/tomcat" includes="**"/> 
405    </copy>
406     
407    <else>
408      <!-- else assume Unix -->
409      <!-- Can't go through the OS-independent <copy> task as it fails to preserve exec permissions -->
410      <echo>Copying to ${gsdl3.writablehome}/packages/tomcat</echo>
411      <exec executable="cp" output="/dev/null" spawn="false">
412            <arg value="-r"/>
413            <arg value="${readonly-packages.home}/tomcat"/>
414            <arg value="${gsdl3.writablehome}/packages/."/>
415      </exec>
416
417      <!-- the packages folder in tmp only has read permissions at this stage, it needs more permissions to work when running GS3 off a disc -->
418      <chmod perm="a+rwx" file="${gsdl3.writablehome}/packages/**" />
419
420    </else>
421      </if>
422     
423      <echo>  => Copying Greenstone's web/WEB-INF to writable area</echo>
424      <copy todir="${gsdl3.writablehome}/WEB-INF"
425        preservelastmodified="true"
426        failonerror="true" > 
427    <fileset dir="${full.web.dir}/WEB-INF" includes="**"/> 
428      </copy>
429
430      <copy todir="${gsdl3.writablehome}"
431        preservelastmodified="true"
432        failonerror="true" > 
433    <fileset dir="${web.home}" includes="index.html"/> 
434      </copy>
435
436    </if>
437  </if>
438
439
440  <!--- flax: the WordNet home -->
441  <property name="wn.home" value="${web.home}/WEB-INF/classes/flax/WordNet"/>
442
443  <!-- jni libraries and java wrappers go here -->
444  <property name="lib.jni" value="${basedir}/lib/jni"/>
445
446  <!-- other jar files needed for installation (but not runtime) go here -->
447  <property name="lib.java" value="${basedir}/lib/java"/>
448 
449  <property name="javadocs" value="${basedir}/docs/javadoc"/>
450
451  <property name="app.name"      value="greenstone3"/>
452  <property name="app.path"      value="/${greenstone.context}"/>
453
454   <property name="admin.dir"      value="${basedir}/admin"/>
455
456  <!-- defaults - set these on the command line or in build.properties or
457       they will take these default values-->
458  <property name="app.version" value="trunk"/>
459  <property name="branch.path" value="trunk"/>
460  <property name="branch.revision" value="HEAD"/>
461
462  <!--constants -->
463  <property name="svn.root" value="http://svn.greenstone.org"/>
464
465  <!-- catalina home is set to tomcat basedir if already installed, otherwise
466       use greenstone's tomcat -->
467  <condition property="catalina.home" value="${tomcat.installed.path}" else="${packages.home}/tomcat">
468    <and>
469      <isset property="tomcat.installed.path"/>
470      <not>
471    <equals arg1="" arg2="${tomcat.installed.path}"/>
472      </not>
473    </and>
474  </condition>
475 
476
477  <!-- is there a better way to do this?? what about solaris?? -->
478  <condition property="os.bin.dir" value="${cross.os}">
479      <istrue value="${compile.cross}"/>
480  </condition>
481  <condition property="os.bin.dir" value="windows">
482    <os family="windows"/>
483  </condition>
484  <condition property="os.bin.dir" value="darwin">
485    <os family="mac"/>
486  </condition>
487  <condition property="os.bin.dir" value="linux">
488    <and>
489      <os family="unix"/>
490      <not>
491    <os family="mac"/>
492      </not>
493    </and>
494  </condition>
495
496 
497  <condition property="collection.building.disabled">
498    <and>
499      <isset property="disable.collection.building"/>
500      <istrue value="${disable.collection.building}"/>
501    </and>
502  </condition>
503
504  <condition property="collection.building.enabled">
505    <not>
506      <istrue value="${disable.collection.building}"/>
507    </not>
508  </condition>
509 
510  <condition property="collection.building.enabled.windows">
511    <and>
512      <istrue value="${collection.building.enabled}"/>
513      <isset property="current.os.iswindows"/>
514    </and>
515  </condition>
516 
517  <condition property="collection.building.enabled.unix">
518    <and>
519      <istrue value="${collection.building.enabled}"/>
520      <isset property="current.os.isunix"/>
521    </and>
522  </condition>
523
524  <condition property="static.arg" value="LDFLAGS=-static" else=" ">
525    <isset property="compile.static"/>
526  </condition>
527
528  <!-- If building a release then we want to adjust environment variables so that the support library can be seen during compilation -->
529  <if><bool><isset property="use.gnomelib.ext"/></bool>
530    <property name="gnome-lib-dir" value="${basedir}/ext/gnome-lib-minimal/${os.bin.dir}"/>
531
532    <if><bool><isset property="env.CFLAGS"/></bool>
533        <property name="cflags.arg" value="CFLAGS=&quot;-I${gnome-lib-dir}/include ${env.CFLAGS}&quot;"/>
534    <else>
535        <property name="cflags.arg" value="CFLAGS=&quot;-I${gnome-lib-dir}/include&quot;"/>
536    </else>
537    </if>
538
539    <if><bool><isset property="env.CPPFLAGS"/></bool>
540        <property name="cppflags.arg" value="CPPFLAGS=&quot;-I${gnome-lib-dir}/include ${env.CPPFLAGS}&quot;"/>
541    <else>
542        <property name="cppflags.arg" value="CPPFLAGS=&quot;-I${gnome-lib-dir}/include&quot;"/>
543    </else>
544    </if>
545
546    <if><bool><isset property="env.CXXFLAGS"/></bool>
547        <property name="cxxflags.arg" value="CXXFLAGS=&quot;-I${gnome-lib-dir}/include ${env.CXXFLAGS}&quot;"/>
548    <else>
549            <property name="cxxflags.arg" value="CXXFLAGS=&quot;-I${gnome-lib-dir}/include&quot;"/>
550    </else>
551    </if>
552
553    <!--https://groups.google.com/forum/#!topic/openkinect/m-hfXeYwKtU
554      compiling up libwv on ElCapitan needs -framework CoreFoundation -->
555    <if><bool><isset property="env.LDFLAGS"/></bool>
556        <property name="ldflags.arg" value="LDFLAGS=&quot;-L${gnome-lib-dir}/lib ${env.LDFLAGS}&quot;"/>
557    <else>
558            <property name="ldflags.arg" value="LDFLAGS=&quot;-L${gnome-lib-dir}/lib&quot;"/>
559    </else>
560    </if>
561
562    <if><bool><isset property="env.PATH"/></bool>
563        <property name="path.arg" value="PATH=&quot;${gnome-lib-dir}/bin:${env.PATH}&quot;"/>
564    <else>
565            <property name="path.arg" value="PATH=&quot;${gnome-lib-dir}/bin&quot;"/>
566    </else>
567    </if>
568
569    <if><bool><isset property="env.PKG_CONFIG_PATH"/></bool>
570        <property name="pcpath.arg" value="PKG_CONFIG_PATH=&quot;${gnome-lib-dir}/lib/pkgconfig:${env.PKG_CONFIG_PATH}&quot;"/>
571    <else>
572            <property name="pcpath.arg" value="PKG_CONFIG_PATH=&quot;${gnome-lib-dir}/lib/pkgconfig&quot;"/>
573    </else>
574    </if>
575
576    <if><bool><equals arg1="${os.bin.dir}" arg2="darwin"/></bool>
577      <!--<if><bool><isset property="env.DYLD_LIBRARY_PATH"/></bool>
578          <property name="ldlpath.arg" value="DYLD_LIBRARY_PATH=&quot;${gnome-lib-dir}/lib:${env.DYLD_LIBRARY_PATH}&quot;"/>
579          <else>
580        <property name="ldlpath.arg" value="DYLD_LIBRARY_PATH=&quot;${gnome-lib-dir}/lib&quot;"/>
581              </else>
582          </if>
583            -->
584      <property name="ldlpath.arg" value="DYLD_LIBRARY_PATH=&quot;${env.DYLD_LIBRARY_PATH}&quot;"/>
585    <else>
586        <if><bool><isset property="env.LD_LIBRARY_PATH"/></bool>
587            <property name="ldlpath.arg" value="LD_LIBRARY_PATH=&quot;${gnome-lib-dir}/lib:${env.LD_LIBRARY_PATH}&quot;"/>
588        <else>
589            <property name="ldlpath.arg" value="LD_LIBRARY_PATH=&quot;${gnome-lib-dir}/lib&quot;"/>
590        </else>
591        </if>
592    </else>
593    </if>
594
595
596    <else>
597        <if><bool><isset property="env.CFLAGS"/></bool>
598            <property name="cflags.arg" value="CFLAGS=&quot;${env.CFLAGS}&quot;"/>
599            <else>
600            <property name="cflags.arg" value=" "/>
601        </else>
602        </if>
603
604        <if><bool><isset property="env.CPPFLAGS"/></bool>
605                <property name="cppflags.arg" value="CPPFLAGS=&quot;${env.CPPFLAGS}&quot;"/>
606            <else>
607            <property name="cppflags.arg" value=" "/>
608        </else>
609        </if>
610
611        <if><bool><isset property="env.CXXFLAGS"/></bool>
612            <property name="cxxflags.arg" value="CXXFLAGS=&quot;${env.CXXFLAGS}&quot;"/>
613        <else>
614            <property name="cxxflags.arg" value=" "/>
615        </else>
616        </if>
617
618        <if><bool><isset property="env.LDFLAGS"/></bool>
619            <property name="ldflags.arg" value="LDFLAGS=&quot;${env.LDFLAGS}&quot;"/>
620        <else>
621            <property name="ldflags.arg" value=" "/>
622        </else>
623        </if>
624
625        <if><bool><isset property="env.PATH"/></bool>
626            <property name="path.arg" value="PATH=&quot;${env.PATH}&quot;"/>
627        <else>
628            <property name="path.arg" value=" "/>
629        </else>
630        </if>
631
632        <if><bool><isset property="env.PKG_CONFIG_PATH"/></bool>
633            <property name="pcpath.arg" value="PKG_CONFIG_PATH=&quot;${env.PKG_CONFIG_PATH}&quot;"/>
634        <else>
635            <property name="pcpath.arg" value=" "/>
636        </else>
637        </if>
638
639        <if><bool><equals arg1="${os.bin.dir}" arg2="darwin"/></bool>
640            <if><bool><isset property="env.DYLD_LIBRARY_PATH"/></bool>
641                <property name="ldlpath.arg" value="DYLD_LIBRARY_PATH=&quot;${env.DYLD_LIBRARY_PATH}&quot;"/>
642            <else>
643                <property name="ldlpath.arg" value=" "/>
644            </else>
645            </if>
646        <else>
647            <if><bool><isset property="env.LD_LIBRARY_PATH"/></bool>
648                <property name="ldlpath.arg" value="LD_LIBRARY_PATH=&quot;${env.LD_LIBRARY_PATH}&quot;"/>
649            <else>
650                <property name="ldlpath.arg" value=" "/>
651            </else>
652            </if>
653        </else> 
654        </if>
655    </else>
656  </if>
657  <property name="allargs" value="${cflags.arg} ${cxxflags.arg} ${cppflags.arg} ${ldflags.arg} ${path.arg} ${ldlpath.arg} ${pcpath.arg}"/>
658
659  <condition property="opt.cross.build"
660         value="--build=${cross.build}" else=" ">
661    <isset property="cross.build"/>
662  </condition>
663
664
665  <condition property="cross.configure.args"
666         value="--host=${cross.host} ${opt.cross.build} CPP=${cross.host}-cpp CC=${cross.host}-gcc CXX=${cross.host}-g++ LD=${cross.host}-ld AR=${cross.host}-ar RANLIB=${cross.host}-ranlib STRIP=${cross.host}-strip ${cross.configure.extraargs} crossOS=${cross.os}" else=" ">
667    <istrue value="${compile.cross}"/>
668  </condition>
669
670  <!-- if we're told to work with gnome-lib, or if there's a gnome-lib-minimal that the user
671       has placed in gs2build/ext, then compile gs2build after sourcing gnome-lib environment -->
672  <condition property="opt.gnomelibext.arg"
673         value="--enable-gnome-lib-ext" else=" ">
674    <or>
675      <available file="${gs2build.home}/ext/gnome-lib-minimal" type="dir"/>
676      <istrue value="${use.gnomelib.ext}"/>
677      <istrue value="${checkout.gnomelib.ext}"/>
678    </or>
679   </condition>
680
681<!-- if you want to disable wvware, do so here: set the value (not else) field to contain minus-minus-disable-wvware -->
682  <condition property="gs2.opt.args" value="${opt.gnomelibext.arg} " else="--disable-mg --disable-mgpp --disable-accentfold --disable-gdbm --disable-sqlite">
683    <istrue value="${with.jni}"/>
684  </condition>
685  <condition property="gs2.compile.target" value="with-jni" else="without-jni">
686    <istrue value="${with.jni}"/>
687  </condition>
688  <condition property="gs2.install.target" value="install-with-jni" else="install-without-jni">
689    <istrue value="${with.jni}"/>
690  </condition>
691  <condition property="gs2.windows.enablejni" value="1" else="0">
692    <istrue value="${with.jni}"/>
693  </condition>
694  <condition property="gs2.windows.enablemg" value="1" else="0">
695    <istrue value="${with.jni}"/>
696  </condition>
697  <condition property="gs2.windows.enablemgpp" value="1" else="0">
698    <istrue value="${with.jni}"/>
699  </condition>
700  <!-- Should accent folding not also be set here ?? -->
701  <condition property="gs2.windows.usegdbm" value="1" else="0">
702    <istrue value="${with.jni}"/>
703  </condition>
704  <condition property="gs2.windows.usesqlite" value="1" else="0">
705    <istrue value="${with.jni}"/>
706  </condition>
707 
708  <!-- where is search4j tool -->
709  <condition property="search4j.exec" value="bin/search4j.exe" else="bin/search4j">
710    <isset property="current.os.iswindows"/>
711  </condition>
712
713 
714  <!-- ============= Base dirs for each package and component ============ -->
715  <property name="src.gsdl3.home" value="${src.home}/org/greenstone/gsdl3"/>
716  <property name="anttasks.home" value="${src.home}/org/greenstone/anttasks"/>
717  <property name="gli.home" value="${basedir}/gli"/>
718  <property name="javagdbm.home" value="${src.packages.home}/javagdbm"/>
719
720  <condition property="common.src.home" value="${basedir}/common-src" else="${gs2build.home}${file.separator}common-src">
721    <istrue value="${disable.collection.building}"/>
722  </condition>
723 
724  <property name="build.src.home" value="${gs2build.home}/build-src"/>
725  <property name="gdbm.home" value="${common.src.home}/packages/gdbm"/>
726  <property name="mg.home" value="${common.src.home}/indexers/mg"/>
727  <property name="mgpp.home" value="${common.src.home}/indexers/mgpp"/>
728  <property name="lucene.home" value="${common.src.home}/indexers/lucene-gs"/>
729
730  <!--  ==================== Compilation Control Options ==================== -->
731
732  <!--
733
734  These properties control option settings on the Javac compiler when it
735  is invoked using the <javac> task.
736
737  compile.debug        Should compilation include the debug option?
738
739  compile.deprecation  Should compilation include the deprecation option?
740
741  compile.optimize     Should compilation include the optimize option?
742
743  -->
744
745  <property name="compile.debug"       value="true"/>
746  <property name="compile.deprecation" value="true"/>
747  <property name="compile.optimize"    value="true"/>
748  <property name="compile.encoding"    value="UTF8"/>
749  <property name="compile.includeantruntime" value="false"/> <!-- to get rid of annoying 'ant' warning -->
750
751  <!--
752
753  Rather than relying on the CLASSPATH environment variable, Ant includes
754  features that makes it easy to dynamically construct the classpath you
755  need for each compilation.  The example below constructs the compile
756  classpath to include the servlet.jar file, as well as the other components
757  that Tomcat makes available to web applications automatically, plus anything
758  that you explicitly added.
759
760  -->
761 
762  <!-- All elements that Tomcat 5 exposes to applications -->
763  <path id="tomcat5">
764    <pathelement location="${catalina.home}/common/classes"/>
765    <fileset dir="${catalina.home}/common/endorsed">
766      <include name="*.jar"/>
767    </fileset>
768    <fileset dir="${catalina.home}/common/lib">
769      <include name="*.jar"/>
770    </fileset>
771    <!-- seems to be empty, but will leave in just in case some people make use of this to customise their install: -->
772    <pathelement location="${catalina.home}/shared/classes"/>
773    <fileset dir="${catalina.home}/shared/lib">
774      <include name="*.jar"/>
775    </fileset>
776  </path>
777 
778  <!-- All elements that Tomcat 7 exposes to applications -->
779  <path id="tomcat8">
780    <fileset dir="${catalina.home}/lib">
781      <include name="*.jar"/>
782    </fileset>
783  </path>
784 
785  <path id="compile.classpath">
786    <!-- Include all jar files and libraries in our jni lib directory -->
787    <pathelement location="${lib.jni}"/>
788    <fileset dir="${lib.jni}">
789      <include name="*.jar"/>
790    </fileset>
791    <!-- Include all jar files in our web lib directory -->
792    <pathelement location="${web.lib}"/>
793    <fileset dir="${web.lib}">
794      <include name="*.jar"/>
795    </fileset>
796   
797    <pathelement location="${lib.java}"/>
798    <fileset dir="${lib.java}">
799      <include name="*.jar"/>
800    </fileset>
801   
802    <!-- include the jar files from the source packages -->
803    <!-- mg and mgpp get installed into lib/jni but they may not be there yet
804    so we add them in by name -->
805    <!-- *** is there any way to make this optional, based on ${with.jni}? -->
806    <pathelement location="${lib.jni}/mg.jar"/>
807    <pathelement location="${lib.jni}/mgpp.jar"/>
808   
809    <!-- Include all elements that Tomcat exposes to applications -->
810    <path refid="tomcat${tomcat.version.major}"/>
811   
812  </path>
813
814  <path id="local.tomcat.classpath">
815    <!-- explicitly include the jni java wrappers in the classpath -->
816    <pathelement location="${lib.jni}"/>
817    <fileset dir="${lib.jni}">
818      <include name="*.jar"/>
819    </fileset>
820   
821    <pathelement location="${web.writablelib}"/>
822    <fileset dir="${web.writablelib}">
823      <include name="derbyclient.jar"/> <!--<include name="derby.jar"/>-->
824    </fileset>
825  </path>
826 
827  <path id="derby.server.classpath">
828    <pathelement location="${web.writablelib}/derbynet.jar"/>
829    <pathelement location="${web.writablelib}/derby.jar"/>
830  </path>
831
832 
833    <if><bool><isset property="env.PATH"/></bool>
834      <path id="local.tomcat.path">
835        <pathelement location="${basedir}/bin/script"/>
836        <pathelement location="${basedir}/bin"/>
837        <pathelement location="${lib.jni}"/>   
838        <pathelement path="${env.PATH}"/>
839        <pathelement path="${wn.home}/bin"/>
840      </path>
841      <!-- Windows can be case sensitive about env.PATH, preferring env.Path. See https://ant.apache.org/manual/Tasks/property.html  -->
842      <else><if><bool><isset property="env.Path"/></bool>
843        <path id="local.tomcat.path">
844          <pathelement location="${basedir}/bin/script"/>
845          <pathelement location="${basedir}/bin"/>
846          <pathelement location="${lib.jni}"/>
847          <pathelement path="${env.Path}"/>
848          <pathelement path="${wn.home}/bin"/>
849        </path>
850      <!-- else print error about no path set -->
851      <else>
852        <echo>No env.PATH (or env.Path) set. Unable to set local.tomcat.path property</echo>
853      </else></if></else>   
854    </if>   
855
856  <target name="test-setup">
857    <echo>ant java version=${ant.java.version}</echo>
858    <echo>is unix : ${current.os.isunix}</echo>
859    <echo>is mac : ${current.os.ismac}</echo>
860    <echo>is unixnotmac : ${current.os.isunixnotmac}</echo>
861    <echo>is windows : ${current.os.iswindows}</echo>
862    <echo>os.unix: ${os.unix}</echo>
863    <echo>env.PATH: ${env.PATH}</echo>
864    <echo>env.Path: ${env.Path}</echo> 
865  </target>
866
867  <target name="needs-gs3-setup">
868    <!-- has the gs3-setup script been run?? -->
869    <condition property="gs3-setup-not-done">
870      <not>
871    <isset property="env.GSDL3HOME"/>
872      </not>
873    </condition>
874
875    <fail if="gs3-setup-not-done" message="Please run 'gs3-setup' (Windows) or 'source gs3-setup.sh' (Linux/Mac) before starting the Greenstone server."/>
876  </target>
877
878  <!-- Appends the current env to the file environment.txt. For debugging env vars used by the release-kit. -->
879  <target name="write-env" description="Writes out the environment that this build.xml is executed in to file environment.txt. For debugging.">
880    <echo message="*****************ENVIRONMENT OUTPUT:****************${line.separator}" file="environment.txt" append="true" />
881
882    <if><bool><istrue value="${current.os.iswindows}"/></bool>
883      <exec executable="cmd" dir="${basedir}" failonerror="false" output="environment.txt" append="true">     
884    <arg value="/c" />
885    <arg value="set" />
886      </exec>
887      <else>
888    <exec executable="env" dir="${basedir}" failonerror="false" output="environment.txt" append="true" />
889      </else>
890    </if>
891
892    <echo message="${line.separator}" file="environment.txt" append="true" />
893  </target>
894
895 
896  <!-- ==================== Primary and Global Targets ============================= -->
897
898  <target name="prepare" depends="accept-properties,init,copy-dot-svn-files,prepare-core,prepare-packages,prepare-common-src,prepare-collection-building,prepare-tomcat,prepare-axis,prepare-web,prepare-collections, prepare-flax"
899    description="Use this when you first checkout the code: 'ant prepare install'. This will do some additional subversion checkouts and downloads, so you need to be online to run this.">
900
901    <!-- make sure .sh files are executable -->
902    <chmod dir="${basedir}" perm="ugo+rx"
903      includes="*.sh"/>
904    <chmod dir="${basedir}/bin/script" perm="ugo+rx"
905      includes="*.sh,*.pl"/>
906  </target>
907
908  <!-- install-common-src and install-collection-building are mutually exclusive and either one or the other will be done depending on whether collection building is enabled or not -->
909  <!--before configuring build-src, make sure that gnome-lib is compiled up-->
910  <target name="install" depends="init,compile-imagemagick,compile-gnome-lib,install-common-src,install-collection-building,install-runtime,install-solr-ext,setup-for-eclipse,get-isisgdl"
911    description="Install Greenstone 3. Use this when you first checkout the code: 'ant prepare new-install'.">
912    <echo>
913        After successful compilation, you can turn on https support on Windows and Linux (requires sudo/admin permissions)
914        by editing build.properties and running 'ant setup-https-cert'.
915    </echo>
916  </target>
917
918  <target name="install-common-src" depends="init"
919    description="Install (configure, compile, install) only the common-src package (shared code from Greenstone 2). " >
920    <antcall target="configure-common-src">
921      <param name="set.ld.path" value="true"/>
922    </antcall>
923    <antcall target="compile-common-src">
924      <param name="set.ld.path" value="true"/>
925    </antcall>
926    <antcall target="install-auxiliary-jar-files"/>
927    <antcall target="install-jni-files"/>
928  </target>
929
930  <target name="install-collection-building" depends="init" if="collection.building.enabled"
931    description="Install (configure, compile, install) the Greenstone 2 collection building package." >
932    <antcall target="configure-collection-building"/>
933    <antcall target="tweak-makefiles" />
934    <antcall target="compile-collection-building"/>
935  </target>
936   
937
938  <target name="install-runtime" depends="init,configure,configure-packages,configure-core,compile-web,compile-packages,compile-core,compile-classpath-jars"
939    description="Install (configure, compile, install) the runtime system. Needs either common-src or collection-building to have been installed first." />
940   
941  <target name="svnupdate" depends="init,svnupdate-packages,svnupdate-core,svnupdate-common-src,svnupdate-collection-building,svnupdate-web"
942    description="Do a `svn update` for all sources. Doesn't recompile the code. You need to be online to run this."/>
943 
944  <target name="configure" depends="init,configure-tomcat,configure-web"
945    description="Configure the installation (not the C++ code). Includes setting up config files. Should be re-run if you change the build.properties file, including if you change the port number."/>
946
947  <target name="clean" depends="init,clean-packages,clean-core,clean-common-src,clean-collection-building,clean-classpath-jars"
948    description="Remove all old compiled code. Includes runtime and collection-building if necessary"/>
949 
950  <target name="distclean" depends="init,distclean-packages,clean-core,distclean-common-src,distclean-collection-building,clean-classpath-jars"
951    description="Remove all compiled code and also any Makefiles etc generated during configure-c++. Includes runtime and collection-building as necessary"/>
952 
953  <target name="update" depends="init,svnupdate,clean,install"
954    description="Update (thru Subversion) all the source (including common-src or collection-building, and runtime), then clean, and re-install. To do this without any SVN updates, run it like 'ant -Dnosvn.mode=yes update'"/>
955
956
957  <target name="perl-for-building" depends="init">
958    <!-- uses perl.path if set in build.properties, otherwise try for
959         environment variable PERLPATH, and failing that assumes 'perl'
960         is on environment PATH -->
961    <!-- if, outside build.properties, we only set perl.path if we have gs2build/build-src (collection building), then we won't set perl.path in a (flax) binary, since it doesn't have build-src -->
962    <if><bool><available file="${gs2build.home}"/></bool>
963
964      <if><bool><not><isset property="perl.path"/></not></bool>
965
966        <if>
967          <bool>
968            <and>
969              <isset property="env.PERLPATH"/>
970              <not><equals arg1="${env.PERLPATH}" arg2=""/></not>
971            </and>
972          </bool>
973          <!-- set perlpath to env.PERLPATH.
974            This is the path to perl\bin that's found by findperl.bat when the server is launched
975            through GLI instead of the console.
976            For windows, this env.PERLPATH is the bin folder and needs a backslash at end, since it
977            will appear suffixed with "perl.exe" in the perl setting in packages\tomcat\config\web.xml.
978            This web.xml's path to perl is then used to find perl when running the perl scripts in the
979            cgi folder, so without a slash appended at this point it becomes "binperl" in web.xml, and
980            things will break when GLI launches the server on Windows and the online GS3 metadata editor
981            is used to save user-edited metadata. -->
982          <if><bool><istrue value="${current.os.iswindows}"/></bool>
983            <property name="perl.path" value="${env.PERLPATH}\"/>
984          <else>
985            <property name="perl.path" value="${env.PERLPATH}"/>
986          </else>   
987          </if>
988         
989          <else>
990            <echo>
991  Using PATH environment variable to locate Perl.
992            </echo>
993            <exec executable="which" os="${os.unix}" spawn="false" outputproperty="full.perl.path">
994              <arg value="perl" />
995            </exec>
996
997        <exec executable="${gs2build.home}/bin/windows/which" osfamily="windows" spawn="false" outputproperty="full.perl.path">
998              <arg value="perl" />
999            </exec>
1000
1001            <stringutil string="${full.perl.path}" property="partial.perl.path">
1002                <replace regex="\/[^\/]*$" replacement="/" />
1003            </stringutil>
1004        <stringutil string="${partial.perl.path}" property="perl.path">
1005                <replace regex="\\[^\\]*$" replacement="\\" />
1006            </stringutil>
1007            <if><bool><istrue value="${current.os.isunix}"/></bool>
1008              <if><bool><not><equals arg1="${full.perl.path}" arg2="/usr/bin/perl"/></not></bool>
1009                <echo>
1010    Non-standard location of Perl found: ${full.perl.path}
1011    Set the environment variable PERLPATH or the perl.path property in
1012    build.properties to explicitly control the version of Perl used.
1013                </echo>
1014              </if>
1015            </if>
1016          </else>
1017        </if>
1018      </if>
1019
1020      <!-- full.perl.path is for pretty-printing only, e.g. used in target "start" -->
1021      <if><bool><isset property="perl.path"/></bool>
1022        <property name="full.perl.path" value="${perl.path}${file.separator}perl"/>
1023        <else>
1024          <property name="full.perl.path" value="perl (will use the enviroment variable PATH to find this executable)"/>
1025        </else>
1026      </if>
1027
1028      <!-- gs2build not available, perl.path -->
1029      <else>
1030    <property name="perl.path" value=""/>
1031      </else>
1032    </if>
1033    <stringutil string="${perl.path}" property="escaped.perl.path">
1034      <replace regex="\\" replacement="\\\\" />
1035    </stringutil>
1036  </target>
1037
1038  <target name="get-default-servlet-url">
1039    <echo>${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}${server.default.servlet}</echo>
1040  </target>
1041
1042  <!-- returns the base local URL, something like HTTP://127.0.0.1:<HTTPport>
1043       or some sane equivalent for 127.0.0.1 -->
1044  <target name="get-local-base-http-url">
1045    <echo>${local.http.url}</echo>
1046  </target>
1047  <!-- Returns something like HTTP://127.0.0.1:<HTTPport>/greenstone3/library -->
1048  <target name="get-local-http-servlet-url">
1049    <echo>${local.http.url}${app.path}${server.default.servlet}</echo>
1050  </target>
1051
1052  <!-- solr should only be accessible locally, which therefore also means only over http.
1053  Note that for http, 127.0.0.1 is safer than localhost (as localhost can be mapped to something
1054  other than 127.0.0.1). See also https://letsencrypt.org/docs/certificates-for-localhost/ -->
1055  <target name="get-solr-servlet-url">
1056    <!--<echo>${default.server.protocol}://${tomcat.server}:${default.tomcat.port}/${solr.context}</echo>-->
1057    <echo>${local.http.url}/${solr.context}</echo>
1058  </target>
1059
1060  <target name="check-derbyserver-running">
1061    <condition property="derby.isrunning" value="true" else="false">
1062      <!--<socket server="jdbc:derby://${derby.server}" port="${derby.server.port}"/>-->
1063      <socket server="${derby.server}" port="${derby.server.port}"/><!-- like telnet machine port -->
1064    </condition>
1065    <echo>Derby is running: ${derby.isrunning}</echo>
1066  </target>
1067
1068  <!-- Need a copy of the check-derby-running target with a distinct property, because ant restart runs
1069       both stop and start, which stop and start derby respectively. Both  need check the derby socket.
1070       Because each property can be set only once during an invocation with ant, ant restart will need
1071       two check-derbyserver properties, one for each derby check. -->
1072  <target name="check-derbyserver-started">
1073    <condition property="derby.isstarted" value="true" else="false">
1074      <socket server="${derby.server}" port="${derby.server.port}"/>
1075    </condition>
1076    <echo>Derby is running: ${derby.isstarted}</echo>
1077  </target>
1078
1079
1080  <!-- Unused -->
1081  <target name="start-derby-java" depends="check-derbyserver-running">
1082    <if><bool><not><istrue value="${derby.isrunning}"/></not></bool>
1083      <echo>Launching derby on ${derby.server}:${derby.server.port}...</echo>
1084      <java classname="org.apache.derby.drda.NetworkServerControl" fork="true" spawn="true" clonevm="true">     
1085    <arg value="start"/>
1086    <classpath refid="derby.server.classpath"/>
1087      </java>
1088      <else>
1089    <echo>Derby server ALREADY RUNNING on ${derby.server}:${derby.server.port}</echo>
1090      </else>
1091    </if>
1092  </target>
1093 
1094  <target name="start-derby" depends="check-derbyserver-started">
1095    <if><bool><not><istrue value="${derby.isstarted}"/></not></bool>
1096      <echo>About to launch derby on ${derby.server}:${derby.server.port}</echo>
1097      <antcall target="force-start-derby"/>
1098      <else>
1099    <echo>Derby networked server ALREADY RUNNING on ${derby.server}:${derby.server.port}</echo>
1100      </else>
1101    </if>
1102  </target>
1103
1104  <!-- Using derby 10.1.2.1
1105       See db-derby-10.1.2.1-bin/docs/html/adminguide/index.html -->
1106  <target name="force-start-derby">
1107      <property name="derby.server.classpath.prop" refid="derby.server.classpath" />
1108     
1109      <exec executable="java" spawn="true"><!-- failonerror="true"-->
1110    <env key="CLASSPATH" path="${derby.server.classpath.prop}"/>
1111    <arg value="org.apache.derby.drda.NetworkServerControl"/>
1112    <arg value="start"/>
1113    <arg value="-p"/>
1114    <arg value="${derby.server.port}"/>
1115      </exec>
1116
1117  </target>
1118
1119  <target name="force-stop-derby">
1120    <java classname="org.apache.derby.drda.NetworkServerControl">
1121      <arg value="shutdown"/>
1122      <arg value="-p"/>
1123      <arg value="${derby.server.port}"/>
1124      <classpath refid="derby.server.classpath"/>
1125    </java>
1126  </target>
1127
1128  <target name="stop-derby" description="Shutdown derby server only if running" depends="check-derbyserver-running"><!-- if="${derby.isrunning}" checks if true or false only from ant 1.8 on -->
1129    <if><bool><istrue value="${derby.isrunning}"/></bool>
1130      <!--<echo>Derby is |${derby.isrunning}| running</echo>-->
1131      <antcall target="force-stop-derby"/>
1132      <else>
1133    <echo>Derby is not running</echo>
1134      </else>
1135    </if>
1136  </target>
1137
1138  <target name="start" depends="needs-gs3-setup,init,configure-tomcat,configure-web,configure-solr-ext,start-derby,start-tomcat"
1139    description="Startup the Tomcat server." >
1140    <echo>${app.name} (${app.version}) server running using Apache Tomcat and Java</echo>
1141    <echo>Tomcat: ${catalina.home}</echo>
1142    <echo>Java  : ${java.home}</echo>
1143    <if><bool><available file="${build.src.home}"/></bool>
1144      <echo>Perl  : ${full.perl.path}</echo>
1145    </if>
1146    <if><bool><isset property="install.flax"/></bool>
1147        <property name="url" value="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}/flax"/>
1148    <else>
1149        <property name="url" value="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}/"/>
1150    </else>
1151    </if>
1152    <echo>URL   : ${url}</echo>
1153    <!-- assuming that index.html is not needed here -->   
1154
1155    <!--Now write out the url with oaiserver suffix as the baseURL property in OAIConfig.xml-->
1156    <available file="${basedir}/resources/oai/OAIConfig.xml.in" property="oaiconfig.present"/>
1157    <antcall target="init-oaiconfig">
1158      <param name="url" value="${url}"/>
1159    </antcall>
1160  </target>
1161
1162  <target name="init-oaiconfig" if="oaiconfig.present">
1163    <echo>Writing out baseURL ${url}oaiserver to ${web.writableclasses}/OAIConfig.xml</echo>
1164    <copy file="${basedir}/resources/oai/OAIConfig.xml.in" tofile="${web.writableclasses}/OAIConfig.xml"/>
1165    <rsr verbosity="1" file="${web.writableclasses}/OAIConfig.xml" pattern="&lt;baseURL&gt;.*&lt;/baseURL&gt;" replacement="&lt;baseURL&gt;${url}oaiserver&lt;/baseURL&gt;" />   
1166  </target>
1167
1168  <target name="stop" depends="init,stop-tomcat,stop-derby"
1169    description="Shutdown the Tomcat server."/>
1170 
1171  <target name="restart" description="Shutdown and restart Tomcat"  depends="init,stop,start"/>
1172
1173  <!-- =========== Help targets ===================================  -->
1174 
1175  <property name="install-command" value="ant [options] prepare install"/>
1176 
1177  <target name="usage" description="Print a help message">
1178    <echo message="  Execute 'ant -projecthelp' for a list of targets."/>
1179    <echo message="  Execute 'ant -help' for Ant help."/>
1180    <echo>
1181  To install Greenstone3, run '${install-command}'.
1182    There are properties defined in build.properties. The install
1183      process will ask you if these properties are set correctly.
1184      To avoid this prompt, use the '-Dproperties.accepted=yes'
1185      option.
1186    To log the output, use the '-logfile build.log' option.
1187  The README.txt file has more information about the ant targets
1188    and install process.
1189    </echo>
1190  </target>
1191 
1192  <target name="help" depends="usage" description="Print a help message"/>
1193 
1194  <target name="debug" depends="init" description="Display all the currently used properties">
1195    <echoproperties/>
1196  </target>
1197
1198  <!-- ====== initialization and setup targets ================== -->
1199
1200  <target name="accept-properties" unless="properties.accepted">
1201    <input addproperty="properties.ok" validargs="y,n">The following properties (among others) are being used from a build.properties file found in this directory:
1202      server.protocols=${server.protocols}     
1203      tomcat.server=${tomcat.server}
1204      tomcat.port.https=${tomcat.port.https}
1205      localhost.port.http=${localhost.port.http}
1206
1207         default.server.protocol=${default.server.protocol}
1208         default.tomcat.port=${default.tomcat.port}
1209         Local base HTTP URL used by Greenstone: ${local.http.url}
1210
1211      tomcat.installed.path=${tomcat.installed.path} (this is the location of Tomcat's base dir if it is already installed)
1212      proxy.host=${proxy.host}
1213      proxy.port=${proxy.port}
1214      disable.collection.building=${disable.collection.building}
1215      If these are not acceptable, please change them and rerun this target. Continue [y/n]?
1216    </input>
1217    <condition property="do.abort">
1218      <equals arg1="n" arg2="${properties.ok}"/>
1219    </condition>
1220    <fail if="do.abort">Build aborted by user. Please change your properties settings and re-run the target</fail>
1221  </target>
1222
1223  <!-- this sets up some initial properties -->
1224  <target name="init">
1225   
1226    <condition property="java.too.old">
1227      <or>
1228        <equals arg1="1.1" arg2="${ant.java.version}"/>
1229        <equals arg1="1.2" arg2="${ant.java.version}"/>
1230        <equals arg1="1.3" arg2="${ant.java.version}"/>
1231      </or>
1232    </condition>
1233    <fail if="java.too.old" message="You need Java 1.4 or greater to run Greenstone 3"/>
1234   
1235    <available file="${basedir}/gli" property="gli.present"/>
1236    <available file="${basedir}/common-src" property="common.src.present"/>
1237    <available file="${basedir}/gs2build" property="gs2build.present"/>
1238    <available file="${gnome-lib-dir}" property="gnome-lib.present"/>
1239
1240    <condition property="tomcat.islocal">
1241      <or>
1242        <not><isset property="tomcat.installed.path"/></not>
1243        <equals arg1="" arg2="${tomcat.installed.path}"/>
1244      </or>
1245    </condition>
1246
1247    <condition property="proxy.present">
1248      <and>
1249        <isset property="proxy.host"/>
1250        <not><equals arg1="" arg2="${proxy.host}"/></not>
1251      </and>
1252    </condition>
1253
1254    <!--
1255    the next block checks if the bundled tomcat is present in the 'packages' directory,
1256    and checks for the lethal combination of tomcat 8 and java 1.4. Test for
1257    tomcat6 is based on the presence of a file inserted by greenstone into the tomcat6
1258    download, as there is no other surefire way to check tomcat version under java 1.4
1259    -->
1260    <condition property="packages.tomcat.ispresent" value="true" else="false">
1261      <available file="packages/tomcat"/>
1262    </condition>
1263    <condition property="packages.tomcat.istomcat8" value="true" else="false">
1264      <available file="packages/tomcat/tomcat8.txt"/>
1265    </condition>
1266    <if>
1267      <bool>
1268        <and>
1269          <istrue value="${packages.tomcat.ispresent}"/>
1270          <istrue value="${packages.tomcat.istomcat8}"/>
1271          <equals arg1="1.4" arg2="${ant.java.version}"/>
1272        </and>
1273      </bool>
1274      <fail>Your Java (version 1.4) is too old to work with the bundled Apache Tomcat (version 6). Please upgrade to Java version 1.5 or greater. Alternatively, you may remove the bundled Apache Tomcat from the 'packages' folder and then run 'ant prepare-tomcat'.</fail>
1275    </if>
1276
1277  </target>
1278
1279  <target name="setup-proxy" depends="init" if="proxy.present">
1280    <condition property="ask.user">
1281      <or>
1282        <equals arg1="" arg2="${proxy.user}"/>
1283        <equals arg1="" arg2="${proxy.password}"/>
1284      </or>
1285    </condition>
1286   
1287    <getuserandpassword message="Using proxy: ${proxy.host}:${proxy.port}" if="ask.user" username="${proxy.user}" userproperty="proxy.username" pwordproperty="proxy.password"/>
1288    <mysetproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" proxyuser="${proxy.username}" proxypassword="${proxy.password}"/>
1289  </target>
1290
1291  <target name="copy-dot-svn-files" depends="init"
1292      description="Copies all resources .svn files to .in versions - which are used during configure to generate the runtime versions." >
1293    <if><bool><available file="${basedir}/resources/tomcat/greenstone3.xml.in"/></bool>
1294      <copy file="${basedir}/resources/tomcat/greenstone3.xml.in" tofile="${basedir}/resources/tomcat/greenstone3.xml.in.backup"  overwrite="true"/>
1295    </if>
1296   
1297    <copy file="${basedir}/resources/tomcat/greenstone3.xml.svn" tofile="${basedir}/resources/tomcat/greenstone3.xml.in"  overwrite="true"/>
1298    <if><bool><available file="${basedir}/resources/tomcat/server_tomcat5.xml.in"/></bool>
1299      <copy file="${basedir}/resources/tomcat/server_tomcat5.xml.in" tofile="${basedir}/resources/tomcat/server_tomcat5.xml.in.backup"  overwrite="true"/>
1300    </if>
1301    <copy file="${basedir}/resources/tomcat/server_tomcat5.xml.svn" tofile="${basedir}/resources/tomcat/server_tomcat5.xml.in"  overwrite="true"/>
1302    <if><bool><available file="${basedir}/resources/tomcat/server_tomcat7.xml.in"/></bool>
1303      <copy file="${basedir}/resources/tomcat/server_tomcat7.xml.in" tofile="${basedir}/resources/tomcat/server_tomcat7.xml.in.backup"  overwrite="true"/>
1304    </if>
1305    <copy file="${basedir}/resources/tomcat/server_tomcat8.xml.svn" tofile="${basedir}/resources/tomcat/server_tomcat8.xml.in" overwrite="true"/>
1306    <if><bool><available file="${basedir}/resources/tomcat/server_tomcat8.xml.in"/></bool>
1307      <copy file="${basedir}/resources/tomcat/server_tomcat8.xml.in" tofile="${basedir}/resources/tomcat/server_tomcat8.xml.in.backup"  overwrite="true"/>
1308    </if>
1309    <copy file="${basedir}/resources/tomcat/server_tomcat8.xml.svn" tofile="${basedir}/resources/tomcat/server_tomcat8.xml.in" overwrite="true"/>
1310    <if><bool><available file="${basedir}/resources/tomcat/web8.xml.in"/></bool>
1311      <copy file="${basedir}/resources/tomcat/web8.xml.in" tofile="${basedir}/resources/tomcat/web8.xml.in.backup"  overwrite="true"/>
1312    </if>
1313    <copy file="${basedir}/resources/tomcat/web8.xml.svn" tofile="${basedir}/resources/tomcat/web8.xml.in"  overwrite="true"/>
1314    <if><bool><available file="${basedir}/resources/oai/OAIConfig.xml.in"/></bool>
1315    <copy file="${basedir}/resources/oai/OAIConfig.xml.in" tofile="${basedir}/resources/oai/OAIConfig.xml.in.backup"  overwrite="true"/>
1316    </if>
1317    <copy file="${basedir}/resources/oai/OAIConfig.xml.svn" tofile="${basedir}/resources/oai/OAIConfig.xml.in"  overwrite="true"/>
1318    <if><bool><available file="${basedir}/resources/cgi/gsdl3site.cfg.in"/></bool>
1319      <copy file="${basedir}/resources/cgi/gsdl3site.cfg.in" tofile="${basedir}/resources/cgi/gsdl3site.cfg.in.backup" overwrite="true"/>
1320    </if>
1321    <copy file="${basedir}/resources/cgi/gsdl3site.cfg.svn" tofile="${basedir}/resources/cgi/gsdl3site.cfg.in" overwrite="true"/>
1322    <if><bool><available file="${basedir}/resources/web/global.properties.in"/></bool>
1323    <copy file="${basedir}/resources/web/global.properties.in" tofile="${basedir}/resources/web/global.properties.in.backup" overwrite="true"/>
1324    </if>
1325    <copy file="${basedir}/resources/web/global.properties.svn" tofile="${basedir}/resources/web/global.properties.in" overwrite="true"/>
1326    <if><bool><available file="${basedir}/resources/web/log4j.properties.in"/></bool>
1327    <copy file="${basedir}/resources/web/log4j.properties.in" tofile="${basedir}/resources/web/log4j.properties.in.backup" overwrite="true"/>
1328    </if>
1329    <copy file="${basedir}/resources/web/log4j.properties.svn" tofile="${basedir}/resources/web/log4j.properties.in" overwrite="true"/>
1330  </target>
1331   
1332  <!-- ========== Web app Targets ================================ -->
1333 
1334  <target name="prepare-web" depends="init">
1335    <mkdir dir="${web.writablehome}/applet"/>
1336    <mkdir dir="${web.writablehome}/logs"/>
1337    <mkdir dir="${web.writablehome}/logs/tmp"/>
1338  </target>
1339 
1340  <!-- if we are using java 1.5+, we need the xalan.jar file in web/WEB-INF/lib,  but if we are using java 1.4, we can't have it there.
1341       The test for whether we need it assumes we won't be trying to compile GS3 against Java versions less than 1.4. -->
1342  <target name="configure-java-version" depends="init"
1343    description="Activates or deactivates some jar libraries as needed depending on your java version">
1344
1345    <available property="have.xalan.jar" file="${web.lib}/xalan.jar"/>
1346    <condition property="need.xalan.jar">
1347      <or>
1348        <not><equals arg1="1.4" arg2="${ant.java.version}"/></not>
1349      </or>
1350    </condition>
1351
1352    <!-- if they have xalan.jar but dont need it -->
1353    <if>
1354      <bool>
1355        <and>
1356          <isset property="have.xalan.jar"/>
1357          <not><isset property="need.xalan.jar"/></not>
1358        </and>
1359      </bool>
1360      <antcall target="deactivate-xalan-jar"/>
1361    </if>
1362
1363    <!-- if they need xalan.jar but dont have it -->
1364    <if>
1365      <bool>
1366        <and>
1367          <not><isset property="have.xalan.jar"/></not>
1368          <isset property="need.xalan.jar"/>
1369        </and>
1370      </bool>
1371      <antcall target="activate-xalan-jar"/>
1372    </if>
1373
1374  </target>
1375 
1376  <target name="activate-xalan-jar">
1377    <echo>activating xalan.jar</echo>
1378    <copy file="${web.lib}/xalan.jar.tmp" tofile="${web.lib}/xalan.jar"/>
1379    <if>
1380      <bool>
1381    <and>
1382      <isset property="current.os.ismac"/>
1383      <available file="${catalina.home}/common/endorsed" type="dir"/>
1384    </and>
1385      </bool>
1386      <copy file="${web.lib}/xalan.jar.tmp" tofile="${catalina.home}/common/endorsed/xalan.jar"/>
1387    </if>
1388  </target>
1389
1390  <target name="deactivate-xalan-jar">
1391    <echo>deactivating xalan.jar</echo>
1392    <delete file="${web.lib}/xalan.jar"/>
1393    <!-- should we be deleting common/endorsed/xalan.jar on mac?? -->
1394  </target>
1395
1396
1397  <target name="prepare-collections" depends="init"
1398    description="Unpack all the collections from their svn zipped versions">
1399    <property name="collect.dir" value="${web.home}/sites/localsite/collect"/>
1400    <property name="index-and-archives.zip" value="index-and-archives.zip"/>
1401
1402    <echo message="installing collections..."/>
1403    <antcall target="gs2mgdemo-install"/>
1404    <antcall target="gs2mgppdemo-install"/>
1405    <antcall target="gberg-install"/>
1406    <antcall target="lucene-jdbm-demo-install"/>
1407  </target>
1408
1409  <target name="gs2mgdemo-prepare" if="collect.dir">
1410    <property name="gs2mgdemo.dir" value="${collect.dir}/gs2mgdemo"/>
1411
1412    <condition property="gs2mgdemo.present">
1413      <and>
1414        <available file="${gs2mgdemo.dir}/${index-and-archives.zip}"/>
1415      </and>
1416    </condition>
1417  </target>
1418
1419  <target name="gs2mgdemo-install" if="gs2mgdemo.present" depends="gs2mgdemo-prepare">
1420    <unzip dest="${gs2mgdemo.dir}" src="${gs2mgdemo.dir}/${index-and-archives.zip}" />
1421    <echo>collection gs2mgdemo installed</echo>
1422  </target>
1423
1424  <target name="gs2mgppdemo-prepare" if="collect.dir">
1425    <property name="gs2mgppdemo.dir" value="${collect.dir}/gs2mgppdemo"/>
1426 
1427    <condition property="gs2mgppdemo.present">
1428      <and>
1429        <available file="${gs2mgppdemo.dir}/${index-and-archives.zip}"/>
1430      </and>
1431    </condition>
1432  </target>
1433
1434  <target name="gs2mgppdemo-install" if="gs2mgppdemo.present" depends="gs2mgppdemo-prepare">
1435    <unzip dest="${gs2mgppdemo.dir}" src="${gs2mgppdemo.dir}/${index-and-archives.zip}" />
1436    <echo>collection gs2mgppdemo installed</echo>
1437  </target>   
1438
1439  <target name="gberg-prepare" if="collect.dir">
1440    <property name="gberg.dir" value="${collect.dir}/gberg"/>
1441    <available file="${gberg.dir}/index/index.zip" property="gberg.present"/>
1442  </target>
1443
1444  <target name="gberg-install" if="gberg.present" depends="gberg-prepare">
1445    <unzip dest="${gberg.dir}/index" src="${gberg.dir}/index/index.zip"/>
1446    <echo>collection gberg installed</echo>
1447  </target>
1448
1449  <target name="lucene-jdbm-demo-prepare" if="collect.dir">
1450    <property name="lucene-jdbm-demo.dir" value="${collect.dir}/lucene-jdbm-demo"/>
1451    <available file="${lucene-jdbm-demo.dir}/${index-and-archives.zip}" property="lucene-jdbm-demo.present"/>
1452  </target>
1453
1454  <target name="lucene-jdbm-demo-install" if="lucene-jdbm-demo.present" depends="lucene-jdbm-demo-prepare">
1455    <unzip dest="${lucene-jdbm-demo.dir}" src="${lucene-jdbm-demo.dir}/${index-and-archives.zip}"/>
1456    <echo>collection lucene-jdbm-demo installed</echo>
1457  </target>
1458
1459 
1460  <target name="install-solr-ext" depends="init" >
1461    <exec executable="ant.bat" osfamily="windows" dir="${solr-ext.home}" spawn="false">
1462      <arg value="add-service"/>
1463    </exec>
1464    <exec executable="ant" os="${os.unix}" dir="${solr-ext.home}" spawn="false">
1465      <arg value="add-service"/>
1466    </exec>
1467    <antcall target="solr-jdbm-demo-install"/>
1468  </target>
1469
1470  <target name="solr-jdbm-demo-prepare" if="collect.dir">
1471    <property name="solr-jdbm-demo.dir" value="${collect.dir}/solr-jdbm-demo"/>
1472    <available file="${solr-jdbm-demo.dir}/${index.zip}" property="solr-jdbm-demo.present"/>
1473  </target>
1474
1475  <target name="solr-jdbm-demo-install" if="solr-jdbm-demo.present" depends="solr-jdbm-demo-prepare">
1476    <unzip dest="${solr-jdbm-demo.dir}" src="${solr-jdbm-demo.dir}/${index.zip}"/>
1477    <echo>collection solr-jdbm-demo installed</echo>
1478  </target>
1479
1480  <!-- Until 64 bit Linux and Mac (Lion) machines can generate a working IsisGdl,
1481       use the ones generated on a 32 bit Linux and Mac (Leopard), respectively -->
1482  <target name="get-isisgdl" if="${current.os.isunix}">
1483    <exec executable="uname" dir="${basedir}" failonerror="false"
1484      outputproperty="uname.val">
1485      <arg value="-m"/>
1486    </exec>
1487   
1488    <if><bool><equals arg1="${uname.val}" arg2="x86_64"/></bool>
1489      <echo>Bitness: ${uname.val}</echo>
1490      <if><bool><contains string="${os.bin.dir}" substring="darwin" casesensitive="false"/></bool>
1491    <get src="http://www.greenstone.org/caveat-emptor/IsisGdl.macleopard"
1492             dest="${basedir}/gs2build/bin/${os.bin.dir}/IsisGdl"/>   
1493      </if>
1494      <if><bool><contains string="${os.bin.dir}" substring="linux" casesensitive="false"/></bool>
1495    <get src="http://www.greenstone.org/caveat-emptor/IsisGdl.bin32"
1496             dest="${basedir}/gs2build/bin/${os.bin.dir}/IsisGdl"/>
1497      </if>
1498      <chmod file="${basedir}/gs2build/bin/${os.bin.dir}/IsisGdl" perm="755"/>
1499    </if>
1500  </target>
1501
1502  <target name="set-perl-shebangs" depends="perl-for-building">
1503    <if>
1504      <bool>
1505        <and><isset property="perl.path"/>
1506          <not><equals arg1="${perl.path}" arg2=""/></not>
1507        </and>
1508      </bool>
1509
1510      <if><bool><istrue value="${current.os.iswindows}"/></bool>
1511    <property name="perl.exec" value="${perl.path}perl.exe"/>
1512    <else>
1513      <property name="perl.exec" value="${perl.path}perl"/>   
1514    </else>
1515      </if>
1516
1517      <!--<echo>**** PERLPATH: ${perl.path}</echo>-->
1518      <echo>Setting perl shebangs to Perl Exec: ${perl.exec}</echo>
1519
1520      <!-- set the shebangs in the cgi files to point to the correct perlpath -->
1521      <if>
1522    <bool><not><equals arg1="${web.home}" arg2="${web.writablehome}"></equals></not></bool>
1523    <mkdir dir="${web.writablehome}"/>
1524    <copy file="${full.web.dir}/WEB-INF/cgi/gliserver.pl"       tofile="${web.writablehome}/WEB-INF/cgi/gliserver.pl"       overwrite="true"/>
1525    <copy file="${full.web.dir}/WEB-INF/cgi/metadata-server.pl" tofile="${web.writablehome}/WEB-INF/cgi/metadata-server.pl" overwrite="true"/>
1526    <copy file="${full.web.dir}/WEB-INF/cgi/checksum.pl"        tofile="${web.writablehome}/WEB-INF/cgi/checksum.pl"        overwrite="true"/>
1527      </if>
1528
1529      <rsr verbosity="1" file="${web.writablehome}/WEB-INF/cgi/gliserver.pl" pattern="^#!.*" replacement="#!${perl.exec} -w" lines="1"/>
1530      <rsr verbosity="1" file="${web.writablehome}/WEB-INF/cgi/metadata-server.pl" pattern="^#!.*" replacement="#!${perl.exec} -w" lines="1"/>
1531      <rsr verbosity="1" file="${web.writablehome}/WEB-INF/cgi/checksum.pl" pattern="^#!.*" replacement="#!${perl.exec} -w" lines="1"/>     
1532      <else>
1533    <echo>WARNING: perl.path is empty. Unable to set the shebangs in the perl files in ${web.writablehome}/WEB-INF/cgi</echo>
1534      </else>
1535    </if>
1536  </target>
1537
1538  <target name="configure-web" depends="init,perl-for-building"
1539    description="Configure only the web app config files">
1540    <!-- we want a unix path in the global.properties file -->
1541    <pathconvert targetos="unix" property="src.gsdl3.home.unix">
1542      <path path="${web.home}"/>
1543    </pathconvert>
1544    <pathconvert targetos="unix" property="src.gsdl3.writablehome.unix">
1545      <path path="${web.writablehome}"/>
1546    </pathconvert>
1547
1548    <antcall target="set-perl-shebangs" inheritAll="true" />
1549   
1550    <filter token="gsdlhome" value="${gs2build.home}"/>
1551    <filter token="gsdlhomequoted" value="&quot;${gs2build.home}&quot;"/>
1552    <filter token="gsdl3srchome" value="${basedir}"/>
1553    <filter token="gsdl3srchomequoted" value="&quot;${basedir}&quot;"/>
1554    <filter token="gsdl3home" value="${src.gsdl3.home.unix}"/>
1555    <filter token="gsdl3homequoted" value="&quot;${src.gsdl3.home.unix}&quot;"/>
1556    <filter token="gsdl3writablehome" value="${src.gsdl3.writablehome.unix}"/>
1557    <filter token="gsdl3version" value="${app.version}"/>
1558    <filter token="server.protocols" value="${server.protocols}"/>
1559    <filter token="default.server.protocol" value="${default.server.protocol}"/>
1560    <filter token="tomcat.server" value="${tomcat.server}"/>
1561    <filter token="default.tomcat.port" value="${default.tomcat.port}"/>
1562    <filter token="localhost.server.http" value="${localhost.server.http}"/>
1563    <filter token="localhost.port.http" value="${localhost.port.http}"/>
1564    <filter token="tomcat.port.https" value="${tomcat.port.https}"/>
1565    <filter token="restrict.http.to.local" value="${restrict.http.to.local}"/>
1566    <filter token="greenstone.context" value="${greenstone.context}"/>
1567    <filter token="solr.context" value="${solr.context}"/>
1568    <filter token="derbyserver" value="${derby.server}"/>
1569    <filter token="derbyserver.port" value="${derby.server.port}"/>
1570    <filter token="perlpath" value="${escaped.perl.path}"/>
1571    <filter token="disable.collection.building" value="${disable.collection.building}"/>
1572    <copy file="${basedir}/resources/cgi/gsdl3site.cfg.in" tofile="${web.writablehome}/WEB-INF/cgi/gsdl3site.cfg" filtering="true" overwrite="true"/>
1573    <copy file="${basedir}/resources/web/global.properties.in" tofile="${web.writableclasses}/global.properties" filtering="true" overwrite="true"/>
1574    <copy file="${basedir}/resources/web/log4j.properties.in" tofile="${web.writableclasses}/log4j.properties" filtering="true" overwrite="true"/>
1575    <if><bool><istrue value="${gsdl3home.isreadonly}"/></bool>
1576      <!-- uncomment the writablehome properties -->
1577      <rsr verbosity="1" file="${web.writableclasses}/global.properties" pattern="^#gsdl3\.(writable{1})?home" replacement="gsdl3.$1home" />
1578    </if>
1579    <chmod file="${web.writableclasses}/global.properties" perm="644"/>
1580    <chmod file="${web.writableclasses}/log4j.properties" perm="644"/>
1581  </target>
1582
1583  <target name="compile-web" depends="init">
1584    <javac srcdir="${web.classes}"
1585      destdir="${web.classes}"
1586      includeantruntime="${compile.includeantruntime}"
1587      debug="${compile.debug}"
1588      deprecation="${compile.deprecation}"
1589      optimize="${compile.optimize}"
1590      encoding="${compile.encoding}">
1591      <classpath><path refid="compile.classpath"/></classpath>
1592    </javac>
1593  </target>
1594
1595  <target name="compile-classpath-jars" depends="init">
1596    <if><bool><available file="admin/cp.mf"/></bool>
1597      <jar destfile="admin/cp.jar" manifest="admin/cp.mf"/>
1598    </if>
1599    <if><bool><available file="${lib.java}/cp.mf"/></bool>
1600      <jar destfile="${lib.java}/cp.jar" manifest="${lib.java}/cp.mf"/>
1601    </if>
1602    <if><bool><available file="${lib.jni}/cp.mf"/></bool>
1603      <jar destfile="${lib.jni}/cp.jar" manifest="${lib.jni}/cp.mf"/>
1604    </if>
1605    <if><bool><available file="${web.lib}/cp.mf"/></bool>
1606      <jar destfile="${web.lib}/cp.jar" manifest="${web.lib}/cp.mf"/>
1607    </if>
1608    <jar destfile="cp.jar">
1609      <manifest>
1610        <attribute name="Class-Path" value="server.jar admin/cp.jar lib/java/cp.jar lib/jni/cp.jar web/WEB-INF/lib/cp.jar"/>
1611      </manifest>
1612    </jar>
1613  </target>
1614
1615  <target name="clean-classpath-jars" depends="init">
1616    <delete file="admin/cp.jar"/>
1617    <delete file="${lib.java}/cp.jar"/>
1618    <delete file="${lib.jni}/cp.jar"/>
1619    <delete file="${web.lib}/cp.jar"/>
1620    <delete file="cp.jar"/>
1621  </target>
1622
1623
1624  <target name="svnupdate-web" unless="nosvn.mode">
1625    <exec executable="svn">
1626      <arg value="update"/>
1627      <arg value="${web.writablehome}"/>
1628      <arg value="-r"/><arg value="${branch.revision}"/>
1629    </exec>
1630  </target>
1631
1632  <target name="update-web" depends="init,svnupdate-web,configure-web"
1633    description="update only the web stuff (config files)"/>
1634
1635  <!-- ============ Targets concerned with https certification ================ -->
1636
1637  <target name="setup-https-cert-info">
1638    <echo>
1639      *********************************************************************
1640               NOTE TO OBTAINING A TLS (SSL) CERTIFICATE FOR HTTPS
1641      *********************************************************************
1642      A signed certificate is needed for your GS server to serve pages over https.
1643      This target will attempt to obtain a certificate for you from the official and free Certificate Authority Let's Encrypt.
1644      However, a certificate can only be obtained if you have admin/sudo permissions on this machine that you're installing Greenstone on.
1645
1646      Note that:
1647      * if you already have a certificate, then you probably don't want to be running this target but the 'ant renew-existing-https-cert' target instead, to renew your existing certificate.
1648      * if you run this target when you already have a generated certificate, the existing certificate will remain unchanged and the script will terminate with a message alerting you to this fact.
1649    </echo>
1650  </target>
1651 
1652
1653  <target name="https-conditions-set">
1654    <input addproperty="https.conditions.ok" validargs="y,n">     
1655      To run this target, ensure you have:
1656      * (if on unix) sudo permissions. Enter the sudo password if prompted.
1657      * (if on windows) sufficient privileges to run the included tomcat on port 80.
1658      * nothing running on port 80 when you run this target
1659      * edited the build.properties file with
1660        - tomcat.server set to the/a domain name of your server
1661        - server.protocols comma-separated list set to contain at least 'https' if not also http (the first in this list will be the default protocol)
1662        - tomcat.port.https set to a valid port number not yet in use
1663        - keystore.pass set to a password for the certification process
1664    * read the Let's Encrypt Subscriber Agreement at https://letsencrypt.org/repository/
1665      If any of the above is not possible, quit this target. Continue [y/n]?
1666    </input>
1667
1668    <condition property="quit.https.setup">
1669      <equals arg1="n" arg2="${https.conditions.ok}"/>
1670    </condition>
1671
1672    <fail if="quit.https.setup">https certification step aborted by user. Please edit build.properties to set server.protocol=http and comment out tomcat.port.https.</fail>
1673  </target>
1674 
1675
1676  <target name="setup-https-cert" depends="setup-https-cert-info,https-conditions-set">
1677    <if><bool><not><matches string="${server.protocols}" pattern="https"/></not></bool>
1678      <fail>To setup https certification, the server.protocols property in file build.properties must contain 'https'</fail>
1679    </if>
1680
1681    <input addproperty="https.cert.email">Enter an email that Let's Encrypt, the certification authority, can send any important notifications to</input>
1682    <input addproperty="https.other.domains">Besides tomcat.server=${tomcat.server}, enter a comma separated list of additional domains to support, if any</input>
1683    <input addproperty="https.cert.agree" validargs="y,n">You've read the Let's Encrypt Subscriber Agreement at https://letsencrypt.org/repository/ and agree</input>
1684    <if>
1685      <bool><equals arg1="y" arg2="${https.cert.agree}"/></bool>
1686
1687      <condition property="https.cert.domains" value="${tomcat.server},${https.other.domains}" else="${tomcat.server}">
1688    <and>
1689      <isset property="https.other.domains" />
1690      <not><matches string="${https.other.domains}" pattern="^\s*$"/></not>
1691    </and>
1692      </condition>     
1693
1694      <input addproperty="https.do.cert" validargs="y,n">
1695    You've agreed to the Let's Encrypt TOS with
1696    - email: ${https.cert.email}
1697    - domains: ${https.cert.domains}
1698    Looks okay? [y/n]
1699      </input>
1700    </if>
1701
1702    <if><bool><equals arg1="n" arg2="${https.do.cert}"/></bool>
1703      <echo>Not proceeding with https certification for the Greenstone 3 web server</echo>
1704    <else>
1705        <echo>Proceeding...</echo>   
1706        <if><bool><istrue value="${current.os.iswindows}"/></bool>
1707            <antcall target="setup-https-cert-windows">
1708                <param name="https.cert.renewal" value=""/><!-- for cert issuance, there are none of the additional parameters specific to cert renewal -->
1709            </antcall>
1710        </if>
1711        <if><bool><istrue value="${current.os.isunixnotmac}"/></bool>
1712            <antcall target="setup-https-cert-linux"/>
1713        </if>
1714        <if><bool><istrue value="${current.os.ismac}"/></bool>
1715            <antcall target="setup-https-cert-mac"/>
1716        </if>
1717     </else>
1718  </if>
1719 
1720  </target>
1721 
1722 
1723  <target name="setup-https-cert-windows">
1724   
1725    <echo>********** The included tomcat will be stopped, then restarted on port 80 and stopped again</echo>
1726   
1727    <!-- create folder packages\tomcat\webapps\ROOT\.well-known\acme-challenge -->
1728    <mkdir dir="${packages.home}/tomcat/webapps/ROOT/.well-known/acme-challenge"/>
1729    <mkdir dir="${packages.home}/tomcat/conf/https_cert"/>
1730 
1731    <!--
1732        For Windows, Greenstone can generate the account and domain keys with the openSSL we compiled up ourselves
1733        and put on SVN (at GS3/bin/windows/openssl) rather than let ZeroSSL generate these keys for the user.
1734        Letting Greenstone generate the keys may be considered more trustworthy by the user than letting a 3rd
1735        party do so. See https://zerossl.com/usage.html#First_time_run_and_regular_use for OpenSSL commands
1736        If we don't generate the keys ourselves with our OpenSSL, then ZeroSSL will do so automatically in the
1737        call to le64/32.exe further below, as it's passed in the flag generate-missing.
1738    -->
1739    <!-- We generate the account key named "privkey.key" in ${packages.home}\tomcat\conf\https_cert -->
1740    <exec executable="cmd" osfamily="windows" dir="${basedir}/bin/${os.bin.dir}/openssl/bin" spawn="false">
1741      <arg value="/c" />
1742      <arg value="openssl.exe" />
1743      <arg value="genrsa" />
1744      <arg value="-out" /><arg value="${packages.home}\tomcat\conf\https_cert\privkey.key" /><arg value="4096" />
1745    </exec>
1746 
1747    <!-- Also generate the domain key (for csr-key parameter to zeroSSL's le.exe)
1748        ${packages.home}\tomcat\conf\https_cert\${tomcat.server}.key
1749        Using 2048 instead of 4096 bits for this. See https://zerossl.com/usage.html#First_time_run_and_regular_use
1750    -->
1751    <exec executable="cmd" osfamily="windows" dir="${basedir}/bin/${os.bin.dir}/openssl/bin" spawn="false">
1752      <arg value="/c" />
1753      <arg value="openssl.exe" />
1754      <arg value="genrsa" />
1755      <arg value="-out" /><arg value="${packages.home}\tomcat\conf\https_cert\${tomcat.server}.key" /><arg value="2048" />
1756    </exec>
1757 
1758    <!-- stop the included tomcat (also stopping derby and solr) -->
1759    <antcall target="stop" />
1760   
1761    <!-- rerun tomcat on port 80
1762        See https://ant.apache.org/manual/Tasks/antcall.html -->
1763    <antcall target="start">
1764        <param name="localhost.port.http" value="80"/>
1765        <param name="default.tomcat.port" value="80"/>
1766        <param name="local.http.url" value="http://${localhost.server.http}"/><!-- For port 80 over http, leave out port number in URL -->
1767        <param name="http.address.restriction" value=""/><!-- don't prevent public access over http of port 80 -->
1768        <param name="https.comment.out.start" value="${comment.start}"/>
1769        <param name="https.comment.out.end" value="${comment.end}"/>
1770    </antcall>
1771 
1772    <!-- get the certificate: use zerossl for windows
1773        Download from https://github.com/do-know/Crypt-LE/releases,
1774        For licence see https://github.com/do-know/Crypt-LE/
1775        Usage instructions at https://zerossl.com/usage.html       
1776       
1777        le64 ==key "${packages.home}\tomcat\conf\https_cert\privkey.key" ==csr "${packages.home}\tomcat\conf\https_cert\${tomcat.server}.csr" ==csr-key "${packages.home}s\tomcat\conf\https_cert\${tomcat.server}.key" ==crt "${packages.home}\tomcat\conf\https_cert\${tomcat.server}.crt" ==domains "${https.cert.domains}" ==path "${packages.home}\tomcat\webapps\ROOT\.well-known\acme-challenge" ==generate-missing ==unlink ==live -export-pfx "${keystore.pass}"
1778       
1779        which generates a .pfx file with the same name as the PEM certificate (.crt param below)
1780        .pfx vs .p12: https://stackoverflow.com/questions/6819079/convert-pfx-format-to-p12
1781       
1782        In this case "fullchain_and_prvtkey.pfx" is generated, which is the windows value of ${keystore.file} property
1783
1784        Helpful for debugging: https://stackoverflow.com/questions/10302489/ant-script-have-exec-tag-dump-out-entire-command-line
1785        -->
1786    <exec executable="cmd" osfamily="windows" dir="${basedir}/bin/${os.bin.dir}" spawn="false">
1787      <arg value="/c" />
1788      <arg value="le${os.bitness}" />
1789      <arg value="--key" /><arg value="${packages.home}\tomcat\conf\https_cert\privkey.key" />
1790      <arg value="--csr" /><arg value="${packages.home}\tomcat\conf\https_cert\${tomcat.server}.csr" />
1791      <arg value="--csr-key" /><arg value="${packages.home}\tomcat\conf\https_cert\${tomcat.server}.key" />
1792      <!--<arg value="==crt" /><arg value="${packages.home}\tomcat\conf\https_cert\${tomcat.server}.crt" />-->
1793      <arg value="--crt" /><arg value="${packages.home}\tomcat\conf\https_cert\fullchain_and_prvtkey.crt" />
1794      <arg value="--domains" /><arg value="${https.cert.domains}" />
1795      <arg value="--path" /><arg value="${packages.home}\tomcat\webapps\ROOT\.well-known\acme-challenge" />
1796      <arg value="--generate-missing" />
1797      <arg value="--unlink" />
1798      <arg line="${https.testing}" /><!-- minus-minus-live if not testing, empty if testing. https://stackoverflow.com/questions/11840284/pass-arguments-to-apache-ant-exec-task-based-on-the-variables-value -->
1799      <!--<arg value="==export-pfx" /><arg value="${keystore.pass}" />
1800      <arg value="==tag-pfx" /><arg value="greenstone3-tomcat" />--><!--Convert the certificate (that contains the full chain AND private key) to pfx format hereafter using OpenSSL instead-->
1801      <arg line="${https.cert.renewal}" /><!-- renew command on windows/mac appends min-min-renew XX, where if the day the renewal is run is XX days within expiry, the certificate will get renewed. -->
1802    </exec>
1803
1804    <!-- stop the tomcat running on port 80 -->
1805    <antcall target="stop">
1806        <param name="localhost.port.http" value="80"/>
1807        <param name="default.tomcat.port" value="80"/>
1808        <param name="local.http.url" value="http://${localhost.server.http}"/><!-- For port 80 over http, leave out port number in URL -->
1809        <param name="http.address.restriction" value=""/>
1810        <param name="https.comment.out.start" value="${comment.start}"/>
1811        <param name="https.comment.out.end" value="${comment.end}"/>
1812    </antcall>
1813
1814    <!-- Use OpenSSL instead of ZeroSSL to convert the certificate to the .pfx format that tomcat likes, using this cmd:
1815            GS3/bin/windows/openssl/bin/openssl.exe pkcs12 -inkey domain.key -in domain.crt -passin pass:pwd -passout pass:pwd -export -out ${keystore.file}
1816            GS3/bin/windows/openssl/bin/openssl.exe pkcs12 -inkey domain.key -in domain.crt -password pass:pwd -export -out ${keystore.file}
1817        where on windows, keystore.file = fullchain_and_prvtkey.pfx
1818    -->
1819    <exec executable="cmd" osfamily="windows" dir="${basedir}/bin/${os.bin.dir}/openssl/bin" spawn="false">
1820      <arg value="/c" />
1821      <arg value="openssl.exe" />
1822      <arg value="pkcs12" />
1823      <arg value="-inkey" /><arg value="${packages.home}\tomcat\conf\https_cert\${tomcat.server}.key" />
1824      <arg value="-in" /><arg value="${packages.home}\tomcat\conf\https_cert\fullchain_and_prvtkey.crt" />
1825      <arg value="-export" />
1826      <arg value="-out" /><arg value="${packages.home}\tomcat\conf\https_cert\${keystore.file}" />
1827      <arg value="-name"/><arg value="greenstone3-tomcat"/><!-- See https://stackoverflow.com/questions/808669/convert-a-cert-pem-certificate-to-a-pfx-certificate -->
1828      <arg value="-password"/><arg value="pass:${keystore.pass}"/>
1829    </exec>
1830   
1831  </target>
1832
1833
1834  <!-- On Mac as on Linux, we need sudo permissions to setup https certification.
1835    But unlike on Linux, on Mac we only need to sudo when running tomcat on port 80
1836    and when stopping tomcat running on port 80. But we don't need to sudo on a Mac when calling le.pl.
1837    This also means all the files in https_cert have the correct (user, not root) permissions.
1838  -->
1839  <target name="setup-https-cert-mac">
1840   
1841    <echo>********** The included tomcat will be stopped, then restarted on port 80 and stopped again</echo>
1842   
1843    <!-- create folder packages\tomcat\webapps\ROOT\.well-known\acme-challenge -->
1844    <mkdir dir="${packages.home}/tomcat/webapps/ROOT/.well-known/acme-challenge"/>
1845    <mkdir dir="${packages.home}/tomcat/conf/https_cert"/>
1846 
1847    <!--
1848        See comments under setup-https-cert-WINDOWS
1849    -->
1850    <!-- We generate the account key named "privkey.key" in ${packages.home}\tomcat\conf\https_cert -->
1851    <if><bool><not><available file="${packages.home}/tomcat/conf/https_cert/privkey.key"/></not></bool>
1852      <exec executable="openssl" osfamily="mac" dir="${basedir}/bin/${os.bin.dir}/openssl/bin" spawn="false">   
1853        <arg value="genrsa" />
1854        <arg value="-out" /><arg value="${packages.home}/tomcat/conf/https_cert/privkey.key" /><arg value="4096" />
1855      </exec>
1856    </if>
1857 
1858    <!-- Also generate the domain key (for csr-key parameter to zeroSSL's le.pl)
1859        ${packages.home}\tomcat\conf\https_cert\${tomcat.server}.key
1860        Using 2048 instead of 4096 bits for this. See https://zerossl.com/usage.html#First_time_run_and_regular_use
1861    -->
1862    <if><bool><not><available file="${packages.home}/tomcat/conf/https_cert/${tomcat.server}.key"/></not></bool>
1863      <exec executable="openssl" osfamily="mac" dir="${basedir}/bin/${os.bin.dir}/openssl/bin" spawn="false">
1864        <arg value="genrsa" />
1865        <arg value="-out" /><arg value="${packages.home}/tomcat/conf/https_cert/${tomcat.server}.key" /><arg value="2048" />
1866      </exec>
1867    </if>
1868 
1869    <!-- stop the included tomcat (also stopping derby and solr) -->
1870    <antcall target="stop" />
1871   
1872    <!-- rerun tomcat on port 80
1873        See https://ant.apache.org/manual/Tasks/antcall.html -->
1874    <antcall target="start">
1875      <param name="sudo.or.not" value="/usr/bin/sudo" />
1876        <param name="localhost.port.http" value="80"/>
1877        <param name="default.tomcat.port" value="80"/>
1878        <param name="local.http.url" value="http://${localhost.server.http}"/><!-- For port 80 over http, leave out port number in URL -->
1879        <param name="http.address.restriction" value=""/><!-- don't prevent public access over http of port 80 -->
1880        <param name="https.comment.out.start" value="${comment.start}"/>
1881        <param name="https.comment.out.end" value="${comment.end}"/>
1882    </antcall>
1883 
1884    <!-- get the certificate: use zerossl's le.pl compiled up for Mac.
1885       For further notes, see under setup-https-cert-WINDOWS
1886    -->
1887
1888    <exec executable="perl" osfamily="mac" dir="${gs2build.home}/perllib/cpan/Crypt/LE/bin" spawn="false">
1889      <env key="PERL5LIB" value="${gs2build.home}/perllib/cpan${path.separator}${gs2build.home}/perllib/cpan/perl-5.18"/>
1890      <arg value="-S" />
1891      <arg value="${gs2build.home}/perllib/cpan/Crypt/LE/bin/le.pl" />
1892      <arg value="--key" /><arg value="${packages.home}/tomcat/conf/https_cert/privkey.key" />
1893      <arg value="--csr" /><arg value="${packages.home}/tomcat/conf/https_cert/${tomcat.server}.csr" />
1894      <arg value="--csr-key" /><arg value="${packages.home}/tomcat/conf/https_cert/${tomcat.server}.key" />
1895      <!--<arg value="==crt" /><arg value="${packages.home}/tomcat/conf/https_cert/${tomcat.server}.crt" />-->
1896      <arg value="--crt" /><arg value="${packages.home}/tomcat/conf/https_cert/fullchain_and_prvtkey.crt" />
1897      <arg value="--domains" /><arg value="${https.cert.domains}" />
1898      <arg value="--path" /><arg value="${packages.home}/tomcat/webapps/ROOT/.well-known/acme-challenge" />
1899      <arg value="--generate-missing" />
1900      <arg value="--unlink" />
1901      <arg line="${https.testing}" /><!-- minus-minus-live if not testing, empty if testing. https://stackoverflow.com/questions/11840284/pass-arguments-to-apache-ant-exec-task-based-on-the-variables-value -->
1902      <!--<arg value="==export-pfx" /><arg value="${keystore.pass}" />
1903          <arg value="==tag-pfx" /><arg value="greenstone3-tomcat" />--><!-- not sure if this generates a keystore filename with ext .p12 or .pfx for Macs -->
1904      <arg line="${https.cert.renewal}" /><!-- renew command on windows/mac appends min-min-renew XX, where if the day the renewal is run is XX days within expiry, the certificate will get renewed. -->
1905    </exec>
1906
1907    <!-- stop the tomcat running on port 80 -->
1908    <antcall target="stop">
1909      <param name="sudo.or.not" value="/usr/bin/sudo" />
1910        <param name="localhost.port.http" value="80"/>
1911        <param name="default.tomcat.port" value="80"/>
1912        <param name="local.http.url" value="http://${localhost.server.http}"/>
1913        <param name="http.address.restriction" value=""/>
1914        <param name="https.comment.out.start" value="${comment.start}"/>
1915        <param name="https.comment.out.end" value="${comment.end}"/>
1916    </antcall>
1917
1918    <!-- Use OpenSSL instead of ZeroSSL to convert the certificate to the .pfx format that tomcat likes, using this cmd:
1919            GS3/bin/windows/openssl/bin/openssl.exe pkcs12 -inkey domain.key -in domain.crt -passin pass:pwd -passout pass:pwd -export -out ${keystore.file}
1920            GS3/bin/windows/openssl/bin/openssl.exe pkcs12 -inkey domain.key -in domain.crt -password pass:pwd -export -out ${keystore.file}
1921        where on windows, keystore.file = fullchain_and_prvtkey.pfx
1922    -->
1923    <exec executable="openssl" osfamily="mac" dir="${basedir}/bin/${os.bin.dir}/openssl/bin" spawn="false">
1924      <arg value="pkcs12" />
1925      <arg value="-inkey" /><arg value="${packages.home}/tomcat/conf/https_cert/${tomcat.server}.key" />
1926      <arg value="-in" /><arg value="${packages.home}/tomcat/conf/https_cert/fullchain_and_prvtkey.crt" />
1927      <arg value="-export" />
1928      <arg value="-out" /><arg value="${packages.home}/tomcat/conf/https_cert/${keystore.file}" />
1929      <arg value="-name"/><arg value="greenstone3-tomcat"/><!-- See https://stackoverflow.com/questions/808669/convert-a-cert-pem-certificate-to-a-pfx-certificate -->
1930      <arg value="-password"/><arg value="pass:${keystore.pass}"/>
1931    </exec>
1932   
1933  </target>
1934 
1935
1936 
1937  <target name="setup-https-cert-linux">
1938      <!-- Running as
1939       ./certbot-auto certonly ==standalone ==preferred-challenges http ==email EMAIL -d DOMAINS
1940       expects input from stdin to accept (A) ToS and say Yes (Y) to sharing email.
1941       We can run in non-interactive mode as the user has at this stage already agreed
1942       to LetsEncrypt's Terms of Service and provided an email address.
1943      -->
1944      <exec executable="/bin/bash" dir="${basedir}/bin/${os.bin.dir}" failonerror="true">
1945    <arg value="./certbot-auto"/>
1946    <arg value="certonly"/>
1947    <arg line="${https.testing}"/><!-- https://stackoverflow.com/questions/11840284/pass-arguments-to-apache-ant-exec-task-based-on-the-variables-value -->
1948    <arg value="--standalone"/>
1949    <arg value="--non-interactive"/>
1950    <arg value="--agree-tos"/>
1951    <arg value="--preferred-challenges"/><arg value="http"/>
1952    <arg value="--email"/><arg value="${https.cert.email}"/>
1953    <arg value="--domains"/><arg value="${https.cert.domains}"/>
1954      </exec>
1955
1956      <!-- sudo openssl pkcs12 -export -out /tmp/DOMAIN_fullchain_and_key.p12 \
1957        -in /etc/letsencrypt/live/DOMAIN/fullchain.pem \
1958        -inkey /etc/letsencrypt/live/DOMAIN/privkey.pem \
1959        -name tomcat
1960        Must run as sudo because only admin has access to the pem files that admin
1961        generated in /etc/letsencrypt
1962        See https://computingforgeeks.com/tomcat-7-with-letsencrypt-ssl-certificate/
1963        but also https://community.letsencrypt.org/t/using-lets-encrypt-with-tomcat/41082
1964        which bypasses the step to generate the java keystore jks file
1965        and uses openssl to generate a pfx file instead of a p12 file
1966      -->
1967
1968      <exec executable="sudo" dir="/tmp" failonerror="true">
1969    <arg value="${basedir}/bin/${os.bin.dir}/openssl/bin/openssl"/>
1970    <arg value="pkcs12"/>
1971    <arg value="-export"/>
1972    <arg value="-out"/><arg value="/tmp/${tomcat.server}_fullchain_and_key.p12"/>
1973    <arg value="-in"/><arg value="/etc/letsencrypt/live/${tomcat.server}/fullchain.pem"/>
1974    <arg value="-inkey"/><arg value="/etc/letsencrypt/live/${tomcat.server}/privkey.pem"/>
1975    <arg value="-name"/><arg value="greenstone3-tomcat"/>
1976    <arg value="-password"/><arg value="pass:${keystore.pass}"/>
1977      </exec>
1978
1979      <!-- Finally, mkdir ${packages.home}/tomcat/conf/https_cert
1980       and copy the file /tmp/${tomcat.server}_fullchain_and_key.p12 into it
1981       and rename to a slightly shorter and simpler name,
1982       see https://stackoverflow.com/questions/8971187/ant-renaming-while-copying-file
1983       The file in tmp has root permissions. But copying it from tmp into
1984       the local account will give the copy local account permissions.
1985       Then sudo to remove the original copy in /tmp
1986      -->
1987      <mkdir dir="${packages.home}/tomcat/conf/https_cert"/>
1988      <!--<copy file="/tmp/${tomcat.server}_fullchain_and_key.p12" todir="${packages.home}/tomcat/conf/https_cert"/>-->
1989      <copy todir="${packages.home}/tomcat/conf/https_cert">
1990    <fileset file="/tmp/${tomcat.server}_fullchain_and_key.p12"/>
1991    <globmapper from="${tomcat.server}_fullchain_and_key.p12" to="${keystore.file}"/>
1992      </copy>
1993
1994      <exec executable="sudo" dir="/tmp" failonerror="true">
1995        <arg line="rm -f /tmp/${tomcat.server}_fullchain_and_key.p12" />
1996      </exec>
1997     
1998  </target>
1999 
2000 
2001  <!-- Revoke the certificate and remove it, including folders.
2002       See https://certbot.eff.org/docs/using.html#revoking-certificates
2003       which also states "if a certificate is a test certificate obtained via the
2004       ==staging or ==test-cert flag, that flag must be passed to the revoke subcommand."
2005  -->
2006  <target name="remove-https-cert">
2007    <echo>
2008      NOTE: If you're on Linux, you need to have sudo permissions to execute this target.
2009      Enter the sudo password if prompted.
2010    </echo>
2011    <!--
2012    On linux, we use certbot-auto.
2013    It says at https://github.com/certbot/certbot/issues/1741
2014    "you shouldn't run letsencrypt-auto [now called certbot-auto] as superuser,
2015    because the program will invoke sudo when it needs to automatically."   
2016    We need to send Y(es) as inputstring to confirm that the
2017    /etc/letsencrypt/live/${tomcat.server} folder can be deleted.
2018    Note osfamily="unix" is separate from osfamily="mac", which comes out handy here as we haven't set up certbot-auto for mac (yet).
2019    -->
2020    <exec executable="./certbot-auto" os="${os.linux},${os.solaris}" dir="${basedir}/bin/${os.bin.dir}" failonerror="true" inputstring="Y">
2021     <arg value="revoke"/>
2022     <arg line="${https.testing}"/>
2023     <arg value="--cert-path"/><arg value="/etc/letsencrypt/live/${tomcat.server}/cert.pem"/>
2024    </exec>
2025    <!-- The above command already deletes the folder when Y(es) was passed in. Explicitly deleting:
2026    <exec executable="./certbot-auto" dir="${basedir}/bin/${os.bin.dir}" failonerror="true">
2027    <arg value="delete"/>
2028    <arg value="==cert-name"/><arg value="${tomcat.server}"/>
2029    </exec>
2030    -->
2031   
2032    <!-- On Windows and Mac, we use zeroSSl. For the revoke command, see https://zerossl.com/usage.html#Certificate_revocation -->
2033    <exec executable="cmd" osfamily="windows" dir="${basedir}/bin/${os.bin.dir}" spawn="false">
2034      <arg value="/c" />
2035      <arg value="le${os.bitness}" />     
2036      <arg value="--key" /><arg value="${packages.home}\tomcat\conf\https_cert\privkey.key" />
2037      <arg value="--crt" /><arg value="${packages.home}\tomcat\conf\https_cert\fullchain_and_prvtkey.crt"/>
2038      <arg value="--revoke"/>
2039      <arg line="${https.testing}"/>
2040    </exec>
2041   
2042    <!-- On Mac, we use the le.pl we compiled up (Crypt::LE) and which needs to have PERL5LIB set correctly to run --> 
2043    <exec executable="perl" osfamily="mac" dir="${gs2build.home}/perllib/cpan/Crypt/LE/bin" spawn="false">
2044      <env key="PERL5LIB" value="${gs2build.home}/perllib/cpan${path.separator}${gs2build.home}/perllib/cpan/perl-5.18"/>
2045      <arg value="-S" />
2046      <arg value="${gs2build.home}/perllib/cpan/Crypt/LE/bin/le.pl" />
2047      <arg value="--key" /><arg value="${packages.home}/tomcat/conf/https_cert/privkey.key" />
2048      <arg value="--crt" /><arg value="${packages.home}/tomcat/conf/https_cert/fullchain_and_prvtkey.crt"/>
2049      <arg value="--revoke"/>
2050      <arg line="${https.testing}"/>
2051    </exec>
2052
2053    <!-- And remove the https_cert folder -->
2054    <delete dir="${packages.home}/tomcat/conf/https_cert"/>
2055  </target>
2056 
2057 
2058    <!-- Renewing existing https certificate
2059       Linux:
2060       https://certbot.eff.org/docs/using.html#renewing-certificates
2061       ./path/to/GS3/bin/linux/certbot-auto renew ==quiet ==no-self-upgrade
2062       Windows: reuse Windows issuance target
2063       see https://zerossl.com/usage.html#Certificate_renewal
2064    -->
2065  <target name="renew-existing-https-cert">
2066    <echo>
2067      NOTE: To run this target,
2068          * ensure nothing is running on port 80
2069          * if you're on Linux or Mac, you need to have sudo permissions. Enter the sudo password if prompted.     
2070
2071      If you want your cronjob to renew a certificate, you can add pre and post hooks
2072      refer to https://certbot.eff.org/docs/using.html#renewing-certificates
2073      For more information run:
2074         ./path/to/GS3/bin/linux/certbot-auto --help renew
2075    </echo>
2076    <exec executable="./certbot-auto" os="${os.linux},${os.solaris}" dir="${basedir}/bin/${os.bin.dir}" failonerror="true">
2077     <arg value="renew"/>
2078     <arg value="--quiet"/>
2079     <arg value="--no-self-upgrade"/>
2080    </exec>
2081   
2082    <!-- For renewal on Windows or Mac, we use ZeroSSL as intermediary between GS3 and Let's Encrypt.
2083     And when using ZeroSSL we need to re-run the original (issuance) command and append "min-min-renew XX" to it,
2084     where if it's within XX days of expiry, the certificate will get renewed.
2085     See https://zerossl.com/usage.html#Certificate_renewal -->
2086    <if><bool><or>
2087      <istrue value="${current.os.iswindows}"/>
2088      <istrue value="${current.os.ismac}"/>
2089      </or></bool>
2090     
2091      <input addproperty="https.other.domains">Enter a comma separated list of additional domains besides tomcat.server=${tomcat.server} that you registered on issuance, if any</input>
2092      <condition property="https.cert.domains" value="${tomcat.server},${https.other.domains}" else="${tomcat.server}">
2093    <and>
2094      <isset property="https.other.domains" />
2095      <not><matches string="${https.other.domains}" pattern="^\s*$"/></not>
2096    </and>
2097      </condition>
2098      <if><bool><istrue value="${current.os.iswindows}"/></bool>
2099    <antcall target="setup-https-cert-windows">
2100      <param name="https.cert.renewal" value="--renew 10"/>         
2101    </antcall>
2102    <else>
2103      <antcall target="setup-https-cert-mac">
2104        <param name="https.cert.renewal" value="--renew 10"/>           
2105      </antcall>
2106    </else>
2107      </if>
2108    </if>
2109  </target>
2110
2111  <!-- ======================= Tomcat Targets ========================== -->
2112 
2113  <!-- this target downloads and installs Tomcat -->
2114  <!-- we download tomcat (version 7 for Java 1.5 and later, version 5 for Java 1.4 plus the 1.4 compatibility package). -->
2115  <target name="prepare-tomcat" depends="init,setup-proxy" if="tomcat.islocal"
2116    description="downloads the appropriate version of Tomcat (Tomcat 5 if using Java 1.4, Tomcat 7 if using Java 1.5 or higher). If you want to change which version of Java you are using between 1.4 and 1.5/7 then you need to run prepare-tomcat">
2117  <if>
2118      <bool>
2119        <not><available file="${packages.home}/tomcat/.flagfile"/></not>
2120      </bool>
2121
2122      <!-- check that packages dir is there -->
2123      <mkdir dir="${packages.home}"/>
2124      <get src="http://www.greenstone.org/gs3files/${tomcat.version}.zip"
2125        dest="${packages.home}/${tomcat.version}.zip"
2126        usetimestamp="true"/>
2127      <unzip src="${packages.home}/${tomcat.version}.zip"
2128        dest="${packages.home}"/>
2129     
2130      <!-- If we are using Java 1.4, we'd be using tomcat 5.5 in which case
2131      we would need to have the tomcat compat package to work with Java 1.4-->
2132      <if>
2133    <bool><equals arg1="1.4" arg2="${ant.java.version}"/></bool>
2134    <get src="http://www.greenstone.org/gs3files/${tomcat.version}-compat.zip"
2135      dest="${packages.home}/${tomcat.version}-compat.zip"
2136      usetimestamp="true"/>
2137    <unzip src="${packages.home}/${tomcat.version}-compat.zip"
2138      dest="${packages.home}"/>
2139      </if>
2140     
2141      <!-- delete any existing tomcat -->
2142      <delete dir="${packages.home}/tomcat"/>
2143      <move todir="${packages.home}/tomcat">
2144        <fileset dir="${packages.home}/${tomcat.version}"/>
2145      </move>
2146     
2147      <!-- To avoid the CGI permissions error appearing continuously in the (localhost) log,
2148        need privileged=true set in the root context.xml file too, not just greenstone context file.
2149        See http://stackoverflow.com/questions/9845936/tomcat-v7-0-load-exception-marking-servlet-ssi-as-unavailable/10305471#10305471
2150        For usage of IfTask IsLessThan: http://antelope.stage.tigris.org/nonav/docs/manual/bk03ch05s02.html -->
2151      <if><bool><not><islessthan arg1="${tomcat.version.major}" arg2="7"/></not></bool>     
2152        <copy file="${basedir}/resources/tomcat/root_context.xml.in" tofile="${packages.home}/tomcat/conf/context.xml" overwrite="true" />     
2153      </if>
2154       
2155     
2156      <!--
2157      <copy file="${basedir}/resources/tomcat/setclasspath.bat"
2158        tofile="${packages.home}/tomcat/bin/setclasspath.bat"
2159        overwrite="true"/>
2160      <copy file="${basedir}/resources/tomcat/setclasspath.sh"
2161        tofile="${packages.home}/tomcat/bin/setclasspath.sh"
2162        overwrite="true"/>
2163      -->
2164      <!-- make sure we have execute permission for the .sh files -->
2165      <chmod dir="${packages.home}/tomcat/bin" perm="ugo+rx"
2166        includes="*.sh"/>   
2167
2168      <echo file="${packages.home}/tomcat/.flagfile">
2169        the timestamp of this file is the time that tomcat was extracted from the zip files.
2170        it is used to figure out whether the files need to be refreshed or not in `ant prepare-tomcat`
2171      </echo>
2172
2173      <!-- this is not strictly a prepare tomcat thing, but if one changes
2174      Java, then they need to change tomcat as well, so might as well call
2175      it here -->
2176      <antcall target="configure-java-version"/>
2177      <else>
2178        <echo>Tomcat has been prepared, will not prepare</echo>
2179        <echo>Delete ${packages.home}/tomcat/.flagfile to force refresh</echo>
2180      </else>
2181
2182    </if>
2183
2184  </target> 
2185 
2186  <target name="configure-tomcat" depends="init,configure-tomcat-local,configure-tomcat-external"/>
2187 
2188  <target name="configure-tomcat-local" depends="init,perl-for-building" if="tomcat.islocal">
2189    <!-- re-setup the server.xml file -->
2190    <copy file="${basedir}/resources/tomcat/server_tomcat${tomcat.version.major}.xml.in"
2191        tofile="${packages.home}/tomcat/conf/server.xml" overwrite="true">
2192      <filterset>
2193        <filter token="shutdown-port" value="${tomcat.shutdown.port}"/>
2194    <filter token="https.redirect.port" value="${https.redirect.port}"/>
2195    <filter token="localhost.port.http" value="${localhost.port.http}"/>
2196    <filter token="tomcat.port.https" value="${tomcat.port.https}"/>
2197    <!-- Relative path preferred for keystore.file, in case tomcat is moved elsewhere -->
2198    <!--<filter token="keystore.file" value="conf/https_cert/${tomcat.server}.jks" />-->
2199    <!--ON UNIX: <filter token="keystore.file" value="conf/https_cert/fullchain_and_prvtkey.p12" />-->
2200    <!--ON WINDOWS: <filter token="keystore.file" value="conf/https_cert/fullchain_and_prvtkey.pfx" />-->
2201    <filter token="keystore.file" value="conf/https_cert/${keystore.file}" />
2202    <!-- tomcat Connector's keystoreType param defaults to JKS (Java keystore), see https://tomcat.apache.org/tomcat-7.0-doc/config/http.html
2203    We'll follow the instructions at https://community.letsencrypt.org/t/using-lets-encrypt-with-tomcat/41082,
2204    https://www.ssl.com/how-to/create-a-pfx-p12-certificate-file-using-openssl/
2205    and https://computingforgeeks.com/tomcat-7-with-letsencrypt-ssl-certificate/
2206    (minus the keytool step) and use the PKCS12 file generated by openssl directly,
2207    instead of an additional step to generate the java keystore file from that -->
2208    <filter token="keystore.type" value="PKCS12"/>
2209    <filter token="keystore.pass" value="${keystore.pass}"/>
2210    <!--
2211        if server.protocols doesn't contain http, then http is only to be locally available (e.g. for solr servlet on 127.0.0.1)
2212        In that case, see https://serverfault.com/questions/218666/how-to-configure-tomcat-to-only-listen-to-127-0-0-1
2213    -->
2214    <filter token="http.address.restriction" value="${http.address.restriction}"/> 
2215    <filter token="https.comment.out.start" value="${https.comment.out.start}"/>
2216    <filter token="https.comment.out.end" value="${https.comment.out.end}"/>
2217      </filterset>
2218    </copy>
2219
2220    <!-- set up the solr context -->
2221
2222    <!-- First work out the IPv4 address for this machine -->
2223    <exec executable="${basedir}/bin/script/IPv4.sh" os="${os.unix}" failonerror="false" outputproperty="ipv4.val">
2224      <arg value="-format-for-tomcat-context"/>
2225    </exec>
2226    <exec executable="${basedir}/bin/script/IPv4.bat" osfamily="windows" failonerror="false" outputproperty="ipv4.val">
2227      <arg value="-format-for-tomcat-context"/>
2228    </exec>
2229
2230    <copy file="${basedir}/ext/solr/solr-tomcat-context.xml.in" tofile="${packages.home}/tomcat/conf/Catalina/localhost/solr.xml" overwrite="true">
2231      <filterset>
2232    <filter token="solr.context" value="${solr.context}"/>
2233        <filter token="gsdl3webhome" value="${web.writablehome}"/>
2234    <filter token="tomcathome" value="${basedir}/packages/tomcat"/>
2235    <filter token="IPv4" value="${ipv4.val}"/>
2236      </filterset>
2237    </copy>
2238
2239    <!-- set up the greenstone3 context, it may have a custom name specified in build.properties -->
2240    <if><bool><not><equals arg1="greenstone3" arg2="${greenstone.context}"></equals></not></bool>
2241        <copy file="${basedir}/resources/tomcat/greenstone3.xml.in" tofile="${basedir}/resources/tomcat/${greenstone.context}.xml.in" overwrite="true"/>
2242    </if>
2243    <copy file="${basedir}/resources/tomcat/${greenstone.context}.xml.in" tofile="${packages.home}/tomcat/conf/Catalina/localhost/${greenstone.context}.xml" overwrite="true">
2244      <filterset>
2245        <filter token="gsdl3webhome" value="${web.home}"/>
2246        <filter token="gsdl3webwritablehome" value="${web.writablehome}"/>
2247    <filter token="privilegedattribute" value="${privileged.attribute}"/>
2248    <filter token="allowedIPs" value="${allowed.IPs}"/>
2249    <filter token="derbyserver" value="${derby.server}"/>
2250    <filter token="derbyserverport" value="${derby.server.port}"/>
2251      </filterset>
2252    </copy>
2253    <if>
2254        <bool>
2255            <and>
2256                <available file="${packages.home}/tomcat/conf/Catalina/localhost/greenstone3.xml"/>
2257                <not><equals arg1="greenstone3" arg2="${greenstone.context}"></equals></not>
2258            </and>
2259        </bool>
2260        <delete file="${packages.home}/tomcat/conf/Catalina/localhost/greenstone3.xml"/>
2261    </if>
2262   
2263    <!-- set up the greenstone3 web.xml file -->
2264    <copy file="${basedir}/resources/tomcat/web8.xml.in" tofile="${packages.home}/tomcat/conf/web.xml" overwrite="true">
2265      <filterset>
2266    <filter token="perlpath" value="${perl.path}"/>
2267      </filterset>
2268    </copy>
2269  </target>
2270 
2271  <target name="configure-tomcat-external" depends="init" unless="tomcat.islocal">
2272    <!-- re-setup the server.xml file -->
2273    <!-- need to edit the config file, or do we get the user to do this???-->
2274  </target>
2275
2276  <target name="configure-solr-ext" depends="init" >
2277    <!-- re-setup the web/ext/solr/solr.xml file -->
2278    <copy file="${web.home}/ext/solr/solr.xml.in"
2279      tofile="${gsdl3.writablehome}/ext/solr/solr.xml" filtering="true" overwrite="true">
2280      <filterset>
2281        <filter token="gsdl3.home" value="${src.gsdl3.home.unix}"/>
2282        <filter token="gsdl3.writablehome" value="${src.gsdl3.writablehome.unix}"/>
2283      </filterset>
2284    </copy>
2285  </target>
2286 
2287  <!-- This target runs tomcat's "bin/catalina.bat(.sh) jpda start"
2288       to allow debugging the running GS3 server in Eclipse. See the instructions at
2289       http://www.wikijava.org/wiki/Debugging_a_servlet_with_tomcat_and_Eclipse_tutorial
2290       on how to use this with eclipse
2291    -->
2292  <target name="debug-start-tomcat" description="Startup Tomcat for debugger" depends="init" if="tomcat.islocal">
2293    <property name="tomcat.classpath" refid="local.tomcat.classpath"/>
2294    <property name="tomcat.path" refid="local.tomcat.path"/>
2295
2296    <if><bool>
2297    <isset property="fedora.maxpermsize"/></bool>
2298      <property name="catalina.opts" value="-Djava.util.prefs.syncInterval=2000000 -DGSDL3HOME=$GSDL3HOME -DGSDLOS=$GSDLOS -DPATH=$PATH -Xmx800M ${readonly.catalina.opts} ${fedora.maxpermsize}"/>
2299      <else>
2300    <property name="catalina.opts" value="-Djava.util.prefs.syncInterval=2000000 -DGSDL3HOME=$GSDL3HOME -DGSDLOS=$GSDLOS -DPATH=$PATH -Xmx800M ${readonly.catalina.opts}"/>
2301      </else>
2302    </if>
2303
2304    <echo file="${catalina.home}/bin/setenv.bat">set CLASSPATH=${tomcat.classpath}</echo>
2305    <echo file="${catalina.home}/bin/setenv.sh">export CLASSPATH=${tomcat.classpath}</echo>
2306   
2307    <exec executable="${catalina.home}/bin/catalina.sh" os="${os.unix}" dir="${catalina.home}/bin" spawn="false">
2308      <arg value="jpda" />
2309      <arg value="start" />
2310      <env key="JPDA_ADDRESS" value="8000"/> <!-- for debugging Tomcat in Eclipse -->
2311      <env key="JPDA_TRANSPORT" value="dt_socket"/> <!-- for debugging Tomcat in Eclipse -->
2312      <!--<env key="GSDLOS" value="linux"/> do we need this?? -->
2313      <env key="PATH" path="${tomcat.path}"/>
2314      <env key="CATALINA_OPTS" value="${catalina.opts}"/>
2315      <env key="CATALINA_HOME" value="${catalina.home}"/>
2316      <env key="CLASSPATH" path="${tomcat.classpath}"/>
2317      <env key="LD_LIBRARY_PATH" path="${env.LD_LIBRARY_PATH}:${lib.jni}"/>
2318      <env key="DYLD_LIBRARY_PATH" path="${env.DYLD_LIBRARY_PATH}:${lib.jni}:${gdbm.home}/lib"/> <!-- for mac os --> <!-- need gdbm here these days ??-->
2319      <env key="WNHOME" path="${wn.home}"/>
2320      <env key="FEDORA_HOME" path="${fedora.home}"/>
2321    </exec>
2322    <exec executable="${catalina.home}/bin/catalina.bat" osfamily="windows" dir="${catalina.home}/bin" spawn="true">
2323      <arg value="jpda" />
2324      <arg value="start" />
2325      <env key="JPDA_ADDRESS" value="8000"/> <!-- for debugging Tomcat in Eclipse -->
2326      <env key="JPDA_TRANSPORT" value="dt_socket"/> <!-- for debugging Tomcat in Eclipse -->
2327      <env key="GSDLOS" value="windows"/>
2328      <env key="GSDL3HOME" value="${basedir}"/>
2329      <env key="Path" path="${tomcat.path}"/>
2330      <env key="PATH" path="${tomcat.path}"/>
2331      <env key="CATALINA_OPTS" value="${catalina.opts}"/>
2332      <env key="CATALINA_HOME" value="${catalina.home}"/>
2333      <env key="CLASSPATH" path="${tomcat.classpath}"/>
2334      <env key="FEDORA_HOME" path="${fedora.home}"/>
2335    </exec>
2336    <!-- wait for the server to startup in case other targets need it running -->
2337    <waitfor maxwait="5" maxwaitunit="second">
2338      <and>
2339        <socket server="${tomcat.server}" port="${default.tomcat.port}"/>
2340    <!--<http url="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}/index.html"/>-->
2341    <http url="${local.http.url}${app.path}/index.html"/>
2342      </and>
2343    </waitfor>
2344  </target> 
2345 
2346  <target name="start-tomcat" description="Startup only Tomcat" depends="check-tomcat-started">
2347
2348    <if><bool><istrue value="${tomcat.isstarted}"/></bool>
2349      <echo>**************************************</echo>
2350      <echo>A WEB SERVER IS ALREADY RUNNING ON ${default.server.protocol}://${tomcat.server}:${default.tomcat.port} (${local.http.url}). NOT STARTING.</echo>
2351      <echo>**************************************</echo>
2352      <else>
2353    <antcall target="force-start-tomcat"/>
2354      </else>
2355      </if>
2356  </target>
2357
2358  <!-- Another way: http://ptrthomas.wordpress.com/2006/03/25/how-to-start-and-stop-tomcat-from-ant/ -->
2359  <target name="force-start-tomcat" description="Startup only Tomcat" depends="init" if="tomcat.islocal">
2360
2361    <property name="tomcat.classpath" refid="local.tomcat.classpath"/>
2362    <property name="tomcat.path" refid="local.tomcat.path"/>
2363
2364    <if><bool>
2365    <isset property="fedora.maxpermsize"/></bool>
2366      <property name="catalina.opts" value="-Djava.util.prefs.syncInterval=2000000 -DGSDL3HOME=$GSDL3HOME -DGSDLOS=$GSDLOS -DPATH=$PATH -Xmx800M ${readonly.catalina.opts} ${fedora.maxpermsize}"/>
2367      <else>
2368    <property name="catalina.opts" value="-Djava.util.prefs.syncInterval=2000000 -DGSDL3HOME=$GSDL3HOME -DGSDLOS=$GSDLOS -DPATH=$PATH -Xmx800M ${readonly.catalina.opts}"/>
2369      </else>
2370    </if>
2371
2372    <echo file="${catalina.home}/bin/setenv.bat">set CLASSPATH=${tomcat.classpath}</echo>
2373    <echo file="${catalina.home}/bin/setenv.sh">export CLASSPATH=${tomcat.classpath}</echo>
2374
2375    <!-- using osfamily instead of testing os against os.windows list of recognised windows versions
2376     so that future windows versions are included. See http://simonharrer.wordpress.com/tag/osfamily/
2377    Can't use the osfamily test for linux-type machines as a group since osfamily=unix is separate from osfamily=mac,
2378    see http://ant-contrib.sourceforge.net/tasks/tasks/osfamily.html -->
2379
2380    <!--<exec executable="${catalina.home}/bin/startup.sh" os="${os.unix}" dir="${catalina.home}/bin" spawn="false">-->
2381    <exec executable="${sudo.or.not}" os="${os.unix}" dir="${catalina.home}/bin" spawn="false">
2382      <!--<env key="GSDLOS" value="linux"/> do we need this?? -->
2383      <env key="GSDL3HOME" value="${basedir}"/>
2384      <env key="PATH" path="${tomcat.path}"/>
2385      <env key="CATALINA_OPTS" value="${catalina.opts}"/>
2386      <env key="CATALINA_HOME" value="${catalina.home}"/>
2387      <env key="CLASSPATH" path="${tomcat.classpath}"/>
2388      <env key="LD_LIBRARY_PATH" path="${env.LD_LIBRARY_PATH}:${lib.jni}"/>
2389      <env key="DYLD_LIBRARY_PATH" path="${env.DYLD_LIBRARY_PATH}:${lib.jni}:${gdbm.home}/lib"/> <!-- for mac os --> <!-- need gdbm here these days ??-->
2390      <env key="WNHOME" path="${wn.home}"/>
2391      <env key="FEDORA_HOME" path="${fedora.home}"/>
2392      <arg value="${catalina.home}/bin/startup.sh"/>
2393    </exec>
2394    <exec executable="${catalina.home}/bin/startup.bat" osfamily="windows" dir="${catalina.home}/bin" spawn="true">
2395      <env key="GSDLOS" value="windows"/>
2396      <env key="GSDL3HOME" value="${basedir}"/>
2397      <env key="Path" path="${tomcat.path}"/>
2398      <env key="PATH" path="${tomcat.path}"/>
2399      <env key="CATALINA_OPTS" value="${catalina.opts}"/>
2400      <env key="CATALINA_HOME" value="${catalina.home}"/>
2401      <env key="CLASSPATH" path="${tomcat.classpath}"/>
2402      <env key="FEDORA_HOME" path="${fedora.home}"/>
2403    </exec>
2404    <!-- wait for the server to startup in case other targets need it running -->
2405    <waitfor maxwait="5" maxwaitunit="second">
2406      <and>
2407        <socket server="${tomcat.server}" port="${default.tomcat.port}"/>
2408        <!--<http url="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}/index.html"/>-->
2409        <http url="${local.http.url}${app.path}/index.html"/>
2410      </and>
2411    </waitfor>
2412
2413  </target>
2414
2415  <!--ant task http: http://www.jajakarta.org/ant/ant-1.6.1/docs/ja/manual/api/org/apache/tools/ant/taskdefs/condition/Http.html-->
2416  <target name="reconfigure" description="Reconfigure the message router">
2417    <waitfor maxwait="5" maxwaitunit="second">
2418      <!--<http url="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}${server.default.servlet}?a=s&amp;sa=c"/>-->
2419      <http url="${local.http.url}${app.path}${server.default.servlet}?a=s&amp;sa=c"/>
2420    </waitfor>
2421  </target>
2422
2423  <!--Command-line args to Ant: http://www.jguru.com/faq/view.jsp?EID=471794-->
2424  <target name="reconfigure-collection" description="Reconfigure the collection">
2425    <waitfor maxwait="5" maxwaitunit="second">
2426      <!--<http url="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}${server.default.servlet}?a=s&amp;sa=c&amp;sc=${collection}"/>-->
2427      <http url="${local.http.url}${app.path}${server.default.servlet}?a=s&amp;sa=c&amp;sc=${collection}"/>
2428    </waitfor>
2429  </target>
2430
2431  <!-- windows: do we want to launch a webrowser?? -->
2432  <!-- shouldn't this test whether anything is running first?
2433       It's safer to always attempt to stop tomcat: that way we won't be dependent on the right time
2434       to check whether the server is stopped or still running before attempting to start again.
2435       This target, which was recently called force-stop-tomcat for a while but is back to being
2436       called stop-tomcat, now hides the Java exception output that appears whenever tomcat is already
2437       stopped as happens when stop-tomcat is called consecutively. -->
2438  <target name="force-stop-tomcat" description="Shutdown only Tomcat" depends="init" if="tomcat.islocal">
2439    <!--<exec executable="${catalina.home}/bin/shutdown.sh" os="${os.unix}" dir="${catalina.home}/bin" spawn="false">-->
2440    <exec executable="${sudo.or.not}" os="${os.unix}" dir="${catalina.home}/bin" spawn="false">
2441      <env key="FEDORA_HOME" path="${fedora.home}"/>
2442      <env key="CATALINA_HOME" value="${catalina.home}"/>
2443      <arg value="${catalina.home}/bin/shutdown.sh"/>
2444      <arg line=">/dev/null 2>&amp;1"/>
2445    </exec>
2446    <exec executable="${catalina.home}/bin/shutdown.bat" osfamily="windows" dir="${catalina.home}/bin" spawn="false">
2447      <env key="FEDORA_HOME" path="${fedora.home}"/>
2448      <env key="CATALINA_HOME" value="${catalina.home}"/>
2449      <arg line=">nul 2>&amp;1"/>
2450    </exec>   
2451  </target>
2452
2453  <!-- Can also try the "socket" condition in place of the "http" condition
2454       And also use a <waitfor> in place of <condition>, such as:
2455       <waitfor maxwait="5" maxwaitunit="second" timeoutproperty="tomcat.isstopped"><http url="..."/></waitfor>
2456       The http URL resolves to host:port/greenstone3
2457       Condition uses <http/> rather than <socket/> for testing, since if the server was stopped, the socket
2458       might still be in use for some moments. We test the URL with the http condition since it's likelier to
2459       fail sooner if the server has indeed been stopped. -->
2460  <target name="check-tomcat-running">
2461    <condition property="tomcat.isrunning">
2462      <!--<http url="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}"/>-->
2463      <!--<http url="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}"/>--><!-- untrusted certificates won't work, so don't test https urls-->
2464      <http url="${local.http.url}"/><!-- testing the local http url instead -->
2465    </condition>
2466  </target>
2467 
2468  <!--
2469      <target name="verbose-check-tomcat-running">
2470      <condition property="tomcat.isrunning" value="true" else="false">
2471      <http url="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}"/>
2472      <http url="${local.http.url}"/>
2473      </condition>
2474      <echo>Tomcat is running: ${tomcat.isrunning}</echo>
2475      </target>
2476  -->
2477  <target name="verbose-check-tomcat-running" depends="check-tomcat-running">   
2478    <if>
2479      <bool>
2480    <istrue value="${tomcat.isrunning}"/>
2481      </bool>     
2482      <echo>Tomcat is running: ${tomcat.isrunning}</echo>
2483      <else><echo>Tomcat is running: false</echo></else><!-- tomcat.isrunning not set -->
2484    </if>
2485  </target> 
2486 
2487  <!-- Need a copy of the check-tomcat-running target with a distinct property, because ant restart runs
2488       both stop and start, both of which need to do tomcat checks. Each property can be set only once during
2489       an invocation with ant. So ant restart will need two properties to store each of the tomcat checks -->
2490  <target name="check-tomcat-started">
2491    <condition property="tomcat.isstarted">
2492      <!--<http url="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}"/>-->
2493      <http url="${local.http.url}"/>
2494    </condition>
2495  </target>
2496
2497
2498
2499  <!-- stop-tomcat checks if the tomcat server is already running. If it appears to be running
2500       (regardless of whether tomcat was just starting to shut down), this target calls force-stop-tomcat
2501       to issue the shutdown command to tomcat. Then it waits for at most 15 seconds for the server to
2502       actually stop by checking the socket at which tomcat listens every second, printing a warning
2503       at the end of the max wait time of 15 seconds if tomcat was still running. -->
2504  <target name="stop-tomcat" description="Shutdown only Tomcat if running" depends="check-tomcat-running" if="tomcat.isrunning">
2505     <antcall target="force-stop-tomcat"/>
2506
2507     <property name="wait.numchecks" value="15"/>
2508     <echo>Waiting for the server to shutdown... (${wait.numchecks} seconds max)</echo>
2509     <waitfor maxwait="${wait.numchecks}" maxwaitunit="second" checkevery="1" checkeveryunit="second" timeoutproperty="tomcat.timedout">
2510       <not><socket server="${tomcat.server}" port="${default.tomcat.port}"/></not>
2511     </waitfor>
2512     
2513     <if>
2514       <bool>
2515     <isset property="${tomcat.timedout}"/>
2516       </bool>
2517       <property name="tomcat.isrunning" value="true"/>
2518       <echo>WARNING: Checked the socket ${wait.numchecks} times, but port ${default.tomcat.port} is still busy.</echo>
2519       <else>
2520     <echo>Tomcat is stopped.</echo>
2521     <property name="tomcat.isrunning" value="false"/>
2522       </else>
2523     </if>
2524  </target>
2525
2526  <target name="restart-tomcat" description="Shutdown and restart only Tomcat" depends="init,stop-tomcat,force-start-tomcat"/>
2527
2528  <target name="setup-catalina-ant-tasks">
2529    <!-- Configure the custom Ant tasks for the Tomcat Manager application -->
2530    <taskdef name="deploy"    classname="org.apache.catalina.ant.DeployTask"
2531      classpath="${catalina.home}/server/lib/catalina-ant.jar"/>
2532    <taskdef name="list"      classname="org.apache.catalina.ant.ListTask"
2533      classpath="${catalina.home}/server/lib/catalina-ant.jar"/>
2534    <taskdef name="reload"    classname="org.apache.catalina.ant.ReloadTask"
2535      classpath="${catalina.home}/server/lib/catalina-ant.jar"/>
2536    <taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"
2537      classpath="${catalina.home}/server/lib/catalina-ant.jar"/>
2538    <taskdef name="roles"     classname="org.apache.catalina.ant.RolesTask"
2539      classpath="${catalina.home}/server/lib/catalina-ant.jar"/>
2540    <taskdef name="start"     classname="org.apache.catalina.ant.StartTask"
2541      classpath="${catalina.home}/server/lib/catalina-ant.jar"/>
2542    <taskdef name="stop"      classname="org.apache.catalina.ant.StopTask"
2543      classpath="${catalina.home}/server/lib/catalina-ant.jar"/>
2544    <taskdef name="undeploy"  classname="org.apache.catalina.ant.UndeployTask"
2545      classpath="${catalina.home}/server/lib/catalina-ant.jar"/>
2546  </target>
2547
2548  <!-- http://blog.andrewbeacock.com/2007/11/how-to-truncate-log-file-using-ubuntu.html
2549    Doing "cat </dev/null > packages/tomcat/logs/catalina.out" doesn't work as an ant target.
2550    It seems to have a problem with cat or </dev/null, with or without the < sign. -->
2551  <target name="reset-logs" description="Empties catalina.out, greenstone.log and contents of web/logs/tmp">
2552    <echo>Truncating catalina.out, solr.log, greenstone.log and server.log, and emptying ${web.writablehome}/logs/tmp</echo>   
2553    <exec executable="rm" os="${os.unix}" dir="${catalina.home}/logs" spawn="false">
2554      <arg value="-f"/>
2555      <arg value="catalina.out"/>
2556    </exec>
2557    <exec executable="rm" os="${os.unix}" dir="${web.writablehome}/logs" spawn="false">
2558      <arg value="-f"/>
2559      <arg value="greenstone.log"/>
2560    </exec>
2561    <exec executable="rm" os="${os.unix}" dir="${web.writablehome}/logs" spawn="false">
2562      <arg value="-f"/>
2563      <arg value="server.log"/>
2564    </exec>
2565
2566    <exec executable="touch" os="${os.unix}" dir="${catalina.home}/logs"
2567    spawn="false">
2568      <arg value="catalina.out"/>
2569    </exec>
2570    <exec executable="touch" os="${os.unix}" dir="${web.writablehome}/logs"
2571      spawn="false">
2572      <arg value="greenstone.log"/>
2573    </exec>
2574    <exec executable="touch" os="${os.unix}" dir="${web.writablehome}/logs"
2575      spawn="false">
2576      <arg value="server.log"/>
2577    </exec>
2578
2579    <exec executable="cmd" osfamily="windows" dir="${catalina.home}/logs" spawn="false">
2580      <arg line="/c echo. > catalina.out"/>
2581    </exec>
2582    <exec executable="cmd" osfamily="windows" dir="${web.writablehome}/logs" spawn="false">
2583      <arg line="/c echo. > greenstone.log"/>
2584    </exec>
2585    <exec executable="cmd" osfamily="windows" dir="${web.writablehome}/logs" spawn="false">
2586      <arg line="/c echo. > server.log"/>
2587    </exec>
2588
2589    <!-- if ext/solr/logs/solr.log exists, truncate it -->
2590    <if><bool><available file="${solr-ext.home}/logs/solr.log" type="file"/></bool>     
2591        <exec executable="rm" os="${os.unix}" dir="${solr-ext.home}/logs" spawn="false">
2592          <arg value="-f"/>
2593          <arg value="solr.log"/>
2594        </exec>
2595        <exec executable="touch" os="${os.unix}" dir="${solr-ext.home}/logs" spawn="false">
2596          <arg value="solr.log"/>
2597        </exec>   
2598        <exec executable="cmd" osfamily="windows" dir="${solr-ext.home}/logs" spawn="false">
2599          <arg line="/c echo. > solr.log"/>
2600        </exec>
2601    </if>
2602   
2603    <if>
2604      <bool><available file="${web.writablehome}/logs/tmp" type="dir"/></bool>
2605      <delete>
2606    <fileset dir="${web.writablehome}/logs/tmp" includes="**/*"/>
2607      </delete>
2608    </if>
2609  </target>
2610
2611  <target name="clear-tomcat-sessions" description="Clear the Tomcat Session info." depends="init">
2612    <exec executable="cmd" osfamily="windows" dir="${catalina.home}/work/Catalina/localhost/greenstone3" spawn="false">
2613      <arg line="/c echo. > SESSIONS.ser"/>
2614    </exec>
2615    <exec executable="rm" os="${os.unix}" dir="${catalina.home}/work/Catalina/localhost/greenstone3" spawn="false">
2616      <arg value="-f"/>
2617      <arg value="SESSIONS.ser"/>
2618    </exec>
2619
2620  </target>
2621  <!-- ======================= ant Targets ============================ -->
2622  <target name="prepare-ant" depends="init">
2623    <if>
2624      <bool>
2625        <not><available file="${packages.home}/ant/.flagfile"/></not>
2626      </bool>
2627      <property name="ant.download.version" value="apache-ant-1.9.13" />
2628      <get src="http://www.greenstone.org/gs3files/${ant.download.version}-bin.zip"
2629        dest="${packages.home}/${ant.download.version}-bin.zip"
2630        usetimestamp="true"/>
2631      <unzip src="${packages.home}/${ant.download.version}-bin.zip"
2632        dest="${packages.home}"/>
2633      <move todir="${packages.home}/ant">
2634        <fileset dir="${packages.home}/${ant.download.version}"/>
2635      </move>
2636      <echo file="${packages.home}/ant/.flagfile">
2637        the timestamp of this file is the time that ant was extracted from the zip files.
2638        it is used to figure out whether the files need to be refreshed or not in `ant prepare-ant`
2639      </echo>
2640
2641      <else>
2642        <echo>Ant has been prepared, will not prepare</echo>
2643        <echo>Delete ${packages.home}/ant/.flagfile to force refresh</echo>
2644      </else>
2645
2646    </if>
2647  </target>
2648
2649  <!-- ======================= Admin Targets ============================ --> 
2650
2651  <!-- This target won't work with Eclipse because the SecureInputHandler used below conflicts with it.
2652    See http://www.dcepler.net/post.cfm/hiding-password-input-in-ant
2653    But you can do: echo mypassword | ant config-admin -->
2654  <target name="config-admin" description="Reset admin password">
2655    <input addproperty="admin.password" defaultvalue="admin" message="New admin password (3-20 characters):&gt;">
2656      <handler classname="org.apache.tools.ant.input.SecureInputHandler" /> <!-- password won't be visible on screen -->
2657    </input>
2658    <!--<echo>PWD: ${admin.password}</echo>-->
2659    <antcall target="update-userdb">
2660      <param name="user.username" value="admin"/>
2661      <param name="user.password" value="${admin.password}"/>
2662      <param name="user.groups" value=""/>
2663      <param name="user.status" value=""/>
2664      <param name="user.comment" value="Password updated."/>
2665      <param name="user.email" value=""/>
2666    </antcall>
2667  </target>
2668
2669  <target name="config-user" description="Add or modify users" depends="get-user-data,update-userdb"/>
2670
2671  <target name="get-user-data" description="Get user details">
2672    <input addproperty="user.username" message="Username:&gt;"/>
2673    <input addproperty="user.password" defaultvalue="" message="Password (3-20 characters):&gt;">
2674      <handler classname="org.apache.tools.ant.input.SecureInputHandler" /> <!-- password won't be visible on screen -->
2675    </input>
2676    <input addproperty="user.groups" defaultvalue="" message="Groups (comma-separated list, e.g. personal-collections-editor):&gt;"/>
2677    <input addproperty="user.status" defaultvalue="true" message="Enabled (true/false):&gt;"/>
2678    <input addproperty="user.comment" defaultvalue="" message="Comment:&gt;"/>
2679    <input addproperty="user.email" defaultvalue="" message="Email:&gt;"/>
2680  </target>
2681
2682  <!-- This target won't work with Eclipse because the SecureInputHandler used below conflicts with it.
2683       See http://www.dcepler.net/post.cfm/hiding-password-input-in-ant
2684       But you can do: echo mypassword | ant config-admin -->
2685  <target name="update-userdb" description="Add or modify users" depends="start-derby">
2686
2687    <!--
2688       We're now using derby networked server, so stopping and starting tomcat is not necessary.
2689       For embedded derby: stop tomcat if running, since derby db is embedded
2690       and only allows connections from one jvm instance at a time
2691     See http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
2692     The ${tomcat.isrunning} property is set by the depends-target "check-tomcat-running" -->
2693   
2694    <!-- Need the derby networked server to be running in order to modify the usersDB.
2695     The start-derby task will check if derby is already running (if not, ${derby.isstarted} will
2696     be false) and will only start up networked derby if it is not already running.
2697     The ${derby.isstarted} property is set by the depends-target "start-derby", since it won't
2698     set the property if called with antcall (like launching in a subshell). Have to use 'depends'.
2699     We'll check ${derby.isstarted} at the end to stop derby again if we had to start it up now.-->
2700    <!--<antcall target="start-derby"/>-->
2701
2702    <!-- wait a max of 5 seconds for the derbyserver to have started up -->
2703    <waitfor maxwait="5" maxwaitunit="second">
2704      <socket server="${derby.server}" port="${derby.server.port}"/>
2705    </waitfor>
2706
2707    <!--<echo>${admin.password}</echo>--> <!-- for testing -->
2708    <echo>gsdl3.writablehome: ${gsdl3.writablehome}</echo> <!-- for testing -->
2709    <echo>web.home: ${web.home}</echo> <!-- for testing -->
2710    <java classname="org.greenstone.gsdl3.util.ModifyUsersDB">
2711      <classpath refid="compile.classpath"/> <!--for ${web.lib}/gsdl3.jar and supporting files-->
2712      <sysproperty key="gsdl3.writablehome" value="${gsdl3.writablehome}" /> <!-- passes -D<syspropKey=syspropVal> to java class ModifyUsersDB. Available in java code as System.getProperty("syspropKey") -->
2713      <arg file="${web.home}/etc/usersDB"/>
2714      <arg value="${user.username}"/>
2715      <arg value="password=${user.password}"/>
2716      <arg value="groups=${user.groups}"/>
2717      <arg value="status=${user.status}"/>
2718      <arg value="comment=${user.comment}"/>
2719      <arg value="email=${user.email}"/>
2720    </java>
2721
2722    <!-- Need to stop networked derby again if we ran it for this target with the depends=start-derby call.
2723     The test here is for <not>derby.isstarted</not>, as the property would be the same as before
2724     derby was started, since properties are immutable within a single ant command. -->
2725    <if>
2726      <bool>
2727    <not><istrue value="${derby.isstarted}"/></not>
2728      </bool>
2729      <antcall target="force-stop-derby"/>
2730    </if>
2731
2732  </target>
2733
2734
2735  <!-- ======================= Axis Targets ============================ --> 
2736 
2737  <target name="prepare-axis" depends="init">
2738
2739    <if>
2740      <bool>
2741        <not><available file="${packages.home}/axis/.flagfile"/></not>
2742      </bool>
2743
2744      <get src="http://www.greenstone.org/gs3files/${axis.zip.version}"
2745        dest="${packages.home}/${axis.zip.version}"
2746        usetimestamp="true"/>
2747      <unzip src="${packages.home}/${axis.zip.version}"
2748        dest="${packages.home}"/>
2749      <move todir="${packages.home}/axis">
2750        <fileset dir="${packages.home}/${axis.dir.version}"/>
2751      </move>
2752      <!-- install axis into greenstone web app -->
2753      <copy todir="${web.lib}">
2754        <fileset dir="${packages.home}/axis/webapps/axis/WEB-INF/lib">
2755          <include name="*.jar"/>
2756        </fileset>
2757      </copy>
2758      <copy todir="${web.home}">
2759        <fileset dir="${packages.home}/axis/webapps/axis/">
2760          <include name="*.jsp"/>
2761          <include name="*.jws"/>
2762        </fileset>
2763      </copy>
2764      <copy tofile="${web.home}/axis.html" file="${packages.home}/axis/webapps/axis/index.html"/>
2765      <copy todir="${web.classes}">
2766        <fileset dir="${packages.home}/axis/webapps/axis/WEB-INF/classes">
2767          <include name="*.properties"/>
2768        </fileset>
2769      </copy>
2770      <echo file="${packages.home}/axis/.flagfile">
2771        the timestamp of this file is the time that axis was extracted from the zip files.
2772        it is used to figure out whether the files need to be refreshed or not in `ant prepare-axis`
2773      </echo>
2774
2775      <else>
2776        <echo>Axis has been prepared, will not prepare</echo>
2777        <echo>Delete ${packages.home}/axis/.flagfile to force refresh</echo>
2778      </else>
2779
2780    </if>
2781  </target>
2782
2783  <target name="soap-deploy-site" depends="init,get-sitename,get-siteuri,get-webservices,create-deployment-files,deploy-site"
2784    description="Deploy a SOAP web service for a local Greenstone site. Tomcat must be running for this to work."/>
2785   
2786    <target name="deploy-site">
2787    <java classname="org.apache.axis.client.AdminClient">
2788      <classpath refid="compile.classpath"/>
2789      <arg value="-l"/>
2790      <arg value="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}/servlet/AxisServlet"/>
2791      <arg file="${basedir}/resources/soap/deploy.wsdd"/>
2792    </java>
2793    <delete file="${basedir}/resources/soap/deploy.wsdd"/> <!--clean up, no longer used-->
2794  </target>
2795 
2796  <target name="soap-undeploy-site" depends="get-undeploy-service-name"
2797    description="Undeploy a SOAP web service for a local Greenstone site. Tomcat must be running for this to work.">
2798    <filter token="servicesname" value="${axis.undeploy.servicename}"/>
2799    <copy file="${basedir}/resources/soap/undeploy-site.wsdd.template"
2800      tofile="${basedir}/resources/soap/undeploy.wsdd"
2801      filtering="true"
2802      overwrite="true"/>
2803    <java classname="org.apache.axis.client.AdminClient">
2804      <classpath refid="compile.classpath"/>
2805      <arg value="-l"/>
2806      <arg value="${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}/servlet/AxisServlet"/>
2807      <arg file="${basedir}/resources/soap/undeploy.wsdd"/>
2808    </java>
2809    <delete file="${basedir}/resources/soap/undeploy.wsdd"/> <!--clean up, no longer used-->
2810  </target> 
2811
2812  <!-- this target used to deploy the default web service SOAPServer (base.webservice.name) on the localsite server
2813  with the default servicename of localsite-->
2814  <target name="deploy-localsite" depends="init"
2815    description="Deploy the SOAP server for localsite. Will start and stop Tomcat.">
2816    <antcall target="force-start-tomcat"/>
2817    <echo>Deploying ${base.webservice.name} web services for localsite under service name: localsite</echo>
2818    <antcall target="create-deployment-files">
2819      <param name="axis.sitename" value="localsite"/>
2820      <param name="axis.servicesname" value="${base.webservice.name}"/>
2821      <param name="axis.siteuri" value="localsite"/>
2822    </antcall>
2823    <antcall target="deploy-site">
2824      <param name="axis.sitename" value="localsite"/>
2825      <param name="axis.servicesname" value="${base.webservice.name}"/>
2826      <param name="axis.siteuri" value="localsite"/>
2827    </antcall>
2828    <echo>The Greenstone server has been started up. If you do not want it running, please type: ant stop.</echo>
2829  </target>
2830   
2831  <target name="get-sitename" unless="axis.sitename">
2832    <input addproperty="axis.sitename" defaultvalue="localsite">What site do you want to deploy services for?
2833Press Enter for default:localsite</input>
2834  </target>
2835
2836  <target name="get-undeploy-service-name" unless="axis.undeploy.servicename">
2837    <input addproperty="axis.undeploy.servicename" defaultvalue="localsite">Please enter the full name of the service you wish to undeploy.
2838To find out which web services you've got deployed, point your browser to ${default.server.protocol}://${tomcat.server}:${default.tomcat.port}/greenstone3/services
2839Or press Enter for undeploying the default:localsite /&gt;</input>
2840     <echo>Name of service to undeploy: ${axis.undeploy.servicename}</echo>
2841  </target>
2842
2843  <target name="get-webservices" unless="axis.servicesname">
2844    <input addproperty="axis.servicesname" defaultvalue="${base.webservice.name}">Which set of web services do you want to deploy?
2845Choose from: ${web.services.list}
2846Or press Enter for default:${base.webservice.name} /&gt;</input>
2847    <echo>${axis.servicesname}</echo>
2848  </target>
2849
2850  <target name="get-siteuri" depends="get-sitename,get-webservices" unless="axis.siteuri">
2851    <input addproperty="axis.siteuri" defaultvalue="${axis.servicesname}${axis.sitename}">What name do you want the service to have? (Press Enter for default:${axis.servicesname}${axis.sitename})</input>
2852    <echo>Site: ${axis.sitename}, services: ${axis.servicesname}, servicesname: ${axis.siteuri}</echo>
2853  </target>
2854
2855  <target name="set-soapmethod" description="Determines whether the service in the wsdd should have the style attribute set to message or the provider attribute set to java:RPC"  if="axis.servicesname">
2856   <condition property="soap.method" value="provider='java:MSG' style='message' use='literal'">
2857      <equals arg1="${axis.servicesname}" arg2="${base.webservice.name}"/>
2858    </condition>
2859   
2860   <!--everything else defaults to java:RPC at present-->
2861   <condition property="soap.method" value="provider='java:RPC'">
2862     <not>
2863      <equals arg1="${axis.servicesname}" arg2="${base.webservice.name}"/>
2864    </not>
2865    </condition>
2866  </target>
2867   
2868  <target name="create-deployment-files" depends="set-soapmethod" if="axis.sitename">
2869    <filter token="sitename" value="${axis.sitename}"/>
2870    <filter token="siteuri" value="${axis.siteuri}"/>
2871    <filter token="servicesname" value="${axis.servicesname}"/>
2872    <filter token="soapmethod" value="${soap.method}"/>
2873    <copy file="${basedir}/resources/soap/site.wsdd.template"
2874      tofile="${basedir}/resources/soap/deploy.wsdd"
2875      filtering="true"
2876      overwrite="true"/>
2877    <!-- create the java files and compile them -->
2878    <copy file="${basedir}/resources/java/${axis.servicesname}.java.in"
2879      tofile="${src.gsdl3.home}/${axis.servicesname}${axis.sitename}.java"
2880      filtering="true"
2881      overwrite="true"/>
2882    <mkdir dir="${build.home}"/>
2883    <javac srcdir="${src.home}"
2884      destdir="${build.home}"
2885      includeantruntime="${compile.includeantruntime}"
2886      debug="${compile.debug}"
2887      deprecation="${compile.deprecation}"
2888      optimize="${compile.optimize}"
2889      encoding="${compile.encoding}">
2890      <classpath refid="compile.classpath"/>
2891      <include name="org/greenstone/gsdl3/${axis.servicesname}${axis.sitename}.java" />
2892    </javac>
2893    <mkdir dir="${web.classes}/org/greenstone/gsdl3"/>
2894    <copy file="${build.home}/org/greenstone/gsdl3/${axis.servicesname}${axis.sitename}.class"
2895      tofile="${web.classes}/org/greenstone/gsdl3/${axis.servicesname}${axis.sitename}.class"
2896      overwrite="true" />
2897  </target>
2898 
2899
2900  <!-- ====================== Core targets ============================== -->
2901  <!-- core targets refer to the core gsdl3 java src -->
2902 
2903  <target name="prepare-core"/>
2904 
2905  <target name="configure-core"/>
2906
2907  <target name="update-core" depends="init,svnupdate-core,clean-core,compile-core"
2908    description="Update only the Greenstone core" />
2909 
2910  <target name="svnupdate-core" unless="nosvn.mode">
2911    <exec executable="svn">
2912      <arg value="update"/>
2913      <arg value="${basedir}"/>
2914      <arg value="-r"/><arg value="${branch.revision}"/>
2915    </exec>
2916  </target>
2917
2918  <target name="clean-core"
2919    description="Clean only the Greenstone core">
2920    <!-- should this delete the gsdl3.jar from web/WEB-INF?? -->
2921    <delete dir="${build.home}"/>
2922  </target>
2923
2924  <target name="compile-core" depends="init"
2925    description="Compile only the Greenstone core">
2926    <mkdir dir="${build.home}"/>
2927   
2928    <if><bool><isset property="with.jni"/></bool>
2929    <javac srcdir="${src.home}"
2930           destdir="${build.home}"
2931           includeantruntime="${compile.includeantruntime}"
2932           debug="${compile.debug}"
2933           deprecation="${compile.deprecation}"
2934           optimize="${compile.optimize}"
2935           encoding="${compile.encoding}">
2936      <classpath>
2937            <path refid="compile.classpath"/>
2938      </classpath>
2939    </javac>
2940    <else>
2941      <property name="gsprefix" value=""/>   
2942      <javac srcdir="${src.home}"
2943         destdir="${build.home}"
2944         includeantruntime="${compile.includeantruntime}"
2945         debug="${compile.debug}"
2946         deprecation="${compile.deprecation}"
2947         optimize="${compile.optimize}"
2948         encoding="${compile.encoding}">
2949        <classpath>
2950              <path refid="compile.classpath"/>
2951        </classpath>
2952        <exclude name="org/greenstone/gsdl3/service/GS2MGPPRetrieve.java"/>
2953        <exclude name="org/greenstone/gsdl3/service/GS2MGPPSearch.java"/>
2954        <exclude name="org/greenstone/gsdl3/service/GS2MGSearch.java"/>
2955        <exclude name="org/greenstone/gsdl3/service/GS2MGRetrieve.java"/>
2956        <exclude name="org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java"/>
2957        <exclude name="org/greenstone/gsdl3/service/PhindPhraseBrowse.java"/>
2958        <exclude name="org/greenstone/gsdl3/util/GDBMWrapper.java"/>
2959      </javac>
2960    </else>
2961    </if>
2962    <jar destfile="${build.home}/gsdl3.jar">
2963      <fileset dir="${build.home}">
2964        <include name="org/greenstone/gsdl3/**"/>
2965        <include name="org/flax/**"/>
2966        <exclude name="**/Test.class"/>
2967      </fileset>
2968      <manifest>
2969        <attribute name="Built-By" value="${user.name}" />
2970      </manifest>
2971    </jar>
2972    <copy file="${build.home}/gsdl3.jar" todir="${web.lib}"/>
2973
2974    <jar destfile="${build.home}/gutil.jar">
2975      <fileset dir="${build.home}">
2976        <include name="org/greenstone/util/**"/>
2977      </fileset>
2978      <manifest>
2979        <attribute name="Built-By" value="${user.name}" />
2980      </manifest>
2981    </jar>
2982    <copy file="${build.home}/gutil.jar" todir="${web.lib}"/>
2983
2984    <!-- copy the localsite server in case we need it -->
2985    <copy file="${build.home}/org/greenstone/gsdl3/${base.webservice.name}localsite.class" tofile="${web.classes}/org/greenstone/gsdl3/${base.webservice.name}localsite.class" />
2986
2987    <!-- Greenstone Administrator Interface -->
2988    <jar destfile="${build.home}/GAI.jar">
2989      <fileset dir="${build.home}">
2990        <include name="org/greenstone/admin/**"/>
2991      </fileset>
2992      <manifest>
2993        <attribute name="Built-By" value="${user.name}" />
2994      </manifest>
2995    </jar>
2996    <copy file="${build.home}/GAI.jar" todir="${web.lib}"/>
2997    <copy file="${build.home}/GAI.jar" todir="${admin.dir}"/>
2998    <jar destfile="${build.home}/phind.jar">
2999      <fileset dir="${build.home}">
3000        <include name="org/greenstone/applet/phind/**"/>
3001      </fileset>
3002      <manifest>
3003        <attribute name="Built-By" value="${user.name}" />
3004      </manifest>
3005    </jar>
3006    <mkdir dir="${web.applet}"/>
3007    <copy file="${build.home}/phind.jar" todir="${web.applet}"/>
3008    <!-- phind also needs xercesImpl.jar and xml-apis.jar to be in web/applet -->
3009    <if>
3010      <bool><istrue value="${tomcat.islocal}"/></bool>
3011      <if><bool><available file="${catalina.home}/lib/xercesImpl.jar"/></bool><!-- moved for solr -->
3012    <copy file="${catalina.home}/lib/xercesImpl.jar" todir="${web.applet}"/>
3013    <copy file="${catalina.home}/lib/xml-apis.jar" todir="${web.applet}"/>
3014   
3015    <else><!-- get from default GS3 web lib location-->
3016      <copy file="${web.lib}/xercesImpl.jar" todir="${web.applet}"/>
3017      <copy file="${web.lib}/xml-apis.jar" todir="${web.applet}"/>
3018    </else>
3019      </if>
3020    </if>
3021
3022
3023    <!-- skip anttasks for now
3024    <jar destfile="${build.home}/anttasks.jar">
3025      <fileset dir="${build.home}">
3026        <include name="org/greenstone/anttasks/**"/>
3027      </fileset>
3028      <manifest>
3029        <attribute name="Built-By" value="${user.name}" />
3030      </manifest>
3031    </jar>
3032    <copy file="${build.home}/anttasks.jar" todir="${basedir}/lib/java"/>-->
3033    <jar destfile="${build.home}/gsdl3test.jar">
3034      <fileset dir="${build.home}">
3035        <include name="org/greenstone/gsdl3/**/*Test.class"/>
3036        <include name="org/greenstone/testing/**"/>
3037      </fileset>
3038      <manifest>
3039        <attribute name="Built-By" value="${user.name}" />
3040      </manifest>
3041    </jar>
3042    <jar destfile="${build.home}/server.jar">
3043      <fileset dir="${build.home}">
3044        <include name="org/greenstone/server/**"/>
3045        <include name="org/greenstone/util/**"/>
3046      </fileset>
3047      <fileset file="${basedir}/resources/java/server.properties"/>
3048      <manifest>
3049        <attribute name="Built-By" value="${user.name}"/>
3050      </manifest>
3051    </jar>
3052    <copy file="${build.home}/server.jar" todir="${basedir}"/>
3053  </target>
3054
3055  <!-- === Eclipse targets == -->
3056  <target name="setup-for-eclipse">
3057
3058    <filter token="gsdlhome" value="${gs2build.home}"/>
3059    <filter token="gsdl3srchome" value="${basedir}"/>
3060    <filter token="gsdl3home" value="${basedir}/web"/>
3061
3062    <if>
3063      <bool><not><available file="${basedir}/TransformingLibrary.launch"/></not></bool>         
3064      <copy file="${basedir}/TransformingLibrary.launch.in" tofile="${basedir}/TransformingLibrary.launch" filtering="true" overwrite="true"/>
3065    </if>
3066<!--
3067    <if>
3068      <bool><not><available file="${basedir}/LibraryCommandline.launch"/></not></bool>         
3069      <copy file="${basedir}/LibraryCommandline.launch.in" tofile="${basedir}/LibraryCommandline.launch" filtering="true" overwrite="true"/>
3070    </if>
3071-->
3072  </target>
3073 
3074  <!-- ================== Packages targets ================================ -->
3075  <!-- these targets refer to the greenstone source packages - these need
3076  updating less often, so are in  separate targets to the core -->
3077  <target name="prepare-packages" depends="init"/>
3078 
3079  <target name="update-packages" depends="init,svnupdate-packages,configure-packages,clean-packages,compile-packages"
3080    description="Update only the source packages"/>
3081
3082  <target name="svnupdate-packages" unless="nosvn.mode">
3083    <exec executable="svn">
3084      <arg value="update"/>
3085      <arg value="${src.packages.home}"/>
3086      <arg value="-r"/><arg value="${branch.revision}"/>
3087    </exec>
3088  </target>
3089
3090 
3091  <target name="configure-packages" depends="init,configure-javagdbm"
3092    description="Configure only the packages."/>
3093 
3094  <target name="configure-javagdbm" if="with.jni">
3095    <echo>
3096      Configuring JavaGDBM
3097    </echo>
3098   
3099    <exec executable="${javagdbm.home}/configure" os="${os.unix}" dir="${javagdbm.home}" failonerror="true">
3100      <arg value="--prefix=${basedir}"/>
3101      <arg value="--libdir=${lib.jni}"/>
3102      <arg value="--with-gdbm=${gdbm.home}"/>
3103      <arg line="${cross.configure.args}"/>
3104    </exec>   
3105  </target>
3106
3107  <target name="clean-packages" depends="init,clean-javagdbm" description="Clean only the packages"/>
3108
3109  <target name="clean-javagdbm" depends="init">
3110    <if><bool><available file="${javagdbm.home}/Makefile"/></bool>
3111    <exec executable="make" os="${os.unix}"
3112      dir="${javagdbm.home}" failonerror="true">
3113      <arg value="clean"/>
3114    </exec>
3115    </if>
3116  </target>
3117 
3118  <target name="distclean-packages" depends="init,distclean-javagdbm" description="Distclean only the packages"/>
3119
3120  <target name="distclean-javagdbm" depends="init">
3121    <if><bool><available file="${javagdbm.home}/Makefile"/></bool>
3122    <exec executable="make" os="${os.unix}"
3123      dir="${javagdbm.home}" failonerror="true">
3124      <arg value="distclean"/>
3125    </exec>
3126    </if>
3127  </target>
3128 
3129  <target name="compile-packages" description="Compile only the source packages">
3130    <!-- javagdbm -->
3131    <antcall target="compile-javagdbm"/>
3132    <!-- Search4j -->
3133    <antcall target="compile-search4j"/>
3134  </target>
3135
3136  <target name="compile-javagdbm" description="Compile JavaGDBM" if="with.jni">
3137   
3138    <!-- unix: -->
3139    <echo>compile javagdbm</echo>
3140    <exec executable="make" os="${os.unix}" dir="${javagdbm.home}" failonerror="true">
3141      <arg value="JAVACOPTIONS=-encoding UTF8"/>
3142    </exec>
3143    <exec executable="make" os="${os.unix}" dir="${javagdbm.home}" failonerror="true">
3144      <arg value="install"/>
3145    </exec>
3146
3147    <!-- windows: Calling without the "compile" argument first will run winMake.bat with
3148         "all" which will then perform both the compile AND link targets in jni/win32.mak
3149         (thereby also generating gdbmjava.dll). Then we run the same command with
3150         the "install" argument to copy the gdbmjava.dll into the correct location. -->
3151    <echo>Windows: compile javagdbm</echo>
3152    <exec executable="${javagdbm.home}/winMake.bat" osfamily="windows" dir="${javagdbm.home}" failonerror="true">     
3153      <env key="GSDL3SRCHOME" path="${basedir}"/>
3154    </exec>
3155    <exec executable="${javagdbm.home}/winMake.bat" osfamily="windows" dir="${javagdbm.home}" failonerror="true">
3156      <env key="GSDL3SRCHOME" path="${basedir}"/>
3157      <arg value="install"/>
3158    </exec>
3159
3160    <!-- install the jar file -->
3161    <echo>Install the javagdbm jar file ${javagdbm.home}/javagdbm.jar ${lib.jni}</echo>
3162    <copy file="${javagdbm.home}/javagdbm.jar" todir="${lib.jni}"/>
3163  </target>
3164
3165  <target name="compile-search4j">
3166
3167    <!-- windows -->
3168    <if><bool><istrue value="${current.os.iswindows}"/></bool>
3169      <exec executable="nmake" dir="${src.packages.home}/search4j" failonerror="true">
3170        <arg value="/f"/>
3171        <arg value="win32.mak"/>
3172        <arg value='BINDIR="${basedir}\bin"'/>
3173      </exec>
3174      <exec executable="nmake" dir="${src.packages.home}/search4j" failonerror="true">
3175        <arg value="/f"/>
3176        <arg value="win32.mak"/>
3177        <arg value="install"/>
3178        <arg value='BINDIR="${basedir}\bin"'/>
3179      </exec>
3180
3181    <!-- unix -->
3182    <else><if><bool><istrue value="${current.os.isunix}"/></bool>
3183      <exec executable="${src.packages.home}/search4j/configure" dir="${src.packages.home}/search4j" failonerror="true">
3184        <arg value="--bindir=${basedir}/bin"/>
3185        <arg value="${static.arg}"/>
3186        <arg line="${cross.configure.args}"/>
3187      </exec>
3188      <exec executable="make" dir="${src.packages.home}/search4j" failonerror="true"/>
3189      <exec executable="make" dir="${src.packages.home}/search4j" failonerror="true">
3190        <arg value="install"/>
3191      </exec>
3192
3193    <!-- else warn -->
3194    <else>
3195      <fail>this target does not support the current os</fail>
3196
3197    </else></if></else></if>
3198
3199  </target>
3200
3201  <target name="install-auxiliary-jar-files" depends="init">
3202
3203    <if>
3204      <bool><available file="${mg.home}/mg.jar"/></bool>
3205      <copy file="${mg.home}/mg.jar" todir="${lib.jni}"/>
3206    </if>
3207
3208    <if>
3209      <bool><available file="${mgpp.home}/mgpp.jar"/></bool>
3210      <copy file="${mgpp.home}/mgpp.jar" todir="${lib.jni}"/>
3211    </if>
3212
3213    <copy file="${lucene.home}/LuceneWrapper4.jar" todir="${web.lib}"/>   
3214  </target>
3215 
3216  <target name="install-jni-files" depends="init" if="with.jni">
3217    <antcall target="install-jni-files-linux"/>
3218    <antcall target="install-jni-files-windows"/>
3219    <antcall target="install-jni-files-macos"/>
3220  </target>
3221
3222  <target name="install-jni-files-linux" depends="init" if="current.os.isunixnotmac">
3223
3224    <if>
3225
3226      <bool><equals arg1="${os.bin.dir}" arg2="windows"/></bool>
3227      <!-- cross compiling to windows -->
3228      <copy file="${mg.home}/jni/mgretrievejni.dll" todir="${lib.jni}"/>
3229      <copy file="${mg.home}/jni/mgsearchjni.dll" todir="${lib.jni}"/>
3230      <copy file="${mg.home}/jni/mgpassjni.dll" todir="${lib.jni}"/>
3231      <copy file="${mgpp.home}/jni/mgppretrievejni.dll" todir="${lib.jni}"/>
3232      <copy file="${mgpp.home}/jni/mgppsearchjni.dll" todir="${lib.jni}"/>
3233      <copy file="${mgpp.home}/jni/mgpppassjni.dll" todir="${lib.jni}"/>
3234     
3235      <else>
3236    <!-- otherwise do the usual Unix copies -->
3237    <copy file="${mg.home}/jni/libmgretrievejni.so" todir="${lib.jni}"/>
3238    <copy file="${mg.home}/jni/libmgsearchjni.so" todir="${lib.jni}"/>
3239    <copy file="${mg.home}/jni/libmgpassjni.so" todir="${lib.jni}"/>
3240    <copy file="${mgpp.home}/jni/libmgppretrievejni.so" todir="${lib.jni}"/>
3241    <copy file="${mgpp.home}/jni/libmgppsearchjni.so" todir="${lib.jni}"/>
3242    <copy file="${mgpp.home}/jni/libmgpppassjni.so" todir="${lib.jni}"/>
3243      </else>
3244    </if>
3245
3246
3247  </target>
3248  <target name="install-jni-files-windows" depends="init" if="current.os.iswindows">
3249    <copy file="${mg.home}/jni/mgretrievejni.dll" todir="${lib.jni}"/>
3250    <copy file="${mg.home}/jni/mgsearchjni.dll" todir="${lib.jni}"/>
3251    <copy file="${mg.home}/jni/mgpassjni.dll" todir="${lib.jni}"/>
3252    <copy file="${mgpp.home}/jni/mgppretrievejni.dll" todir="${lib.jni}"/>
3253    <copy file="${mgpp.home}/jni/mgppsearchjni.dll" todir="${lib.jni}"/>
3254    <copy file="${mgpp.home}/jni/mgpppassjni.dll" todir="${lib.jni}"/>
3255  </target>
3256  <target name="install-jni-files-macos" depends="init" if="current.os.ismac">
3257    <copy file="${mg.home}/jni/libmgretrievejni.jnilib" todir="${lib.jni}"/>
3258    <copy file="${mg.home}/jni/libmgsearchjni.jnilib" todir="${lib.jni}"/>
3259    <copy file="${mg.home}/jni/libmgpassjni.jnilib" todir="${lib.jni}"/>
3260    <copy file="${mgpp.home}/jni/libmgppretrievejni.jnilib" todir="${lib.jni}"/>
3261    <copy file="${mgpp.home}/jni/libmgppsearchjni.jnilib" todir="${lib.jni}"/>
3262    <copy file="${mgpp.home}/jni/libmgpppassjni.jnilib" todir="${lib.jni}"/>
3263  </target>
3264 
3265  <!-- ========common-src targets =================================-->
3266  <!-- these are used to get common-src (for indexers, gdbm, sqlite etc) when
3267  collection building is not enabled -->
3268
3269  <target name="update-common-src" depends="init" if="collection.building.disabled">
3270  </target>
3271
3272  <target name="svnupdate-common-src" depends="init" if="collection.building.disabled" unless="nosvn.mode">
3273    <exec executable="svn">
3274      <arg value="update"/>
3275      <arg value="${common.src.home}"/>
3276      <arg value="-r"/><arg value="${branch.revision}"/>
3277    </exec>
3278  </target>
3279
3280  <target name="prepare-common-src" depends="init" if="collection.building.disabled" unless="common.src.present">
3281    <antcall target="checkout-common-src"/>
3282    <antcall target="unzip-windows-packages"/>
3283  </target>
3284
3285  <target name="checkout-common-src" depends="init" if="collection.building.disabled" unless="nosvn.mode">
3286    <echo>checking out common-src</echo>
3287    <exec executable="svn">
3288      <arg value="checkout"/>
3289      <arg value="${svn.root}/main/${branch.path}/greenstone2/common-src"/>
3290            <arg value="common-src"/>
3291      <arg value="-r"/><arg value="${branch.revision}"/>
3292    </exec>
3293  </target>
3294   
3295  <target name="configure-common-src" depends="init">
3296<!--
3297    <echo>cross configure args: ${cross.configure.args}</echo>
3298-->
3299    <exec executable="${common.src.home}/configure" os="${os.unix}"
3300      dir="${common.src.home}" failonerror="true">
3301      <arg value="--prefix=${gs2build.home}"/> <!-- what value to use?? -->
3302      <arg value="--bindir=${gs2build.home}/bin/${os.bin.dir}"/> <!-- what value to use?? -->
3303      <arg line="${gs2.opt.args}"/>
3304      <arg line="${static.arg}"/>
3305      <arg line="${cross.configure.args}"/>
3306      <arg line="${allargs}"/>
3307    </exec>
3308  </target>
3309
3310  <target name="clean-common-src" depends="init">
3311    <!-- unix:  -->
3312    <if><bool><available file="${common.src.home}/Makefile"/></bool>
3313    <exec executable="make" os="${os.unix}" dir="${common.src.home}" failonerror="true">
3314      <arg value="clean"/>
3315    </exec>
3316    </if>
3317    <!-- windows: -->   
3318    <exec executable="nmake" dir="${common.src.home}" osfamily="windows" failonerror="true">
3319      <arg value="/f"/>
3320      <arg value="win32.mak"/>
3321      <arg value="clean"/>
3322      <arg value="GSDLHOME=${gs2build.home}"/>
3323    </exec>
3324  </target>
3325  <target name="distclean-common-src" depends="init">
3326    <!-- unix:  -->
3327    <if><bool><available file="${common.src.home}/Makefile"/></bool>
3328    <exec executable="make" os="${os.unix}" dir="${common.src.home}" failonerror="true">
3329      <arg value="distclean"/>
3330    </exec>
3331    </if>
3332    <!-- windows: distclean = clean + remove configure products (remove makefiles). But on Windows there is no removing makefiles, so we just call clean -->   
3333    <exec executable="nmake" dir="${common.src.home}" osfamily="windows" failonerror="true">
3334      <arg value="/f"/>
3335      <arg value="win32.mak"/>
3336      <arg value="clean"/>
3337      <arg value="GSDLHOME=${gs2build.home}"/>
3338    </exec>
3339  </target>
3340  <target name="compile-common-src" depends="init">
3341    <!-- unix: -->
3342    <exec executable="make" os="${os.unix}" dir="${common.src.home}" failonerror="true">
3343      <arg value="${gs2.compile.target}"/>
3344    </exec>
3345    <!-- windows: -->
3346    <exec executable="nmake" dir="${common.src.home}" osfamily="windows" failonerror="true">
3347      <arg value="/f"/>
3348      <arg value="win32.mak"/>
3349      <arg value="GSDLHOME=${gs2build.home}"/>
3350      <arg value="ENABLE_JNI=${gs2.windows.enablejni}"/>
3351      <arg value="ENABLE_MG=${gs2.windows.enablemg}"/>
3352      <arg value="ENABLE_MGPP=${gs2.windows.enablemgpp}"/>
3353      <arg value="USE_GDBM=${gs2.windows.usegdbm}"/>
3354      <arg value="USE_SQLITE=${gs2.windows.usesqlite}"/>
3355    </exec>
3356  </target>
3357 
3358  <!-- ======= collection-building targets ===========================-->
3359
3360  <target name="update-collection-building" if="collection.building.enabled"
3361    depends="init,svnupdate-collection-building,gs2build-edit-setup-bat,configure-common-src,clean-common-src,compile-common-src,configure-collection-building,clean-collection-building,compile-collection-building"
3362    description="Update (SVN update, configure, compile etc) only the collection building components"/>
3363
3364  <target name="svnupdate-collection-building" if="collection.building.enabled" depends="init,svnupdate-gs2build,svnupdate-cgi,svnupdate-gli" unless="nosvn.mode"
3365    description="SVN update the collection building components">
3366  </target>
3367
3368  <target name="prepare-collection-building" depends="init,prepare-gs2build,svnupdate-cgi,prepare-gli" if="collection.building.enabled">
3369  </target>
3370
3371  <target name="configure-collection-building" depends="init,configure-build-src" if="collection.building.enabled"
3372    description="Configure the collection building components">
3373  </target>
3374
3375  <target name="clean-collection-building" depends="init,clean-gli,clean-build-src"
3376    description="Clean only the collection building components"
3377    if="collection.building.enabled"/>
3378
3379  <target name="distclean-collection-building" depends="init,clean-build-src,distclean-build-src"
3380    description="Distclean only the collection building components"
3381    if="collection.building.enabled"/>
3382
3383  <target name="compile-collection-building" depends="init,compile-build-src,compile-gli" if="collection.building.enabled"
3384    description="Compile only the collection building components">
3385    <!-- make install for common-src -->
3386    <!-- unix: -->
3387    <exec executable="make" os="${os.unix}" dir="${common.src.home}" failonerror="true">
3388      <arg value="${gs2.install.target}"/>
3389    </exec>
3390     
3391    <!-- windows: -->
3392    <exec executable="nmake" dir="${common.src.home}" osfamily="windows" failonerror="true">
3393      <arg value="/f"/>
3394      <arg value="win32.mak"/>
3395      <arg value="install"/>
3396      <arg value="GSDLHOME=${gs2build.home}"/>
3397      <arg value="ENABLE_JNI=${gs2.windows.enablejni}"/>
3398      <arg value="ENABLE_MG=${gs2.windows.enablemg}"/>
3399      <arg value="ENABLE_MGPP=${gs2.windows.enablemgpp}"/>
3400      <arg value="USE_GDBM=${gs2.windows.usegdbm}"/>
3401      <arg value="USE_SQLITE=${gs2.windows.usesqlite}"/>
3402      <!--
3403      <arg value="ENABLE_JNI=${gs2.windows.enablejni}"/>
3404      <arg value="USE_SQLITE=0"/>--> <!-- why is this not on by default? -->
3405    </exec>
3406
3407    <!-- install gs2build indexers for windows -->
3408      <if>
3409    <bool><istrue value="${current.os.iswindows}"/></bool>
3410    <copy todir="${gs2build.home}/bin/windows">
3411      <fileset dir="${gs2build.home}/common-src/indexers/bin">
3412        <include name="*.*"/>
3413      </fileset>
3414    </copy>
3415      </if>
3416
3417    <!-- LuceneWrapper jar file not installed by default -->
3418    <mkdir dir="${gs2build.home}/bin/java"/>
3419    <copy file="${lucene.home}/LuceneWrapper4.jar" todir="${gs2build.home}/bin/java"/>
3420
3421  </target>
3422
3423  <!-- ============== gli targets ================================= -->
3424 
3425  <!-- gliserver.pl, gsdlCGI.pm, metadata-server.pl and checksum.pl are updated alongside
3426       this in target svnupdate-collection-building -->
3427  <target name="svnupdate-gli" if="collection.building.enabled" depends="init" unless="nosvn.mode">
3428
3429    <exec executable="svn">
3430      <arg value="update"/>
3431      <arg value="${gli.home}"/>
3432      <arg value="-r"/><arg value="${branch.revision}"/>
3433    </exec>
3434
3435  </target>
3436
3437  <!-- gliserver.pl, gsdlCGI.pm, metadata-server.pl and checksum.pl are updated
3438       alongside this prepare-gli target in target prepare-collection-building -->
3439  <target name="prepare-gli" depends="init" if="collection.building.enabled" unless="gli.present">
3440    <!-- checkout -->
3441    <if><bool><and><not><istrue value="${nosvn.mode}"/></not><isset property="with.gli.and.gems"/></and></bool>
3442
3443    <exec executable="svn">
3444      <arg value="checkout"/>
3445      <arg value="${svn.root}/main/${branch.path}/gli"/>
3446      <arg value="-r"/><arg value="${branch.revision}"/>
3447    </exec>
3448
3449    </if>
3450  </target>
3451
3452  <!-- svn checkout gliserver.pl, gsdlCGI.pm for gli applet, as well as gsdlCGI.pm-dependent metadata-server.pl
3453       (checksum.pl is used by GS2 for depositdspace.dm and may eventually be used by GS3 too) -->
3454  <target name="svnupdate-cgi">
3455
3456    <exec executable="svn" dir="web/WEB-INF/cgi">
3457      <arg value="export"/>
3458      <arg value="-r"/><arg value="${branch.revision}"/>
3459      <arg value="${svn.root}/main/${branch.path}/greenstone2/common-src/cgi-bin/gliserver.pl"/>
3460    </exec>
3461    <exec executable="svn" dir="web/WEB-INF/cgi">
3462      <arg value="export"/>
3463      <arg value="-r"/><arg value="${branch.revision}"/>
3464      <arg value="${svn.root}/main/${branch.path}/greenstone2/common-src/cgi-bin/gsdlCGI.pm"/>
3465    </exec>
3466    <exec executable="svn" dir="web/WEB-INF/cgi">
3467      <arg value="export"/>
3468      <arg value="-r"/><arg value="${branch.revision}"/>
3469      <arg value="${svn.root}/main/${branch.path}/greenstone2/common-src/cgi-bin/metadata-server.pl"/>
3470    </exec>
3471    <exec executable="svn" dir="web/WEB-INF/cgi">
3472      <arg value="export"/>
3473      <arg value="-r"/><arg value="${branch.revision}"/>
3474      <arg value="${svn.root}/main/${branch.path}/greenstone2/common-src/cgi-bin/checksum.pl"/>
3475    </exec>
3476  </target>
3477
3478 
3479  <target name="clean-gli" depends="init" if="collection.building.enabled">
3480    <!-- gli -->
3481    <property name="gli.home" value="${basedir}/gli"/>
3482    <!-- linux -->
3483    <exec executable="clean.sh" os="${os.unix}" dir="${gli.home}"
3484      resolveExecutable="true" failonerror="true"/>
3485    <!-- windows -->
3486    <exec executable="clean.bat" osfamily="windows" dir="${gli.home}"
3487      resolveExecutable="true" failonerror="true"/>
3488  </target>
3489 
3490  <target name="compile-gli" depends="init" if="collection.building.enabled">
3491    <if><bool><isset property="with.gli.and.gems"/></bool>
3492      <!-- gli -->
3493      <property name="gli.home" value="${basedir}/gli"/>
3494
3495      <!-- linux -->
3496      <exec executable="makegli.sh" os="${os.unix}" dir="${gli.home}" resolveExecutable="true" failonerror="true"/>
3497      <!--remote gli-->
3498      <exec executable="makejar.sh" os="${os.unix}" dir="${gli.home}"
3499        resolveExecutable="true" failonerror="true"/>
3500      <!-- windows -->
3501      <exec executable="makegli.bat" osfamily="windows" dir="${gli.home}" resolveExecutable="true" failonerror="true"/>
3502      <!--remote gli-->
3503      <exec executable="makejar.bat" osfamily="windows" dir="${gli.home}"
3504        resolveExecutable="true" failonerror="true"/>
3505      <copy file="${gli.home}/GLIServer.jar" todir="${gs2build.home}/bin/java" />
3506    </if>
3507  </target>
3508
3509  <target name="gli" description="Run the Greenstone Librarian Interface" depends="init" if="collection.building.enabled">
3510    <exec executable="${basedir}/gli/gli.sh" os="${os.linux},${os.solaris}" dir="${basedir}/gli" spawn="true">
3511      <env key="gsdl3path" path="${basedir}"/>
3512      <env key="gsdlpath" path="${gs2build.home}"/>
3513    </exec>
3514    <exec executable="${basedir}/gli/gli.sh" os="${os.mac}" dir="${basedir}/gli" spawn="true">
3515      <env key="gsdl3path" path="${basedir}"/>
3516      <env key="gsdlpath" path="${gs2build.home}"/>
3517      <env key="DYLD_LIBRARY_PATH" path="${env.DYLD_LIBRARY_PATH}:${gdbm.home}/lib"/>
3518    </exec>
3519    <exec executable="${basedir}/gli/gli.bat" osfamily="windows" dir="${basedir}/gli" spawn="true">
3520      <env key="GSDL3PATH" path="${basedir}"/>
3521      <env key="GSDLPATH" path="${gs2build.home}"/>
3522    </exec>
3523    <echo>Running GLI from Ant means that you don't get to see any of the terminal output. If you have problems with GLI and want to see the output, please run the script gli.sh/bat from the greenstone3/gli directory.
3524    </echo>
3525  </target>
3526
3527  <!-- ================ gs2build targets =========================== -->
3528
3529  <target name="svnupdate-gs2build" if="collection.building.enabled" depends="init" unless="nosvn.mode">
3530    <echo>svn updating gs2build</echo>
3531    <exec executable="svn">
3532      <arg value="update"/>
3533      <arg value="${gs2build.home}"/>
3534      <arg value="-r"/><arg value="${branch.revision}"/>
3535    </exec>
3536  </target>
3537   
3538  <target name="prepare-gs2build" depends="init" if="collection.building.enabled" unless="gs2build.present">
3539    <antcall target="checkout-gs2build"/>
3540    <antcall target="prepare-pdfbox"/>
3541    <antcall target="prepare-imagemagick"/> <!-- has to be done before calling prepare-gnome-lib -->
3542    <antcall target="prepare-gnome-lib"/>
3543    <antcall target="unzip-windows-packages"/>
3544    <antcall target="checkout-winbin"/>
3545    <antcall target="get-windows-binaries"/>
3546    <antcall target="delete-winbin"/>
3547  </target>
3548
3549  <target name="checkout-gs2build" depends="init" if="collection.building.enabled" unless="nosvn.mode">
3550    <echo>checking out gs2build</echo>
3551    <exec executable="svn">
3552      <arg value="checkout"/>
3553      <arg value="${svn.root}/main/${branch.path}/gs2build"/>
3554      <arg value="-r"/><arg value="${branch.revision}"/>
3555    </exec>
3556  </target>
3557
3558  <!-- Gets the PDFBox extension into gs2build/ext if checkout.pdfbox.ext is set to true in build.properties
3559       (which it is by default) -->
3560  <target name="prepare-pdfbox" depends="init" if="collection.building.enabled">
3561    <if>
3562      <bool>
3563    <istrue value="${checkout.pdfbox.ext}"/>
3564      </bool>
3565     
3566      <property name="pdfbox.ext.dir" value="${gs2build.home}/ext/pdf-box"/>
3567      <condition property="pdfbox.ext.present">
3568    <available file="${pdfbox.ext.dir}" type="dir" />
3569      </condition>
3570     
3571      <!-- get the pdfbox tar.gz file if we don't already have it and extract it if there's no pdf-box directory in gs2build/ext-->
3572      <if>
3573    <bool>
3574      <not><istrue value="${pdfbox.ext.present}"/></not>
3575    </bool>
3576
3577    <if>
3578      <bool>
3579        <not><istrue value="${gs2build.home}/ext/pdf-box-java.tar.gz"/></not>
3580      </bool>
3581
3582      <echo>Checking out the PDFBox extension into the GSDLHOME extension area</echo>
3583      <exec executable="svn">
3584        <arg value="export"/>
3585        <arg value="${svn.root}/gs2-extensions/pdf-box/trunk/pdf-box-java.tar.gz"/>
3586        <arg value="${gs2build.home}/ext/pdf-box-java.tar.gz"/>
3587      </exec>
3588    </if>   
3589
3590    <echo>Extacting the PDFBox extension into the GSDLHOME extension area</echo>
3591    <untar compression="gzip"
3592           src="${gs2build.home}/ext/pdf-box-java.tar.gz"
3593           dest="${gs2build.home}/ext"/>
3594
3595    <delete file="${gs2build.home}/ext/pdf-box-java.tar.gz"/>
3596
3597    <else>
3598      <echo>The PDFBox extension already exists at ${pdfbox.ext.dir}</echo>
3599    </else>
3600      </if>
3601
3602      <else>
3603    <echo>**** Not preparing the PDFBox extension:</echo>
3604    <echo>The property checkout.pdfbox.ext in build.properties was not set or was set to false</echo>
3605      </else>
3606    </if>
3607  </target>
3608
3609  <target name="prepare-imagemagick" depends="init" if="collection.building.enabled">
3610    <if>
3611      <bool>
3612    <istrue value="${checkout.imagemagick.ext}"/>
3613      </bool>
3614
3615      <antcall target="checkout-imagemagick"/>
3616      <!--Compilation of imagemagick now happens during ant install, still before configuring the src code, as before -->
3617
3618      <else>
3619    <echo>**** Not preparing imagemagick:</echo>
3620    <echo>property checkout.imagemagick.ext in build.properties was not set or was set to false</echo>
3621      </else>
3622    </if>
3623  </target>
3624
3625  <target name="checkout-imagemagick" depends="init" if="collection.building.enabled" unless="nosvn.mode">
3626   
3627    <property name="imagemagick.src.dir" value="${gs2build.home}/ext/imagemagick"/>
3628    <condition property="imagemagick.src.present">
3629      <available file="${imagemagick.src.dir}" type="dir" />
3630    </condition>
3631
3632    <if>
3633      <bool>
3634    <not><istrue value="${imagemagick.src.present}"/></not>
3635      </bool>
3636     
3637      <echo>checking out imagemagick source into the extension area</echo>
3638
3639      <exec executable="svn">
3640    <arg value="checkout"/>
3641    <arg value="${svn.root}/gs2-extensions/imagemagick/trunk/src"/>
3642    <arg value="${imagemagick.src.dir}"/>
3643      </exec>
3644
3645      <else>
3646    <echo>imagemagick source code already exists at ${imagemagick.src.dir}</echo>
3647      </else>
3648    </if>
3649  </target>
3650
3651 <!-- Compile up imagemagick src folder if: the checkout.imagemagick.ext flag is turned on, if the imagick source code exists and if hasn't already been compiled up, then compile it up. Later can check if a gs-specific binary version has been installed already, in which case compilation won't be necessary. -->
3652  <target name="compile-imagemagick" if="checkout.imagemagick.ext">
3653   
3654    <property name="imagemagick.src.dir" value="${gs2build.home}/ext/imagemagick"/>
3655    <property name="imagemagick.compiled.dir" value="${gs2build.home}/ext/imagemagick/${os.bin.dir}"/>
3656
3657    <condition property="imagemagick.src.present.firstcheck">
3658      <available file="${imagemagick.src.dir}" type="dir" />
3659    </condition>
3660    <condition property="imagemagick.compiled.present">
3661      <available file="${imagemagick.compiled.dir}" type="dir"/>
3662    </condition>
3663    <!--<condition property="imagemagick.bin.present">
3664      <available file="${basedir}/wherever/the/imgmagick/binary/is/to/be/found" type="dir" />
3665    </condition>-->
3666
3667    <!-- imagemagick will only be checked out if the user set the checkout.imagemagick.ext in build.properties -->
3668    <if>
3669      <bool>
3670    <isfalse value="${imagemagick.src.present.firstcheck}"/>
3671      </bool>
3672      <antcall target="checkout-imagemagick"/>
3673    </if>
3674
3675    <!-- keep track of whether the imagemagick src is now indeed present. Need to know this for a subsequent test -->
3676    <condition property="imagemagick.src.present">
3677      <available file="${imagemagick.src.dir}" type="dir" />
3678    </condition>
3679
3680    <if>
3681      <bool>
3682    <and>
3683      <istrue value="${imagemagick.src.present}"/> <!-- imagemagick src code is present -->
3684      <isfalse value="${imagemagick.compiled.present}"/> <!-- imagemagick src not compiled yet, so no imagemagick/os subfolder yet -->
3685    </and>
3686      </bool>
3687      <!-- then compile it. Only necessary for mac/linux, since windows has a stable working binary of imagemagick -->
3688      <exec executable="/bin/bash" dir="${imagemagick.src.dir}" failonerror="true">
3689        <arg value="CASCADE-MAKE.sh"/>
3690      </exec> 
3691    </if>
3692  </target>
3693
3694
3695  <!-- Compile up gnome-lib src folder if: checkout.gnomelib.ext is turned on, and if not using the binary
3696       version (gnome-lib-minimal), and if the gnome-lib src folder is not already compiled up. -->
3697  <target name="compile-gnome-lib" if="checkout.gnomelib.ext">
3698
3699    <!-- http://stackoverflow.com/questions/3290307/sourcing-a-shell-profile-in-an-ant-build-file
3700     TODO: CASCADE-MAKE already sources devel.bash, but we still want to source it more globally,
3701     so that the rest of the GS3 compilation process also has access to those env variables -->
3702   
3703    <property name="gnome.lib.src.dir" value="${basedir}/gs2build/ext/gnome-lib"/>
3704    <property name="gnome.lib.compiled.dir" value="${basedir}/gs2build/ext/gnome-lib/${os.bin.dir}"/>
3705
3706    <condition property="gnome.src.lib.present.firstcheck" value="true" else="false">
3707      <available file="${gnome.lib.src.dir}" type="dir" />
3708    </condition>
3709    <condition property="gnome.compiled.lib.present" value="true" else="false">
3710      <available file="${gnome.lib.compiled.dir}" type="dir"/>
3711    </condition>
3712    <condition property="gnome.lib.min.present" value="true" else="false">
3713      <available file="${basedir}/gs2build/ext/gnome-lib-minimal" type="dir" />
3714    </condition>
3715
3716    <!-- Make sure to checkout gnome-lib if it was not checked out at this stage
3717     since we're instructed to do so in th pre-condition to this target -->
3718    <if>
3719      <bool>
3720    <and>
3721      <isfalse value="${gnome.lib.min.present}"/>
3722      <isfalse value="${gnome.src.lib.present.firstcheck}"/>
3723    </and>
3724      </bool>
3725      <antcall target="checkout-gnome-lib"/>
3726    </if>
3727
3728    <!-- Keep track of whether we have the gnome-lib src folder now. Need to know this for a subsequent test -->
3729    <condition property="gnome.src.lib.present" value="true" else="false">
3730      <available file="${gnome.lib.src.dir}" type="dir" />
3731    </condition>
3732
3733    <!--<echo>MIN: ${gnome.lib.min.present}
3734      SRC LIB: ${gnome.src.lib.present}
3735      COMPILED: ${gnome.compiled.lib.present}</echo>-->
3736
3737    <if>
3738      <bool>
3739    <and>
3740      <isfalse value="${gnome.lib.min.present}"/> <!-- no gnome-lib-minimal binary present -->
3741      <istrue value="${gnome.src.lib.present}"/> <!-- gnome-lib folder for compilation is present-->
3742      <isfalse value="${gnome.compiled.lib.present}"/> <!-- gnome-lib not yet compiled, so no gnome-lib/os subfolder yet -->
3743    </and>
3744      </bool>
3745
3746      <!-- then compile it. Only necessary for mac/linux, since windows doesn't need gnome lib -->
3747      <exec executable="/bin/bash" dir="${gnome.lib.src.dir}" failonerror="true">
3748        <arg value="CASCADE-MAKE.sh"/>
3749      </exec> 
3750    </if>
3751  </target>
3752
3753
3754  <target name="prepare-gnome-lib" depends="init" if="collection.building.enabled" unless="gnome-lib.present">
3755    <if>
3756      <bool>
3757    <istrue value="${checkout.gnomelib.ext}"/>
3758      </bool>
3759
3760      <antcall target="checkout-gnome-lib"/>
3761      <!--Compilation of gnome-lib happens during ant install, just before configuring (common-src and) build-src-->
3762
3763      <else>
3764    <echo>**** Not preparing gnome-lib:</echo>
3765    <echo>property checkout.gnomelib.ext in build.properties was not set or was set to false</echo>
3766      </else>
3767    </if>
3768  </target>
3769
3770
3771  <target name="checkout-gnome-lib" depends="init" if="collection.building.enabled" unless="nosvn.mode">
3772
3773    <property name="gnomelib.src.dir" value="${basedir}/gs2build/ext/gnome-lib"/>
3774    <condition property="gnome.src.present">
3775      <available file="${gnomelib.src.dir}" type="dir" />
3776    </condition>
3777
3778    <if>
3779      <bool>
3780    <not><istrue value="${gnome.src.present}"/></not>
3781      </bool>
3782
3783      <echo>checking out gnome-lib extension</echo>
3784      <exec executable="svn">
3785    <arg value="checkout"/>
3786    <arg value="${svn.root}/gs2-extensions/gnome-lib/trunk/src"/>
3787    <arg value="${gs2build.home}/ext/gnome-lib"/>
3788      </exec>
3789
3790      <else>
3791    <echo>gnomelib source code already exists at ${gnomelib.src.dir}</echo>
3792      </else>
3793    </if>
3794
3795  </target>
3796
3797  <target name="checkout-winbin" depends="init" if="current.os.iswindows"
3798    unless="nosvn.mode">
3799
3800    <exec executable="svn">
3801      <arg value="checkout"/>
3802      <arg value="${svn.root}/main/${branch.path}/binaries/windows"/>
3803      <arg value="-r"/><arg value="${branch.revision}"/>
3804      <arg value="winbin"/>
3805    </exec>
3806
3807  </target>
3808
3809  <target name="update-winbin" depends="init" if="current.os.iswindows" unless="nosvn.mode">
3810    <exec executable="svn">
3811      <arg value="update"/>
3812      <arg value="winbin"/>
3813      <arg value="-r"/><arg value="${branch.revision}"/>
3814    </exec>
3815
3816  </target>
3817 
3818  <target name="get-windows-binaries" depends="init" if="collection.building.enabled.windows">
3819    <move todir="${gs2build.home}/bin/windows" failonerror="false">
3820      <fileset dir="${basedir}/winbin/bin"/>
3821    </move>
3822  </target>
3823
3824  <target name="delete-winbin" depends="init" if="collection.building.enabled.windows">
3825    <delete dir="${basedir}/winbin"/>
3826  </target>
3827 
3828  <target name="unzip-windows-packages" depends="init" if="current.os.iswindows"> 
3829    <unzip src="${common.src.home}/packages/windows/crypt/crypt.zip"
3830      dest="${common.src.home}/packages/windows/crypt"/>
3831    <untar compression="gzip"
3832      src="${common.src.home}/packages/sqlite/${sqlite.targz.version}"
3833      dest="${common.src.home}/packages/sqlite"/>
3834    <unzip src="${common.src.home}/indexers/packages/windows/iconv/iconv.zip"
3835      dest="${common.src.home}/indexers/packages/windows/iconv"/>
3836  </target>
3837   
3838  <target name="gs2build-edit-setup-bat" if="collection.building.enabled.windows">
3839    <!-- we want a windows path in the setup.bat file -->
3840    <pathconvert targetos="windows" property="gs2build.home.windows">
3841      <path path="${gs2build.home}"/>
3842    </pathconvert>
3843    <move file="${gs2build.home}/setup.bat" tofile="${gs2build.home}/setup-tmp.bat">
3844      <filterset>
3845        <filter token="gsdlhome" value="${gs2build.home.windows}"/>
3846      </filterset>
3847    </move> 
3848    <move file="${gs2build.home}/setup-tmp.bat" tofile="${gs2build.home}/setup.bat" />
3849  </target>
3850 
3851 
3852  <target name="clean-build-src" depends="init" if="collection.building.enabled">
3853    <!-- unix:  -->
3854    <if><bool><available file="${build.src.home}/Makefile"/></bool>
3855    <exec executable="make" os="${os.unix}" dir="${build.src.home}" failonerror="true">
3856      <arg value="clean"/>
3857    </exec>
3858    </if>
3859    <!-- windows: -->   
3860    <exec executable="nmake" dir="${build.src.home}" osfamily="windows" failonerror="true">
3861      <arg value="/f"/>
3862      <arg value="win32.mak"/>
3863      <arg value="clean"/>
3864      <arg value="GSDLHOME=${gs2build.home}"/>
3865    </exec>
3866  </target>
3867 
3868 
3869  <target name="distclean-build-src" depends="init,clean-build-src" if="collection.building.enabled">
3870    <!-- unix:  -->
3871    <if><bool><available file="${build.src.home}/Makefile"/></bool>
3872    <exec executable="make" os="${os.unix}" dir="${build.src.home}" failonerror="true">
3873      <arg value="distclean"/>
3874    </exec>
3875    </if>
3876    <!-- windows: distclean = clean + remove configure products (remove makefiles). But on Windows there is no removing makefiles, so we just call clean -->   
3877    <exec executable="nmake" dir="${build.src.home}" osfamily="windows" failonerror="true">
3878      <arg value="/f"/>
3879      <arg value="win32.mak"/>
3880      <arg value="clean"/>
3881      <arg value="GSDLHOME=${gs2build.home}"/>
3882    </exec>
3883  </target>
3884 
3885  <target name="configure-build-src" depends="init" if="collection.building.enabled"
3886    description="Configure the build-src component">
3887    <exec executable="${build.src.home}/configure" os="${os.unix}"
3888      dir="${build.src.home}" failonerror="true">
3889      <arg value="--prefix=${gs2build.home}"/>
3890      <arg line="${gs2.opt.args} ${static.arg} ${cross.configure.args} ${allargs}"/>
3891    </exec>
3892  </target>
3893
3894  <!-- common-src is done separately and needs to be compiled first -->
3895  <target name="compile-build-src" depends="init" if="collection.building.enabled">
3896   
3897    <exec executable="make" dir="${build.src.home}" os="${os.unix}" failonerror="true">
3898        <arg line="${ldlpath.arg}"/>
3899    </exec>
3900   
3901    <exec executable="make" dir="${build.src.home}" os="${os.unix}" failonerror="true">
3902    <env key="GSDLOS" value="${os.bin.dir}"/>
3903    <arg value="install"/>
3904    </exec>
3905
3906    <!-- run the setup script -->
3907    <!-- <exec executable="${compile.windows.c++.setup}" osfamily="windows" failonerror="true"/>-->
3908      <!--Above does not work: even though vcvars.bat executes, the env changes it makes don't get saved. Need user to run vcvars.bat first before calling ant-->
3909      <exec executable="nmake" dir="${build.src.home}" osfamily="windows" failonerror="true">
3910        <arg value="/f"/>
3911        <arg value="win32.mak"/>
3912    <arg value="GSDLHOME=${gs2build.home}"/>
3913      </exec>
3914      <exec executable="nmake" dir="${build.src.home}" osfamily="windows" failonerror="true">
3915        <arg value="/f"/>
3916        <arg value="win32.mak"/>
3917        <arg value="install"/>
3918    <arg value="GSDLHOME=${gs2build.home}"/>
3919      </exec>
3920  </target>
3921 
3922
3923  <!-- ======================== TESTING Targets ========================= -->
3924 
3925  <target name="test" description="Run the (incomplete) JUnit test suite "
3926    depends="init">
3927    <mkdir dir="${basedir}/test"/>
3928    <junit printsummary="withOutAndErr"
3929      errorproperty="test.failed"
3930      failureproperty="test.failed"
3931      fork="${junit.fork}">
3932      <formatter type="plain"/>
3933      <classpath>
3934        <pathelement location="${build.home}/gsdl3test.jar"/>
3935        <path refid="compile.classpath"/>
3936      </classpath>
3937      <test name="${testcase}" if="testcase"/>
3938      <batchtest todir="${basedir}/test" unless="testcase">
3939        <fileset dir="${build.home}" includes="**/*Test.class" />
3940      </batchtest>
3941    </junit>
3942    <echo>
3943      *********************************************
3944      Test output can be found in directory 'test'
3945      *********************************************
3946    </echo>
3947  </target>
3948
3949  <!-- ======================== FLAX Targets ========================= -->
3950  <target name="prepare-flax" description="check out flax source code from another repository" if="install.flax">
3951    <echo>checking out flax ...</echo>
3952    <mkdir dir="${basedir}/src/java/org/flax"/>
3953    <mkdir dir="${basedir}/src/java/org/greenstone/gsdl3/flax"/>
3954    <mkdir dir="${basedir}/src/java/org/greenstone/gsdl3/action/flax"/>
3955    <mkdir dir="${web.home}/WEB-INF/classes/flax"/>
3956    <mkdir dir="${web.home}/interfaces/flax"/>
3957    <mkdir dir="${web.home}/sites/flax"/>
3958    <mkdir dir="${basedir}/flax-resources"/>
3959    <mkdir dir="${basedir}/flax-lib"/>
3960    <exec executable="svn"><arg value="checkout"/><arg value="${flax.checkout.path}/src/java/org/flax"/>
3961      <arg value="src/java/org/flax"/></exec>
3962    <exec executable="svn"><arg value="checkout"/><arg value="${flax.checkout.path}/src/java/org/greenstone/gsdl3/flax"/>
3963      <arg value="src/java/org/greenstone/gsdl3/flax"/></exec>
3964    <exec executable="svn"><arg value="checkout"/><arg value="${flax.checkout.path}/src/java/org/greenstone/gsdl3/action/flax"/>
3965      <arg value="src/java/org/greenstone/gsdl3/action/flax"/></exec>
3966     <exec executable="svn"><arg value="checkout"/><arg value="${flax.checkout.path}/web/WEB-INF/classes/flax"/>
3967      <arg value="${web.home}/WEB-INF/classes/flax"/></exec>
3968    <exec executable="svn"><arg value="checkout"/><arg value="${flax.checkout.path}/web/interfaces/flax"/>
3969      <arg value="${web.home}/interfaces/flax"/></exec>
3970    <exec executable="svn"><arg value="checkout"/><arg value="${flax.checkout.path}/web/sites/flax"/>
3971      <arg value="${web.home}/sites/flax"/></exec>
3972    <exec executable="svn"><arg value="checkout"/><arg value="${flax.checkout.path}/flax-resources"/>
3973      <arg value="flax-resources"/></exec>
3974    <exec executable="svn"><arg value="checkout"/><arg value="${flax.checkout.path}/lib"/>
3975      <arg value="flax-lib"/></exec>
3976    <antcall target="flax-copy-del-files" />
3977  </target>
3978 
3979  <target name="flax-copy-del-files" description="copy some flax files into the appropriate greenstone3 directories and delete some unwanted greenstone stuff">
3980    <copy file="${web.home}/WEB-INF/classes/flax/web.xml" todir="${web.home}/WEB-INF" overwrite="true" />
3981    <copy todir="${web.home}/WEB-INF/lib">
3982            <fileset dir="${basedir}/flax-lib">
3983               <include name="*.jar"/>
3984            </fileset> 
3985    </copy>
3986    <!--<delete dir="${web.home}/sites/gateway"/>
3987    <delete dir="${web.home}/sites/localsite"/>-->
3988  </target>
3989
3990  <target name="update-flax" description="update flax from repository">
3991    <echo>updating flax ...</echo>
3992    <exec executable="svn"><arg value="update"/>
3993      <arg value="src/java/org/flax"/></exec>
3994    <exec executable="svn"><arg value="update"/>
3995      <arg value="src/java/org/greenstone/gsdl3/action/flax"/></exec>
3996    <exec executable="svn"><arg value="update"/>
3997      <arg value="src/java/org/greenstone/gsdl3/flax"/></exec>
3998    <exec executable="svn"><arg value="update"/>
3999      <arg value="${web.home}/WEB-INF/classes/flax"/></exec>
4000    <exec executable="svn"><arg value="update"/>
4001      <arg value="${web.home}/interfaces/flax"/></exec>
4002    <exec executable="svn"><arg value="update"/>
4003      <arg value="${web.home}/web/sites/flax"/></exec>
4004    <exec executable="svn"><arg value="update"/>
4005      <arg value="flax-resources"/></exec>
4006    <exec executable="svn"><arg value="update"/>
4007      <arg value="flax-lib"/></exec>
4008    <antcall target="compile-core" />
4009  </target>
4010
4011  <!-- ========================End of FLAX Targets ========================= -->
4012
4013  <target name="compile-javadocs">
4014    <javadoc packagenames="org.greenstone.*"
4015           sourcepath="src/java"
4016           defaultexcludes="yes"
4017           destdir="docs/javadoc"
4018           author="true"
4019           version="true"
4020           use="true"
4021           windowtitle="Greenstone3 API">
4022    <doctitle><![CDATA[<h1>Greenstone3 API</h1>]]></doctitle>
4023    </javadoc>
4024  </target>
4025
4026<!-- ========== Some distribution targets ======================== -->
4027  <target name="remove-source">
4028    <if><bool><isset property="with.gli.and.gems"/></bool>
4029    <delete includeEmptyDirs="true">
4030      <fileset dir="." defaultexcludes="false">
4031        <patternset refid="greenstone3.source.component"/>
4032     </fileset>
4033    </delete>
4034   
4035    <else>
4036    <delete includeEmptyDirs="true">
4037      <fileset dir="." defaultexcludes="false">
4038        <patternset refid="greenstone3.source.no.gli.component"/>
4039     </fileset>
4040    </delete>
4041    </else>
4042    </if>
4043  </target>
4044
4045  <target name="dist-tidy"
4046    description="'tidies-up' a greenstone3 installation for distribution."
4047    unless="${properties.keep.src}">
4048
4049    <!-- delete unneeded things -->
4050    <delete dir="${packages.home}/axis"/>
4051    <delete><fileset dir="${packages.home}" includes="*.zip"/></delete>
4052    <delete file="README-SVN.txt"/>
4053    <delete file="build.properties.svn"/>
4054
4055    <!-- delete source files -->
4056    <antcall target="remove-source"/>
4057
4058    <!-- create empty directories -->
4059    <mkdir dir="${web.writablehome}/applet"/>
4060    <mkdir dir="${web.writablehome}/logs"/>
4061    <mkdir dir="${web.writablehome}/logs/tmp"/>
4062
4063    <!-- Lines with ***** are commented out because these files are useful if we want hybrid installations -->
4064   
4065    <!-- os specific tidy-ups -->
4066    <!-- linux, mac -->
4067    <if><bool><istrue value="${current.os.isunix}"/></bool>
4068      <!--*****<delete><fileset dir="." includes="*.bat"/></delete>-->
4069      <if><bool><isset property="with.gli.and.gems"/></bool>
4070        <!--*****<delete><fileset dir="gli" includes="*.bat"/></delete>-->
4071      </if>
4072      <!--*****<delete><fileset dir="gs2build" includes="*.bat"/></delete>-->
4073      <!--*****<delete><fileset dir="bin/script" includes="*.bat"/></delete>-->
4074      <delete file="${basedir}/gs2build/win32cfg.h"/>
4075      <delete file="${basedir}/gs2build/win32.mak"/>
4076      <delete dir="${basedir}/winutil"/>
4077      <delete failonerror="false"><fileset dir="${lib.jni}" includes="*.dll"/></delete>
4078
4079    <!-- windows -->
4080    <else><if><bool><istrue value="${current.os.iswindows}"/></bool>
4081      <!--*****<delete><fileset dir="." includes="*.sh,*.bash,*.csh"/></delete>-->
4082      <if><bool><isset property="with.gli.and.gems"/></bool>
4083    <!--*****<delete><fileset dir="gli" includes="*.sh,*.bash,*.csh"/></delete>-->
4084      </if>
4085      <!--*****<delete><fileset dir="gs2build" includes="*.sh,*.bash,*.csh"/></delete>-->
4086      <!--*****<delete><fileset dir="bin/script" includes="*.sh,*.bash,*.csh"/></delete>-->
4087    </if></else></if>
4088
4089  </target>
4090
4091  <!-- fix up executable permissions for binary release -->
4092  <target name="fix-execute-permissions">
4093    <echo>Setting binaries to executable</echo>
4094    <chmod perm="775">
4095      <fileset dir="."><patternset refid="greenstone3.executables"/></fileset>
4096    </chmod>
4097  </target>
4098 
4099  <!-- fix up executable permissions for source code release -->
4100  <target name="fix-execute-permissions-source">
4101    <chmod perm="775">
4102      <fileset dir="."><patternset refid="greenstone3.source.executables"/></fileset>
4103    </chmod>
4104  </target>
4105
4106  <!-- for macs, set up the .app shortcuts to gsi, gli, client-gli and gems -->
4107  <target name="gen-mac-shortcuts">   
4108    <if><bool><istrue value="${current.os.ismac}"/></bool>
4109      <filter token="gsdl3srchome" value="${basedir}"/>
4110      <copy file="${basedir}/gs3-server.app/Contents/document.wflow.in" tofile="${basedir}/gs3-server.app/Contents/document.wflow" filtering="true" overwrite="true"/>
4111      <copy file="${basedir}/gli.app/Contents/document.wflow.in" tofile="${basedir}/gli.app/Contents/document.wflow" filtering="true" overwrite="true"/>
4112      <copy file="${basedir}/client-gli.app/Contents/document.wflow.in" tofile="${basedir}/client-gli.app/Contents/document.wflow" filtering="true" overwrite="true"/>
4113      <copy file="${basedir}/gems.app/Contents/document.wflow.in" tofile="${basedir}/gems.app/Contents/document.wflow" filtering="true" overwrite="true"/>
4114    </if>
4115  </target>
4116
4117  <!-- ============= tweaks for making compilation static ========== --> 
4118  <target name="tweak-makefiles" depends="init" if="compile.static">
4119    <antcall target="rtftohtml-add-static" />
4120  </target>
4121   
4122  <target name="rtftohtml-add-static" depends="init" if="collection.building.enabled">
4123    <rsr verbosity="1" file="${gs2build.home}/build-src/packages/rtftohtml/rtftohtml_src/Makefile" pattern="-o rtftohtml(.{2})EXEEXT(.{1})" replacement="-o rtftohtml$1EXEEXT$2 -static" />
4124  </target>
4125   
4126    <target name="run-collection-tests">
4127        <if><bool><not><available file="${basedir}/ext/testing" type="dir"/></not></bool>
4128            <fail>The testing extension is not available. This is required to perform the tests. It can be acquired from SVN by running the command "svn co http://svn.greenstone.org/gs3-extensions/testing/trunk/src testing" in the ext directory of your Greenstone 3 installation. </fail>
4129        </if>
4130        <for param="testjar">
4131            <path>
4132                <fileset dir="${basedir}" includes="web/sites/*/collect/*/tests/tests.jar"/>
4133            </path>
4134            <sequential>
4135                <echo>Testing @{testjar}</echo>
4136                <java classname="org.junit.runner.JUnitCore" fork="true">
4137                    <!--https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr-->
4138                    <sysproperty key="webdriver.gecko.driver" path="${basedir}/ext/testing/geckodriver"/>
4139                    <arg value="gstests.TestClass"/>
4140                    <jvmarg value="-DSERVERURL=${default.server.protocol}://${tomcat.server}:${default.tomcat.port}${app.path}${server.default.servlet} "/>
4141                    <classpath>
4142                        <fileset dir="${basedir}/ext/testing/lib/java">
4143                            <include name="*.jar"/>
4144                        </fileset>
4145                        <files includes="@{testjar}"/>
4146                    </classpath>
4147                </java>
4148            </sequential>
4149        </for>
4150    </target>
4151   
4152    <target name="build-collection-tests">
4153        <if><bool><not><available file="${basedir}/ext/testing" type="dir"/></not></bool>
4154            <fail>The testing extension is not available. This is required to perform the tests. It can be acquired from SVN by running the command "svn co http://svn.greenstone.org/gs3-extensions/testing/trunk/src testing" in the ext directory of your Greenstone 3 installation. </fail>
4155        </if>
4156        <for param="compiledir">
4157            <path>
4158                <dirset dir="${basedir}" includes="web/sites/*/collect/*/tests/src"/>
4159            </path>
4160            <sequential>
4161                <echo>Compiling @{compiledir}</echo>
4162                <if><bool><not><available file="@{compiledir}/../build" type="dir"/></not></bool>
4163                    <mkdir dir="@{compiledir}/../build"/>
4164                </if>
4165                <javac
4166                    srcdir="@{compiledir}"
4167                    destdir="@{compiledir}/../build"
4168                        includeantruntime="${compile.includeantruntime}"
4169                    debug="${compile.debug}"
4170                    deprecation="${compile.deprecation}"
4171                    optimize="${compile.optimize}"
4172                    encoding="${compile.encoding}">
4173                    <classpath>
4174                        <fileset dir="${basedir}/ext/testing/lib/java">
4175                            <include name="*.jar"/>
4176                        </fileset>
4177                    </classpath>
4178                    <include name="gstests/*.java"/>
4179                </javac>
4180                <jar destfile="@{compiledir}/../tests.jar">
4181                    <fileset dir="@{compiledir}/../build">
4182                        <include name="gstests/**"/>
4183                    </fileset>
4184                    <manifest>
4185                        <attribute name="Built-By" value="${user.name}" />
4186                    </manifest>
4187                </jar>
4188            </sequential>
4189        </for>
4190    </target>
4191</project>
Note: See TracBrowser for help on using the browser.