-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.xml
343 lines (300 loc) · 15.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
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
<?xml version="1.0"?>
<!-- ant build file for Freetalk -->
<project name="Freetalk" default="dist" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless">
<!-- ======================================================================================= -->
<!-- Configuration -->
<!-- ======================================================================================= -->
<!-- You can use this file to override the below properties. -->
<property file="override.properties"/>
<!-- Dependencies. These are the most important to configure! -->
<!-- -->
<!-- Freenet build01481 compiled with "./gradlew jar copyRuntimeLibs" will copy the -->
<!-- freenet.jar and its dependencies to this directory: -->
<property name="freenet.lib.new.location" location="../fred/build/output/"/>
<!-- Older Freenet builds will use these places for the JARs, some of which have to be -->
<!-- downloaded manually: -->
<property name="freenet.lib.old.location.1" location="../fred/lib/bcprov.jar"/>
<property name="freenet.lib.old.location.2" location="../fred/lib/jna-platform.jar"/>
<property name="freenet.lib.old.location.3" location="../fred/lib/jna.jar"/>
<property name="freenet.lib.old.location.4" location="../fred/lib/freenet/freenet-ext.jar"/>
<property name="freenet.lib.old.location.5" location="../fred/dist/freenet.jar"/>
<!-- Unit test dependencies -->
<property name="junit.location" value="/usr/share/java/junit4.jar"/>
<!-- Optional, only needed if using "ant -Dtest.coverage=true" -->
<property name="cobertura.location" value="/usr/share/java/cobertura.jar"/>
<!-- Minimum Java version which fred officially requires
= Maximum version which Freetalk's code can use features of. -->
<property name="source-version" value="8"/>
<property name="target-version" value="8"/>
<!-- To allow you to restart your debug node after recompiling without manually reloading
the Freetalk plugin you can specifiy this property to point to the node's Freetalk.jar.
The Ant builder will delete it automatically as part of the "clean" target. -->
<property name="debug-node-freetalk-plugin.location" location="../fred/plugins/Freetalk.jar"/>
<!-- ======================================================================================= -->
<!-- Configuration which you should probably leave as is! -->
<!-- ======================================================================================= -->
<!-- Git submodule directory of the db4o source code. Will be compiled automatically! -->
<property name="db4o-submodule.location" location="db4o-7.4"/>
<!-- JAR which the Ant builder of db4o produces. -->
<property name="db4o.location" location="${db4o-submodule.location}/db4o.jar"/>
<property name="svn.revision" value="@custom@"/>
<property name="build" location="build/"/>
<property name="build-test" location="build-test/"/>
<property name="build-test-jar" location="${build-test}/Freetalk-with-unit-tests.jar"/>
<property name="build-test-coverage" location="test-coverage/"/>
<property name="dist" location="dist/"/>
<property name="src" location="src/"/>
<property name="version.src" value="plugins/Freetalk/Version.java" />
<property name="version.build" value="plugins/Freetalk/Version.class" />
<available file="src/plugins/Freetalk/Version.java" property="version.present"/>
<available file="${cobertura.location}" property="cobertura.present"/>
<property name="test.coverage" unless:set="${test.coverage}" if:true="${cobertura.present}" value="true"/>
<!-- Libraries whose classes are to be bundled in our own JAR. -->
<path id="submodules.path">
<pathelement location="${db4o.location}"/>
</path>
<!-- Libraries which we get from fred. -->
<path id="libraries.classpath">
<!-- Use filesets instead of <pathelement> to:
- allow using wildcards when including freenet.lib.new.location so we don't need to
synchronize the list of JARs which fred needs with what this build file includes.
- for the old JAR locations ensure the print-libs task won't print files which don't
exist as that is what he wildcard usage dictates for thew new location already. -->
<fileset dir="${freenet.lib.new.location}" erroronmissingdir="no" casesensitive="no">
<include name="**/*.jar"/>
</fileset>
<fileset file="${freenet.lib.old.location.1}" erroronmissingdir="no"/>
<fileset file="${freenet.lib.old.location.2}" erroronmissingdir="no"/>
<fileset file="${freenet.lib.old.location.3}" erroronmissingdir="no"/>
<fileset file="${freenet.lib.old.location.4}" erroronmissingdir="no"/>
<fileset file="${freenet.lib.old.location.5}" erroronmissingdir="no"/>
</path>
<path id="junit.classpath">
<pathelement location="${junit.location}" />
</path>
<path id="cobertura.path">
<pathelement location="${cobertura.location}"/>
</path>
<!-- For print-libs task: All runtime dependencies of Freetalk plus the build-time dependencies.
Uses <fileset> instead of <pathelement> so it only contains only those which exist as that
is what lib.path does already. -->
<path id="lib.external.all.path">
<path refid="libraries.classpath"/>
<path refid="junit.classpath" />
<fileset file="${cobertura.location}"/>
</path>
<presetdef name="javac">
<!--
includeantruntime is a workaround for an ant 1.8 misfeature. TODO: Remove when ant fixes this.
If we don't set this to false, we will get "warning: 'includeantruntime' was not set, defaulting to
build.sysclasspath=last; set to false for repeatable builds"
(includeAntRuntime = "Whether to include the Ant run-time libraries in the classpath; defaults to yes,
unless build.sysclasspath is set. It is usually best to set this to false so the script's behavior
is not sensitive to the environment in which it is run."
Source: https://ant.apache.org/manual/Tasks/javac.html)
-->
<javac includeantruntime="false" encoding="UTF-8"/>
</presetdef>
<exec executable="git"
failifexecutionfails="false"
errorProperty="git.errror"
outputproperty="git.describe"
resultproperty="git.result">
<arg value="describe" />
<arg value="--always" />
<arg value="--abbrev=4" />
<arg value="--dirty" />
</exec>
<condition property="git.revision" value="${git.describe}" else="@unknown@">
<and>
<equals arg1="${git.result}" arg2="0" />
<isset property="git.describe" />
</and>
</condition>
<target name="get-submodules" description="Downloads the git submodules required by Freetalk">
<echo>Downloading db4o git submodule if it doesn't exist already...</echo>
<exec executable="git">
<arg line="submodule update --init"/>
</exec>
</target>
<target name="db4o" depends="get-submodules" description="Compiles the database submodule">
<echo>Compiling db4o submodule...</echo>
<ant dir="${db4o-submodule.location}" inheritAll="false" useNativeBasedir="true">
<property name="javac.source.version" value="${source-version}"/>
<property name="javac.target.version" value="${target-version}"/>
</ant>
</target>
<target name="clean-db4o" depends="get-submodules" description="Cleans the database submodule">
<echo>Cleaning db4o submodule...</echo>
<ant dir="${db4o-submodule.location}" target="clean" inheritAll="false"
useNativeBasedir="true"/>
</target>
<target name="print-libs">
<echo>External dependencies on classpath follow, but ONLY those which did exist.</echo>
<echo>(This cannot tell which JARs are missing because that would require ant-contrib</echo>
<echo>and I don't want to require Freenet release managers to install it. Sorry.)</echo>
<echo></echo>
<echo>If compiling fails due to missing classes please:</echo>
<echo>- ensure fred was built with "./gradlew jar copyRuntimeLibs" to make it copy</echo>
<echo> its dependencies' JARs to "build/output/".</echo>
<echo>- compare the found JARs against the configuration at top of build.xml to find</echo>
<echo> out which JARs are missing.</echo>
<echo></echo>
<pathconvert refid="lib.external.all.path" pathsep="${line.separator}" property="all.path.printable"/>
<echo>${all.path.printable}</echo>
</target>
<target name="mkdir">
<mkdir dir="${build}"/>
<mkdir dir="${build-test}"/>
<mkdir dir="${build-test}/classes"/>
<mkdir dir="${build-test-coverage}"/>
<mkdir dir="${dist}"/>
</target>
<!-- ================================================== -->
<target name="compile" depends="print-libs, db4o, mkdir">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the Version file with patched revision number in ${build} -->
<copy file="${src}/${version.src}" tofile="${build}/${version.src}" overwrite="true" />
<delete file="${build}/${version.build}" quiet="true" />
<replace file="${build}/${version.src}">
<replacefilter token="@custom@" value="${git.revision}"/>
</replace>
<echo message="Updated build version to ${git.revision} in ${build}/${version.src}"/>
<!-- Force compile of Version.java in case compile of ${src} didn't trigger it -->
<javac srcdir="${build}" destdir="${build}" debug="on" optimize="on" source="${source-version}" target="${target-version}">
<classpath>
<path refid="submodules.path"/>
<path refid="libraries.classpath"/>
</classpath>
<include name="${version.src}"/>
</javac>
<javac srcdir="src/" destdir="${build}" debug="on" optimize="on" source="${source-version}" target="${target-version}">
<classpath>
<path refid="submodules.path"/>
<path refid="libraries.classpath"/>
</classpath>
<include name="**/*.java"/>
<exclude name="${version.src}"/>
</javac>
<copy todir="${build}">
<fileset dir="src/">
<include name="**/*.l10n" />
<include name="plugins/Freetalk/ui/web/css/*.css" />
</fileset>
</copy>
</target>
<!-- ================================================== -->
<target name="junit-compile" depends="compile">
<javac srcdir="test/" destdir="${build-test}/classes" debug="on" optimize="on"
source="${source-version}" target="${target-version}">
<classpath>
<path refid="submodules.path"/>
<path refid="libraries.classpath"/>
<pathelement path="${build}"/>
<path refid="junit.classpath"/>
</classpath>
<compilerarg value="-Xlint"/>
<include name="**/*.java"/>
</javac>
<!-- Copy main non-test classes to tests so we can produce a full working Freetalk JAR -->
<copy todir="${build-test}/classes" overwrite="false">
<fileset dir="${build}/"/>
</copy>
</target>
<target name="junit-inject-cobertura" depends="clean, junit-compile"
if="${test.coverage}" unless="${test.benchmark}">
<fail unless:true="${cobertura.present}" message="${cobertura.location} not found!"/>
<taskdef classpathref="cobertura.path" resource="tasks.properties"/>
<cobertura-instrument datafile="${build-test-coverage}/cobertura.ser">
<auxClasspath>
<path refid="submodules.path"/>
<path refid="libraries.classpath"/>
</auxClasspath>
<fileset dir="${build-test}/classes">
<include name="**/*.class" />
<exclude name="**/*Test.class"/>
<exclude name="**/*Benchmark*.class"/>
</fileset>
</cobertura-instrument>
</target>
<target name="junit-package" depends="junit-compile, junit-inject-cobertura">
<jar jarfile="${build-test-jar}" duplicate="fail">
<manifest>
<attribute name="Plugin-Main-Class" value="plugins.Freetalk.Freetalk"/>
</manifest>
<fileset dir="src/" casesensitive="no">
<include name="*.txt"/> <!-- Include the GPL -->
</fileset>
<fileset dir="${build-test}/classes/"/> <!-- Separate directory to exclude the JAR -->
<zipfileset>
<path refid="submodules.path"/>
</zipfileset>
</jar>
</target>
<target name="junit" depends="junit-package" unless="${test.skip}"
description="Runs all unit tests. Options to specify with 'ant -D':
- Set test.coverage=true to analyze test coverage. View by e.g.: firefox test-coverage/html/index.html
- Set test.skip=true to skip. The tests will still be compiled so you can run them from e.g. Eclipse!
- Set test.class=<test class> (e.g. test.class=plugins.Freetalk.FreetalkTest) to run a single test
- Set test.benchmark=true to run benchmarks. ">
<!-- The 512mb limit was arbitrarily chosen to:
- be the same as WoT uses.
- be reasonable as compared to the memory size of the latest Raspberry Pi as of 2019-05.
TODO: Peformance: Determine a proper one by measuring execution time with various
limits and using the smallest limit such that any smaller limit runs slower. -->
<junit printsummary="yes" fork="yes" haltonfailure="yes" maxmemory="512m" showoutput="yes">
<classpath>
<path refid="libraries.classpath"/>
<pathelement location="${build-test-jar}"/>
<path refid="junit.classpath"/>
<pathelement location="${cobertura.location}" if:true="${test.coverage}"/>
</classpath>
<assertions><enable/></assertions>
<formatter type="plain" usefile="false"/>
<test if="test.class" name="${test.class}"/>
<batchtest unless="test.class" skipNonTests="yes">
<zipfileset src="${build-test-jar}">
<include name="**/*Test.class"/>
<exclude name="com/db4o/**"/>
</zipfileset>
</batchtest>
<sysproperty key="net.sourceforge.cobertura.datafile"
file="${build-test-coverage}/cobertura.ser" if:true="${test.coverage}"/>
<sysproperty key="benchmark" value="${test.benchmark}" />
<sysproperty key="extensiveTesting" value="${extensiveTesting}" />
<sysproperty key="is_FT_unit_test" value="true"/>
</junit>
<cobertura-report if:true="${test.coverage}" unless:true="${test.benchmark}"
srcdir="${src}"
datafile="${build-test-coverage}/cobertura.ser"
destdir="${build-test-coverage}/html"
format="html"/>
</target>
<!-- ================================================== -->
<!-- Not only depend on junit but also junit-compile and junit-package so tests can be run from
e.g. Eclipse even if their execution in junit is disabled by test.skip=true. -->
<target name="dist" depends="clean,compile,junit-compile,junit-package,junit"
description="generate the distribution" >
<jar jarfile="${dist}/Freetalk.jar" duplicate="fail">
<manifest>
<attribute name="Plugin-Main-Class" value="plugins.Freetalk.Freetalk"/>
</manifest>
<fileset dir="src/" casesensitive="no">
<include name="*.txt"/> <!-- Include the GPL -->
</fileset>
<fileset dir="${build}/"/>
<zipfileset>
<path refid="submodules.path"/>
</zipfileset>
</jar>
</target>
<!-- ================================================== -->
<target name="clean" depends="clean-db4o" description="Delete class files and docs dir and the plugin file in plugins/ of your debug node..">
<delete dir="${build}"/>
<delete dir="${build-test}"/>
<delete dir="${build-test-coverage}"/>
<delete dir="${dist}"/>
<delete file="${debug-node-freetalk-plugin.location}"/>
</target>
</project>