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

Revision 32365, 166.2 KB (checked in by ak19, 10 months ago)

Minor changes before major one to use ant 1.9.13

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