source: osm/applications/editors/josm/plugins/build-common.xml@ 32306

Last change on this file since 32306 was 32306, checked in by donvip, 8 years ago

rework/simplify plugins build.xml file - automatically run unit tests of all plugins, without having to maintain list manually

File size: 23.0 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!--
3** Template for the build targets common to all plugins
4** ====================================================
5**
6** To override a property, add it to the plugin build.xml _before_
7** this template has been imported.
8** To override a target, add it _after_ this template has been imported.
9**
10** Paths are relative to the build.xml that imports this template.
11**
12-->
13<project name="plugin_common" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
14
15 <property name="josm" location="../../core/dist/josm-custom.jar"/>
16 <property name="josm.test.build.dir" location="../../core/test/build"/>
17 <property name="groovy.jar" location="../00_core_tools/groovy-all-2.4.6.jar"/>
18 <property name="annotations.jar" location="../00_core_tools/findbugs/annotations.jar"/>
19 <property name="plugin.build.dir" location="build"/>
20 <property name="plugin.test.dir" location="test"/>
21 <property name="plugin.src.dir" location="src"/>
22 <property name="plugin.lib.dir" location="lib"/>
23 <!-- this is the directory where the plugin jar is copied to -->
24 <property name="plugin.dist.dir" location="../../dist"/>
25 <property name="ant.build.javac.target" value="1.7"/>
26 <property name="ant.build.javac.source" value="1.7"/>
27 <property name="plugin.jar" location="${plugin.dist.dir}/${ant.project.name}.jar"/>
28
29 <!-- For Windows-specific stuff -->
30 <condition property="isWindows">
31 <os family="Windows"/>
32 </condition>
33 <target name="-jaxb_win" if="isWindows">
34 <property name="xjc" value="${java.home}\..\bin\xjc.exe" />
35 </target>
36 <target name="-jaxb_nix" unless="isWindows">
37 <property name="xjc" value="${java.home}/../bin/xjc" />
38 </target>
39
40 <!-- To be overriden in plugin build file before inclusion if other plugins are required -->
41 <fileset id="plugin.requires.jars" dir="${plugin.dist.dir}" includes="nothing"/>
42
43 <!--
44 **********************************************************
45 ** init - initializes the build
46 **********************************************************
47 -->
48 <target name="init">
49 <mkdir dir="${plugin.build.dir}"/>
50 </target>
51 <!--
52 **********************************************************
53 ** compile - compiles the source tree
54 **********************************************************
55 -->
56 <target name="compile" depends="init">
57 <echo message="compiling sources for ${plugin.jar} ..."/>
58 <javac srcdir="src" debug="true" destdir="${plugin.build.dir}" includeantruntime="false" encoding="UTF-8">
59 <compilerarg value="-Xlint:deprecation"/>
60 <compilerarg value="-Xlint:unchecked"/>
61 <classpath>
62 <pathelement location="${josm}"/>
63 <fileset dir="${plugin.lib.dir}" erroronmissingdir="no">
64 <include name="**/*.jar"/>
65 <exclude name="**/*-sources.jar"/>
66 <exclude name="**/*-javadoc.jar"/>
67 </fileset>
68 <fileset refid="plugin.requires.jars"/>
69 </classpath>
70 </javac>
71 </target>
72 <!--
73 **********************************************************
74 ** setup-dist - copies files for distribution
75 **********************************************************
76 -->
77 <target name="setup-dist-default">
78 <copy todir="${plugin.build.dir}/resources" failonerror="no" includeemptydirs="no">
79 <fileset dir="resources"/>
80 </copy>
81 <copy todir="${plugin.build.dir}/images" failonerror="no" includeemptydirs="no">
82 <fileset dir="images"/>
83 </copy>
84 <copy todir="${plugin.build.dir}/data" failonerror="no" includeemptydirs="no">
85 <fileset dir="data"/>
86 </copy>
87 <copy todir="${plugin.build.dir}">
88 <fileset dir=".">
89 <include name="README"/>
90 <include name="LICENSE*"/>
91 <include name="*GPL*"/>
92 </fileset>
93 </copy>
94 </target>
95 <target name="setup-dist">
96 <antcall target="setup-dist-default" />
97 </target>
98 <!--
99 **********************************************************
100 ** dist - creates the plugin jar
101 **********************************************************
102 -->
103 <target name="dist" depends="compile,revision">
104 <echo message="creating ${ant.project.name}.jar ... "/>
105 <antcall target="setup-dist" />
106 <delete file="MANIFEST" failonerror="no"/>
107 <manifest file="MANIFEST" mode="update">
108 <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
109 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
110 <attribute name="Plugin-Class" value="${plugin.class}" />
111 <attribute name="Plugin-Description" value="${plugin.description}" />
112 <attribute name="Plugin-Date" value="${version.entry.commit.date}" />
113 <attribute name="Author" value="${plugin.author}"/>
114 </manifest>
115 <antcall target="add-manifest-attribute">
116 <param name="manifest.attribute" value="Plugin-Link"/>
117 <param name="property.name" value="plugin.link"/>
118 <param name="property.value" value="${plugin.link}"/>
119 </antcall>
120 <antcall target="add-manifest-attribute">
121 <param name="manifest.attribute" value="Plugin-Icon"/>
122 <param name="property.name" value="plugin.icon"/>
123 <param name="property.value" value="${plugin.icon}"/>
124 </antcall>
125 <antcall target="add-manifest-attribute">
126 <param name="manifest.attribute" value="Plugin-Early"/>
127 <param name="property.name" value="plugin.early"/>
128 <param name="property.value" value="${plugin.early}"/>
129 </antcall>
130 <antcall target="add-manifest-attribute">
131 <param name="manifest.attribute" value="Plugin-Requires"/>
132 <param name="property.name" value="plugin.requires"/>
133 <param name="property.value" value="${plugin.requires}"/>
134 </antcall>
135 <antcall target="add-manifest-attribute">
136 <param name="manifest.attribute" value="Plugin-Stage"/>
137 <param name="property.name" value="plugin.stage"/>
138 <param name="property.value" value="${plugin.stage}"/>
139 </antcall>
140 <antcall target="add-manifest-attribute">
141 <param name="manifest.attribute" value="Plugin-Canloadatruntime"/>
142 <param name="property.name" value="plugin.canloadatruntime"/>
143 <param name="property.value" value="${plugin.canloadatruntime}"/>
144 </antcall>
145 <antcall target="additional-manifest" />
146 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}" manifest="MANIFEST" manifestencoding="UTF-8">
147 <restrict>
148 <not><or>
149 <name name="META-INF/maven/*"/>
150 <name name="META-INF/DEPENDENCIES"/>
151 <name name="META-INF/LICENSE"/>
152 <name name="META-INF/NOTICE"/>
153 <name name="META-INF/*.RSA"/>
154 <name name="META-INF/*.SF"/>
155 </or></not>
156 <archives>
157 <zips>
158 <fileset dir="${plugin.lib.dir}" includes="*.jar" excludes="*-sources.jar, *-javadoc.jar" erroronmissingdir="no"/>
159 </zips>
160 </archives>
161 </restrict>
162 </jar>
163 <delete file="MANIFEST" failonerror="no"/>
164 <antcall target="post-dist" />
165 </target>
166 <target name="post-dist">
167 <!-- to be overidden by plugins that need to perform additional tasks on resulting jar -->
168 </target>
169 <target name="add-manifest-attribute" depends="check-manifest-attribute" if="have-${property.name}">
170 <manifest file="MANIFEST" mode="update">
171 <attribute name="${manifest.attribute}" value="${property.value}" />
172 </manifest>
173 </target>
174 <!-- target to add additional entries, empty in commons -->
175 <target name="additional-manifest">
176 </target>
177 <target name="check-manifest-attribute">
178 <condition property="have-${property.name}">
179 <and>
180 <isset property="${property.name}"/>
181 <not>
182 <equals arg1="${property.value}" arg2=""/>
183 </not>
184 <not>
185 <equals arg1="${property.value}" arg2="..."/>
186 </not>
187 </and>
188 </condition>
189 </target>
190 <!--
191 **********************************************************
192 ** revision - extracts the current revision number for the
193 ** file build.number and stores it in the XML property
194 ** version.*
195 **********************************************************
196 -->
197 <!--
198 ** Initializes the REVISION.XML file from SVN information
199 -->
200 <target name="init-svn-revision-xml">
201 <exec append="false" output="REVISION.XML" executable="svn" failifexecutionfails="false" resultproperty="svn.info.result">
202 <env key="LANG" value="C"/>
203 <arg value="info"/>
204 <arg value="--xml"/>
205 <arg value="."/>
206 </exec>
207 <condition property="svn.info.success">
208 <equals arg1="${svn.info.result}" arg2="0" />
209 </condition>
210 </target>
211 <!--
212 ** Initializes the REVISION.XML file from git-svn information.
213 Obtains the revision from the git-svn-id field.
214 -->
215 <target name="init-git-svn-revision-xml" unless="svn.info.success">
216 <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false" resultproperty="git.svn.info.result">
217 <arg value="log"/>
218 <arg value="-1"/>
219 <arg value="--grep=git-svn-id"/>
220 <!--
221 %B: raw body (unwrapped subject and body)
222 %n: new line
223 %ai: author date, ISO 8601 format
224 -->
225 <arg value="--pretty=format:%B%n%ai"/>
226 <arg value="."/>
227 </exec>
228 <replaceregexp file="REVISION.XML" flags="s"
229 match=".*git-svn-id: [^@]*@([0-9]+).*(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
230 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;"/>
231 <condition property="git.svn.fail">
232 <not>
233 <and>
234 <equals arg1="${git.svn.info.result}" arg2="0" />
235 <length file="REVISION.XML" when="greater" length="1" />
236 </and>
237 </not>
238 </condition>
239 </target>
240 <!--
241 ** Initializes the REVISION.XML file from git (w/o svn) information.
242 Uses Unix date as revision number.
243 -->
244 <target name="init-git-revision-xml" if="git.svn.fail">
245 <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false" resultproperty="git.info.result">
246 <arg value="log"/>
247 <arg value="-1"/>
248 <arg value="--pretty=format:%at%n%ai"/>
249 <arg value="."/>
250 </exec>
251 <replaceregexp file="REVISION.XML" flags="s"
252 match="\s*(\d*)\s+(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
253 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;"/>
254 <condition property="git.fail">
255 <not>
256 <and>
257 <equals arg1="${git.info.result}" arg2="0" />
258 <length file="REVISION.XML" when="greater" length="1" />
259 </and>
260 </not>
261 </condition>
262 </target>
263 <target name="init-revision-fallback" if="git.fail">
264 <tstamp>
265 <format property="current.time" pattern="yyyy-MM-dd'T'HH:mm:ss.SSS" />
266 </tstamp>
267 <echo file="REVISION.XML"><![CDATA[<info><entry><commit revision="UNKNOWN"><date>${current.time}</date></commit></entry></info>]]></echo>
268 </target>
269 <target name="revision" depends="init-svn-revision-xml, init-git-svn-revision-xml, init-git-revision-xml, init-revision-fallback">
270 <xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
271 <delete file="REVISION.XML"/>
272 </target>
273 <!--
274 **********************************************************
275 ** clean - clean up the build environment
276 **********************************************************
277 -->
278 <target name="clean">
279 <delete dir="${plugin.build.dir}"/>
280 <delete file="${plugin.jar}"/>
281 </target>
282 <!--
283 **********************************************************
284 ** install - install the plugin in your local JOSM installation
285 **********************************************************
286 -->
287 <target name="install" depends="dist">
288 <property environment="env"/>
289 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins">
290 <and>
291 <os family="windows"/>
292 </and>
293 </condition>
294 <condition property="josm.plugins.dir" value="${user.home}/Library/JOSM/plugins">
295 <and>
296 <os family="mac"/>
297 </and>
298 </condition>
299 <condition property="josm.plugins.dir" value="${user.home}/.josm/plugins">
300 <and>
301 <not><os family="windows"/></not>
302 <not><os family="mac"/></not>
303 </and>
304 </condition>
305 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
306 </target>
307 <!--
308 ************************** Publishing the plugin ***********************************
309 -->
310 <!--
311 ** extracts the JOSM release for the JOSM version in ../core and saves it in the
312 ** property ${coreversion.info.entry.revision}
313 **
314 -->
315 <target name="core-info">
316 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
317 <env key="LANG" value="C"/>
318 <arg value="info"/>
319 <arg value="--xml"/>
320 <arg value="../../core"/>
321 </exec>
322 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
323 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
324 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
325 <delete file="core.info.xml"/>
326 </target>
327 <!--
328 ** commits the source tree for this plugin
329 -->
330 <target name="commit-current">
331 <echo>Commiting the plugin source with message '${commit.message}' ...</echo>
332 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
333 <env key="LANG" value="C"/>
334 <arg value="commit"/>
335 <arg value="-m"/>
336 <arg value="${commit.message}"/>
337 <arg value="."/>
338 </exec>
339 </target>
340 <!--
341 ** updates (svn up) the source tree for this plugin
342 -->
343 <target name="update-current">
344 <echo>Updating plugin source ...</echo>
345 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
346 <env key="LANG" value="C"/>
347 <arg value="up"/>
348 <arg value="."/>
349 </exec>
350 <echo>Updating ${plugin.jar} ...</echo>
351 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
352 <env key="LANG" value="C"/>
353 <arg value="up"/>
354 <arg value="../dist/${plugin.jar}"/>
355 </exec>
356 </target>
357 <!--
358 ** commits the plugin.jar
359 -->
360 <target name="commit-dist">
361 <echo>
362 ***** Properties of published ${plugin.jar} *****
363 Commit message : '${commit.message}'
364 Plugin-Mainversion: ${plugin.main.version}
365 JOSM build version: ${coreversion.info.entry.revision}
366 Plugin-Version : ${version.entry.commit.revision}
367 ***** / Properties of published ${plugin.jar} *****
368
369 Now commiting ${plugin.jar} ...
370 </echo>
371 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
372 <env key="LANG" value="C"/>
373 <arg value="-m"/>
374 <arg value="${commit.message}"/>
375 <arg value="commit"/>
376 <arg value="${plugin.jar}"/>
377 </exec>
378 </target>
379 <!-- ** make sure svn is present as a command line tool ** -->
380 <target name="ensure-svn-present">
381 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">
382 <env key="LANG" value="C"/>
383 <arg value="--version"/>
384 </exec>
385 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">
386 <!-- return code not set at all? Most likely svn isn't installed -->
387 <condition>
388 <not>
389 <isset property="svn.exit.code"/>
390 </not>
391 </condition>
392 </fail>
393 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">
394 <!-- error code from SVN? Most likely svn is not what we are looking on this system -->
395 <condition>
396 <isfailure code="${svn.exit.code}"/>
397 </condition>
398 </fail>
399 </target>
400
401 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
402 </target>
403
404 <path id="test.classpath">
405 <fileset dir="../00_core_test_lib">
406 <include name="**/*.jar"/>
407 </fileset>
408 <fileset dir="${plugin.test.dir}/lib" erroronmissingdir="no">
409 <include name="**/*.jar"/>
410 <exclude name="**/*-sources.jar"/>
411 <exclude name="**/*-javadoc.jar"/>
412 </fileset>
413 <fileset dir="lib" erroronmissingdir="no">
414 <include name="**/*.jar"/>
415 <exclude name="**/*-sources.jar"/>
416 <exclude name="**/*-javadoc.jar"/>
417 </fileset>
418 <pathelement path="${plugin.test.dir}/data"/>
419 <pathelement path="${josm.test.build.dir}/unit"/>
420 <pathelement path="${josm}"/>
421 <pathelement path="${plugin.jar}"/>
422 <pathelement path="${groovy.jar}"/>
423 <pathelement path="${annotations.jar}"/>
424 </path>
425 <macrodef name="init-test-preferences">
426 <sequential>
427 <copy file="${plugin.test.dir}/config/preferences.template.xml" tofile="${plugin.test.dir}/config/unit-josm.home/preferences.xml"/>
428 <replace file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_USERNAME@" value="${osm.username}"/>
429 <replace file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_PASSWORD@" value="${osm.password}"/>
430 </sequential>
431 </macrodef>
432 <target name="check-test">
433 <available file="${plugin.test.dir}" type="dir" property="test.present"/>
434 </target>
435 <target name="test-init" depends="check-test" if="test.present">
436 <mkdir dir="${plugin.test.dir}/build"/>
437 <mkdir dir="${plugin.test.dir}/build/unit"/>
438 <mkdir dir="${plugin.test.dir}/report"/>
439 <init-test-preferences/>
440 </target>
441 <target name="test-clean">
442 <delete dir="${plugin.test.dir}/build"/>
443 <delete dir="${plugin.test.dir}/report"/>
444 <delete file="${plugin.test.dir}/jacoco.exec" />
445 <delete file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" />
446 <delete dir="${plugin.test.dir}/config/unit-josm.home/cache" failonerror="false"/>
447 </target>
448 <target name="test-compile" depends="test-init,dist" if="test.present">
449 <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpath="${groovy.jar}"/>
450 <sequential>
451 <groovyc srcdir="${plugin.test.dir}/unit" destdir="${plugin.test.dir}/build/unit" encoding="UTF-8">
452 <classpath>
453 <fileset refid="plugin.requires.jars"/>
454 <path refid="test.classpath"/>
455 </classpath>
456 <javac target="1.7" source="1.7" debug="on" encoding="UTF-8">
457 <compilerarg value="-Xlint:all"/>
458 <compilerarg value="-Xlint:-serial"/>
459 </javac>
460 </groovyc>
461 </sequential>
462 </target>
463 <target name="test" depends="dist, test-clean, test-compile" if="test.present"
464 description="Run unit tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
465 <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="../00_core_tools/jacocoant.jar" />
466 <sequential>
467 <echo message="Running unit tests with JUnit"/>
468 <jacoco:coverage destfile="${plugin.test.dir}/jacoco.exec">
469 <junit printsummary="yes" fork="true" forkmode="once" dir="${basedir}">
470 <jvmarg value="-Dfile.encoding=UTF-8"/>
471 <sysproperty key="josm.home" value="${plugin.test.dir}/config/unit-josm.home"/>
472 <sysproperty key="josm.test.data" value="${plugin.test.dir}/data"/>
473 <sysproperty key="java.awt.headless" value="true"/>
474 <sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
475 <classpath>
476 <fileset refid="plugin.requires.jars"/>
477 <path refid="test.classpath"/>
478 <pathelement path="${plugin.test.dir}/build/unit"/>
479 </classpath>
480 <formatter type="plain"/>
481 <formatter type="xml"/>
482 <batchtest fork="yes" todir="${plugin.test.dir}/report">
483 <fileset dir="${plugin.test.dir}/build/unit" includes="**/*Test.class"/>
484 </batchtest>
485 </junit>
486 </jacoco:coverage>
487 </sequential>
488 </target>
489
490 <target name="runjosm" depends="install">
491 <java jar="${josm}" fork="true">
492 </java>
493 </target>
494
495 <target name="profilejosm" depends="install">
496 <nbprofiledirect>
497 </nbprofiledirect>
498 <java jar="${josm}" fork="true">
499 <jvmarg value="${profiler.info.jvmargs.agent}"/>
500 </java>
501 </target>
502 <!--
503 ** shows a help text
504 -->
505 <target name="help">
506 <echo>
507 You can use following targets:
508 * dist This default target builds the plugin jar file
509 * clean Cleanup automatical created files
510 * test Run unit tests (if any)
511 * publish Checkin source code, build jar and checkin plugin jar
512 (requires proper entry for SVN commit message!)
513 * install Install the plugin in current system
514 * runjosm Install plugin and start josm
515 * profilejosm Install plugin and start josm in profiling mode
516
517 There are other targets, which usually should not be called manually.
518 </echo>
519 </target>
520</project>
Note: See TracBrowser for help on using the repository browser.