forked from lz4/lz4-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
427 lines (380 loc) · 15.9 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="lz4" default="dist" basedir="."
xmlns:cpptasks="antlib:net.sf.antcontrib.cpptasks"
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:junit4="antlib:com.carrotsearch.junit4"
xmlns:mvn="antlib:org.apache.maven.artifact.ant">
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="lib" location="lib" />
<property name="javac.source" value="1.6" />
<property name="javac.target" value="1.6" />
<property name="ivy.jar.version" value="2.2.0"/>
<property name="ivy.jar.name" value="ivy-${ivy.jar.version}.jar"/>
<condition property="platform" value="linux">
<os name="Linux"/>
</condition>
<condition property="platform" value="win32">
<os family="windows"/>
</condition>
<condition property="platform" value="solaris">
<os name="SunOS"/>
</condition>
<condition property="platform" value="darwin">
<os family="mac"/>
</condition>
<target name="clean" description="clean working copy">
<delete dir="${build}" />
<delete dir="${dist}" />
<delete dir="${lib}" />
</target>
<target name="ivy-bootstrap" description="install ivy" unless="ivy.available">
<condition property="ivy.available">
<typefound uri="antlib:org.apache.ivy.ant" name="configure" />
</condition>
<antcall target="-ivy-install" />
</target>
<target name="-ivy-install" unless="ivy.available">
<mkdir dir="${user.home}/.ant/lib" />
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.jar.version}/${ivy.jar.name}" dest="${user.home}/.ant/lib/${ivy.jar.name}"/>
</target>
<target name="install-cpptasks" unless="cpptasks.available">
<ivy:cachepath organisation="ant-contrib" module="cpptasks" revision="1.0b5"
inline="true" conf="default" transitive="true" pathid="cpptasks.classpath"/>
<taskdef uri="antlib:net.sf.antcontrib.cpptasks" resource="net/sf/antcontrib/cpptasks/antlib.xml" classpathref="cpptasks.classpath"/>
<property name="cpptasks.available" value="true"/>
</target>
<target name="install-maven-ant-tasks" unless="maven-ant-tasks.available">
<ivy:cachepath organisation="org.apache.maven" module="maven-ant-tasks" revision="2.1.3"
inline="true" conf="default" transitive="true" pathid="maven-ant-tasks.classpath"/>
<taskdef uri="antlib:org.apache.maven.artifact.ant" resource="org/apache/maven/artifact/ant/antlib.xml" classpathref="maven-ant-tasks.classpath"/>
<property name="maven-ant-tasks.available" value="true"/>
</target>
<target name="install-forbidden-apis" unless="forbidden-apis.available">
<ivy:cachepath organisation="de.thetaphi" module="forbiddenapis" revision="1.3"
inline="true" conf="default" transitive="true" pathid="forbidden-apis.classpath"/>
<taskdef name="forbidden-apis" classname="de.thetaphi.forbiddenapis.AntTask" classpathref="forbidden-apis.classpath"/>
<property name="forbidden-apis.available" value="true"/>
</target>
<target name="install-bnd" unless="bnd.available">
<!-- using bnd 1.50.0 because more recent versions have broken JAR wrapping -->
<ivy:cachepath organisation="biz.aQute" module="bnd" revision="1.50.0"
inline="true" conf="default" transitive="true" pathid="bnd.classpath"/>
<taskdef resource="aQute/bnd/ant/taskdef.properties" classpathref="bnd.classpath"/>
<property name="bnd.available" value="true"/>
</target>
<target name="init">
<tstamp />
<ivy:resolve conf="test" />
<ivy:retrieve />
</target>
<target name="install-junit4" depends="init" unless="junit4.available">
<taskdef uri="antlib:com.carrotsearch.junit4">
<classpath>
<fileset dir="${lib}" includes="*.jar" />
</classpath>
</taskdef>
<property name="junit4.available" value="true" />
</target>
<target name="generate-sources" depends="init">
<ivy:cachepath organisation="org.mvel" module="mvel2" revision="2.3.2.Final"
inline="true" conf="default" transitive="true" pathid="mvel.classpath"/>
<mkdir dir="${build}/java" />
<java
fork="true"
failonerror="true"
classpathref="mvel.classpath"
classname="org.mvel2.sh.Main"
dir="${src}/build/source_templates">
<sysproperty key="out.dir" value="${build}/java"/>
<arg value="${src}/build/gen_sources.mvel" />
</java>
</target>
<target name="compile-java" depends="init, generate-sources">
<mkdir dir="${build}/classes" />
<javac
includeAntRuntime="false"
srcdir="${src}/java"
source="${javac.source}"
target="${javac.target}"
encoding="UTF-8"
debug="true"
destdir="${build}/classes"/>
<mkdir dir="${build}/unsafe-classes" />
<javac
includeAntRuntime="false"
srcdir="${src}/java-unsafe"
source="${javac.source}"
target="${javac.target}"
encoding="UTF-8"
debug="true"
classpath="${build}/classes"
destdir="${build}/unsafe-classes"/>
<mkdir dir="${build}/generated-classes" />
<javac
includeAntRuntime="false"
srcdir="${build}/java"
source="${javac.source}"
target="${javac.target}"
encoding="UTF-8"
debug="true"
destdir="${build}/generated-classes">
<classpath>
<pathelement location="${build}/classes/" />
<pathelement location="${build}/unsafe-classes" />
</classpath>
</javac>
</target>
<target name="generate-headers" depends="compile-java" unless="${skip.jni}">
<mkdir dir="${build}/jni-headers" />
<javah
destDir="${build}/jni-headers">
<classpath>
<pathelement location="${build}/classes/" />
</classpath>
<class name="net.jpountz.lz4.LZ4JNI" />
<class name="net.jpountz.xxhash.XXHashJNI" />
</javah>
</target>
<target name="compile-jni" depends="install-cpptasks,generate-headers" unless="${skip.jni}">
<mkdir dir="${build}/objects" />
<mkdir dir="${build}/jni/net/jpountz/util/${platform}/${os.arch}" />
<cpptasks:cc
debug="false"
optimize="extreme"
objdir="${build}/objects"
outfile="${build}/jni/net/jpountz/util/${platform}/${os.arch}/lz4-java"
outtype="shared">
<includepath path="${src}/lz4/lib" />
<includepath path="${java.home}/../include" />
<includepath path="${java.home}/../include/${platform}/" />
<!-- In Java 9, java.home points not to jre/ but to the top directory -->
<includepath path="${java.home}/include" />
<includepath path="${java.home}/include/${platform}/" />
<includepath path="${build}/jni-headers" />
<fileset dir="${src}/lz4/lib" includes="lz4.c, lz4hc.c, xxhash.c" />
<fileset dir="${src}/jni" includes="*.c" />
<linker />
</cpptasks:cc>
</target>
<target name="compile" depends="compile-java, compile-jni" />
<target name="compile-tests" depends="compile">
<mkdir dir="${build}/test-classes" />
<javac
includeAntRuntime="false"
srcdir="${src}/test"
encoding="UTF-8"
debug="true"
destdir="${build}/test-classes">
<classpath refid="${prop.compile.tests.classpath}" />
</javac>
</target>
<path id="compile.tests.classpath">
<pathelement path="${build}/classes" />
<pathelement path="${build}/unsafe-classes" />
<pathelement path="${build}/generated-classes" />
<fileset dir="lib" includes="*.jar" />
</path>
<path id="compile.tests.classpath.with.jar">
<pathelement path="${lz4-java.jar}" />
<fileset dir="lib" includes="*.jar" />
</path>
<path id="test.classpath">
<pathelement path="${build}/jni" />
<pathelement path="${src}/resources" />
<pathelement path="${src}/test-resources" />
<pathelement path="${build}/classes" />
<pathelement path="${build}/unsafe-classes" />
<pathelement path="${build}/generated-classes" />
<pathelement path="${build}/test-classes" />
<fileset dir="${lib}" includes="*.jar" />
</path>
<path id="test.classpath.with.jar">
<pathelement path="${lz4-java.jar}" />
<pathelement path="${src}/test-resources" />
<pathelement path="${build}/test-classes" />
<fileset dir="${lib}" includes="*.jar" />
</path>
<target name="test" description="run tests">
<property name="prop.compile.tests.classpath" value="compile.tests.classpath" />
<property name="prop.test.classpath" value="test.classpath" />
<antcall target="-test" />
</target>
<target name="test-jar" description="run tests with jar specified by lz4-java.jar property">
<property name="prop.compile.tests.classpath" value="compile.tests.classpath.with.jar" />
<property name="prop.test.classpath" value="test.classpath.with.jar" />
<antcall target="-test" />
</target>
<target name="-test" depends="compile-tests, install-junit4">
<mkdir dir="${build}/tests" />
<junit4:junit4
dir="${java.io.tmpdir}"
maxmemory="300m"
parallelism="auto">
<assertions>
<enable package="net.jpountz.lz4"/>
</assertions>
<classpath refid="${prop.test.classpath}" />
<fileset dir="${build}/test-classes/">
<include name="**/*Test.class" />
<exclude name="**/*$*" />
<exclude name="**/Abstract*" />
</fileset>
<listeners>
<junit4:report-text
showThrowable="true"
showStackTraces="true"
showOutput="never"
showStatusOk="true"
showStatusError="true"
showStatusFailure="true"
showStatusIgnored="true"
showSuiteSummary="false" />
<!-- For enkins -->
<junit4:report-ant-xml dir="${build}/tests" />
</listeners>
</junit4:junit4>
</target>
<target name="test-skip-jni" description="run tests without building JNI">
<property name="skip.jni" value="true" />
<antcall target="test" />
</target>
<target name="sources" description="package sources">
<mkdir dir="${dist}" />
<jar
destfile="${dist}/${ivy.module}-${ivy.revision}-sources.jar">
<fileset dir="${src}/java" />
<fileset dir="${src}/java-unsafe" />
</jar>
</target>
<target name="docs" description="generate javadocs" depends="init">
<mkdir dir="${build}/docs" />
<javadoc
overview="${src}/java/overview.html"
packagenames="net.jpountz.lz4,net.jpountz.xxhash"
windowtitle="lz4 / xxhash - Java API ${ivy.revision}"
destDir="${build}/docs">
<link href="http://download.oracle.com/javase/6/docs/api/" />
<sourcepath>
<pathelement location="${src}/java"/>
</sourcepath>
</javadoc>
<mkdir dir="${dist}" />
<jar
destfile="${dist}/${ivy.module}-${ivy.revision}-javadoc.jar">
<fileset dir="${build}/docs" />
</jar>
</target>
<target name="jar" description="generate JAR" depends="compile">
<mkdir dir="${dist}" />
<jar
destfile="${dist}/${ivy.module}.jar">
<fileset dir="${src}/resources" erroronmissingdir="false" />
<fileset dir="${build}/classes" />
<fileset dir="${build}/unsafe-classes" />
<fileset dir="${build}/generated-classes" />
<fileset dir="${build}/jni" erroronmissingdir="false" />
</jar>
</target>
<target name="jar-no-jni" description="generate JAR without native libraries">
<property name="skip.jni" value="true" />
<antcall target="-jar-no-jni" />
</target>
<target name="-jar-no-jni" depends="compile">
<mkdir dir="${dist}" />
<jar
destfile="${dist}/${ivy.module}-no-jni-${ivy.revision}.jar">
<fileset dir="${build}/classes" />
<fileset dir="${build}/unsafe-classes" />
<fileset dir="${build}/generated-classes" />
</jar>
</target>
<target name="bundle" description="makes the JAR a valid OSGi bundle" depends="install-bnd, jar">
<taskdef resource="aQute/bnd/ant/taskdef.properties" classpathref="bnd.classpath"/>
<property name="packages.version" value="${ivy.revision}"/>
<!-- We need to remove potential -SNAPSHOT qualifiers as package versions... -->
<script language="javascript">
<![CDATA[
// lz4 is the ant project name
version = lz4.getProperty("packages.version");
lz4.setProperty("packages.version", version.replace("-SNAPSHOT", ""));
]]>
</script>
<!-- wrap the JAR as a bundle and set the proper name -->
<bndwrap definitions="${basedir}" output="${dist}/${ivy.module}-${ivy.revision}.jar" trace="true">
<fileset dir="${dist}/" includes="${ivy.module}.jar"/>
</bndwrap>
<!-- remove plain JAR -->
<delete file="${dist}/${ivy.module}.jar"/>
</target>
<target name="makepom" description="generate a pom file">
<ivy:makepom
ivyfile="${basedir}/ivy.xml"
pomfile="${dist}/${ivy.module}-${ivy.revision}.pom"
templatefile="${src}/build/pom.template">
<mapping conf="default" scope="compile" />
<mapping conf="test" scope="test" />
</ivy:makepom>
</target>
<target name="dist" description="package" depends="bundle,docs,sources,makepom" />
<target name="dist-skip-jni" description="package without building native libraries">
<property name="skip.jni" value="true" />
<antcall target="dist" />
</target>
<target name="forbidden-apis" description="check API usage" depends="install-forbidden-apis,compile">
<forbidden-apis internalRuntimeForbidden="true" classpathref="forbidden-apis.classpath">
<bundledSignatures name="jdk-unsafe-${javac.target}"/>
<bundledSignatures name="jdk-deprecated-${javac.target}"/>
<fileset dir="${build}/classes" includes="**/*.class" />
</forbidden-apis>
<forbidden-apis classpathref="forbidden-apis.classpath">
<bundledSignatures name="jdk-unsafe-${javac.target}"/>
<bundledSignatures name="jdk-deprecated-${javac.target}"/>
<fileset dir="${build}/classes" includes="**/*.class" />
<fileset dir="${build}/unsafe-classes" includes="**/*.class" />
</forbidden-apis>
</target>
<macrodef name="deploy">
<attribute name="repositoryid" />
<attribute name="repositoryurl" />
<sequential>
<mvn:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.4:sign-and-deploy-file" />
<arg value="-Durl=@{repositoryurl}" />
<arg value="-DrepositoryId=@{repositoryid}" />
<arg value="-DpomFile=${dist}/${ivy.module}-${ivy.revision}.pom" />
<arg value="-Dfile=${dist}/${ivy.module}-${ivy.revision}.jar" />
<arg value="-Dfiles=${dist}/${ivy.module}-${ivy.revision}-sources.jar,${dist}/${ivy.module}-${ivy.revision}-javadoc.jar" />
<arg value="-Dclassifiers=sources,javadoc" />
<arg value="-Dtypes=jar,jar" />
<arg value="-Pgpg" />
</mvn:mvn>
</sequential>
</macrodef>
<target name="deploy" description="deploy snapshot to snapshot repo" depends="install-maven-ant-tasks">
<property name="skip.jni" value="true" />
<antcall target="-deploy" />
</target>
<target name="-deploy" depends="clean,dist">
<deploy repositoryid="sonatype-nexus-snapshots" repositoryurl="https://oss.sonatype.org/content/repositories/snapshots" />
</target>
<!-- before this, update project version from SNAPSHOT to RELEASE -->
<target name="stage" description="deploy to release repo" depends="install-maven-ant-tasks,test-skip-jni,forbidden-apis">
<property name="skip.jni" value="true" />
<antcall target="-stage" />
</target>
<target name="-stage" depends="clean,dist">
<deploy repositoryid="sonatype-nexus-staging" repositoryurl="https://oss.sonatype.org/service/local/staging/deploy/maven2" />
</target>
</project>