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

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

[josm_plugins] support for unit tests

File size: 20.9 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.4.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="propery.name" value="plugin.link"/>
100 <param name="propery.value" value="${plugin.link}"/>
101 </antcall>
102 <antcall target="add-manifest-attribute">
103 <param name="manifest.attribute" value="Plugin-Icon"/>
104 <param name="propery.name" value="plugin.icon"/>
105 <param name="propery.value" value="${plugin.icon}"/>
106 </antcall>
107 <antcall target="add-manifest-attribute">
108 <param name="manifest.attribute" value="Plugin-Early"/>
109 <param name="propery.name" value="plugin.early"/>
110 <param name="propery.value" value="${plugin.early}"/>
111 </antcall>
112 <antcall target="add-manifest-attribute">
113 <param name="manifest.attribute" value="Plugin-Requires"/>
114 <param name="propery.name" value="plugin.requires"/>
115 <param name="propery.value" value="${plugin.requires}"/>
116 </antcall>
117 <antcall target="add-manifest-attribute">
118 <param name="manifest.attribute" value="Plugin-Stage"/>
119 <param name="propery.name" value="plugin.stage"/>
120 <param name="propery.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-${propery.name}">
133 <manifest file="MANIFEST" mode="update">
134 <attribute name="${manifest.attribute}" value="${propery.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-${propery.name}">
142 <and>
143 <isset property="${propery.name}"/>
144 <not>
145 <equals arg1="${propery.value}" arg2=""/>
146 </not>
147 <not>
148 <equals arg1="${propery.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 <macrodef name="init-test-preferences">
372 <attribute name="testfamily"/>
373 <sequential>
374 <copy file="${plugin.test.dir}/config/preferences.template.xml" tofile="${plugin.test.dir}/config/@{testfamily}-josm.home/preferences.xml"/>
375 <replace file="${plugin.test.dir}/config/@{testfamily}-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_USERNAME@" value="${osm.username}"/>
376 <replace file="${plugin.test.dir}/config/@{testfamily}-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_PASSWORD@" value="${osm.password}"/>
377 </sequential>
378 </macrodef>
379 <target name="test-init">
380 <mkdir dir="${plugin.test.dir}/build"/>
381 <mkdir dir="${plugin.test.dir}/build/unit"/>
382 <mkdir dir="${plugin.test.dir}/report"/>
383 <init-test-preferences testfamily="unit"/>
384 </target>
385 <target name="test-clean">
386 <delete dir="${plugin.test.dir}/build"/>
387 <delete dir="${plugin.test.dir}/report"/>
388 <delete file="${plugin.test.dir}/jacoco.exec" />
389 <delete file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" />
390 <delete dir="${plugin.test.dir}/config/unit-josm.home/cache" failonerror="false"/>
391 </target>
392 <macrodef name="call-groovyc">
393 <attribute name="testfamily"/>
394 <element name="cp-elements"/>
395 <sequential>
396 <groovyc srcdir="${plugin.test.dir}/@{testfamily}" destdir="${plugin.test.dir}/build/@{testfamily}" encoding="UTF-8">
397 <classpath>
398 <cp-elements/>
399 </classpath>
400 <javac target="1.7" source="1.7" debug="on">
401 <compilerarg value="-Xlint:all"/>
402 <compilerarg value="-Xlint:-serial"/>
403 </javac>
404 </groovyc>
405 </sequential>
406 </macrodef>
407 <target name="test-compile" depends="test-init,dist">
408 <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpath="${groovy.jar}"/>
409 <call-groovyc testfamily="unit">
410 <cp-elements>
411 <path refid="test.classpath"/>
412 </cp-elements>
413 </call-groovyc>
414 </target>
415 <macrodef name="call-junit">
416 <attribute name="testfamily"/>
417 <sequential>
418 <echo message="Running @{testfamily} tests with JUnit"/>
419 <jacoco:coverage destfile="${plugin.test.dir}/jacoco.exec">
420 <junit printsummary="yes" fork="true" forkmode="once" dir="${basedir}">
421 <sysproperty key="josm.home" value="${plugin.test.dir}/config/@{testfamily}-josm.home"/>
422 <sysproperty key="josm.test.data" value="${plugin.test.dir}/data"/>
423 <sysproperty key="java.awt.headless" value="true"/>
424 <sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
425 <classpath>
426 <path refid="test.classpath"/>
427 <pathelement path="${plugin.test.dir}/build/unit"/>
428 <pathelement path="${plugin.test.dir}/build/@{testfamily}"/>
429 <pathelement path="${plugin.test.dir}/config"/>
430 </classpath>
431 <formatter type="plain"/>
432 <formatter type="xml"/>
433 <batchtest fork="yes" todir="${plugin.test.dir}/report">
434 <fileset dir="${plugin.test.dir}/build/@{testfamily}" includes="**/*Test.class"/>
435 </batchtest>
436 </junit>
437 </jacoco:coverage>
438 </sequential>
439 </macrodef>
440 <target name="test" depends="test-compile"
441 description="Run unit tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
442 <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="../00_core_tools/jacocoant.jar" />
443 <call-junit testfamily="unit"/>
444 </target>
445
446 <target name="runjosm" depends="install">
447 <java jar="${josm}" fork="true">
448 </java>
449 </target>
450
451 <target name="profilejosm" depends="install">
452 <nbprofiledirect>
453 </nbprofiledirect>
454 <java jar="${josm}" fork="true">
455 <jvmarg value="${profiler.info.jvmargs.agent}"/>
456 </java>
457 </target>
458 <!--
459 ** shows a help text
460 -->
461 <target name="help">
462 <echo>
463 You can use following targets:
464 * dist This default target builds the plugin jar file
465 * clean Cleanup automatical created files
466 * test Run unit tests (if any)
467 * publish Checkin source code, build jar and checkin plugin jar
468 (requires proper entry for SVN commit message!)
469 * install Install the plugin in current system
470 * runjosm Install plugin and start josm
471 * profilejosm Install plugin and start josm in profiling mode
472
473 There are other targets, which usually should not be called manually.
474 </echo>
475 </target>
476</project>
477
Note: See TracBrowser for help on using the repository browser.