source: josm/trunk/build.xml@ 6540

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

fix #9450 - Allow to build JOSM from a git mirror clone with ant -Dgit_revision=true

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