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

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

fix findbugs task configuration

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