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

Revision 30758, 146.2 KB (checked in by davidb, 3 years ago)

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