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

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

[josm_plugins] refactor common build file

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