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

Revision 30757, 146.0 KB (checked in by davidb, 3 years ago)

Experiment to see if this helps the release on El Capitan compile. The issue we are looking at is that setting DYLD_LIBRARY_PATH at this point leads to a problem with java, because it now sees the libiconv that gnome-lib-minimal has, which turns out to be incompatible with JDK 1.7_79

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