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

Last change on this file since 31909 was 31886, checked in by simon04, 9 years ago

JOSM: plugins built from a Git repository now use the revision when the plugin was actually changed

File size: 22.5 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.5.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" manifestencoding="UTF-8">
146 <restrict>
147 <not><or>
148 <name name="META-INF/maven/*"/>
149 <name name="META-INF/DEPENDENCIES"/>
150 <name name="META-INF/LICENSE"/>
151 <name name="META-INF/NOTICE"/>
152 </or></not>
153 <archives>
154 <zips>
155 <fileset dir="${plugin.lib.dir}" includes="*.jar" excludes="*-sources.jar, *-javadoc.jar" erroronmissingdir="no"/>
156 </zips>
157 </archives>
158 </restrict>
159 </jar>
160 <delete file="MANIFEST" failonerror="no"/>
161 <antcall target="post-dist" />
162 </target>
163 <target name="post-dist">
164 <!-- to be overidden by plugins that need to perform additional tasks on resulting jar -->
165 </target>
166 <target name="add-manifest-attribute" depends="check-manifest-attribute" if="have-${property.name}">
167 <manifest file="MANIFEST" mode="update">
168 <attribute name="${manifest.attribute}" value="${property.value}" />
169 </manifest>
170 </target>
171 <!-- target to add additional entries, empty in commons -->
172 <target name="additional-manifest">
173 </target>
174 <target name="check-manifest-attribute">
175 <condition property="have-${property.name}">
176 <and>
177 <isset property="${property.name}"/>
178 <not>
179 <equals arg1="${property.value}" arg2=""/>
180 </not>
181 <not>
182 <equals arg1="${property.value}" arg2="..."/>
183 </not>
184 </and>
185 </condition>
186 </target>
187 <!--
188 **********************************************************
189 ** revision - extracts the current revision number for the
190 ** file build.number and stores it in the XML property
191 ** version.*
192 **********************************************************
193 -->
194 <!--
195 ** Initializes the REVISION.XML file from SVN information
196 -->
197 <target name="init-svn-revision-xml">
198 <exec append="false" output="REVISION.XML" executable="svn" failifexecutionfails="false" resultproperty="svn.info.result">
199 <env key="LANG" value="C"/>
200 <arg value="info"/>
201 <arg value="--xml"/>
202 <arg value="."/>
203 </exec>
204 <condition property="svn.info.success">
205 <equals arg1="${svn.info.result}" arg2="0" />
206 </condition>
207 </target>
208 <!--
209 ** Initializes the REVISION.XML file from git-svn information.
210 Obtains the revision from the git-svn-id field.
211 -->
212 <target name="init-git-svn-revision-xml" unless="svn.info.success">
213 <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false" resultproperty="git.svn.info.result">
214 <arg value="log"/>
215 <arg value="-1"/>
216 <arg value="--grep=git-svn-id"/>
217 <!--
218 %B: raw body (unwrapped subject and body)
219 %n: new line
220 %ai: author date, ISO 8601 format
221 -->
222 <arg value="--pretty=format:%B%n%ai"/>
223 <arg value="."/>
224 </exec>
225 <replaceregexp file="REVISION.XML" flags="s"
226 match=".*git-svn-id: [^@]*@([0-9]+).*(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
227 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;"/>
228 <condition property="git.svn.fail">
229 <not>
230 <and>
231 <equals arg1="${git.svn.info.result}" arg2="0" />
232 <length file="REVISION.XML" when="greater" length="1" />
233 </and>
234 </not>
235 </condition>
236 </target>
237 <!--
238 ** Initializes the REVISION.XML file from git (w/o svn) information.
239 Uses Unix date as revision number.
240 -->
241 <target name="init-git-revision-xml" if="git.svn.fail">
242 <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false" resultproperty="git.info.result">
243 <arg value="log"/>
244 <arg value="-1"/>
245 <arg value="--pretty=format:%at%n%ai"/>
246 <arg value="."/>
247 </exec>
248 <replaceregexp file="REVISION.XML" flags="s"
249 match="\s*(\d*)\s+(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
250 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;"/>
251 <condition property="git.fail">
252 <not>
253 <and>
254 <equals arg1="${git.info.result}" arg2="0" />
255 <length file="REVISION.XML" when="greater" length="1" />
256 </and>
257 </not>
258 </condition>
259 </target>
260 <target name="init-revision-fallback" if="git.fail">
261 <tstamp>
262 <format property="current.time" pattern="yyyy-MM-dd'T'HH:mm:ss.SSS" />
263 </tstamp>
264 <echo file="REVISION.XML"><![CDATA[<info><entry><commit revision="UNKNOWN"><date>${current.time}</date></commit></entry></info>]]></echo>
265 </target>
266 <target name="revision" depends="init-svn-revision-xml, init-git-svn-revision-xml, init-git-revision-xml, init-revision-fallback">
267 <xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
268 <delete file="REVISION.XML"/>
269 </target>
270 <!--
271 **********************************************************
272 ** clean - clean up the build environment
273 **********************************************************
274 -->
275 <target name="clean">
276 <delete dir="${plugin.build.dir}"/>
277 <delete file="${plugin.jar}"/>
278 </target>
279 <!--
280 **********************************************************
281 ** install - install the plugin in your local JOSM installation
282 **********************************************************
283 -->
284 <target name="install" depends="dist">
285 <property environment="env"/>
286 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins">
287 <and>
288 <os family="windows"/>
289 </and>
290 </condition>
291 <condition property="josm.plugins.dir" value="${user.home}/Library/JOSM/plugins">
292 <and>
293 <os family="mac"/>
294 </and>
295 </condition>
296 <condition property="josm.plugins.dir" value="${user.home}/.josm/plugins">
297 <and>
298 <not><os family="windows"/></not>
299 <not><os family="mac"/></not>
300 </and>
301 </condition>
302 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
303 </target>
304 <!--
305 ************************** Publishing the plugin ***********************************
306 -->
307 <!--
308 ** extracts the JOSM release for the JOSM version in ../core and saves it in the
309 ** property ${coreversion.info.entry.revision}
310 **
311 -->
312 <target name="core-info">
313 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
314 <env key="LANG" value="C"/>
315 <arg value="info"/>
316 <arg value="--xml"/>
317 <arg value="../../core"/>
318 </exec>
319 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
320 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
321 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
322 <delete file="core.info.xml"/>
323 </target>
324 <!--
325 ** commits the source tree for this plugin
326 -->
327 <target name="commit-current">
328 <echo>Commiting the plugin source with message '${commit.message}' ...</echo>
329 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
330 <env key="LANG" value="C"/>
331 <arg value="commit"/>
332 <arg value="-m"/>
333 <arg value="${commit.message}"/>
334 <arg value="."/>
335 </exec>
336 </target>
337 <!--
338 ** updates (svn up) the source tree for this plugin
339 -->
340 <target name="update-current">
341 <echo>Updating plugin source ...</echo>
342 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
343 <env key="LANG" value="C"/>
344 <arg value="up"/>
345 <arg value="."/>
346 </exec>
347 <echo>Updating ${plugin.jar} ...</echo>
348 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
349 <env key="LANG" value="C"/>
350 <arg value="up"/>
351 <arg value="../dist/${plugin.jar}"/>
352 </exec>
353 </target>
354 <!--
355 ** commits the plugin.jar
356 -->
357 <target name="commit-dist">
358 <echo>
359 ***** Properties of published ${plugin.jar} *****
360 Commit message : '${commit.message}'
361 Plugin-Mainversion: ${plugin.main.version}
362 JOSM build version: ${coreversion.info.entry.revision}
363 Plugin-Version : ${version.entry.commit.revision}
364 ***** / Properties of published ${plugin.jar} *****
365
366 Now commiting ${plugin.jar} ...
367 </echo>
368 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
369 <env key="LANG" value="C"/>
370 <arg value="-m"/>
371 <arg value="${commit.message}"/>
372 <arg value="commit"/>
373 <arg value="${plugin.jar}"/>
374 </exec>
375 </target>
376 <!-- ** make sure svn is present as a command line tool ** -->
377 <target name="ensure-svn-present">
378 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">
379 <env key="LANG" value="C"/>
380 <arg value="--version"/>
381 </exec>
382 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">
383 <!-- return code not set at all? Most likely svn isn't installed -->
384 <condition>
385 <not>
386 <isset property="svn.exit.code"/>
387 </not>
388 </condition>
389 </fail>
390 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">
391 <!-- error code from SVN? Most likely svn is not what we are looking on this system -->
392 <condition>
393 <isfailure code="${svn.exit.code}"/>
394 </condition>
395 </fail>
396 </target>
397
398 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
399 </target>
400
401 <path id="test.classpath">
402 <fileset dir="../00_core_test_lib">
403 <include name="**/*.jar"/>
404 </fileset>
405 <fileset dir="${plugin.test.dir}/lib" erroronmissingdir="no">
406 <include name="**/*.jar"/>
407 <exclude name="**/*-sources.jar"/>
408 <exclude name="**/*-javadoc.jar"/>
409 </fileset>
410 <fileset dir="lib" erroronmissingdir="no">
411 <include name="**/*.jar"/>
412 <exclude name="**/*-sources.jar"/>
413 <exclude name="**/*-javadoc.jar"/>
414 </fileset>
415 <pathelement path="${josm.test.build.dir}/unit"/>
416 <pathelement path="${josm}"/>
417 <pathelement path="${plugin.jar}"/>
418 <pathelement path="${groovy.jar}"/>
419 </path>
420 <macrodef name="init-test-preferences">
421 <sequential>
422 <copy file="${plugin.test.dir}/config/preferences.template.xml" tofile="${plugin.test.dir}/config/unit-josm.home/preferences.xml"/>
423 <replace file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_USERNAME@" value="${osm.username}"/>
424 <replace file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_PASSWORD@" value="${osm.password}"/>
425 </sequential>
426 </macrodef>
427 <target name="test-init">
428 <mkdir dir="${plugin.test.dir}/build"/>
429 <mkdir dir="${plugin.test.dir}/build/unit"/>
430 <mkdir dir="${plugin.test.dir}/report"/>
431 <init-test-preferences/>
432 </target>
433 <target name="test-clean">
434 <delete dir="${plugin.test.dir}/build"/>
435 <delete dir="${plugin.test.dir}/report"/>
436 <delete file="${plugin.test.dir}/jacoco.exec" />
437 <delete file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" />
438 <delete dir="${plugin.test.dir}/config/unit-josm.home/cache" failonerror="false"/>
439 </target>
440 <target name="test-compile" depends="test-init,dist">
441 <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpath="${groovy.jar}"/>
442 <sequential>
443 <groovyc srcdir="${plugin.test.dir}/unit" destdir="${plugin.test.dir}/build/unit" encoding="UTF-8">
444 <classpath>
445 <fileset refid="plugin.requires.jars"/>
446 <path refid="test.classpath"/>
447 </classpath>
448 <javac target="1.7" source="1.7" debug="on" encoding="UTF-8">
449 <compilerarg value="-Xlint:all"/>
450 <compilerarg value="-Xlint:-serial"/>
451 </javac>
452 </groovyc>
453 </sequential>
454 </target>
455 <target name="test" depends="dist, test-clean, test-compile"
456 description="Run unit tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
457 <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="../00_core_tools/jacocoant.jar" />
458 <sequential>
459 <echo message="Running unit tests with JUnit"/>
460 <jacoco:coverage destfile="${plugin.test.dir}/jacoco.exec">
461 <junit printsummary="yes" fork="true" forkmode="once" dir="${basedir}">
462 <jvmarg value="-Dfile.encoding=UTF-8"/>
463 <sysproperty key="josm.home" value="${plugin.test.dir}/config/unit-josm.home"/>
464 <sysproperty key="josm.test.data" value="${plugin.test.dir}/data"/>
465 <sysproperty key="java.awt.headless" value="true"/>
466 <sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
467 <classpath>
468 <fileset refid="plugin.requires.jars"/>
469 <path refid="test.classpath"/>
470 <pathelement path="${plugin.test.dir}/build/unit"/>
471 </classpath>
472 <formatter type="plain"/>
473 <formatter type="xml"/>
474 <batchtest fork="yes" todir="${plugin.test.dir}/report">
475 <fileset dir="${plugin.test.dir}/build/unit" includes="**/*Test.class"/>
476 </batchtest>
477 </junit>
478 </jacoco:coverage>
479 </sequential>
480 </target>
481
482 <target name="runjosm" depends="install">
483 <java jar="${josm}" fork="true">
484 </java>
485 </target>
486
487 <target name="profilejosm" depends="install">
488 <nbprofiledirect>
489 </nbprofiledirect>
490 <java jar="${josm}" fork="true">
491 <jvmarg value="${profiler.info.jvmargs.agent}"/>
492 </java>
493 </target>
494 <!--
495 ** shows a help text
496 -->
497 <target name="help">
498 <echo>
499 You can use following targets:
500 * dist This default target builds the plugin jar file
501 * clean Cleanup automatical created files
502 * test Run unit tests (if any)
503 * publish Checkin source code, build jar and checkin plugin jar
504 (requires proper entry for SVN commit message!)
505 * install Install the plugin in current system
506 * runjosm Install plugin and start josm
507 * profilejosm Install plugin and start josm in profiling mode
508
509 There are other targets, which usually should not be called manually.
510 </echo>
511 </target>
512</project>
513
Note: See TracBrowser for help on using the repository browser.