source: josm/trunk/build.xml @ 17254

Last change on this file since 17254 was 17254, checked in by Don-vip, 3 years ago

see #19937 - see #19724 - Enable macOS build on Java 16-ea instead of 15, add an option to disable Error-Prone at build time

  • Property svn:eol-style set to native
File size: 61.9 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!-- ** build.xml - main ant file for JOSM
3**
4** To build run
5**    ant clean
6**    ant dist
7** This will create 'josm-custom.jar' in directory 'dist'. See also
8**   https://josm.openstreetmap.de/wiki/DevelopersGuide/CreateBuild
9**
10-->
11<project name="josm" default="dist"
12         xmlns:as="antlib:org.codehaus.mojo.animal_sniffer"
13         xmlns:if="ant:if"
14         xmlns:ivy="antlib:org.apache.ivy.ant"
15         xmlns:jacoco="antlib:org.jacoco.ant"
16         xmlns:unless="ant:unless"
17>
18    <target name="init-ivy">
19        <property name="ivy.version" value="2.5.0"/>
20        <dirname property="base.dir" file="${ant.file.josm}"/>
21        <property name="lib.dir"   location="${base.dir}/lib"/>
22        <property name="tools.dir" location="${base.dir}/tools"/>
23        <property name="tools.ivy" location="${tools.dir}/ivy.xml"/>
24        <property name="ivy.jar.dir" location="${tools.dir}/ivy"/>
25        <property name="ivy.jar.file" location="${ivy.jar.dir}/ivy-${ivy.version}.jar"/>
26        <mkdir dir="${ivy.jar.dir}"/>
27        <get src="https://josm.openstreetmap.de/nexus/content/repositories/public/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar"
28             dest="${ivy.jar.file}"
29             skipexisting="true"
30        />
31        <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="${ivy.jar.file}"/>
32    </target>
33    <target name="init-properties">
34        <property environment="env"/>
35        <!-- Load properties in a target and not at top level, so this build file can be
36        imported from an IDE ant file (Netbeans) without messing up IDE properties.
37        When imported from another file, ${basedir} will point to the parent directory
38        of the importing ant file. Use ${base.dir} instead, which is always the parent
39        directory of this file. -->
40        <dirname property="base.dir" file="${ant.file.josm}"/>
41        <property name="test.dir" location="${base.dir}/test"/>
42        <property name="src.dir" location="${base.dir}/src"/>
43        <condition property="noJavaFX">
44            <or>
45                <isset property="env.JOSM_NOJAVAFX"/>
46                <not>
47                    <available classname="javafx.scene.media.Media"/>
48                </not>
49            </or>
50        </condition>
51        <available property="svn.present" file="${base.dir}/.svn"/>
52        <available property="git.present" file="${base.dir}/.git"/>
53        <property name="build.dir" location="${base.dir}/build"/>
54        <property name="dist.dir" location="${base.dir}/dist"/>
55        <property name="resources.dir" location="${base.dir}/resources"/>
56        <property name="modules.dir" location="${dist.dir}/modules"/>
57        <property name="tools.dir" location="${base.dir}/tools"/>
58        <property name="pmd.dir" location="${tools.dir}/pmd"/>
59        <property name="checkstyle.dir" location="${tools.dir}/checkstyle"/>
60        <property name="spotbugs.dir" location="${tools.dir}/spotbugs"/>
61        <property name="javacc.home" location="${tools.dir}"/>
62        <property name="mapcss.dir" location="${src.dir}/org/openstreetmap/josm/gui/mappaint/mapcss"/>
63        <property name="proj-build.dir" location="${base.dir}/build2"/>
64        <property name="script-build.dir" location="${base.dir}/build2"/>
65        <property name="checkstyle-build.dir" location="${base.dir}/build2"/>
66        <property name="epsg.output" location="${resources.dir}/data/projection/custom-epsg"/>
67        <property name="commons-lang3.jar" location="${tools.dir}/commons-lang3.jar"/>
68        <property name="dist.jar" location="${dist.dir}/josm-custom.jar"/>
69        <property name="dist-optimized.jar" location="${dist.dir}/josm-custom-optimized.jar"/>
70        <property name="dist-sources.jar" location="${dist.dir}/josm-custom-sources.jar"/>
71        <property name="java.lang.version" value="1.8" />
72        <property name="test.headless" value="true" />
73        <property name="jacoco.includes" value="org.openstreetmap.josm.*" />
74        <property name="jacoco.inclbootstrapclasses" value="false" />
75        <property name="jacoco.inclnolocationclasses" value="false" />
76        <property name="junit.printsummary" value="on" />
77        <property name="default-junit-includes" value="**/*Test.class"/>
78        <property name="default-junitIT-includes" value="**/*TestIT.class"/>
79        <!-- build parameter: compression level (ant -Dclevel=N)
80                 N ranges from 0 (no compression) to 9 (maximum compression)
81                 default: 9 -->
82        <condition property="clevel" value="${clevel}" else="9">
83            <isset property="clevel"/>
84        </condition>
85        <!-- For Java specific stuff by version -->
86        <condition property="isJava9"><matches string="${ant.java.version}" pattern="(1.)?(9|1[0-9])" /></condition>
87        <condition property="isJava10"><matches string="${ant.java.version}" pattern="1[0-9]" /></condition>
88        <condition property="isJava11"><matches string="${ant.java.version}" pattern="1[1-9]" /></condition>
89        <condition property="isJava12"><matches string="${ant.java.version}" pattern="1[2-9]" /></condition>
90        <condition property="isJava13"><matches string="${ant.java.version}" pattern="1[3-9]" /></condition>
91        <condition property="isJava16"><matches string="${ant.java.version}" pattern="1[6-9]" /></condition>
92        <!-- Disable jacoco on Java 16+, see https://github.com/jacoco/jacoco/pull/992 -->
93        <condition property="coverageByDefault">
94            <not>
95                <isset property="isJava16"/>
96            </not>
97        </condition>
98        <condition property="java.library.dir" value="jmods" else="lib">
99            <isset property="isJava9"/>
100        </condition>
101    </target>
102    <!--
103      ** Initializes the REVISION.XML file from SVN information
104    -->
105    <target name="init-svn-revision-xml" if="svn.present" depends="init-properties">
106        <exec append="false" output="${base.dir}/REVISION.XML" executable="svn" dir="${base.dir}" resultproperty="svn.info.result">
107            <env key="LANG" value="C"/>
108            <arg value="info"/>
109            <arg value="--xml"/>
110            <arg value="."/>
111        </exec>
112    </target>
113    <!--
114      ** Initializes the REVISION.XML file from git information
115    -->
116    <target name="init-git-revision-xml" if="git.present" depends="init-properties">
117        <exec append="false" output="${base.dir}/REVISION.XML" executable="git" dir="${base.dir}">
118            <arg value="log"/>
119            <arg value="-1"/>
120            <arg value="--grep=git-svn-id"/>
121            <!--
122            %B:  raw body (unwrapped subject and body)
123            %n:  new line
124            %ai: author date, ISO 8601 format
125            -->
126            <arg value="--pretty=format:%B%n%ai"/>
127            <arg value="HEAD"/>
128        </exec>
129        <replaceregexp file="${base.dir}/REVISION.XML" flags="s"
130                       match=".*git-svn-id: [^@]*@([0-9]+).*(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
131                       replace="&lt;info&gt;&lt;entry&gt;&lt;commit revision=&quot;\1&quot;&gt;&lt;date&gt;\2&lt;/date&gt;&lt;/commit&gt;&lt;/entry&gt;&lt;/info&gt;"/>
132    </target>
133    <!--
134      ** Creates the REVISION file to be included in the distribution
135    -->
136    <target name="create-revision" depends="init-properties,init-svn-revision-xml,init-git-revision-xml">
137        <xmlproperty file="${base.dir}/REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
138        <delete file="${base.dir}/REVISION.XML"/>
139        <tstamp>
140            <format property="build.tstamp" pattern="yyyy-MM-dd HH:mm:ss"/>
141        </tstamp>
142        <property name="version.entry.commit.revision" value="UNKNOWN"/>
143        <property name="version.entry.commit.date" value="UNKNOWN"/>
144        <!-- add Build-Name: ... when making special builds, e.g. DEBIAN -->
145        <echo file="${resources.dir}/REVISION">
146# automatically generated by JOSM build.xml - do not edit
147Revision: ${version.entry.commit.revision}
148Is-Local-Build: true
149Build-Date: ${build.tstamp}
150</echo>
151    </target>
152    <!--
153      ** Check internal XML files against their XSD
154    -->
155    <target name="check-schemas" unless="check-schemas.notRequired" depends="init-properties">
156        <schemavalidate file="${resources.dir}/data/defaultpresets.xml" >
157            <schema namespace="http://josm.openstreetmap.de/tagging-preset-1.0" file="${resources.dir}/data/tagging-preset.xsd" />
158        </schemavalidate>
159    </target>
160    <!--
161      ** Main target that builds JOSM and checks XML against schemas
162    -->
163    <target name="dist" depends="compile,extract-libraries,epsg,copy-resources,check-schemas">
164        <echo>Revision ${version.entry.commit.revision}</echo>
165        <copy file="CONTRIBUTION" todir="${build.dir}"/>
166        <copy file="README" todir="${build.dir}"/>
167        <copy file="LICENSE" todir="${build.dir}"/>
168        <!-- create josm-custom.jar -->
169        <delete file="${dist.jar}"/>
170        <jar destfile="${dist.jar}" basedir="${build.dir}" level="${clevel}">
171            <!-- add attribute excludes="**/*BZip2*,**/*Bzip2*" to create a non-bzip2 supporting jar -->
172            <manifest>
173                <attribute name="Main-class" value="org.openstreetmap.josm.gui.MainApplication"/>
174                <attribute name="Main-Version" value="${version.entry.commit.revision} SVN"/>
175                <attribute name="Main-Date" value="${version.entry.commit.date}"/>
176                <attribute name="Permissions" value="all-permissions"/>
177                <attribute name="Codebase" value="josm.openstreetmap.de"/>
178                <attribute name="Application-Name" value="JOSM - Java OpenStreetMap Editor"/>
179                <!-- Java 9 stuff. Entries are safely ignored by Java 8 -->
180                <attribute name="Add-Exports" value="java.desktop/com.apple.eawt java.desktop/com.sun.imageio.spi java.desktop/com.sun.imageio.plugins.jpeg javafx.graphics/com.sun.javafx.application jdk.deploy/com.sun.deploy.config" />
181                <attribute name="Add-Opens" value="java.base/java.lang java.base/java.nio java.base/jdk.internal.loader java.base/jdk.internal.ref java.desktop/javax.imageio.spi java.desktop/javax.swing.text.html java.prefs/java.util.prefs" />
182            </manifest>
183        </jar>
184    </target>
185    <!-- Mac OS X target -->
186    <target name="mac" depends="init">
187        <!-- Using https://bitbucket.org/infinitekind/appbundler to create mac application bundle -->
188        <taskdef name="bundleapp" classname="com.oracle.appbundler.AppBundlerTask" classpath="${tools.dir}/appbundler.jar"/>
189        <!-- create MacOS X application bundle -->
190        <bundleapp outputdirectory="${bundle.outdir}" name="JOSM" displayname="JOSM" executablename="JOSM" identifier="org.openstreetmap.josm"
191                   mainclassname="org.openstreetmap.josm.gui.MainApplication"
192                   copyright="JOSM, and all its integral parts, are released under the GNU General Public License v2 or later"
193                   applicationCategory="public.app-category.utilities"
194                   shortversion="${version.entry.commit.revision} SVN"
195                   version="${version.entry.commit.revision} SVN"
196                   icon="native/macosx/JOSM.icns"
197                   highResolutionCapable="true">
198
199            <arch name="x86_64"/>
200            <arch name="i386"/>
201
202            <classpath file="${bundle.jar}"/>
203
204            <option value="-Xmx2048m"/>
205
206            <option value="-Xdock:icon=Contents/Resources/JOSM.icns"/>
207            <option value="-Xdock:name=JOSM"/>
208
209            <!-- OSX specific options, optional -->
210            <option value="-Dapple.laf.useScreenMenuBar=true"/>
211            <option value="-Dcom.apple.macos.use-file-dialog-packages=true"/>
212            <option value="-Dcom.apple.macos.useScreenMenuBar=true"/>
213            <option value="-Dcom.apple.mrj.application.apple.menu.about.name=JOSM"/>
214            <option value="-Dcom.apple.smallTabs=true"/>
215        </bundleapp>
216
217        <!-- appbundler lacks the possibility of defining our own keys or using a template, so update the .plist manually -->
218        <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="${tools.dir}/xmltask.jar"/>
219
220        <xmltask source="${bundle.outdir}/JOSM.app/Contents/Info.plist" dest="${bundle.outdir}/JOSM.app/Contents/Info.plist" indent="false">
221            <!-- remove empty CFBundleDocumentTypes definition -->
222            <remove path="/plist/dict/key[text()='CFBundleDocumentTypes']|/plist/dict/key[text()='CFBundleDocumentTypes']/following-sibling::array[1]"/>
223            <!-- insert our own keys -->
224            <insert position="before" path="/plist/dict/key[1]" file="native/macosx/JOSM.app/Contents/Info.plist_template.xml" />
225        </xmltask>
226
227        <!-- create ZIP file with MacOS X application bundle -->
228        <zip destfile="${bundle.outdir}/josm-custom-macosx.zip" update="true">
229            <zipfileset dir="." includes="CONTRIBUTION README LICENSE"/>
230            <zipfileset dir="${bundle.outdir}" includes="JOSM.app/**/*" filemode="755" />
231        </zip>
232    </target>
233    <target name="distmac" depends="dist">
234        <antcall target="mac">
235            <param name="bundle.outdir" value="${dist.dir}"/>
236            <param name="bundle.jar" value="${dist.jar}"/>
237        </antcall>
238    </target>
239    <!-- Windows target -->
240    <target name="distwin" depends="dist">
241        <exec dir="native/windows" executable="./josm-setup-unix.sh">
242            <arg value="${version.entry.commit.revision}"/>
243            <arg value="${dist.jar}"/>
244        </exec>
245    </target>
246    <target name="javacc" depends="init" unless="javacc.notRequired">
247        <ivy:cachepath log="download-only" file="${tools.ivy}" pathid="javacc.classpath" conf="javacc"/>
248        <mkdir dir="${mapcss.dir}/parsergen"/>
249        <java classname="javacc" fork="true" failonerror="true">
250            <classpath path="${tools.dir}/javacc"/>
251            <classpath refid="javacc.classpath"/>
252            <arg value="-DEBUG_PARSER=false"/>
253            <arg value="-DEBUG_TOKEN_MANAGER=false"/>
254            <arg value="-JDK_VERSION=${java.lang.version}"/>
255            <arg value="-GRAMMAR_ENCODING=UTF-8"/>
256            <arg value="-OUTPUT_DIRECTORY=${mapcss.dir}/parsergen"/>
257            <arg value="${mapcss.dir}/MapCSSParser.jj"/>
258        </java>
259    </target>
260    <target name="compile-cots" depends="init" description="Compiles third-party dependencies not retrieved with Ivy">
261        <!-- COTS -->
262        <javac srcdir="${src.dir}" includes="com/kitfox/**" excludes="**/package-info.java" nowarn="on" encoding="iso-8859-1"
263            destdir="${build.dir}" target="${java.lang.version}" source="${java.lang.version}" debug="on" includeAntRuntime="false">
264            <!-- get rid of "internal proprietary API" warning -->
265            <compilerarg value="-XDignore.symbol.file"/>
266            <classpath>
267                <path refid="runtime.path"/>
268            </classpath>
269        </javac>
270    </target>
271    <target name="compile" depends="init,javacc,compile-cots" unless="compile.notRequired" description="Compiles JOSM">
272        <ivy:cachepath log="download-only" file="${tools.ivy}" pathid="errorprone.classpath" conf="errorprone"/>
273        <ivy:cachepath log="download-only" file="${tools.ivy}" pathid="errorprone_javac.classpath" conf="errorprone_javac"/>
274        <!-- JOSM -->
275        <javac sourcepath="" srcdir="${src.dir}" fork="yes"
276            excludes="com/**,org/apache/commons/**,**/package-info.java"
277            destdir="${build.dir}" target="${java.lang.version}" source="${java.lang.version}" debug="on" includeantruntime="false" encoding="UTF-8">
278            <compilerarg value="-J-Xbootclasspath/p:${toString:errorprone_javac.classpath}" unless:set="isJava9"/>
279            <compilerarg line="-XDcompilePolicy=simple"/>
280            <compilerarg value="-processorpath"/>
281            <compilerarg pathref="errorprone.classpath"/>
282            <compilerarg value="-Xlint:cast"/>
283            <compilerarg value="-Xlint:deprecation"/>
284            <compilerarg value="-Xlint:dep-ann"/>
285            <compilerarg value="-Xlint:divzero"/>
286            <compilerarg value="-Xlint:empty"/>
287            <compilerarg value="-Xlint:finally"/>
288            <compilerarg value="-Xlint:overrides"/>
289            <!--<compilerarg value="-Xlint:rawtypes"/>-->
290            <compilerarg value="-Xlint:static"/>
291            <compilerarg value="-Xlint:try"/>
292            <compilerarg value="-Xlint:unchecked"/>
293            <!-- Undocumented argument to ignore "Sun internal proprietary API" warning, see http://stackoverflow.com/a/13862308/2257172 -->
294            <compilerarg value="-XDignore.symbol.file"/>
295            <compilerarg value="-Xplugin:ErrorProne -XepExcludedPaths:.*/parsergen/.* -Xep:ReferenceEquality:OFF -Xep:FutureReturnValueIgnored:OFF -Xep:JdkObsolete:OFF -Xep:EqualsGetClass:OFF -Xep:UndefinedEquals:OFF -Xep:BadImport:OFF -Xep:AnnotateFormatMethod:OFF" unless:set="noErrorProne"/>
296            <compilerarg line="-Xmaxwarns 1000"/>
297            <classpath>
298                <path refid="runtime.path"/>
299            </classpath>
300        </javac>
301    </target>
302    <target name="create-resources" depends="create-revision" description="Create generated resource files">
303        <copy todir="${resources.dir}">
304            <file file="CONTRIBUTION"/>
305            <file file="README"/>
306            <file file="LICENSE"/>
307        </copy>
308    </target>
309    <target name="copy-resources" depends="create-resources" description="Copy resource files to build directory">
310        <copy todir="build" failonerror="no" includeemptydirs="no">
311            <fileset dir="${resources.dir}"/>
312        </copy>
313    </target>
314    <target name="init" depends="init-properties,resolve">
315        <uptodate property="javacc.notRequired" targetfile="${mapcss.dir}/parsergen/MapCSSParser.java" >
316            <srcfiles dir="${mapcss.dir}" includes="MapCSSParser.jj"/>
317        </uptodate>
318        <uptodate property="epsg.notRequired" targetfile="${epsg.output}">
319            <srcfiles file="${base.dir}/scripts/BuildProjectionDefinitions.java"/>
320            <srcfiles dir="nodist/data/projection"/>
321        </uptodate>
322        <mkdir dir="${build.dir}"/>
323        <mkdir dir="${dist.dir}"/>
324    </target>
325    <target name="javadoc" depends="init">
326        <javadoc destdir="javadoc"
327                sourcepath="${src.dir}"
328                classpathref="compile.path"
329                encoding="UTF-8"
330                packagenames="org.openstreetmap.josm.*"
331                excludepackagenames="org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.*"
332                windowtitle="JOSM"
333                use="true"
334                private="true"
335                linksource="true"
336                author="false">
337            <link href="https://docs.oracle.com/javase/8/docs/api" unless:set="isJava11" />
338            <link href="https://docs.oracle.com/en/java/javase/11/docs/api" if:set="isJava11" />
339            <doctitle><![CDATA[<h2>
340                <img src="https://josm.openstreetmap.de/svn/trunk/nodist/images/logo/header.png" style="vertical-align: middle;" alt="JOSM">
341                &mdash; Javadoc
342            </h2>]]></doctitle>
343            <bottom><![CDATA[<a href="https://josm.openstreetmap.de/">JOSM</a>]]></bottom>
344            <!-- Disable HTML checking until we switch to Java13+, see https://bugs.openjdk.java.net/browse/JDK-8223552 -->
345            <arg value="-Xdoclint:-html" if:set="isJava13" />
346            <arg value="-html5" if:set="isJava9" />
347            <arg value="--add-exports" if:set="isJava9" unless:set="noJavaFX" />
348            <arg value="javafx.graphics/com.sun.javafx.application=ALL-UNNAMED" if:set="isJava9" unless:set="noJavaFX" />
349        </javadoc>
350    </target>
351    <target name="clean" depends="init-properties">
352        <delete dir="${build.dir}"/>
353        <delete dir="${proj-build.dir}"/>
354        <delete dir="${script-build.dir}"/>
355        <delete dir="${checkstyle-build.dir}"/>
356        <delete dir="${dist.dir}"/>
357        <delete dir="${mapcss.dir}/parsergen"/>
358        <delete file="${src.dir}/org/w3/_2001/xmlschema/Adapter1.java"/>
359        <delete dir="${src.dir}/org/openstreetmap/josm/data/imagery/types"/>
360        <delete file="${epsg.output}"/>
361        <delete file="${pmd.dir}/cache"/>
362    </target>
363    <macrodef name="init-test-preferences">
364        <attribute name="testfamily"/>
365        <sequential>
366            <copy file="${test.dir}/config/preferences.template.xml" tofile="${test.dir}/config/@{testfamily}-josm.home/preferences.xml"/>
367            <replace file="${test.dir}/config/@{testfamily}-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_USERNAME@" value="${osm.username}"/>
368            <replace file="${test.dir}/config/@{testfamily}-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_PASSWORD@" value="${osm.password}"/>
369        </sequential>
370    </macrodef>
371    <target name="test-init" depends="init">
372        <mkdir dir="${test.dir}/build"/>
373        <mkdir dir="${test.dir}/build/unit"/>
374        <mkdir dir="${test.dir}/build/functional"/>
375        <mkdir dir="${test.dir}/build/performance"/>
376        <mkdir dir="${test.dir}/report"/>
377        <init-test-preferences testfamily="unit"/>
378        <init-test-preferences testfamily="functional"/>
379        <init-test-preferences testfamily="performance"/>
380        <path id="test.classpath">
381            <path refid="test.path"/>
382            <pathelement path="${build.dir}"/>
383            <pathelement path="${resources.dir}"/>
384        </path>
385        <ivy:retrieve log="download-only" pattern="${test.dir}/lib/[artifact].[ext]" conf="jmockit"/>
386        <ivy:retrieve log="download-only" pattern="${tools.dir}/[artifact].[ext]" conf="commonslang"/>
387        <ivy:retrieve log="download-only" pattern="${tools.dir}/[conf].[ext]" conf="jacocoant"/>
388        <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="${tools.dir}/jacocoant.jar" />
389    </target>
390    <target name="test-clean" depends="init-properties">
391        <delete dir="${test.dir}/build"/>
392        <delete dir="${test.dir}/report"/>
393        <delete file="${test.dir}/jacoco.exec" />
394        <delete file="${test.dir}/jacocoIT.exec" />
395        <delete file="${test.dir}/config/unit-josm.home" failonerror="false"/>
396        <delete file="${test.dir}/config/functional-josm.home" failonerror="false"/>
397        <delete file="${test.dir}/config/performance-josm.home" failonerror="false"/>
398    </target>
399    <macrodef name="call-javac">
400        <attribute name="testfamily"/>
401        <element name="cp-elements"/>
402        <sequential>
403            <javac srcdir="${test.dir}/@{testfamily}" destdir="${test.dir}/build/@{testfamily}"
404                target="${java.lang.version}" source="${java.lang.version}" debug="on"
405                includeantruntime="false" encoding="UTF-8">
406                <compilerarg value="-Xlint:all"/>
407                <compilerarg value="-Xlint:-path"/><!-- Suppress "bad path element .../xmpcore-6.0.6.jar: no such file or directory" warning, see https://github.com/drewnoakes/metadata-extractor/pull/483 -->
408                <compilerarg value="-Xlint:-serial"/>
409                <classpath>
410                    <cp-elements/>
411                </classpath>
412            </javac>
413        </sequential>
414    </macrodef>
415    <target name="test-compile" depends="test-init,compile,extract-libraries,epsg,copy-resources" description="Compiles all tests">
416        <call-javac testfamily="unit">
417            <cp-elements>
418                <path refid="test.classpath"/>
419            </cp-elements>
420        </call-javac>
421        <call-javac testfamily="functional">
422            <cp-elements>
423                <path refid="test.classpath"/>
424                <pathelement path="${test.dir}/build/unit"/>
425            </cp-elements>
426        </call-javac>
427        <call-javac testfamily="performance">
428            <cp-elements>
429                <path refid="test.classpath"/>
430                <pathelement path="${test.dir}/build/unit"/>
431            </cp-elements>
432        </call-javac>
433    </target>
434    <macrodef name="call-junit">
435        <attribute name="testfamily"/>
436        <attribute name="testITsuffix" default=""/>
437        <attribute name="coverage" default="${coverageByDefault}"/>
438        <attribute name="includes" default="${default-junit@{testITsuffix}-includes}"/>
439        <attribute name="excludes" default="${default-junit@{testITsuffix}-excludes}"/>
440        <sequential>
441            <echo message="Running @{testfamily}@{testITsuffix} tests with JUnit"/>
442            <jacoco:agent destfile="${test.dir}/jacoco@{testITsuffix}.exec" enabled="@{coverage}" includes="${jacoco.includes}" dumponexit="true"
443                    inclbootstrapclasses="${jacoco.inclbootstrapclasses}" inclnolocationclasses="${jacoco.inclnolocationclasses}" property="jacocoagent@{testfamily}@{testITsuffix}" if:true="@{coverage}"/>
444            <junitlauncher printsummary="${junit.printsummary}" failureproperty="test.@{testfamily}@{testITsuffix}.failed">
445                <classpath>
446                    <path refid="test.classpath"/>
447                    <pathelement path="${test.dir}/build/unit"/> <!-- required for functional/etc to have JOSMTestRules -->
448                    <pathelement path="${test.dir}/build/@{testfamily}"/>
449                </classpath>
450                <testclasses outputDir="${test.dir}/report">
451                    <fileset dir="${test.dir}/build/@{testfamily}" includes="@{includes}" excludes="@{excludes}"/>
452                        <fork>
453                            <jvmarg value="${jacocoagent@{testfamily}@{testITsuffix}}" if:set="jacocoagent@{testfamily}@{testITsuffix}" />
454                            <jvmarg value="-Dfile.encoding=UTF-8"/>
455                            <jvmarg value="-javaagent:${test.dir}/lib/jmockit.jar"/>
456                            <jvmarg value="-Djunit.jupiter.extensions.autodetection.enabled=true"/>
457                            <jvmarg value="--add-modules" if:set="isJava9" unless:set="isJava11" />
458                            <jvmarg value="java.activation,java.se.ee" if:set="isJava9" unless:set="isJava11" />
459                            <jvmarg value="--add-exports" if:set="isJava9" unless:set="noJavaFX" />
460                            <jvmarg value="javafx.graphics/com.sun.javafx.application=ALL-UNNAMED" if:set="isJava9" unless:set="noJavaFX" />
461                            <jvmarg value="--add-exports" if:set="isJava9" unless:set="isJava11" />
462                            <jvmarg value="jdk.deploy/com.sun.deploy.config=ALL-UNNAMED" if:set="isJava9" unless:set="isJava11" />
463                            <jvmarg value="--add-opens" if:set="isJava9" />
464                            <jvmarg value="java.base/java.io=ALL-UNNAMED" if:set="isJava9" />
465                            <jvmarg value="--add-opens" if:set="isJava9" />
466                            <jvmarg value="java.base/java.lang=ALL-UNNAMED" if:set="isJava9" />
467                            <jvmarg value="--add-opens" if:set="isJava9" />
468                            <jvmarg value="java.base/java.nio=ALL-UNNAMED" if:set="isJava9" />
469                            <jvmarg value="--add-opens" if:set="isJava9" />
470                            <jvmarg value="java.base/java.text=ALL-UNNAMED" if:set="isJava9" />
471                            <jvmarg value="--add-opens" if:set="isJava9" />
472                            <jvmarg value="java.base/java.util=ALL-UNNAMED" if:set="isJava9" />
473                            <jvmarg value="--add-opens" if:set="isJava9" />
474                            <jvmarg value="java.base/jdk.internal.loader=ALL-UNNAMED" if:set="isJava9" />
475                            <jvmarg value="--add-opens" if:set="isJava9" />
476                            <jvmarg value="java.desktop/java.awt=ALL-UNNAMED" if:set="isJava9" />
477                            <sysproperty key="josm.home" value="${test.dir}/config/@{testfamily}-josm.home"/>
478                            <sysproperty key="josm.test.data" value="${test.dir}/data"/>
479                            <sysproperty key="java.awt.headless" value="${test.headless}"/>
480                            <sysproperty key="glass.platform" value="Monocle"/>
481                            <sysproperty key="monocle.platform" value="Headless"/>
482                            <sysproperty key="prism.order" value="sw"/>
483                            <sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
484                        </fork>
485                    <listener type="legacy-plain" />
486                    <listener type="legacy-xml" />
487                </testclasses>
488            </junitlauncher>
489        </sequential>
490    </macrodef>
491    <target name="test" depends="test-compile" unless="test.notRequired"
492        description="Run unit and functional tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
493        <call-junit testfamily="unit"/>
494        <call-junit testfamily="functional"/>
495    </target>
496    <target name="test-hardfail" depends="test" description="Run 'test' target but abort if tests failed">
497        <fail message="'test' failed">
498            <condition>
499                <or>
500                    <isset property="test.unit.failed"/>
501                    <isset property="test.functional.failed"/>
502                </or>
503            </condition>
504        </fail>
505    </target>
506    <target name="test-unit" depends="test-compile" unless="test-unit.notRequired"
507        description="Run unit tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
508        <call-junit testfamily="unit"/>
509    </target>
510    <target name="test-unit-hardfail" depends="test-unit" description="Run 'test-unit' target but abort if tests failed">
511        <fail message="'test-unit' failed" if="test.unit.failed"/>
512    </target>
513    <target name="test-it" depends="test-compile,create-revision" unless="test-it.notRequired"
514        description="Run integration tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
515        <call-junit testfamily="unit" testITsuffix="IT"/>
516        <call-junit testfamily="functional" testITsuffix="IT"/>
517    </target>
518    <target name="test-it-hardfail" depends="test-it" description="Run 'test-it' target but abort if tests failed">
519        <fail message="'test-it' failed">
520            <condition>
521                <or>
522                    <isset property="test.unitIT.failed"/>
523                    <isset property="test.functionalIT.failed"/>
524                </or>
525            </condition>
526        </fail>
527    </target>
528    <target name="test-perf" depends="test-compile" unless="test-perf.notRequired"
529        description="Run performance tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
530        <call-junit testfamily="performance" coverage="false"/>
531    </target>
532    <target name="test-perf-hardfail" depends="test-perf" description="Run 'test-perf' target but abort if tests failed">
533        <fail message="'test-perf' failed" if="test.performance.failed"/>
534    </target>
535    <target name="test-html" depends="test, test-it, test-perf" description="Generate HTML, CSV and XML test reports">
536        <!-- May require additional ant dependencies like ant-trax package -->
537        <junitreport todir="${test.dir}/report">
538            <fileset dir="${test.dir}/report">
539                <include name="TEST-*.xml"/>
540            </fileset>
541            <report todir="${test.dir}/report/html"/>
542        </junitreport>
543        <jacoco:report>
544            <executiondata>
545                <fileset dir="${test.dir}" includes="*.exec"/>
546            </executiondata>
547            <structure name="JOSM Test Coverage">
548                <classfiles>
549                    <fileset dir="${build.dir}" includes="org/openstreetmap/"/>
550                </classfiles>
551                <sourcefiles encoding="UTF-8">
552                    <fileset dir="${src.dir}" includes="org/openstreetmap/"/>
553                </sourcefiles>
554            </structure>
555            <html destdir="${test.dir}/report/jacoco"/>
556            <xml destfile="${test.dir}/report/jacoco.xml"/>
557            <csv destfile="${test.dir}/report/jacoco.csv"/>
558        </jacoco:report>
559    </target>
560    <target name="dist-optimized" depends="dist" unless="isJava13">
561        <ivy:cachepath log="download-only" file="${tools.ivy}" pathid="proguard.classpath" conf="proguard"/>
562        <taskdef resource="proguard/ant/task.properties" classpathref="proguard.classpath"/>
563        <proguard>
564        -injars ${dist.jar}
565        -outjars ${dist-optimized.jar}
566
567        -libraryjars ${java.home}/${java.library.dir}
568
569        -dontoptimize
570        -dontobfuscate
571        -dontwarn org.jetbrains.annotations.**
572
573        # These options probably are not necessary (and make processing a bit slower)
574        -dontskipnonpubliclibraryclasses
575        -dontskipnonpubliclibraryclassmembers
576
577        -keepclasseswithmembers public class org.openstreetmap.josm.gui.MainApplication {
578            public static void main(java.lang.String[]);
579        }
580
581        -keep class * extends org.openstreetmap.josm.io.FileImporter
582        -keep class * extends org.openstreetmap.josm.io.FileExporter
583        -keep class org.openstreetmap.josm.actions.search.SearchCompiler$Never
584        -keep class org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory$PseudoClasses {
585            static boolean *(org.openstreetmap.josm.gui.mappaint.Environment);
586        }
587
588        -keepclassmembers enum  * {
589            public static **[] values();
590            public static ** valueOf(java.lang.String);
591        }
592
593        # Keep unused public classes and methods (needed for plugins)
594        -keep public class * {
595            public protected *;
596        }
597
598        # Keep serialization code
599        -keepclassmembers class * implements java.io.Serializable {
600            static final long serialVersionUID;
601            private static final java.io.ObjectStreamField[] serialPersistentFields;
602            private void writeObject(java.io.ObjectOutputStream);
603            private void readObject(java.io.ObjectInputStream);
604            java.lang.Object writeReplace();
605            java.lang.Object readResolve();
606        }
607
608        # Disable annoying [proguard] Note: the configuration keeps the entry point '...', but not the descriptor class '...'.
609        # This note should not be a problem as we don't use obfuscation
610        -dontnote
611        </proguard>
612    </target>
613    <target name="dist-optimized-report" depends="dist-optimized">
614        <!-- generate difference report between optimized jar and normal one -->
615        <exec executable="perl" dir="${basedir}">
616            <arg value="${tools.dir}/japicc/japi-compliance-checker.pl"/>
617            <arg value="--lib=JOSM"/>
618            <arg value="--keep-internal"/>
619            <arg value="--v1=${version.entry.commit.revision}"/>
620            <arg value="--v2=${version.entry.commit.revision}-optimized"/>
621            <arg value="--report-path=${dist.dir}/compat_report.html"/>
622            <arg value="${dist.jar}"/>
623            <arg value="${dist-optimized.jar}"/>
624        </exec>
625    </target>
626    <target name="check-plugins" depends="dist-optimized" description="Check of plugins binary compatibility" unless="isJava11">
627        <local name="dir"/>
628        <local name="plugins"/>
629        <property name="dir" value="plugin-check"/>
630        <typedef uri="antlib:org.codehaus.mojo.animal_sniffer">
631            <classpath path="${tools.dir}/animal-sniffer-ant-tasks.jar"/>
632        </typedef>
633        <delete dir="${dir}" failonerror="false"/>
634        <mkdir dir="${dir}"/>
635        <!-- List of deprecated plugins -->
636        <loadfile property="deprecated-plugins" srcFile="${src.dir}/org/openstreetmap/josm/plugins/PluginHandler.java">
637            <filterchain>
638                <linecontains>
639                    <contains value="new DeprecatedPlugin("/>
640                </linecontains>
641                <tokenfilter>
642                    <replaceregex pattern=".*new DeprecatedPlugin\(&quot;(.+?)&quot;.*" replace="\1|" flags="gi"/>
643                </tokenfilter>
644                <striplinebreaks/>
645                <tokenfilter>
646                    <replaceregex pattern="\|$" replace="" flags="gi"/>
647                </tokenfilter>
648            </filterchain>
649        </loadfile>
650        <!-- Download list of plugins -->
651        <loadresource property="plugins">
652            <url url="https://josm.openstreetmap.de/plugin"/>
653            <filterchain>
654                <linecontainsregexp negate="true">
655                    <regexp pattern="^\t.*"/>
656                </linecontainsregexp>
657                <linecontainsregexp negate="true">
658                    <regexp pattern="${deprecated-plugins}"/>
659                </linecontainsregexp>
660                <linecontainsregexp negate="true" unless:set="isJava10">
661                    <!-- Skip javafx on Java 8/9, built for Java 10+ only -->
662                    <regexp pattern="javafx.*"/>
663                </linecontainsregexp>
664                <linecontainsregexp negate="true" unless:set="isJava11">
665                    <!-- Skip http2 on Java 8/9/10, built for Java 11+ only -->
666                    <regexp pattern="http2.*"/>
667                </linecontainsregexp>
668                <tokenfilter>
669                    <replaceregex pattern="^.*;" replace="" flags="gi"/>
670                </tokenfilter>
671            </filterchain>
672        </loadresource>
673        <!-- Delete files that are not in plugin list (like old plugins) -->
674        <loadresource property="file-list">
675            <propertyresource name="plugins"/>
676            <filterchain>
677                <tokenfilter>
678                    <replaceregex pattern="^.*/(.*)$" replace="\1\|" flags=""/>
679                </tokenfilter>
680                <striplinebreaks/>
681                <tokenfilter>
682                    <replaceregex pattern="\|$" replace="" flags="gi"/>
683                </tokenfilter>
684            </filterchain>
685        </loadresource>
686        <delete>
687            <restrict>
688                <fileset dir="${dir}"/>
689                <not>
690                    <name regex="${file-list}"/>
691                </not>
692            </restrict>
693        </delete>
694        <!-- Download plugins -->
695        <copy todir="${dir}" flatten="true" verbose="true" failonerror="false">
696            <resourcelist>
697                <string value="${plugins}"/>
698            </resourcelist>
699        </copy>
700        <!-- Check plugins -->
701        <as:build-signatures destfile="${dir}/api.sig">
702            <path>
703                <fileset file="${dist-optimized.jar}"/>
704                <fileset file="${java.home}/lib/rt.jar" unless:set="isJava9"/>
705                <fileset file="${java.home}/lib/jce.jar" unless:set="isJava9"/>
706                <fileset file="${java.home}/lib/ext/jfxrt.jar" unless:set="isJava9"/>
707                <fileset dir="${java.home}/jmods" if:set="isJava9"/>
708                <fileset dir="/usr/share/openjfx/lib" unless:set="isJava9"/>
709            </path>
710        </as:build-signatures>
711        <as:check-signature signature="${dir}/api.sig" failonerror="false">
712            <ignore classname="afu.*"/>
713            <ignore classname="android.*"/>
714            <ignore classname="au.*"/>
715            <ignore classname="com.*"/>
716            <ignore classname="de.*"/>
717            <ignore classname="edu.*"/>
718            <ignore classname="groovy.*"/>
719            <ignore classname="io.*"/>
720            <ignore classname="it.*"/>
721            <ignore classname="java.lang.invoke.MethodHandle"/>
722            <ignore classname="java.nio.ByteBuffer"/>
723            <ignore classname="java.nio.FloatBuffer"/>
724            <ignore classname="java.util.list.kotlin.*"/>
725            <ignore classname="javax.*"/>
726            <ignore classname="jdk.swing.interop.*"/>
727            <ignore classname="jogamp.*"/>
728            <ignore classname="junit.*"/>
729            <ignore classname="kdu_jni.*"/>
730            <ignore classname="kotlin.*"/>
731            <ignore classname="net.*"/>
732            <ignore classname="netscape.*"/>
733            <ignore classname="nu.*"/>
734            <ignore classname="oracle.*"/>
735            <ignore classname="org.apache.*"/>
736            <ignore classname="org.bouncycastle.*"/>
737            <ignore classname="org.checkerframework.*"/>
738            <ignore classname="org.codehaus.*"/>
739            <ignore classname="org.conscrypt.*"/>
740            <ignore classname="org.dom4j.*"/>
741            <ignore classname="org.eclipse.*"/>
742            <ignore classname="org.ejml.*"/>
743            <ignore classname="org.fusesource.*"/>
744            <ignore classname="org.gdal.*"/>
745            <ignore classname="org.geotools.data.h2.*"/>
746            <ignore classname="org.geotools.gce.imagemosaic.*"/>
747            <ignore classname="org.hibernate.*"/>
748            <ignore classname="org.hsqldb.*"/>
749            <ignore classname="org.ibex.*"/>
750            <ignore classname="org.iso_relax.*"/>
751            <ignore classname="org.jaitools.*"/>
752            <ignore classname="org.jaxen.*"/>
753            <ignore classname="org.jboss.*"/>
754            <ignore classname="org.jctools.*"/>
755            <ignore classname="org.jdom.*"/>
756            <ignore classname="org.jdom2.*"/>
757            <ignore classname="org.jfree.*"/>
758            <ignore classname="org.jgraph.*"/>
759            <ignore classname="org.joda.*"/>
760            <ignore classname="org.json.*"/>
761            <ignore classname="org.junit.*"/>
762            <ignore classname="org.jvnet.*"/>
763            <ignore classname="org.kxml2.*"/>
764            <ignore classname="org.locationtech.*"/>
765            <ignore classname="org.mozilla.*"/>
766            <ignore classname="org.objectweb.*"/>
767            <ignore classname="org.opentest4j.*"/>
768            <ignore classname="org.osgi.*"/>
769            <ignore classname="org.postgresql.*"/>
770            <ignore classname="org.python.*"/>
771            <ignore classname="org.seasar.*"/>
772            <ignore classname="org.slf4j.*"/>
773            <ignore classname="org.springframework.*"/>
774            <ignore classname="org.testng.*"/>
775            <ignore classname="org.w3c.*"/>
776            <ignore classname="org.zeromq.*"/>
777            <ignore classname="waffle.*"/>
778            <!-- plugins used by another ones -->
779            <ignore classname="org.openstreetmap.josm.plugins.geotools.*"/>
780            <ignore classname="org.openstreetmap.josm.plugins.jaxb.*"/>
781            <ignore classname="org.openstreetmap.josm.plugins.jna.*"/>
782            <ignore classname="org.openstreetmap.josm.plugins.jts.*"/>
783            <ignore classname="org.openstreetmap.josm.plugins.log4j.*"/>
784            <ignore classname="org.openstreetmap.josm.plugins.openjfx.*"/>
785            <ignore classname="org.openstreetmap.josm.plugins.utilsplugin2.*"/>
786            <ignore classname="sun.*"/>
787            <path path="${dir}"/>
788        </as:check-signature>
789    </target>
790
791    <target name="script-compile" depends="test-compile" description="Compiles all scripts">
792        <javac sourcepath="" srcdir="${base.dir}/scripts" failonerror="true" includes="*.java"
793               destdir="${script-build.dir}" target="${java.lang.version}" source="${java.lang.version}" debug="on"
794               includeantruntime="false" encoding="UTF-8">
795            <classpath>
796                <pathelement path="${build.dir}"/>
797                <pathelement path="${test.dir}/build/unit"/>
798                <pathelement path="${commons-lang3.jar}"/>
799            </classpath>
800        </javac>
801    </target>
802
803    <macrodef name="_taginfo">
804        <attribute name="type"/>
805        <attribute name="output"/>
806        <sequential>
807            <echo message="Generating Taginfo for type @{type} to @{output}"/>
808            <java classname="TagInfoExtract" failonerror="true" fork="false">
809                <sysproperty key="java.awt.headless" value="true"/>
810                <classpath>
811                    <pathelement path="${build.dir}"/>
812                    <pathelement path="${script-build.dir}"/>
813                    <pathelement path="${commons-lang3.jar}"/>
814                </classpath>
815                <arg value="--type"/>
816                <arg value="@{type}"/>
817                <arg value="--noexit"/>
818                <arg value="--imgurlprefix"/>
819                <arg value="http://josm.openstreetmap.de/download/taginfo/taginfo-img"/>
820                <arg value="--output"/>
821                <arg value="@{output}"/>
822            </java>
823        </sequential>
824    </macrodef>
825
826    <target name="taginfo" depends="script-compile">
827        <_taginfo type="mappaint" output="taginfo_style.json"/>
828        <_taginfo type="presets" output="taginfo_presets.json"/>
829        <_taginfo type="external_presets" output="taginfo_external_presets.json"/>
830    </target>
831
832    <target name="imageryindex" depends="script-compile">
833        <echo message="Checking editor imagery difference"/>
834        <java classname="SyncEditorLayerIndex" failonerror="true" fork="false">
835            <classpath>
836                <pathelement path="${build.dir}"/>
837                <pathelement path="${script-build.dir}"/>
838                <pathelement path="${commons-lang3.jar}"/>
839            </classpath>
840            <arg value="--noeli"/>
841            <arg value="-p"/>
842            <arg value="imagery_eliout.imagery.xml"/>
843            <arg value="-q"/>
844            <arg value="imagery_josmout.imagery.xml"/>
845        </java>
846    </target>
847
848    <target name="imageryindexdownload">
849        <exec append="false" executable="wget" failifexecutionfails="true">
850            <arg value="https://josm.openstreetmap.de/maps"/>
851            <arg value="-O"/>
852            <arg value="imagery_josm.imagery.xml"/>
853            <arg value="--unlink"/>
854        </exec>
855        <exec append="false" executable="wget" failifexecutionfails="true">
856            <arg value="https://josm.openstreetmap.de/wiki/ImageryCompareIgnores?format=txt"/>
857            <arg value="-O"/>
858            <arg value="imagery_josm.ignores.txt"/>
859            <arg value="--unlink"/>
860        </exec>
861        <exec append="false" executable="wget" failifexecutionfails="true">
862            <arg value="https://raw.githubusercontent.com/osmlab/editor-layer-index/gh-pages/imagery.geojson"/>
863            <arg value="-O"/>
864            <arg value="imagery_eli.geojson"/>
865            <arg value="--unlink"/>
866        </exec>
867        <antcall target="imageryindex"/>
868    </target>
869
870    <target name="checkstyle-compile" depends="init">
871        <ivy:cachepath log="download-only" file="${tools.ivy}" pathid="checkstyle.classpath" conf="checkstyle"/>
872        <mkdir dir="${checkstyle-build.dir}"/>
873        <javac sourcepath="" srcdir="${checkstyle.dir}/src" failonerror="true"
874            destdir="${checkstyle-build.dir}" target="${java.lang.version}" source="${java.lang.version}" debug="on"
875            includeantruntime="false"
876            encoding="UTF-8" classpathref="checkstyle.classpath">
877        </javac>
878    </target>
879    <target name="checkstyle-changed" depends="checkstyle-compile">
880        <exec append="false" osfamily="unix" executable="bash" failifexecutionfails="true">
881            <arg value="-c"/>
882            <arg value="(git ls-files src test --modified 2>/dev/null || svn status -q --ignore-externals src test) | grep -o '\(src\|test\)/.*' | xargs java -cp '${toString:checkstyle.classpath}:${checkstyle-build.dir}' com.puppycrawl.tools.checkstyle.Main -c ${checkstyle.dir}/josm_checks.xml | sed -e 's:\([^ ]*\) [^:]*/\([^:/]*.java\:[^:]*\):(\2)\1:'"/>
883        </exec>
884        <exec append="false" osfamily="windows" executable="powershell" failifexecutionfails="true">
885            <arg value="/c"/>
886            <arg value="svn status -q --ignore-externals src test | ForEach-Object {java -cp '${toString:checkstyle.classpath};${checkstyle-build.dir}' com.puppycrawl.tools.checkstyle.Main -c ${checkstyle.dir}/josm_checks.xml $_.split(' ')[7]}"/>
887        </exec>
888    </target>
889    <target name="checkstyle" depends="checkstyle-compile">
890        <taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties">
891            <classpath refid="checkstyle.classpath"/>
892            <classpath path="${checkstyle-build.dir}"/>
893        </taskdef>
894        <checkstyle config="${checkstyle.dir}/josm_checks.xml">
895            <fileset dir="${base.dir}/src/org/openstreetmap/josm" includes="**/*.java"
896                excludes="gui/mappaint/mapcss/parsergen/*.java"/>
897            <fileset dir="${base.dir}/test" includes="**/*.java"/>
898            <fileset dir="${base.dir}/scripts" includes="**/*.java"/>
899            <formatter type="plain"/>
900            <formatter type="xml" toFile="checkstyle-josm.xml"/>
901        </checkstyle>
902    </target>
903
904    <target name="spotbugs" depends="dist">
905        <ivy:cachepath log="download-only" file="${tools.ivy}" pathid="spotbugs.classpath" conf="spotbugs"/>
906        <taskdef name="spotbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="spotbugs.classpath"/>
907        <spotbugs output="xml"
908                outputFile="spotbugs-josm.xml"
909                classpath="${toString:spotbugs.classpath}"
910                pluginList=""
911                excludeFilter="${spotbugs.dir}/josm-filter.xml"
912                onlyAnalyze="org.openstreetmap.josm.-"
913                effort="max"
914                reportLevel="low"
915                >
916            <class location="${dist.jar}" />
917        </spotbugs>
918    </target>
919
920    <target name="pmd" depends="init">
921        <ivy:cachepath log="download-only" file="${tools.ivy}" pathid="pmd.classpath" conf="pmd"/>
922        <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath"/>
923        <pmd shortFilenames="true" cacheLocation="${pmd.dir}/cache" encoding="UTF-8">
924            <sourceLanguage name="java" version="${java.lang.version}" />
925            <ruleset>${pmd.dir}/josm-ruleset.xml</ruleset>
926            <formatter type="text" toConsole="true" />
927            <formatter type="xml" toFile="pmd-josm.xml">
928                <param name="encoding" value="UTF-8" />
929            </formatter>
930            <fileset dir="${src.dir}">
931                <include name="org/openstreetmap/josm/**/*.java"/>
932                <exclude name="org/openstreetmap/josm/gui/mappaint/mapcss/parsergen/*.java" />
933            </fileset>
934            <fileset dir="${base.dir}/scripts" includes="**/*.java"/>
935        </pmd>
936    </target>
937
938    <target name="run" depends="dist">
939        <java jar="${dist.jar}" fork="true">
940            <arg value="--set=expert=true"/>
941            <arg value="--set=iso.dates=true"/>
942            <jvmarg value="-Djosm.home=/tmp/.josm/"/>
943        </java>
944    </target>
945    <!--
946      ** Compile build script for generating projection list.
947    -->
948    <target name="epsg-compile" depends="init">
949        <property name="proj-classpath" location="${build.dir}"/>
950        <mkdir dir="${proj-build.dir}"/>
951        <javac sourcepath="" srcdir="${base.dir}/scripts" failonerror="true" includes="BuildProjectionDefinitions.java"
952            destdir="${proj-build.dir}" target="${java.lang.version}" source="${java.lang.version}" debug="on"
953            includeantruntime="false"
954            encoding="UTF-8" classpath="${proj-classpath}">
955        </javac>
956    </target>
957    <!--
958      ** generate projection list.
959    -->
960    <target name="epsg" unless="epsg.notRequired" depends="epsg-compile">
961        <touch file="${epsg.output}" mkdirs="true"/>
962        <java classname="BuildProjectionDefinitions" failonerror="true" fork="true">
963            <sysproperty key="java.awt.headless" value="true"/>
964            <classpath>
965                <pathelement path="${resources.dir}"/>
966                <pathelement path="${proj-classpath}"/>
967                <pathelement path="${proj-build.dir}"/>
968            </classpath>
969            <arg value="${base.dir}"/>
970        </java>
971    </target>
972    <!--
973      ** update projection test files after an update of projection definitions
974    -->
975    <target name="update-proj-files" depends="test-compile">
976        <java classname="org.openstreetmap.josm.data.projection.ProjectionRefTest" failonerror="true" fork="true">
977            <classpath>
978                <path refid="test.classpath"/>
979                <pathelement path="${test.dir}/build/unit"/>
980            </classpath>
981        </java>
982        <java classname="org.openstreetmap.josm.data.projection.ProjectionRegressionTest" failonerror="true" fork="true">
983            <classpath>
984                <path refid="test.classpath"/>
985                <pathelement path="${test.dir}/build/unit"/>
986            </classpath>
987        </java>
988    </target>
989    <!--
990      ** generate jdeps dependency graph
991    -->
992    <target name="jdeps" depends="compile">
993        <delete dir="${modules.dir}"/>
994        <mkdir dir="${modules.dir}"/>
995        <!-- JOSM only -->
996        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/josm-actions.jar" includes="org/openstreetmap/josm/actions/**/*.class"/>
997        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/josm-cli.jar" includes="org/openstreetmap/josm/cli/**/*.class"/>
998        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/josm-command.jar" includes="org/openstreetmap/josm/command/**/*.class"/>
999        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/josm-data.jar" includes="org/openstreetmap/josm/data/**/*.class"/>
1000        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/josm-gui.jar" includes="org/openstreetmap/josm/gui/**/*.class"/>
1001        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/josm-io.jar" includes="org/openstreetmap/josm/io/**/*.class"/>
1002        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/josm-plugins.jar" includes="org/openstreetmap/josm/plugins/**/*.class"/>
1003        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/josm-spi.jar" includes="org/openstreetmap/josm/spi/**/*.class"/>
1004        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/josm-tools.jar" includes="org/openstreetmap/josm/tools/**/*.class"/>
1005        <exec executable="jdeps" dir="${modules.dir}">
1006            <arg line="-f 'java.*|org.xml.*|org.w3c.*|sun.*|com.*|oauth.*|org.apache.*|org.glassfish.*|org.openstreetmap.gui.*'"/>
1007            <arg line="-dotoutput dots *.jar"/>
1008        </exec>
1009        <exec executable="dot" dir="${modules.dir}/dots">
1010            <arg line="-O -Tpng summary.dot"/>
1011        </exec>
1012        <move file="${modules.dir}/dots/summary.dot.png" tofile="${modules.dir}/josm-without-dependencies.png"/>
1013        <!-- Direct dependencies -->
1014        <copy todir="${modules.dir}" flatten="true">
1015            <fileset refid="runtime.fileset" />
1016        </copy>
1017        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/svgSalamander.jar" includes="com/kitfox/**/*.class"/>
1018        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/oauth-signpost.jar" includes="oauth/**/*.class"/>
1019        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/commons-jcs.jar" includes="org/apache/commons/jcs3/**/*.class"/>
1020        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/jmapviewer.jar" includes="org/openstreetmap/gui/**/*.class"/>
1021        <exec executable="jdeps" dir="${modules.dir}">
1022            <arg line="-f 'java.*|org.xml.*|org.w3c.*|sun.*|com.sun.*|com.google.*|org.tukaani.*'"/>
1023            <arg line="-dotoutput dots *.jar"/>
1024        </exec>
1025        <exec executable="dot" dir="${modules.dir}/dots">
1026            <arg line="-O -Tpng summary.dot"/>
1027        </exec>
1028        <move file="${modules.dir}/dots/summary.dot.png" tofile="${modules.dir}/josm-with-direct-dependencies.png"/>
1029        <!-- All dependencies -->
1030        <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/google-gdata.jar" includes="com/google/**/*.class"/>
1031        <exec executable="jdeps" dir="${modules.dir}">
1032            <arg line="-dotoutput dots *.jar"/>
1033        </exec>
1034        <exec executable="dot" dir="${modules.dir}/dots">
1035            <arg line="-O -Tpng summary.dot"/>
1036        </exec>
1037        <move file="${modules.dir}/dots/summary.dot.png" tofile="${modules.dir}/josm-with-all-dependencies.png"/>
1038    </target>
1039    <target name="resolve" depends="init-ivy" unless="resolve.notRequired" description="Resolve Ivy dependencies">
1040        <ivy:settings file="${base.dir}/ivysettings.xml"/>
1041        <ivy:resolve log="download-only" file="${base.dir}/ivy.xml" keep="true"/>
1042        <ivy:cachepath log="download-only" pathid="compile.path" conf="compile"/>
1043        <ivy:cachepath log="download-only" pathid="runtime.path" conf="runtime"/>
1044        <ivy:cachefileset log="download-only" setid="runtime.fileset" conf="runtime"/>
1045        <ivy:cachepath log="download-only" pathid="test.path" conf="test"/>
1046    </target>
1047    <target name="extract-libraries" depends="resolve" description="extract libraries to build dir">
1048        <unzip dest="${build.dir}">
1049            <fileset refid="runtime.fileset"/>
1050            <patternset>
1051                <exclude name="META-INF/*"/>
1052                <exclude name="META-INF/maven/**"/>
1053                <exclude name="META-INF/versions/**"/>
1054                <exclude name="*"/>
1055                <exclude name="org/openstreetmap/gui/jmapviewer/Demo*"/>
1056                <exclude name="com/drew/imaging/FileTypeDetector*"/>
1057                <exclude name="com/drew/imaging/ImageMetadataReader*"/>
1058                <exclude name="com/drew/imaging/avi/**"/>
1059                <exclude name="com/drew/imaging/bmp/**"/>
1060                <exclude name="com/drew/imaging/eps/**"/>
1061                <exclude name="com/drew/imaging/gif/**"/>
1062                <exclude name="com/drew/imaging/heif/**"/>
1063                <exclude name="com/drew/imaging/ico/**"/>
1064                <exclude name="com/drew/imaging/mp3/**"/>
1065                <exclude name="com/drew/imaging/mp4/**"/>
1066                <exclude name="com/drew/imaging/pcx/**"/>
1067                <exclude name="com/drew/imaging/png/**"/>
1068                <exclude name="com/drew/imaging/psd/**"/>
1069                <exclude name="com/drew/imaging/quicktime/**"/>
1070                <exclude name="com/drew/imaging/raf/**"/>
1071                <exclude name="com/drew/imaging/riff/**"/>
1072                <exclude name="com/drew/imaging/wav/**"/>
1073                <exclude name="com/drew/imaging/webp/**"/>
1074                <exclude name="com/drew/metadata/avi/**"/>
1075                <exclude name="com/drew/metadata/bmp/**"/>
1076                <exclude name="com/drew/metadata/eps/**"/>
1077                <exclude name="com/drew/metadata/gif/**"/>
1078                <exclude name="com/drew/metadata/heif/**"/>
1079                <exclude name="com/drew/metadata/ico/**"/>
1080                <exclude name="com/drew/metadata/mov/**"/>
1081                <exclude name="com/drew/metadata/mp3/**"/>
1082                <exclude name="com/drew/metadata/mp4/**"/>
1083                <exclude name="com/drew/metadata/pcx/**"/>
1084                <exclude name="com/drew/metadata/png/**"/>
1085                <exclude name="com/drew/metadata/wav/**"/>
1086                <exclude name="com/drew/metadata/webp/**"/>
1087                <exclude name="com/drew/tools/**"/>
1088                <exclude name="org/apache/commons/compress/PasswordRequiredException*"/>
1089                <exclude name="org/apache/commons/compress/archivers/**"/>
1090                <exclude name="org/apache/commons/compress/changes/**"/>
1091                <exclude name="org/apache/commons/compress/compressors/bzip2/BZip2Utils*"/>
1092                <exclude name="org/apache/commons/compress/compressors/brotli/**"/>
1093                <exclude name="org/apache/commons/compress/compressors/CompressorStreamFactory*"/>
1094                <exclude name="org/apache/commons/compress/compressors/CompressorStreamProvider*"/>
1095                <exclude name="org/apache/commons/compress/compressors/CompressorException*"/>
1096                <exclude name="org/apache/commons/compress/compressors/FileNameUtil*"/>
1097                <exclude name="org/apache/commons/compress/compressors/deflate/**"/>
1098                <exclude name="org/apache/commons/compress/compressors/gzip/**"/>
1099                <exclude name="org/apache/commons/compress/compressors/lz4/**"/>
1100                <exclude name="org/apache/commons/compress/compressors/lzma/**"/>
1101                <exclude name="org/apache/commons/compress/compressors/lz77support/**"/>
1102                <exclude name="org/apache/commons/compress/compressors/pack200/**"/>
1103                <exclude name="org/apache/commons/compress/compressors/snappy/**"/>
1104                <exclude name="org/apache/commons/compress/compressors/xz/XZUtils*"/>
1105                <exclude name="org/apache/commons/compress/compressors/z/**"/>
1106                <exclude name="org/apache/commons/compress/compressors/zstandard/**"/>
1107                <exclude name="org/apache/commons/compress/parallel/**"/>
1108                <exclude name="org/apache/commons/compress/utils/ArchiveUtils*"/>
1109                <exclude name="org/apache/commons/jcs3/auxiliary/disk/jdbc/**"/>
1110                <exclude name="org/apache/commons/jcs3/auxiliary/remote/http/client/**"/>
1111                <exclude name="org/apache/commons/jcs3/auxiliary/remote/http/server/RemoteHttpCacheServlet*"/>
1112                <exclude name="org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheStartupServlet*"/>
1113                <exclude name="org/apache/commons/jcs3/log/Log4j2Factory*"/>
1114                <exclude name="org/apache/commons/jcs3/log/Log4j2LogAdapter*"/>
1115                <exclude name="org/apache/commons/jcs3/utils/servlet/**"/>
1116            </patternset>
1117        </unzip>
1118    </target>
1119    <target name="sources" description="Generates jar file of JOSM source files and its dependencies" depends="init,epsg,resolve">
1120        <ivy:cachefileset log="download-only" setid="sources.fileset" conf="sources"/>
1121        <jar destfile="${dist-sources.jar}" level="${clevel}">
1122            <zipgroupfileset refid="sources.fileset"/>
1123            <fileset dir="${src.dir}"/>
1124            <fileset dir="${resources.dir}"/>
1125        </jar>
1126    </target>
1127    <target name="bootstrap-workspace" description="Copy libraries from ivy cache to workspace folders for IDE" depends="resolve">
1128        <delete dir="${lib.dir}"/>
1129        <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type].[ext]" conf="compile,runtime,sources,test"/>
1130        <ivy:retrieve pattern="${lib.dir}/tools/[artifact]-[type].[ext]" conf="javacc,checkstyle,pmd,spotbugs,errorprone" file="${tools.ivy}"/>
1131    </target>
1132    <target name="ivy-report" description="Generates Ivy reports of dependency resolving" depends="resolve">
1133        <ivy:report todir="${tools.dir}/ivy-report" graph="false"/>
1134    </target>
1135    <target name="ivy-checkdepsupdate" description="Display dependency updates on the console" depends="resolve">
1136        <ivy:checkdepsupdate/>
1137    </target>
1138    <target name="api-dependency-tree" description="Displays Ivy dependency tree for JOSM API" depends="resolve">
1139        <ivy:dependencytree conf="api"/>
1140    </target>
1141    <target name="test-dependency-tree" description="Displays Ivy dependency tree for JOSM tests" depends="resolve">
1142        <ivy:dependencytree conf="test"/>
1143    </target>
1144</project>
Note: See TracBrowser for help on using the repository browser.