-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
263 lines (214 loc) · 10.1 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
<!--
Generalized Zimbra server extension Ant buildfile.
Needs jsch-libraries for the deployment tasks.
-->
<project name="Serverextension"
default="compile"
xmlns:if="ant:if"
xmlns:unless="ant:unless">
<!-- Taskdefs for third-party ant libs -->
<!--
This is used to include condtions based on Zimbra versions in our code :
/* $if ZimbraVersion > 8.0.0 $ */
...
/* $else $ */
...
/* $endif $ */
-->
<taskdef name="preprocess" classname="com.objfac.prebop.ant.PreprocessorTask">
<classpath>
<pathelement location="ant/preprocessor.jar"/>
</classpath>
</taskdef>
<description>Building and deployment of a Zimbra Server extension</description>
<!-- Read in site properties -->
<property file="build.properties" />
<!-- Fill up empty properties with distribution properties -->
<property file="build.properties.dist" />
<!-- Class and dependencies paths -->
<path id="libs.local">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
<!-- Build env tasks -->
<target name="gen-classpath" description="Generate .classpath file for given zimbra version">
<echo unless:set="zimbra-version">Command must be run with -Dzimbra-version=X.X.X</echo>
<fail unless="zimbra-version" />
<echo file=".classpath">./lib/*:${zimbra.jars.dir}/${zimbra-version}/*</echo>
<echo file=".zimbra_version">${zimbra-version}</echo>
<echo>Generated .classpath and .zimbra_version</echo>
</target>
<macrodef name="install-ant-dep">
<attribute name="maven-path" />
<attribute name="jar-name" />
<sequential>
<get src="http://central.maven.org/maven2/@{maven-path}/maven-metadata.xml" dest="/tmp/_maven.xml" />
<xmlproperty file="/tmp/_maven.xml" keepRoot="true" />
<get src="http://central.maven.org/maven2/@{maven-path}/${metadata.versioning.latest}/@{jar-name}-${metadata.versioning.latest}.jar" dest="${user.home}/.ant/lib/@{jar-name}.jar" />
<delete file="/tmp/_maven.xml" />
</sequential>
</macrodef>
<target name="init-dev" depends="gen-classpath" description="Install ant build dependencies">
<echo>Installing ANT dependencies</echo>
<available file="${user.home}/.ant/lib/jsch.jar" type="dir" property="ant.dir" />
<available file="${user.home}/.ant/lib/jsch.jar" property="ant.jsch" />
<available file="${user.home}/.ant/lib/ant-jsch.jar" property="ant.ant-jsch" />
<mkdir unless:set="ant.dir" dir="${user.home}/.ant/lib" />
<install-ant-dep unless:set="ant.jsch" maven-path="com/jcraft/jsch" jar-name="jsch" />
<install-ant-dep unless:set="ant.ant-jsch" maven-path="org/apache/ant/ant-jsch" jar-name="ant-jsch" />
</target>
<import file="bump-tasks.xml" />
<target name="init">
<tstamp />
<available file="version" property="version.exists" />
<echo unless:set="version.exists" file="version">0.0.0</echo>
<loadfile srcFile="version" property="version" failonerror="false" quiet="true" />
<echo> Generating Extension BuildInfo - version ${version} </echo>
<exec executable="./gen_buildinfo.sh" failonerror="true">
<arg value="${dist.src}/BuildInfo.java" />
<arg value="${dist.name}" />
<arg value="${version}" />
</exec>
<!-- Also create some properties -->
</target>
<macrodef name="gen-slug">
<sequential>
<loadresource property="slug">
<propertyresource name="dist.name"/>
<filterchain>
<tokenfilter>
<replacestring from="." to="_"/>
</tokenfilter>
</filterchain>
</loadresource>
<property name="dist.jarfile" value="${slug}.jar"/>
</sequential>
</macrodef>
<!-- Macros to be used by build tasks -->
<macrodef name="build-extension">
<attribute name="ZimbraVersion" default="${zimbra-version}" />
<attribute name="MajorZimbraVersion" default="${zmajor}" />
<attribute name="MiddleZimbraVersion" default="${zmiddle}" />
<attribute name="MinorZimbraVersion" default="${zminor}" />
<attribute name="nojar" default="false" />
<sequential>
<local name="tmpsrc" />
<local name="build" />
<local name="dist" />
<local name="version" />
<property name="tmpsrc" value="${tmpsrc.dir}/@{ZimbraVersion}/" />
<property name="build" value="${build.dir}/@{ZimbraVersion}/" />
<property name="dist" value="${dist.dir}/@{ZimbraVersion}/" />
<loadfile srcFile="version" property="version" failonerror="false" quiet="true" />
<mkdir dir="${tmpsrc}" />
<mkdir dir="${build}" />
<mkdir dir="${dist}" />
<echo>Creating extension JAR for zimbra @{ZimbraVersion} ...</echo>
<echo>Preprocessing...</echo>
<preprocess indir="${dist.src}" outdir="${tmpsrc}" out="replace" >
<var name="ZimbraVersion" value="@{MajorZimbraVersion}.@{MiddleZimbraVersion}.@{MinorZimbraVersion}" />
<var name="MajorZimbraVersion" value="@{MajorZimbraVersion}" />
<var name="MiddleZimbraVersion" value="@{MiddleZimbraVersion}" />
<var name="MinorZimbraVersion" value="@{MinorZimbraVersion}" />
<filetype commentend="*/" commentbegin="/*" extensions="java" />
</preprocess>
<javac includeantruntime="false" debug="true"
debuglevel="lines,vars,source"
srcdir="${tmpsrc}" destdir="${build}">
<classpath>
<path>
<fileset dir="${zimbra.jars.dir}/@{ZimbraVersion}/">
<include name="*.jar" />
</fileset>
</path>
<path refid="libs.local" />
<pathelement path="${build}" />
</classpath>
<!-- <compilerarg value="-Xlint:all" /> -->
<compilerarg value="-Xlint:unchecked" />
</javac>
<gen-slug />
<jar unless:true="nojar" manifest="${project.manifest}" destfile="${dist}/${dist.jarfile}" basedir="${build}" duplicate="fail">
<zipgroupfileset dir="lib" includes="*.jar" />
<manifest>
<attribute name="Specification-Title" value="${dist.fullname}" />
<attribute name="Specification-Version" value="${version}" />
<attribute name="Specification-Vendor" value="${dist.vendor}" />
<attribute name="Implementation-Version" value="@{ZimbraVersion}" />
<attribute name="Created-By" value="${dist.vendor}" />
</manifest>
</jar>
</sequential>
</macrodef>
<!-- Release build targets -->
<target name="build-8.6.0"
description="Create jar for Zimbra 8.6.0"
depends="init"
extensionOf="build-all">
<build-extension ZimbraVersion="8.6.0"
MajorZimbraVersion="8"
MiddleZimbraVersion="6"
MinorZimbraVersion="0" />
</target>
<!-- <target name="build-8.7.0"
description="Create jar for Zimbra 8.7.0"
depends="init"
extensionOf="build-all">
<build-extension ZimbraVersion="8.7.0"
MajorZimbraVersion="8"
MiddleZimbraVersion="7"
MinorZimbraVersion="0" />
</target> -->
<extension-point name="build-all" />
<!-- Dev process targets: lint, compile, deploy, ... -->
<macrodef name="build">
<attribute name="nojar" default="false" />
<sequential>
<loadfile srcFile=".zimbra_version" property="zimbra-version" failonerror="true" />
<script language="javascript">
<![CDATA[
// needs this for split to work...
zimbra_version = String(new java.lang.String(project.getProperty('zimbra-version')));
arr = zimbra_version.split('.');
project.setProperty('zmajor', arr[0]);
project.setProperty('zmiddle', arr[1]);
project.setProperty('zminor', arr[2]);
]]>
</script>
<build-extension nojar="@{nojar}" />
</sequential>
</macrodef>
<target name="lint" depends="init" description="Compiles sources for linting">
<build nojar="true"/>
</target>
<target name="compile" depends="init" description="Compiles and create jar">
<build />
</target>
<target name="deploy" depends="init" description="Transfers the jar to the server">
<sequential>
<build />
<gen-slug />
<property name="deploy.path" value="/opt/zimbra/lib/ext/${slug}"/>
<sshexec host="${deploy.host}" trust="true"
username="${deploy.username}" keyfile="${deploy.keyfile}"
command="mkdir -p ${deploy.path}" failonerror="false"/>
<scp file="${dist.dir}/${zimbra-version}/${dist.jarfile}" trust="true"
todir="${deploy.username}@${deploy.host}:${deploy.path}"
keyfile="${deploy.keyfile}"/>
</sequential>
</target>
<target name="deployrestart" depends="deploy"
description="Deploy the jar file and restart mailboxd">
<sshexec host="${deploy.host}" trust="true"
username="root" keyfile="${deploy.keyfile}"
command="${deploy.restartmailboxd}"/>
</target>
<target name="clean" description="Build directories cleanup">
<delete includeemptydirs="true">
<fileset dir="${tmpsrc.dir}" includes="**/*" />
<fileset dir="${build.dir}" includes="**/*" />
<fileset dir="${dist.dir}" includes="**/*" />
</delete>
</target>
</project>