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

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

[josm_plugins] support for unit tests

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