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

Last change on this file since 31248 was 31070, checked in by donvip, 9 years ago

[josm_plugins] update to Groovy 2.4.3

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