-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
329 lines (295 loc) · 15 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<?xml version="1.0"?>
<!--
This software is published under the terms of the Apache License, Version 2.0,
a copy of which is included in this distribution.
-->
<!--
Build Requirements:
* Ant 1.7.1 or higher (including optional tasks)
* JDK 1.7 or higher
-->
<project name="Openfire Out Of Tree Plugin Example" default="plugin-build" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless">
<description>
Openfire out of tree build script.
</description>
<!-- ======================================================================================= -->
<!-- GLOBAL PROPERTIES -->
<!-- ======================================================================================= -->
<property name="plugin.name" value="ootexample"/>
<property environment="env"/>
<property name="javac.source" value="1.7"/>
<property name="javac.target" value="1.7"/>
<property name="work.dir" value="${basedir}/work"/>
<property name="build.dir" value="${basedir}/build"/>
<echo>Openfire Home is set to ${env.OPENFIRE_HOME}</echo>
<condition property="openfire.home" value="${env.OPENFIRE_HOME}">
<isset property="env.OPENFIRE_HOME"/>
</condition>
<fail unless="openfire.home" message="OPENFIRE_HOME environment variable must be set to the root of an openfire source directory"/>
<property name="lib.ant.dir" value="${openfire.home}/build/lib/ant"/>
<path id="ant.dependencies">
<fileset dir="${lib.ant.dir}" includes="*.jar"/>
<fileset dir="${ant.home}/lib" includes="ant.jar"/>
</path>
<!-- Reference DTDs and XSDs on the classpath, to prevent them from being looked up online. -->
<xmlcatalog id="dtds">
<!-- Provided on the classpath (by Jetty/Jasper) -->
<entity publicId="http://java.sun.com/xml/ns/j2ee" location="javax/servlet/jsp/resources/jsp_2_0.xsd"/>
<entity publicId="http://java.sun.com/xml/ns/javaee" location="javax/servlet/jsp/resources/jsp_2_1.xsd"/>
<entity publicId="http://java.sun.com/xml/ns/javaee" location="javax/servlet/jsp/resources/jsp_2_2.xsd"/>
<entity publicId="http://xmlns.jcp.org/xml/ns/javaee" location="javax/servlet/jsp/resources/jsp_2_3.xsd"/>
<entity publicId="http://java.sun.com/JSP/Page" location="javax/servlet/jsp/resources/jspxml_2_0.xsd"/>
<entity publicId="http://java.sun.com/xml/ns/j2ee" location="javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd"/>
<entity publicId="http://java.sun.com/xml/ns/javaee" location="javax/servlet/jsp/resources/web-jsptaglibrary_2_1.xsd"/>
<dtd publicId="http://java.sun.com/JSP/Page" location="javax/servlet/jsp/resources/jspxml_2_0.dtd"/>
<dtd publicId="-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" location="javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd"/>
<!-- Provided in the lib folder -->
<dtd publicId="-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" location="${lib.ant.dir}/web-app_2_3.dtd"/>
</xmlcatalog>
<!-- ======================================================================================= -->
<!-- GLOBAL TASKDEFs -->
<!-- ======================================================================================= -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath refid="ant.dependencies" />
</taskdef>
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath refid="ant.dependencies" />
</taskdef>
<taskdef name="propertymerge" classname="org.jugbb.ant.propertymerge.PropertyMergeTask">
<classpath refid="ant.dependencies" />
</taskdef>
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath refid="ant.dependencies" />
</taskdef>
<!-- ======================================================================================= -->
<!-- PATHs / PATTERNSETs / FILTERSETs -->
<!-- ======================================================================================= -->
<presetdef name="of.javac">
<javac encoding="utf8" source="${javac.source}" target="${javac.target}" includeAntRuntime="no" debug="on"/>
</presetdef>
<!-- ======================================================================================= -->
<!-- TARGETs -->
<!-- ======================================================================================= -->
<!-- init ================================================================================== -->
<target name="init">
<!-- Check for min build requirements -->
<condition property="ant.not.ok" value="true">
<not>
<antversion atleast="1.7.1"/>
</not>
</condition>
<condition property="java.not.ok" value="true">
<not>
<or>
<contains string="${ant.java.version}" substring="1.7"/>
<contains string="${ant.java.version}" substring="1.8"/>
<contains string="${ant.java.version}" substring="1.9"/>
</or>
</not>
</condition>
<fail if="ant.not.ok" message="Must use Ant 1.7.1 or higher to build Openfire"/>
<fail if="java.not.ok" message="Must use JDK 1.7 or higher to build Openfire"/>
<tstamp/>
<tstamp>
<format property="builddate" pattern="MM/dd/yyyy"/>
</tstamp>
<tstamp>
<format property="dailybuild.tstamp" pattern="yyyy-MM-dd" locale="en"/>
</tstamp>
<echo>Setting up build directory structure</echo>
<mkdir dir="${work.dir}"/>
<mkdir dir="${work.dir}/classes"/>
<mkdir dir="${work.dir}/database"/>
<mkdir dir="${work.dir}/i18n"/>
<mkdir dir="${work.dir}/lib"/>
<mkdir dir="${work.dir}/web"/>
<mkdir dir="${build.dir}"/>
</target>
<target name="clean">
<delete>
<fileset dir="${work.dir}" includes="**/*"/>
</delete>
<delete>
<fileset dir="${build.dir}" includes="**/*"/>
</delete>
</target>
<macrodef name="compileplugin">
<attribute name="plugin"/>
<sequential>
<xmlproperty file="plugin.xml" prefix="plugin.xmlproperty" keeproot="false"/>
<condition property="plugin.parent" value="${plugin.xmlproperty.parentPlugin}">
<isset property="plugin.xmlproperty.parentPlugin"/>
</condition>
<if>
<isset property="plugin.parent"/>
<then>
<echo>Parent plugin is ${plugin.parent}</echo>
</then>
</if>
<path id="openfire.libraries">
<fileset dir="${openfire.home}/build" includes="lib/*.jar"/>
<fileset dir="${openfire.home}/build" includes="lib/merge/*.jar"/>
<fileset dir="${openfire.home}/target/openfire" includes="lib/openfire.jar"/>
</path>
<path id="plugin.dependencies">
<path refid="openfire.libraries"/>
<fileset dir="${openfire.home}/work/plugins-dev">
<include name="${plugin.parent}/target/lib/*.jar" if:set="${plugin.parent}"/>
</fileset>
</path>
<path id="plugin.classpath.source">
<path refid="plugin.dependencies"/>
<fileset dir="." includes="lib/*.jar"/>
</path>
<echo>Building Java classes to ${build.dir}/classes</echo>
<of.javac destdir="${build.dir}/classes" classpathref="plugin.classpath.source">
<src path="src/java"/>
</of.javac>
</sequential>
</macrodef>
<macrodef name="compilejsps">
<attribute name="plugin"/>
<sequential>
<xmlproperty file="plugin.xml" prefix="plugin.xmlproperty" keeproot="false"/>
<condition property="plugin.parent" value="${plugin.xmlproperty.parentPlugin}">
<isset property="plugin.xmlproperty.parentPlugin"/>
</condition>
<if>
<isset property="plugin.parent"/>
<then>
<echo>Parent plugin is ${plugin.parent}</echo>
</then>
</if>
<path id="openfire.libraries">
<fileset dir="${openfire.home}/build" includes="lib/*.jar"/>
<fileset dir="${openfire.home}/build" includes="lib/merge/*.jar"/>
<fileset dir="${openfire.home}/target/openfire" includes="lib/openfire.jar"/>
<path refid="ant.dependencies"/>
</path>
<path id="plugin.dependencies">
<path refid="openfire.libraries"/>
<fileset dir="${openfire.home}/work/plugins-dev/${plugin.parent}/target" includes="lib/*.jar" if:set="${plugin.parent}"/>
</path>
<path id="plugin.classpath.source">
<path refid="plugin.dependencies"/>
<fileset dir="." includes="lib/*.jar"/>
<fileset dir="${work.dir}" includes="lib/plugin-${plugin.name}.jar"/>
</path>
<echo>Compiling JSP pages to Java in ${build.dir}/jsps</echo>
<mkdir dir="src/web"/>
<java classname="org.apache.jasper.JspC" fork="true">
<classpath>
<pathelement location="${java.home}/../lib/tools.jar"/>
<path refid="plugin.classpath.source"/>
</classpath>
<arg line="-uriroot 'src/web'"/>
<arg line="-d '${build.dir}/jsps'"/>
<arg line="-p org.jivesoftware.openfire.plugin.@{plugin}"/>
<arg line="-webxml '${build.dir}/jsps/web.xml'"/>
</java>
<!-- Use xmltask to merge the generated web.xml file and a developer one (if any) -->
<available property="plugin.webxml.available"
type="file" file="src/web/WEB-INF/web-custom.xml"/>
<mkdir dir="${work.dir}/web/WEB-INF"/>
<if>
<equals arg1="${plugin.webxml.available}" arg2="true"/>
<then>
<echo>Merging generated web.xml with custom</echo>
<!-- Copy the servlet and servlet-mapping elements from the original web.xml to a temp buffer.
Note: The original web.xml can only contain one servlet and servlet-mapping -->
<xmltask source="src/web/WEB-INF/web-custom.xml">
<xmlcatalog refid="dtds"/>
<!--<copy path="//*[name()='web-app']/*[name()='servlet'][last()]" buffer="foobar"/>-->
<copy path="//web-app/servlet[last()]" buffer="foobar"/>
<copy path="//web-app/servlet-mapping[last()]" buffer="foobar2"/>
</xmltask>
<!-- Add the copied servlet and servlet-mapping elements to the generated web.xml -->
<xmltask source="${build.dir}/jsps/web.xml"
dest="${work.dir}/web/WEB-INF/web.xml">
<xmlcatalog refid="dtds"/>
<insert path="/web-app/servlet[last()]" buffer="foobar"
position="after"/>
<insert path="/web-app/servlet-mapping[last()]" buffer="foobar2"
position="after"/>
</xmltask>
</then>
<else>
<echo>Copying generated web.xml</echo>
<copy todir="${work.dir}/web/WEB-INF"
file="${build.dir}/jsps/web.xml"
overwrite="${overwrite}"/>
</else>
</if>
<echo>Compiling JSP java classes</echo>
<mkdir dir="${build.dir}/jspc"/>
<of.javac destdir="${build.dir}/jspc" classpathref="plugin.classpath.source">
<src path="${build.dir}/jsps"/>
</of.javac>
</sequential>
</macrodef>
<target name="plugin-build" depends="init">
<!-- Copy of root files -->
<copy file="plugin.xml" todir="${work.dir}"/>
<copy failonerror="false" file="readme.html" todir="${work.dir}" quiet="true"/>
<copy failonerror="false" file="changelog.html" todir="${work.dir}" quiet="true"/>
<copy failonerror="false" todir="${work.dir}" quiet="true">
<fileset dir="." includes="logo_*.*"/>
</copy>
<!-- Copy of classes dir -->
<copy failonerror="false" todir="${work.dir}/classes" quiet="true">
<fileset dir="classes" includes="*"/>
</copy>
<!-- Copy of database dir -->
<copy failonerror="false" todir="${work.dir}/database" quiet="true">
<fileset dir="database" includes="*"/>
</copy>
<!-- Copy of i18n dir -->
<copy failonerror="false" todir="${work.dir}/i18n" quiet="true">
<fileset dir="i18n" includes="*"/>
</copy>
<!-- Copy of lib dir -->
<copy failonerror="false" todir="${work.dir}/lib" quiet="true">
<fileset dir="lib" includes="*"/>
</copy>
<!-- Now we do the build of the plugin-NAME.jar from the src/java files -->
<delete>
<fileset dir="${build.dir}" includes="**/*"/>
</delete>
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.dir}/classes"/>
<mkdir dir="${build.dir}/jsps"/>
<compileplugin plugin="${plugin.name}"/>
<!-- Make a jar of the compiled classes -->
<jar jarfile="${work.dir}/lib/plugin-${plugin.name}.jar" update="true">
<fileset dir="${build.dir}/classes" includes="**/*.*"/>
</jar>
<resourcecount property="plugin.jsps.count">
<fileset dir="src/web" erroronmissingdir="false">
<include name="*.jsp"/>
</fileset>
</resourcecount>
<echo>Found ${plugin.jsps.count} jsp files</echo>
<if>
<equals arg1="${plugin.jsps.count}" arg2="0"/>
<then>
<if>
<available file="src/web/WEB-INF/web-custom.xml"/>
<then>
<copy file="src/web/WEB-INF/web-custom.xml" tofile="${work.dir}}/web/WEB-INF/web-xml"/>
</then>
</if>
</then>
<else>
<compilejsps plugin="${plugin.name}"/>
<!-- Make a jar of the compiled JSPs -->
<jar jarfile="${work.dir}/lib/plugin-${plugin.name}-jspc.jar" update="true">
<fileset dir="${build.dir}/jspc" includes="**/*.class"/>
</jar>
</else>
</if>
<!-- Build plugin jar -->
<jar jarfile="${plugin.name}.jar">
<fileset dir="${work.dir}"/>
</jar>
</target>
</project>