source: gs3-extensions/solr/trunk/src/build.xml@ 30035

Last change on this file since 30035 was 30035, checked in by ak19, 9 years ago

Solr servlet and commands to its URL need to work in binary, for which the solr.xml tomcat context file needs to be regenerated with the correct values.

File size: 12.4 KB
Line 
1<?xml version="1.0"?>
2<project name="gs3-solr-ext" default="usage" basedir=".">
3
4 <!-- DIRECTORY LOCATIONS -->
5 <!-- local ext paths -->
6 <property name="src.home" value="${basedir}/src/java"/>
7 <property name="build.home" value="${basedir}/build"/>
8 <available property="ext.web.exists" file="${basedir}/web" type="dir" />
9
10 <!-- greenstone3 paths -->
11 <!-- http://stackoverflow.com/questions/3136849/how-do-i-convert-a-relative-path-in-ant-to-an-absolute-path
12 http://stackoverflow.com/questions/8295860/pathconvert-with-relative-file-names -->
13 <property name="web.home" location="${basedir}/../../web"/> <!-- location property creates an absolute path -->
14 <property name="localsite.collectdir" value="${web.home}/sites/localsite/collect"/>
15 <property name="web.classesdir" value="${web.home}/WEB-INF/classes"/>
16 <property name="web.libdir" value="${web.home}/WEB-INF/lib"/>
17 <property name="web.extdir" value="${web.home}/ext/solr"/>
18
19 <property name="tomcat.dir" location="${basedir}/../../packages/tomcat"/> <!-- location property creates an absolute path -->
20 <property name="tomcat.lib.dir" value="${tomcat.dir}/lib"/>
21 <property name="tomcat.context.dir" value="${tomcat.dir}/conf/Catalina/localhost"/>
22
23 <path id="compile.classpath">
24 <!-- gs3 jar files we need -->
25 <pathelement location="${web.libdir}/gsdl3.jar"/>
26 <pathelement location="${web.libdir}/gutil.jar"/>
27 <pathelement location="${web.libdir}/LuceneWrapper4.jar"/>
28 <pathelement location="${web.libdir}/gson-1.7.1.jar"/>
29 <!-- local jar files -->
30 <fileset dir="lib/java">
31 <include name="*.jar"/>
32 </fileset>
33 <pathelement location="lib/servlet-api-3.0.jar"/>
34 </path>
35
36
37 <!-- FILE LISTINGS.-->
38 <!-- Created as property elements rather than as filelist elements, since
39 they can then be reused for the add-service and delete-service targets. -->
40 <property name="jars"
41 value="solr-core-4.7.2.jar
42 solr-solrj-4.7.2.jar
43 lucene-core-4.7.2.jar
44 lucene-analyzers-common-4.7.2.jar
45 lucene-analyzers-kuromoji-4.7.2.jar
46 lucene-analyzers-phonetic-4.7.2.jar
47 lucene-grouping-4.7.2.jar
48 lucene-highlighter-4.7.2.jar
49 lucene-queries-4.7.2.jar
50 lucene-queryparser-4.7.2.jar
51 lucene-memory-4.7.2.jar
52 lucene-misc-4.7.2.jar
53 lucene-spatial-4.7.2.jar
54 lucene-suggest-4.7.2.jar
55 httpclient-4.3.1.jar
56 httpcore-4.3.jar
57 httpmime-4.3.1.jar
58 commons-fileupload-1.2.1.jar
59 commons-io-2.1.jar
60 commons-lang-2.6.jar
61 velocity-1.6.1.jar
62 log4j-over-slf4j-1.6.6.jar
63 slf4j-api-1.6.6.jar
64 slf4j-jdk14-1.6.6.jar
65 spatial4j-0.4.1.jar
66 zookeeper-3.4.5.jar
67 guava-14.0.1.jar
68 noggit-0.5.jar"/>
69<!-- jcl-over-slf4j-1.6.6.jar
70 jul-to-slf4j-1.6.6.jar
71 log4j-1.2.16.jar
72 wstx-asl-3.2.7.jar
73-->
74<!--
75 lucene-spellchecker-3.3.0.jar replaced with lucene-suggest-4.7.2.jar, since both contain packages org/.../spell and org/.../suggest
76
77 commons-fileupload-1.2.1.jar - in solr war file
78 velocity-1.6.1.jar
79 log4j-over-slf4j-1.6.1.jar - have to download slf4j jar file for version 1.6.6
80 slf4j-jdk14-1.6.1.jar - have to download slf4j jar file for version 1.6.6
81 -->
82
83 <property name="shared-xalan-jars"
84 value="xalan.jar
85 xercesImpl.jar
86 xml-apis.jar
87 xsltc.jar
88 serializer.jar"/>
89 <property name="russian-morph-jars"
90 value="russian-4.7.2.jar
91 morph-4.7.2.jar"/>
92
93 <property name="java-service-files"
94 value="SolrSearch.java
95 GS2SolrSearch.java
96 GS2SolrRetrieve.java"/>
97
98 <property name="java-util-files"
99 value="SolrFacetWrapper.java
100 SolrQueryWrapper.java
101 SolrQueryResult.java"/>
102
103 <property name="property-files"
104 value="GS2SolrSearch.properties"/>
105
106
107 <!-- TARGETS -->
108 <target name="usage" description="Print a help message">
109 <echo message=" Execute 'ant -projecthelp' for a list of targets."/>
110 <echo message=" Execute 'ant -help' for Ant help."/>
111 <echo>To install the Solr extension for Greenstone3, run 'ant add-service'.
112 To remove the files and folders installed by add-service, run 'ant del-service'.
113 </echo>
114 </target>
115
116 <target name="compile" description="Compile up the solr java classes, jar them up, and install gs3-solr.jar into Greenstone's web/WEB-INF/lib dir">
117 <mkdir dir="${build.home}"/>
118 <javac srcdir="${src.home}" destdir="${build.home}" debug="true">
119 <classpath>
120 <path refid="compile.classpath"/>
121 </classpath>
122 </javac>
123 <jar destfile="${build.home}/gs3-solr.jar">
124 <fileset dir="${build.home}">
125 <include name="org/greenstone/gsdl3/**"/>
126 </fileset>
127 <manifest>
128 <attribute name="Built-By" value="${user.name}" />
129 </manifest>
130 </jar>
131 <copy file="${build.home}/gs3-solr.jar" todir="${web.libdir}"/>
132
133 <!-- customisations to the http solr server -->
134 <jar destfile="${build.home}/gs3-solrserver.jar">
135 <fileset dir="${build.home}">
136 <include name="org/greenstone/solrserver/**"/>
137 </fileset>
138 <manifest>
139 <attribute name="Built-By" value="greenstone3" />
140 </manifest>
141 </jar>
142 <!--<copy file="${build.home}/gs3-solrserver.jar" todir="${tomcat.dir}/webapps/solr/WEB-INF/lib"/>
143
144 But there's no guarantee the destination will exist at the beginning.
145 The jar file also needs to go into solr.war. Which is taken care of in the add-service task.
146 Instead, for testing, call ant compile-gs3-solrserver, which will copy it across to solr webapp.
147 -->
148 </target>
149
150 <target name="copy-files" description="Helper-target: copy files across for add-service target">
151
152 <echo/>
153 <echo>Adding to gsdl3 properties area: properties/${property-files}</echo>
154 <copy todir="${web.classesdir}">
155 <filelist id="prop-files" dir="properties" files="${property-files}"/>
156 </copy>
157 <echo/>
158 <echo>Adding to gsdl3 web jar lib directory: ${basedir}/lib/java's ${jars}</echo>
159 <copy todir="${web.libdir}">
160 <filelist id="jar-files" dir="lib/java" files="${jars}"/>
161 </copy>
162
163 <echo/>
164 <echo>Creating web extension directory: ${web.extdir}</echo>
165 <mkdir dir="${web.extdir}"/>
166
167 <echo/>
168 <echo>Adding to gsdl3 web solr ext directory: solr.xml and solr.xml.in</echo>
169 <copy file="solr.xml.in" tofile="${web.extdir}/solr.xml.in"/>
170 <pathconvert targetos="unix" property="src.gsdl3.home.unix">
171 <path path="../../web"/>
172 </pathconvert>
173 <filter token="gsdl3home" value="${src.gsdl3.home.unix}"/>
174 <copy file="solr.xml.in" tofile="${web.extdir}/solr.xml" filtering="true" overwrite="true"/>
175
176 <echo/>
177 <echo>Adding example solr-jdbm-demo collection to ${localsite.collectdir}</echo>
178 <copy todir="${localsite.collectdir}/solr-jdbm-demo"
179 preservelastmodified="true"
180 failonerror="true" >
181 <fileset dir="${basedir}/collect/solr-jdbm-demo" includes="**"/>
182 </copy>
183 <echo>Unzipping pre-built index</echo>
184 <unzip dest="${localsite.collectdir}/solr-jdbm-demo" src="${localsite.collectdir}/solr-jdbm-demo/index.zip" />
185 </target>
186
187 <!-- Setting up solr to work with tomcat server instead of jetty server -->
188 <target name="solr-for-tomcat" description="Helper-target: setting up solr to work tomcat">
189
190 <echo>Copying solr jars needed for running solr with tomcat: ${basedir}/lib/ext</echo>
191 <copy todir="${tomcat.lib.dir}">
192 <fileset dir="lib/ext">
193 <include name="*.jar"/>
194 </fileset>
195 </copy>
196
197 <!-- slf4j and commons logging bridge needed to avoid exception about incompatibility in tomcat log files-->
198 <echo>Copying ${basedir}/lib/ext/jcl-over-slf4j-1.6.6.jar again to ${web.libdir}</echo>
199 <copy todir="${web.libdir}">
200 <filelist id="logging-bridge" dir="lib/ext" files="jcl-over-slf4j-1.6.6.jar"/>
201 </copy>
202
203 <echo>Copying ${basedir}/webapps/solr.war to ${tomcat.dir}/webapps</echo>
204 <copy todir="${tomcat.dir}/webapps" file="webapps/solr.war" />
205 <unwar src="${tomcat.dir}/webapps/solr.war" dest="${tomcat.dir}/webapps/solr"/>
206 <echo>Copying xalan related jar files, morphology and gs3-solrserver jars from ${web.libdir} into ${tomcat.dir}/webapps/solr.war</echo>
207 <copy todir="${tomcat.dir}/webapps/solr/WEB-INF/lib">
208 <filelist dir="${web.libdir}" files="${shared-xalan-jars}" />
209 <filelist dir="${build.home}" files="gs3-solrserver.jar" />
210 <filelist dir="lib/russianmorphology" files="${russian-morph-jars}" />
211 </copy>
212 <jar destfile="${tomcat.dir}/webapps/solr.war" basedir="${tomcat.dir}/webapps/solr" />
213 <!-- delete the webapps\solr temporary dir: tomcat will unpack the modified war file on startup-->
214 <delete failonerror="true" dir="${tomcat.dir}/webapps/solr" />
215
216 <echo>Generating solr context file in ${tomcat.context.dir}</echo>
217
218 <!-- we want unix paths (forward slashes) in the tomcat context file -->
219 <pathconvert targetos="unix" property="gsdl3.web.home">
220 <path path="${web.home}"/><!-- creates an absolute path-->
221 </pathconvert>
222 <pathconvert targetos="unix" property="tomcat.home">
223 <path path="${tomcat.dir}"/><!-- creates an absolute path-->
224 </pathconvert>
225 <filter token="gsdl3webhome" value="${gsdl3.web.home}"/>
226 <filter token="tomcathome" value="${tomcat.home}"/>
227 <copy file="solr-tomcat-context.xml.in" tofile="${tomcat.context.dir}/solr.xml" filtering="true" overwrite="true"/>
228
229 </target>
230
231 <!-- copy the content of the web folder (avoiding the top-level .svn directory) -->
232 <target name="copy-solr-web" if="ext.web.exists">
233 <echo/>
234 <echo>Copy to gsdl3 web: the content of the ${basedir}/web folder (excluding .svn)</echo>
235 <copy todir="${web.extdir}">
236 <dirset dir="${basedir}/web">
237 <exclude name=".svn"/>
238 </dirset>
239 </copy>
240 </target>
241
242
243 <target name="add-service" depends="copy-solr-web,copy-files,compile,solr-for-tomcat" description="Run this target to setup the Solr extension for Greenstone3" />
244
245 <target name="del-service" depends="del-files,del-solr-for-tomcat"
246 description="Run this target to unset the Solr extension for Greenstone3" />
247
248
249 <target name="del-files" description="Helper-target to delete files for del-service target">
250 <!-- failonerror is set to false in case some files don't exist
251 and can't be deleted therefore -->
252
253 <echo/>
254 <echo>Removing from gsdl3 properties area: properties/${property-files}</echo>
255 <delete failonerror="false">
256 <filelist dir="${web.classesdir}" files="${property-files}"/>
257 </delete>
258
259 <echo/>
260 <echo>Removing from gsdl3 web jar lib directory: ${basedir}/lib/java's ${jars} gs3-solr.jar</echo>
261 <delete failonerror="false">
262 <filelist dir="${web.libdir}" files="${jars} gs3-solr.jar"/>
263 </delete>
264
265 <echo/>
266 <echo>Removing web solr extension directory: ${web.extdir}</echo>
267 <delete failonerror="false" includeEmptyDirs="true" dir="${web.extdir}"/>
268
269 <echo/>
270 <echo>Removing solr-jdbm-demo collection from: ${localsite.collectdir}</echo>
271 <delete failonerror="false" includeEmptyDirs="true" dir="${localsite.collectcdir}/solr-jdbm-demo"/>
272
273 </target>
274
275 <target name="del-solr-for-tomcat" description="Helper-target to remove files for getting solr to work with tomcat">
276
277 <echo/>
278 <echo>Removing solr modifications to tomcat: context file, solr.war and deployed version, jar files</echo>
279
280 <!-- Actually need to ensure tomcat is not running at this point
281 But if solr.war is deleted first, it can't be re-deployed when deleting the solr folder subsequently
282 -->
283 <delete failonerror="false" file="${tomcat.dir}/webapps/solr.war"/>
284 <delete failonerror="false" includeEmptyDirs="true" dir="${tomcat.dir}/webapps/solr"/>
285
286 <delete failonerror="false" file="${tomcat.context.dir}/solr.xml"/>
287
288 <!-- delete all the jar files in tomcat/lib that were copied from ext/solr/lib/ext
289 which are all the jar files that are present in both tomcat/lib and ext/solr/lib/ext
290 https://ant.apache.org/manual/Types/selectors.html#presentselect -->
291 <delete failonerror="false">
292 <fileset dir="${tomcat.lib.dir}" includes="**/*.jar">
293 <present present="both" targetdir="lib/ext"/>
294 </fileset>
295 </delete>
296
297 <!-- remove logging bridge jar file that was added into greenstone 3 web lib area -->
298 <delete failonerror="false" file="${web.libdir}/jcl-over-slf4j-1.6.6.jar"/>
299
300 <!--http://stackoverflow.com/questions/2140637/how-do-i-build-a-list-of-file-names-->
301 </target>
302
303 <target name="compile-gs3-solrserver" description="TEST Target to compile the solr server side gs3-solserver.jar for testing">
304 <delete dir="build/org/greenstone/solrserver" />
305 <delete file="build/gs3-solrserver.jar" />
306 <antcall target="compile" />
307 <copy file="${build.home}/gs3-solrserver.jar" todir="${tomcat.dir}/webapps/solr/WEB-INF/lib" />
308 </target>
309
310</project>
Note: See TracBrowser for help on using the repository browser.