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

Revision 32423, 175.7 KB (checked in by ak19, 13 months ago)

Introduced the Windows https cert renewal part of the renewal target. It reuses the Win issuance target.

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