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

Last change on this file since 30639 was 30562, checked in by donvip, 10 years ago

[josm_plugins] support for unit tests

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