source: josm/trunk/build.xml@ 18973

Last change on this file since 18973 was 18871, checked in by taylor.smock, 13 months ago

See #23218: Use newer error_prone versions when compiling on Java 11+

error_prone 2.11 dropped support for compiling with Java 8, although it still
supports compiling for Java 8. The "major" new check for us is NotJavadoc since
we used /** in quite a few places which were not javadoc.

Other "new" checks that are of interest:

  • AlreadyChecked: if (foo) { doFoo(); } else if (!foo) { doBar(); }
  • UnnecessaryStringBuilder: Avoid StringBuilder (Java converts + to StringBuilder behind-the-scenes, but may also do something else if it performs better)
  • NonApiType: Avoid specific interface types in function definitions
  • NamedLikeContextualKeyword: Avoid using restricted names for classes and methods
  • UnusedMethod: Unused private methods should be removed

This fixes most of the new error_prone issues and some SonarLint issues.

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