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

Revision 32338, 152.2 KB (checked in by ak19, 2 years ago)

Removing newly introduced tomcat-init target. Instead, any ant command will fail directly the minute the protocol and port variables have not been set up correctly or consistently.

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