source: josm/trunk/build.xml@ 6564

Last change on this file since 6564 was 6545, checked in by simon04, 11 years ago

see #9450 - JOSM build from a git mirror: remove need for perl script, automatically obtain revision from Git if SVN fails (removes need for git_revision=true)

File size: 21.3 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/CreateBuild
9**
10-->
11<project xmlns:as="antlib:org.codehaus.mojo.animal_sniffer" name="josm" default="dist" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
12 <property name="test.dir" location="test"/>
13 <property name="src.dir" location="src"/>
14 <property name="build.dir" location="build"/>
15 <property name="javacc.home" location="tools"/>
16 <property name="mapcss.dir" location="${src.dir}/org/openstreetmap/josm/gui/mappaint/mapcss"/>
17 <!-- build parameter: compression level (ant -Dclevel=N)
18 N ranges from 0 (no compression) to 9 (maximum compression)
19 default: 9 -->
20 <condition property="clevel" value="${clevel}" else="9">
21 <isset property="clevel"/>
22 </condition>
23 <!-- Java classpath addition (all jar files to compile tests with this) -->
24 <path id="classpath">
25 <fileset dir="lib">
26 <include name="**/*.jar"/>
27 </fileset>
28 </path>
29
30 <!--
31 ** Used by Eclipse ant builder for updating
32 ** the REVISION file used by JOSM
33 -->
34 <target name="create-revision-eclipse">
35 <property name="revision.dir" value="bin"/>
36 <antcall target="create-revision"/>
37 </target>
38 <!--
39 ** Initializes the REVISION.XML file from SVN information
40 -->
41 <target name="init-svn-revision-xml">
42 <exec append="false" output="REVISION.XML" executable="svn" failifexecutionfails="false" errorproperty="svn.info.failed">
43 <env key="LANG" value="C"/>
44 <arg value="info"/>
45 <arg value="--xml"/>
46 <arg value="."/>
47 </exec>
48 </target>
49 <!--
50 ** Initializes the REVISION.XML file from git information
51 -->
52 <target name="init-git-revision-xml" if="svn.info.failed">
53 <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false">
54 <arg value="log"/>
55 <arg value="-1"/>
56 <arg value="--grep=git-svn-id"/>
57 <!--
58 %B: raw body (unwrapped subject and body)
59 %n: new line
60 %ai: author date, ISO 8601 format
61 -->
62 <arg value="--pretty=format:%B%n%ai"/>
63 <arg value="HEAD"/>
64 </exec>
65 <replaceregexp file="REVISION.XML" flags="s"
66 match=".*git-svn-id: [^@]*@([0-9]+).*(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
67 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;"/>
68 </target>
69 <!--
70 ** Creates the REVISION file to be included in the distribution
71 -->
72 <target name="create-revision" depends="init-svn-revision-xml, init-git-revision-xml">
73 <property name="revision.dir" value="${build.dir}"/>
74 <xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
75 <delete file="REVISION.XML"/>
76 <tstamp>
77 <format property="build.tstamp" pattern="yyyy-MM-dd HH:mm:ss"/>
78 </tstamp>
79 <property name="version.entry.commit.revision" value="UNKNOWN"/>
80 <property name="version.entry.commit.date" value="UNKNOWN"/>
81 <mkdir dir="${revision.dir}"/>
82 <!-- add Build-Name: ... when making special builds, e.g. DEBIAN -->
83 <echo file="${revision.dir}/REVISION">
84# automatically generated by JOSM build.xml - do not edit
85Revision: ${version.entry.commit.revision}
86Is-Local-Build: true
87Build-Date: ${build.tstamp}
88</echo>
89 </target>
90 <!--
91 ** Check internal XML files against their XSD
92 -->
93 <target name="check-schemas">
94 <schemavalidate file="data/defaultpresets.xml" >
95 <schema namespace="http://josm.openstreetmap.de/tagging-preset-1.0" file="data/tagging-preset.xsd" />
96 </schemavalidate>
97 <schemavalidate file="styles/standard/elemstyles.xml" >
98 <schema namespace="http://josm.openstreetmap.de/mappaint-style-1.0" file="data/mappaint-style.xsd" />
99 </schemavalidate>
100 </target>
101 <!--
102 ** Main target that builds JOSM and checks XML against schemas
103 -->
104 <target name="dist" depends="compile,create-revision,check-schemas">
105 <echo>Revision ${version.entry.commit.revision}</echo>
106 <copy file="CONTRIBUTION" todir="build"/>
107 <copy file="README" todir="build"/>
108 <copy file="LICENSE" todir="build"/>
109 <!-- create josm-custom.jar -->
110 <delete file="dist/josm-custom.jar"/>
111 <jar destfile="dist/josm-custom.jar" basedir="build" level="${clevel}">
112 <!-- add attribute excludes="**/*BZip2*,**/*Bzip2*" to create a non-bzip2 supporting jar -->
113 <manifest>
114 <attribute name="Main-class" value="JOSM"/>
115 <attribute name="Main-Version" value="${version.entry.commit.revision} SVN"/>
116 <attribute name="Main-Date" value="${version.entry.commit.date}"/>
117 <attribute name="Permissions" value="all-permissions"/>
118 <attribute name="Codebase" value="josm.openstreetmap.de"/>
119 <attribute name="Application-Name" value="JOSM - Java OpenStreetMap Editor"/>
120 </manifest>
121 <zipfileset dir="images" prefix="images"/>
122 <zipfileset dir="data" prefix="data"/>
123 <zipfileset dir="styles" prefix="styles"/>
124 <zipfileset dir="src/org/openstreetmap/gui/jmapviewer/images" prefix="org/openstreetmap/gui/jmapviewer/images"/>
125 <!-- All jar files necessary to run only JOSM (no tests) -->
126 <!-- <zipfileset src="lib/metadata-extractor-2.3.1-nosun.jar"/> -->
127 <!-- <zipfileset src="lib/signpost-core-1.2.1.1.jar"/> -->
128 </jar>
129 </target>
130 <!-- Compatibility Mac OS X target for Java 6 (incompatible with new on for Java 7, see #8654, #9035) -->
131 <target name="distmac" depends="dist">
132 <!-- modify MacOS X Info.plist file to hold the SVN version number -->
133 <copy file="macosx/JOSM.app/Contents/Info.plist" todir="build"/>
134 <replace file="build/Info.plist" token="@SVNVersion@" value="${version.entry.commit.revision}"/>
135 <!-- create ZIP file with MacOS X application bundle -->
136 <zip destfile="dist/josm-custom-macosx.zip" update="true">
137 <zipfileset dir="build" includes="CONTRIBUTION README LICENSE"/>
138 <zipfileset dir="macosx" includes="JOSM.app/Contents JOSM.app/Contents/MacOS JOSM.app/Contents/Resources JOSM.app/Contents/Resources/Java JOSM.app/Contents/PkgInfo JOSM.app/Contents/Resources/JOSM.icns"/>
139 <zipfileset dir="build" includes="Info.plist" prefix="JOSM.app/Contents"/>
140 <zipfileset dir="dist" includes="josm-custom.jar" prefix="JOSM.app/Contents/Resources/Java"/>
141 <zipfileset dir="macosx" includes="JOSM.app/Contents/MacOS/JOSM" filemode="755"/>
142 </zip>
143 </target>
144 <!-- New Mac OS X target for Java 7 -->
145 <target name="distmac7" depends="dist">
146 <!-- Using https://bitbucket.org/infinitekind/appbundler to create mac application bundle -->
147 <taskdef name="bundleapp" classname="com.oracle.appbundler.AppBundlerTask" classpath="tools/appbundler-1.0ea.jar"/>
148 <!-- create MacOS X application bundle -->
149 <bundleapp outputdirectory="dist" name="JOSM" displayname="JOSM" executablename="JOSM" identifier="org.openstreetmap.josm"
150 mainclassname="org.openstreetmap.josm.gui.MainApplication"
151 copyright="JOSM, and all its integral parts, are released under the GNU General Public License v2 or later"
152 applicationCategory="public.app-category.utilities"
153 shortversion="${version.entry.commit.revision} SVN"
154 version="${version.entry.commit.revision} SVN"
155 icon="macosx/JOSM.app/Contents/Resources/JOSM.icns"
156 highResolutionCapable="true">
157
158 <arch name="x86_64"/>
159 <arch name="i386"/>
160
161 <classpath file="dist/josm-custom.jar"/>
162
163 <option value="-Xmx512m"/>
164
165 <option value="-Xdock:icon=Contents/Resources/JOSM.icns"/>
166 <option value="-Xdock:name=JOSM"/>
167
168 <!-- OSX specific options, optional -->
169 <option value="-Dapple.laf.useScreenMenuBar=true"/>
170 <option value="-Dcom.apple.macos.use-file-dialog-packages=true"/>
171 <option value="-Dcom.apple.macos.useScreenMenuBar=true"/>
172 <option value="-Dcom.apple.mrj.application.apple.menu.about.name=JOSM"/>
173 <option value="-Dcom.apple.smallTabs=true"/>
174 </bundleapp>
175
176 <!-- appbundler lacks the possibility of defining our own keys or using a template, so update the .plist manually -->
177 <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="tools/xmltask.jar"/>
178
179 <xmltask source="dist/JOSM.app/Contents/Info.plist" dest="dist/JOSM.app/Contents/Info.plist" indent="false">
180 <insert position="before" path="/plist/dict/key[1]"><![CDATA[<key>CFBundleAllowMixedLocalizations</key>
181<string>true</string>
182]]></insert>
183 </xmltask>
184
185 <!-- create ZIP file with MacOS X application bundle -->
186 <zip destfile="dist/josm-custom-macosx-java7.zip" update="true">
187 <zipfileset dir="build" includes="CONTRIBUTION README LICENSE"/>
188 <zipfileset dir="dist" includes="JOSM.app/**/*" filemode="755" />
189 </zip>
190 </target>
191 <target name="javacc" depends="init" unless="javacc.notRequired">
192 <mkdir dir="${mapcss.dir}/parsergen"/>
193 <exec append="false" executable="java" failifexecutionfails="true">
194 <arg value="-cp"/>
195 <arg value="${javacc.home}/javacc.jar"/>
196 <arg value="javacc"/>
197 <arg value="-JDK_VERSION=1.6"/>
198 <arg value="-GRAMMAR_ENCODING=UTF-8"/>
199 <arg value="-UNICODE_INPUT"/>
200 <arg value="-OUTPUT_DIRECTORY=${mapcss.dir}/parsergen"/>
201 <arg value="${mapcss.dir}/MapCSSParser.jj"/>
202 </exec>
203 </target>
204 <target name="compile" depends="init,javacc">
205 <javac srcdir="src" includes="com/**,oauth/**,org/apache/commons/codec/**" destdir="build" target="1.6" source="1.6" debug="on" includeantruntime="false" encoding="iso-8859-1"/>
206 <javac srcdir="src" excludes="com/**,oauth/**,org/apache/commons/codec/**" destdir="build" target="1.6" source="1.6" debug="on" includeantruntime="false" encoding="UTF-8">
207 <compilerarg value="-Xlint:deprecation"/>
208 <compilerarg value="-Xlint:unchecked"/>
209 </javac>
210 </target>
211 <target name="init">
212 <uptodate property="javacc.notRequired" targetfile="${mapcss.dir}/parsergen/MapCSSParser.java" >
213 <srcfiles dir="${mapcss.dir}" includes="MapCSSParser.jj"/>
214 </uptodate>
215 <mkdir dir="build"/>
216 <mkdir dir="dist"/>
217 </target>
218 <target name="javadoc">
219 <javadoc destdir="javadoc"
220 sourcepath="src"
221 packagenames="org.openstreetmap.josm.*,org.openstreetmap.gui.jmapviewer.*"
222 windowtitle="JOSM"
223 use="true"
224 private="true"
225 linksource="true"
226 author="false">
227 <link href="http://docs.oracle.com/javase/6/docs/api"/>
228 <doctitle><![CDATA[<h2>JOSM - Javadoc</h2>]]></doctitle>
229 <bottom><![CDATA[<a href="http://josm.openstreetmap.de/">JOSM</a>]]></bottom>
230 </javadoc>
231 </target>
232 <target name="clean">
233 <delete dir="build"/>
234 <delete dir="dist"/>
235 <delete dir="${mapcss.dir}/parsergen"/>
236 </target>
237 <path id="test.classpath">
238 <fileset dir="${test.dir}/lib">
239 <include name="**/*.jar"/>
240 </fileset>
241 <fileset dir="lib">
242 <include name="**/*.jar"/>
243 </fileset>
244 <pathelement path="dist/josm-custom.jar"/>
245 </path>
246 <target name="test-init">
247 <mkdir dir="${test.dir}/build"/>
248 <mkdir dir="${test.dir}/report"/>
249 </target>
250 <target name="test-clean">
251 <delete dir="${test.dir}/build"/>
252 <delete dir="${test.dir}/report"/>
253 <delete file="${test.dir}/jacoco.exec" />
254 </target>
255 <target name="test-compile" depends="test-init,dist">
256 <javac srcdir="${test.dir}/unit" classpathref="test.classpath" destdir="${test.dir}/build" target="1.6" source="1.6" debug="on" includeantruntime="false" encoding="UTF-8">
257 <compilerarg value="-Xlint:deprecation"/>
258 <compilerarg value="-Xlint:unchecked"/>
259 </javac>
260 <javac srcdir="${test.dir}/functional" classpathref="test.classpath" destdir="${test.dir}/build" target="1.6" source="1.6" debug="on" includeantruntime="false" encoding="UTF-8">
261 <compilerarg value="-Xlint:deprecation"/>
262 <compilerarg value="-Xlint:unchecked"/>
263 </javac>
264 </target>
265 <target name="test" depends="test-compile">
266 <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="tools/jacocoant.jar" />
267 <jacoco:coverage destfile="${test.dir}/jacoco.exec">
268 <junit printsummary="yes" fork="true" forkmode="once">
269 <sysproperty key="josm.home" value="${test.dir}/config/unit-josm.home"/>
270 <sysproperty key="josm.test.data" value="${test.dir}/data"/>
271 <sysproperty key="java.awt.headless" value="true"/>
272 <sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
273 <classpath>
274 <path refid="test.classpath"/>
275 <pathelement path="${test.dir}/build"/>
276 <pathelement path="${test.dir}/config"/>
277 </classpath>
278 <formatter type="plain"/>
279 <formatter type="xml"/>
280 <batchtest fork="yes" todir="${test.dir}/report">
281 <fileset dir="${test.dir}/unit" includes="**/*.java"/>
282 </batchtest>
283 </junit>
284 </jacoco:coverage>
285 </target>
286 <target name="test-html" depends="test" description="Generate HTML test reports">
287 <!-- May require additional ant dependencies like ant-trax package -->
288 <junitreport todir="${test.dir}/report">
289 <fileset dir="${test.dir}/report">
290 <include name="TEST-*.xml"/>
291 </fileset>
292 <report todir="${test.dir}/report/html"/>
293 </junitreport>
294 <jacoco:report>
295 <executiondata>
296 <file file="${test.dir}/jacoco.exec"/>
297 </executiondata>
298 <structure name="JOSM Test Coverage">
299 <classfiles>
300 <fileset dir="${build.dir}" includes="org/openstreetmap/"/>
301 </classfiles>
302 <sourcefiles encoding="UTF-8">
303 <fileset dir="${src.dir}" includes="org/openstreetmap/"/>
304 </sourcefiles>
305 </structure>
306 <html destdir="${test.dir}/report/jacoco"/>
307 </jacoco:report>
308 </target>
309 <target name="dist-optimized" depends="dist">
310 <taskdef resource="proguard/ant/task.properties" classpath="tools/proguard.jar"/>
311 <proguard>
312 -injars dist/josm-custom.jar
313 -outjars dist/josm-custom-optimized.jar
314
315 -libraryjars ${java.home}/lib/rt.jar
316 -libraryjars ${java.home}/lib/jce.jar
317
318 -dontoptimize
319 -dontobfuscate
320
321 # These options probably are not necessary (and make processing a bit slower)
322 -dontskipnonpubliclibraryclasses
323 -dontskipnonpubliclibraryclassmembers
324
325 -keepclasseswithmembers public class org.openstreetmap.josm.gui.MainApplication {
326 public static void main(java.lang.String[]);
327 }
328 -keepclasseswithmembers public class org.openstreetmap.josm.gui.MainApplet
329
330 -keep class JOSM
331 -keep class * extends org.openstreetmap.josm.io.FileImporter
332 -keep class * extends org.openstreetmap.josm.io.FileExporter
333 -keep class org.openstreetmap.josm.data.imagery.types.Adapter1
334 -keep class org.openstreetmap.josm.actions.search.SearchCompiler$Never
335
336 -keepclassmembers enum * {
337 public static **[] values();
338 public static ** valueOf(java.lang.String);
339 }
340
341 # Keep unused public methods (can be useful for plugins)
342 -keepclassmembers class * {
343 public protected *;
344 }
345
346 # Disable annoying [proguard] Note: the configuration keeps the entry point '...', but not the descriptor class '...'. This notes should not be a problem as we don't use obfuscation
347 -dontnote
348 </proguard>
349 </target>
350 <target name="check-plugins" depends="dist-optimized">
351 <echo message="Check of plugins binary compatibility (needs ant 1.8)"/>
352 <local name="dir"/>
353 <local name="plugins"/>
354 <property name="dir" value="plugin-check"/>
355 <typedef uri="antlib:org.codehaus.mojo.animal_sniffer">
356 <classpath path="tools/animal-sniffer-ant-tasks-1.8.jar"/>
357 </typedef>
358 <mkdir dir="${dir}"/>
359 <!-- List of deprecated plugins -->
360 <loadfile property="deprecated-plugins" srcFile="src/org/openstreetmap/josm/plugins/PluginHandler.java">
361 <filterchain>
362 <linecontains>
363 <contains value="new DeprecatedPlugin("/>
364 </linecontains>
365 <tokenfilter>
366 <replaceregex pattern=".*new DeprecatedPlugin\(&quot;(.+?)&quot;.*" replace="\1|" flags="gi"/>
367 </tokenfilter>
368 <striplinebreaks/>
369 <tokenfilter>
370 <replaceregex pattern="\|$" replace="" flags="gi"/>
371 </tokenfilter>
372 </filterchain>
373 </loadfile>
374 <!-- Download list of plugins -->
375 <loadresource property="plugins">
376 <url url="http://josm.openstreetmap.de/plugin"/>
377 <filterchain>
378 <linecontainsregexp negate="true">
379 <regexp pattern="^\t.*"/>
380 </linecontainsregexp>
381 <linecontainsregexp negate="true">
382 <regexp pattern="${deprecated-plugins}"/>
383 </linecontainsregexp>
384 <tokenfilter>
385 <replaceregex pattern="^.*;" replace="" flags="gi"/>
386 </tokenfilter>
387 </filterchain>
388 </loadresource>
389 <!-- Delete files that are not in plugin list (like old plugins) -->
390 <loadresource property="file-list">
391 <propertyresource name="plugins"/>
392 <filterchain>
393 <tokenfilter>
394 <replaceregex pattern="^.*/(.*)$" replace="\1\|" flags=""/>
395 </tokenfilter>
396 <striplinebreaks/>
397 <tokenfilter>
398 <replaceregex pattern="\|$" replace="" flags="gi"/>
399 </tokenfilter>
400 </filterchain>
401 </loadresource>
402 <delete>
403 <restrict>
404 <fileset dir="${dir}"/>
405 <not>
406 <name regex="${file-list}"/>
407 </not>
408 </restrict>
409 </delete>
410 <!-- Download plugins -->
411 <copy todir="${dir}" flatten="true">
412 <resourcelist>
413 <string value="${plugins}"/>
414 </resourcelist>
415 </copy>
416 <!-- Check plugins -->
417 <as:build-signatures destfile="${dir}/api.sig">
418 <path>
419 <fileset file="dist/josm-custom-optimized.jar"/>
420 <fileset file="${java.home}/lib/rt.jar"/>
421 <fileset file="${java.home}/lib/jce.jar"/>
422 </path>
423 </as:build-signatures>
424 <as:check-signature signature="${dir}/api.sig">
425 <ignore classname="org.jgraph.*"/>
426 <ignore classname="com.touchgraph.*"/>
427 <ignore classname="com.sun.xml.fastinfoset.*"/>
428 <ignore classname="javax.jms.*"/>
429 <ignore classname="org.jvnet.staxex.*"/>
430 <ignore classname="javax.mail.*"/>
431 <ignore classname="com.sun.jdmk.*"/>
432 <ignore classname="org.apache.avalon.framework.logger.Logger"/>
433 <ignore classname="org.apache.log.*"/>
434 <ignore classname="junit.*"/>
435 <path path="${dir}"/>
436 </as:check-signature>
437 </target>
438
439 <target name="findbugs" depends="dist">
440 <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="tools/findbugs/findbugs-ant.jar"/>
441 <path id="findbugs-classpath">
442 <fileset dir="tools/findbugs/">
443 <include name="*.jar"/>
444 </fileset>
445 </path>
446 <property name="findbugs-classpath" refid="findbugs-classpath"/>
447 <findbugs output="xml"
448 outputFile="findbugs-josm.xml"
449 classpath="${findbugs-classpath}"
450 pluginList=""
451 excludeFilter="tools/findbugs/josm-filter.xml"
452 effort="max"
453 >
454 <sourcePath path="${basedir}/src" />
455 <class location="${basedir}/dist/josm-custom.jar" />
456 </findbugs>
457 </target>
458 <target name="run" depends="dist">
459 <java jar="dist/josm-custom.jar" fork="true">
460 <arg value="--set=expert=true"/>
461 <arg value="--set=remotecontrol.enabled=true"/>
462 <arg value="--set=debug.edt-checker.enable=false"/>
463 <jvmarg value="-Djosm.home=/tmp/.josm/"/>
464 </java>
465 </target>
466
467</project>
Note: See TracBrowser for help on using the repository browser.