source: core/java/build.xml @ 08d1ea8

Last change on this file since 08d1ea8 was 08d1ea8, checked in by zzz <zzz@…>, 4 years ago

Build: Set Java 7 build target for all jars;
embedders (esp. Android) targetting 1.6 must
set javac.version=1.6 in override.properties and set
both bootclasspath variables.

  • Property mode set to 100644
File size: 18.1 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<project basedir="." default="all" name="i2p_sdk">
3    <target name="all" depends="clean, build" />
4    <target name="build" depends="builddep, jar" />
5    <target name="builddep">
6        <!-- noop, since the core doesnt depend on anything -->
7    </target>
8    <condition property="depend.available">
9        <typefound name="depend" />
10    </condition>
11    <target name="depend" if="depend.available">
12        <depend
13            cache="../../build"
14            srcdir="./src" 
15            destdir="./build/obj" >
16        </depend>
17    </target>
18
19    <!-- only used if not set by a higher build.xml -->
20    <property name="javac.compilerargs" value="" />
21    <property name="javac.classpath" value="" />
22    <property name="javac.version" value="1.7" />
23
24    <!-- fixups if we're using libintl.jar for GettextResource.java -->
25    <condition property="source.exclude1" value="gnu/gettext/GettextResource.java" else="NOTHING" >
26        <istrue value="${with-gettext-base}" />
27    </condition>
28    <condition property="javac.classpath.mod1" value="build/libintl.jar:" else="" >
29        <istrue value="${with-gettext-base}" />
30    </condition>
31    <!-- fixups if we're using gnu-getopt.jar for gnu/getopt/* -->
32    <condition property="source.exclude2" value="gnu/getopt/**" else="NOTHING" >
33        <istrue value="${with-libgetopt-java}" />
34    </condition>
35    <condition property="javac.classpath.mod2" value="build/gnu-getopt.jar:" else="" >
36        <istrue value="${with-libgetopt-java}" />
37    </condition>
38    <condition property="translation.includes" value="NOTHING" else="gnu/getopt/*.properties" >
39        <istrue value="${with-libgetopt-java}" />
40    </condition>
41    <!-- fixups if we're using httpclient.jar and httpcore.jar for org.apache.http classes -->
42    <condition property="source.exclude3" value="org/apache/http/**" else="NOTHING" >
43        <istrue value="${with-libhttpclient-java}" />
44    </condition>
45    <condition property="javac.classpath.mod3" value="build/httpclient.jar:build/httpcore.jar:" else="" >
46        <istrue value="${with-libhttpclient-java}" />
47    </condition>
48    <property name="javac.classpath.mod" value="${javac.classpath.mod1}${javac.classpath.mod2}${javac.classpath.mod3}${javac.classpath}" />
49
50    <!-- jar classpath fixups -->
51    <condition property="gettext.jar" value="/usr/share/java/libintl.jar" else="" >
52        <istrue value="${with-gettext-base}" />
53    </condition>
54    <condition property="getopt.jar" value="/usr/share/java/gnu-getopt.jar" else="" >
55        <istrue value="${with-libgetopt-java}" />
56    </condition>
57    <condition property="httpclient.jar" value="/usr/share/java/httpclient.jar /usr/share/java/httpcore.jar" else="" >
58        <istrue value="${with-libhttpclient-java}" />
59    </condition>
60
61    <target name="compile" depends="depend">
62        <mkdir dir="./build" />
63        <mkdir dir="./build/obj" />
64        <!-- sourcepath="" necessary for excludes to work, see ant manual for javac -->
65        <javac sourcepath="" srcdir="./src" debug="true" source="${javac.version}" target="${javac.version}" deprecation="on"
66               debuglevel="lines,vars,source"
67               includeAntRuntime="false"
68               destdir="./build/obj" classpath="${javac.classpath.mod}" >
69            <compilerarg line="${javac.compilerargs}" />
70            <include name="**/*.java" />
71            <exclude name="${source.exclude1}" />
72            <exclude name="${source.exclude2}" />
73            <exclude name="${source.exclude3}" />
74        </javac>
75    </target>
76
77    <target name="listChangedFiles" if="mtn.available" >
78        <exec executable="mtn" outputproperty="workspace.changes" errorproperty="mtn.error2" failifexecutionfails="false" >
79            <arg value="list" />
80            <arg value="changed" />
81            <arg value="." />
82        </exec>
83        <!-- \n in an attribute value generates an invalid manifest -->
84        <exec executable="tr" inputstring="${workspace.changes}" outputproperty="workspace.changes.tr" errorproperty="mtn.error2" failifexecutionfails="false" >
85            <arg value="-s" />
86            <arg value="[:space:]" />
87            <arg value="," />
88        </exec>
89    </target>
90
91    <target name="jar" depends="compile, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
92        <!-- set if unset -->
93        <property name="workspace.changes.tr" value="" />
94        <jar destfile="./build/i2p.jar" >
95            <fileset dir="./build/obj" includes="**/*.class" />
96            <!-- the getopt translation files -->
97            <fileset dir="src" includes="${translation.includes}" />
98            <manifest>
99                <attribute name="Class-Path" value="${gettext.jar} ${getopt.jar} ${httpclient.jar}" />
100                <attribute name="Specification-Title" value="I2P Core API" />
101                <attribute name="Specification-Version" value="${release.number}" />
102                <attribute name="Specification-Vendor" value="The I2P Project https://geti2p.net/" />
103                <attribute name="Implementation-Title" value="I2P Java Core API" />
104                <attribute name="Implementation-Version" value="${full.version}" />
105                <attribute name="Implementation-Vendor" value="The I2P Project https://geti2p.net/" />
106                <attribute name="Built-By" value="${build.built-by}" />
107                <attribute name="Build-Date" value="${build.timestamp}" />
108                <attribute name="Base-Revision" value="${workspace.version}" />
109                <attribute name="Main-Class" value="net.i2p.util.CommandLine" />
110                <attribute name="Workspace-Changes" value="${workspace.changes.tr}" />
111            </manifest>
112        </jar>
113    </target>
114
115    <target name="jarUpToDate" >
116        <uptodate property="jar.uptodate" targetfile="build/i2p.jar" >
117            <srcfiles dir= "build/obj" includes="**/*.class" />
118        </uptodate>
119    </target>
120
121    <target name="javadoc">
122        <mkdir dir="./build" />
123        <mkdir dir="./build/javadoc" />
124        <javadoc sourcepath="./src:./test/junit" destdir="./build/javadoc" packagenames="*" use="true" splitindex="true" windowtitle="I2P SDK" />
125    </target>
126
127    <!-- for Maven Central -->
128    <target name="javadocJar" depends="javadoc">
129        <jar jarfile="./build/i2p-${release.number}-javadoc.jar">
130            <fileset dir="./build/javadoc" />
131        </jar>
132    </target>
133    <target name="sourcesJar">
134        <jar jarfile="./build/i2p-${release.number}-sources.jar">
135            <fileset dir="./src" />
136        </jar>
137    </target>
138
139    <!-- scala paths -->
140    <target name="scala.init">
141        <property name="scala-library.jar" value="${scalatest.libs}/scala-library.jar" />
142        <property name="scalatest.jar" value="${scalatest.libs}/scalatest.jar" />
143        <taskdef resource="scala/tools/ant/antlib.xml">
144            <classpath>
145                <pathelement location="${scalatest.libs}/scala-compiler.jar" />
146                <pathelement location="${scala-library.jar}" />
147            </classpath>
148        </taskdef>
149    </target>
150
151    <!-- unit tests -->
152    <target name="scalatest.compileTest" depends="compile, scala.init">
153        <mkdir dir="./build" />
154        <mkdir dir="./build/obj_scala" />
155        <scalac srcdir="./test/scalatest" destdir="./build/obj_scala" deprecation="on" >
156            <classpath>
157                <pathelement location="${javac.classpath.mod}" />
158                <pathelement location="${scala-library.jar}" />
159                <pathelement location="${scalatest.jar}" />
160                <pathelement location="./build/obj" />
161            </classpath>
162        </scalac>
163    </target>
164    <target name="junit.compileTest" depends="compile">
165        <mkdir dir="./build" />
166        <mkdir dir="./build/obj" />
167        <!-- set hamcrest and junit homes to the old default unless overridden elsewhere -->
168        <echo message="[DEBUG] ant home is ${ant.home}" />
169        <echo message="[DEBUG] junit home before override is ${junit.home}" />
170        <echo message="[DEBUG] hamcrest home before override is ${hamcrest.home}" />
171        <property name="hamcrest.home" value="${ant.home}/lib/" />
172        <property name="junit.home" value="${ant.home}/lib/" />
173        <echo message="[DEBUG] junit home after override is ${junit.home}" />
174        <echo message="[DEBUG] hamcrest home after override is ${hamcrest.home}" />
175        <javac srcdir="./test/junit" debug="true" source="${javac.version}" target="${javac.version}" deprecation="on"
176               debuglevel="lines,vars,source"
177               includeAntRuntime="true"
178               excludes="${source.exclude}"
179               destdir="./build/obj" >
180            <classpath>
181                <pathelement path="${javac.classpath.mod}" />
182                <pathelement location="${hamcrest.home}/hamcrest-core.jar" />
183                <pathelement location="${hamcrest.home}/hamcrest-library.jar" />
184                <pathelement location="${hamcrest.home}/hamcrest-integration.jar" />
185                <pathelement location="${hamcrest.home}/hamcrest-all.jar" />
186                <pathelement location="${junit.home}/junit4.jar" />
187            </classpath>
188            <compilerarg line="${javac.compilerargs}" />
189        </javac>
190        <!-- EdDSA test vectors -->
191        <copy todir="./build/obj">
192            <fileset dir="./test/junit/">
193                <include name="net/i2p/crypto/eddsa/test.data"/>
194                <include name="net/i2p/crypto/eddsa/math/baseDblPrecmp"/>
195                <include name="net/i2p/crypto/eddsa/math/basePrecmp"/>
196            </fileset>
197        </copy>
198    </target>
199    <!-- jars with tests -->
200    <target name="jarScalaTest" depends="scalatest.compileTest">
201        <mkdir dir="./build/obj_scala_jar" />
202        <copy todir="./build/obj_scala_jar">
203            <fileset dir="./build/">
204                <include name="obj/**/*.class"/>
205            </fileset>
206            <mapper type="glob" from="obj/*" to="*" />
207        </copy>
208        <copy todir="./build/obj_scala_jar">
209            <fileset dir="./build/">
210                <include name="obj_scala/**/*.class"/>
211            </fileset>
212            <mapper type="glob" from="obj_scala/*" to="*" />
213        </copy>
214        <jar destfile="./build/i2pscalatest.jar" basedir="./build/obj_scala_jar" includes="**/*.class" />
215    </target>
216    <target name="jarTest" depends="junit.compileTest">
217        <!-- warning - The junit.test target below doesn't actually include i2ptest.jar in the classpath,
218             only the build/obj directory.
219          -->
220        <jar destfile="./build/i2ptest.jar" basedir="./build/obj" includes="**/*.class **/test.data **/baseDblPrecmp **/basePrecmp" />
221    </target>
222    <!-- preparation of code coverage tool of choice -->
223    <target name="prepareClover" depends="compile" if="with.clover">
224        <taskdef resource="clovertasks"/>
225        <mkdir dir="../../reports/core/clover" />
226        <clover-setup initString="../../reports/core/clover/coverage.db"/>
227    </target>
228    <target name="prepareCobertura" depends="compile" if="with.cobertura">
229        <taskdef classpath="${with.cobertura}" resource="tasks.properties" onerror="report" />
230        <mkdir dir="./build/obj_cobertura" />
231        <delete file="./cobertura.ser" />
232        <cobertura-instrument todir="./build/obj_cobertura">
233            <fileset dir="./build/obj">
234                <include name="**/*.class"/>
235                <!-- exclude Test classes -->
236                <exclude name="**/*Test.class" />
237                <exclude name="**/*TestSuite.class" />
238                <!-- specific excludes -->
239                <exclude name="**/AllCoreTests.class" />
240                <exclude name="**/stat/SimpleStatDumper.class" />
241                <exclude name="**/stat/SizeMeasure.class" />
242                <exclude name="**/stat/StatLogSplitter.class" />
243                <!-- exclude anything not in net.i2p.* -->
244                <exclude name="com/nettgryppa/**/*.class" />
245                <exclude name="freenet/**/*.class" />
246                <exclude name="gnu/**/*.class" />
247                <exclude name="net/metanotion/**/*.class" />
248                <exclude name="org/bouncycastle/**/*.class" />
249                <exclude name="org/xlattice/**/*.class" />
250            </fileset>
251        </cobertura-instrument>
252    </target>
253    <target name="prepareTest" depends="prepareClover, prepareCobertura" />
254    <!-- end preparation of code coverage tool -->
255    <target name="scalatest.test" depends="clean, scalatest.compileTest, prepareTest">
256        <mkdir dir="../../reports/core/scalatest/" />
257        <delete>
258            <fileset dir="../../reports/core/scalatest">
259                <include name="TEST-*.xml"/>
260            </fileset>
261        </delete>
262        <taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestAntTask">
263            <classpath>
264                <pathelement location="${scala-library.jar}" />
265                <pathelement location="${scalatest.jar}" />
266                <pathelement location="./build/obj_cobertura" />
267                <pathelement location="./build/obj" />
268                <pathelement location="../../build/jbigi.jar" />
269                <pathelement location="${with.clover}" />
270                <pathelement location="${with.cobertura}" />
271            </classpath>
272        </taskdef>
273        <scalatest runpath="./build/obj_scala" fork="yes" maxmemory="384M">
274            <tagsToExclude>
275                SlowTests
276            </tagsToExclude>
277            <reporter type="stdout" />
278            <reporter type="junitxml" directory="../../reports/core/scalatest/" />
279        </scalatest>
280        <!-- set if unset -->
281        <property name="host.fakename" value="i2ptester" />
282        <!-- replace hostname that junit inserts into reports with fake one -->
283        <replaceregexp byline="true"
284            match="(hostname=)&quot;[^&quot;]+&quot;"
285            replace="\1&quot;${host.fakename}&quot;">
286            <fileset dir="../../reports/core/scalatest/" />
287        </replaceregexp>
288    </target>
289    <target name="junit.test" depends="clean, junit.compileTest, prepareTest">
290        <property name="hamcrest.home" value="${ant.home}/lib/" />
291        <property name="junit.home" value="${ant.home}/lib/" />
292        <mkdir dir="../../reports/core/junit/" />
293        <delete>
294            <fileset dir="../../reports/core/junit">
295                <include name="TEST-*.xml"/>
296            </fileset>
297        </delete>
298        <junit printsummary="withOutAndErr" fork="yes" maxmemory="384m" showoutput="yes" >
299            <sysproperty key="net.sourceforge.cobertura.datafile" file="./cobertura.ser" />
300            <classpath>
301                <pathelement location="../../installer/resources/" />
302                <pathelement path="${javac.classpath.mod}" />
303                <pathelement location="${hamcrest.home}/hamcrest-core.jar" />
304                <pathelement location="${hamcrest.home}/hamcrest-library.jar" />
305                <pathelement location="${hamcrest.home}/hamcrest-integration.jar" />
306                <pathelement location="${hamcrest.home}/hamcrest-all.jar" />
307                <pathelement location="${junit.home}/junit4.jar" />
308                <pathelement location="./build/obj_cobertura" />
309                <pathelement location="./build/obj" />
310                <pathelement location="../../build/jbigi.jar" />
311                <pathelement location="${with.clover}" />
312                <pathelement location="${with.cobertura}" />
313            </classpath>
314            <batchtest todir="../../reports/core/junit/">
315                <fileset dir="./test/junit/">
316                    <include name="**/*Test.java" />
317                    <exclude name="**/ElGamalAESEngineTest.java" />
318                    <exclude name="**/StructureTest.java" />
319                    <!-- DataHelperTest is *very* slow with cobertura -->
320                    <!--
321                    <exclude name="**/DataHelperTest.java" />
322                    -->
323                </fileset>
324            </batchtest>
325            <formatter type="xml"/>
326        </junit>
327        <!-- set if unset -->
328        <property name="host.fakename" value="i2ptester" />
329        <!-- replace hostname that junit inserts into reports with fake one -->
330        <replaceregexp byline="true"
331            match="(hostname=)&quot;[^&quot;]+&quot;"
332            replace="\1&quot;${host.fakename}&quot;">
333            <fileset dir="../../reports/core/junit/" />
334        </replaceregexp>
335    </target>
336    <target name="test" depends="junit.test, scalatest.test"/>
337    <!-- test reports -->
338    <target name="scalatest.report">
339        <junitreport todir="../../reports/core/scalatest">
340            <fileset dir="../../reports/core/scalatest">
341                <include name="TEST-*.xml"/>
342            </fileset>
343            <report format="frames" todir="../../reports/core/html/scalatest"/>
344        </junitreport>
345    </target>
346    <target name="junit.report">
347        <junitreport todir="../../reports/core/junit">
348            <fileset dir="../../reports/core/junit">
349                <include name="TEST-*.xml"/>
350            </fileset>
351            <report format="frames" todir="../../reports/core/html/junit"/>
352        </junitreport>
353    </target>
354    <target name="clover.report" depends="test" if="with.clover">
355        <clover-report>
356            <current outfile="../../reports/core/html/clover">
357                <format type="html"/>
358            </current>
359        </clover-report>
360    </target>
361    <target name="cobertura.report" depends="test" if="with.cobertura">
362        <mkdir dir="../../reports/core/cobertura" />
363        <cobertura-report format="xml" srcdir="./src" destdir="../../reports/core/cobertura" />
364        <mkdir dir="../../reports/core/html/cobertura" />
365        <cobertura-report format="html" srcdir="./src" destdir="../../reports/core/html/cobertura" />
366        <delete file="./cobertura.ser" />
367    </target>
368    <target name="test.report" depends="junit.report, scalatest.report, clover.report, cobertura.report"/>
369    <!-- end test reports -->
370    <target name="fulltest" depends="test, test.report" />
371    <!-- end unit tests -->
372
373    <target name="clean">
374        <delete dir="./build" />
375    </target>
376    <target name="cleandep" depends="clean">
377        <!-- noop, since the core doesn't depend on anything -->
378    </target>
379    <target name="distclean" depends="clean">
380        <!-- noop, since the core doesn't depend on anything -->
381    </target>
382</project>
Note: See TracBrowser for help on using the repository browser.