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

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

[josm_opendata] remove generated source files

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