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

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

JOSM/pluins: revert build-common.xml modification from r31470 - this broke building of all plugins!

Please ask before applying changes to shared build files.

File size: 22.5 KB
RevLine 
[26341]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-->
[30550]13<project name="plugin_common" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
[26341]14
[31508]15 <property name="josm" location="../../core/dist/josm-custom.jar"/>
16 <property name="josm.test.build.dir" location="../../core/test/build"/>
[31070]17 <property name="groovy.jar" location="../00_core_tools/groovy-all-2.4.3.jar"/>
[30550]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"/>
[26341]22 <!-- this is the directory where the plugin jar is copied to -->
[30550]23 <property name="plugin.dist.dir" location="../../dist"/>
[30416]24 <property name="ant.build.javac.target" value="1.7"/>
25 <property name="ant.build.javac.source" value="1.7"/>
[30550]26 <property name="plugin.jar" location="${plugin.dist.dir}/${ant.project.name}.jar"/>
[26341]27
[30699]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
[30747]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
[26341]42 <!--
43 **********************************************************
44 ** init - initializes the build
45 **********************************************************
46 -->
47 <target name="init">
48 <mkdir dir="${plugin.build.dir}"/>
49 </target>
50 <!--
51 **********************************************************
[29442]52 ** compile - compiles the source tree
[26341]53 **********************************************************
54 -->
55 <target name="compile" depends="init">
[28290]56 <echo message="compiling sources for ${plugin.jar} ..."/>
[29694]57 <javac srcdir="src" debug="true" destdir="${plugin.build.dir}" includeantruntime="false" encoding="UTF-8">
[26341]58 <compilerarg value="-Xlint:deprecation"/>
59 <compilerarg value="-Xlint:unchecked"/>
[28990]60 <classpath>
61 <pathelement location="${josm}"/>
62 <fileset dir="${plugin.lib.dir}" erroronmissingdir="no">
63 <include name="**/*.jar"/>
[30820]64 <exclude name="**/*-sources.jar"/>
65 <exclude name="**/*-javadoc.jar"/>
[28990]66 </fileset>
[30747]67 <fileset refid="plugin.requires.jars"/>
[28990]68 </classpath>
[26341]69 </javac>
70 </target>
71 <!--
72 **********************************************************
[29005]73 ** setup-dist - copies files for distribution
[28990]74 **********************************************************
75 -->
[29005]76 <target name="setup-dist-default">
[28990]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"/>
[28996]89 <include name="LICENSE*"/>
90 <include name="*GPL*"/>
[28990]91 </fileset>
92 </copy>
[29005]93 </target>
94 <target name="setup-dist">
[29007]95 <antcall target="setup-dist-default" />
[29005]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 ... "/>
[29007]104 <antcall target="setup-dist" />
[28990]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"/>
[30562]116 <param name="property.name" value="plugin.link"/>
117 <param name="property.value" value="${plugin.link}"/>
[28990]118 </antcall>
119 <antcall target="add-manifest-attribute">
120 <param name="manifest.attribute" value="Plugin-Icon"/>
[30562]121 <param name="property.name" value="plugin.icon"/>
122 <param name="property.value" value="${plugin.icon}"/>
[28990]123 </antcall>
124 <antcall target="add-manifest-attribute">
125 <param name="manifest.attribute" value="Plugin-Early"/>
[30562]126 <param name="property.name" value="plugin.early"/>
127 <param name="property.value" value="${plugin.early}"/>
[28990]128 </antcall>
129 <antcall target="add-manifest-attribute">
130 <param name="manifest.attribute" value="Plugin-Requires"/>
[30562]131 <param name="property.name" value="plugin.requires"/>
132 <param name="property.value" value="${plugin.requires}"/>
[28990]133 </antcall>
134 <antcall target="add-manifest-attribute">
135 <param name="manifest.attribute" value="Plugin-Stage"/>
[30562]136 <param name="property.name" value="plugin.stage"/>
137 <param name="property.value" value="${plugin.stage}"/>
[28990]138 </antcall>
[30952]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>
[29435]144 <antcall target="additional-manifest" />
[28990]145 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}" manifest="MANIFEST">
[31281]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>
[28990]159 </jar>
160 <delete file="MANIFEST" failonerror="no"/>
[29007]161 <antcall target="post-dist" />
[28990]162 </target>
[29007]163 <target name="post-dist">
[31281]164 <!-- to be overidden by plugins that need to perform additional tasks on resulting jar -->
[29007]165 </target>
[30562]166 <target name="add-manifest-attribute" depends="check-manifest-attribute" if="have-${property.name}">
[28990]167 <manifest file="MANIFEST" mode="update">
[30562]168 <attribute name="${manifest.attribute}" value="${property.value}" />
[28990]169 </manifest>
170 </target>
[29435]171 <!-- target to add additional entries, empty in commons -->
172 <target name="additional-manifest">
173 </target>
[28990]174 <target name="check-manifest-attribute">
[30562]175 <condition property="have-${property.name}">
[28990]176 <and>
[30562]177 <isset property="${property.name}"/>
[28990]178 <not>
[30562]179 <equals arg1="${property.value}" arg2=""/>
[28990]180 </not>
181 <not>
[30562]182 <equals arg1="${property.value}" arg2="..."/>
[28990]183 </not>
184 </and>
185 </condition>
186 </target>
187 <!--
188 **********************************************************
[26341]189 ** revision - extracts the current revision number for the
190 ** file build.number and stores it in the XML property
191 ** version.*
192 **********************************************************
193 -->
[30161]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">
[26341]199 <env key="LANG" value="C"/>
200 <arg value="info"/>
201 <arg value="--xml"/>
202 <arg value="."/>
203 </exec>
[30161]204 <condition property="svn.info.success">
205 <equals arg1="${svn.info.result}" arg2="0" />
206 </condition>
[26341]207 </target>
208 <!--
[30306]209 ** Initializes the REVISION.XML file from git-svn information.
210 Obtains the revision from the git-svn-id field.
[30161]211 -->
[30306]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">
[30161]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="HEAD"/>
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;"/>
[30306]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>
[30562]236 </target>
[30306]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">
[30309]242 <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false" resultproperty="git.info.result">
[30306]243 <arg value="log"/>
244 <arg value="-1"/>
245 <arg value="--pretty=format:%at%n%ai"/>
246 <arg value="HEAD"/>
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;"/>
[30309]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>
[30161]259 </target>
[30309]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">
[30161]267 <xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
268 <delete file="REVISION.XML"/>
269 </target>
270 <!--
[26341]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"/>
[30907]286 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins">
[26341]287 <and>
288 <os family="windows"/>
289 </and>
290 </condition>
[30896]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>
[26341]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"/>
[28400]332 <arg value="-m"/>
333 <arg value="${commit.message}"/>
[26341]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} *****
[27960]360 Commit message : '${commit.message}'
[26341]361 Plugin-Mainversion: ${plugin.main.version}
362 JOSM build version: ${coreversion.info.entry.revision}
363 Plugin-Version : ${version.entry.commit.revision}
[27960]364 ***** / Properties of published ${plugin.jar} *****
365
[26341]366 Now commiting ${plugin.jar} ...
367 </echo>
368 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
369 <env key="LANG" value="C"/>
[28400]370 <arg value="-m"/>
371 <arg value="${commit.message}"/>
[26341]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>
[28807]397
[26341]398 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
399 </target>
[31281]400
[30550]401 <path id="test.classpath">
[30552]402 <fileset dir="../00_core_test_lib">
[30550]403 <include name="**/*.jar"/>
404 </fileset>
405 <fileset dir="${plugin.test.dir}/lib" erroronmissingdir="no">
406 <include name="**/*.jar"/>
[30820]407 <exclude name="**/*-sources.jar"/>
408 <exclude name="**/*-javadoc.jar"/>
[30550]409 </fileset>
410 <fileset dir="lib" erroronmissingdir="no">
411 <include name="**/*.jar"/>
[30820]412 <exclude name="**/*-sources.jar"/>
413 <exclude name="**/*-javadoc.jar"/>
[30550]414 </fileset>
[30553]415 <pathelement path="${josm.test.build.dir}/unit"/>
[30550]416 <pathelement path="${josm}"/>
417 <pathelement path="${plugin.jar}"/>
418 <pathelement path="${groovy.jar}"/>
419 </path>
420 <macrodef name="init-test-preferences">
421 <sequential>
[30562]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}"/>
[30550]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"/>
[30562]431 <init-test-preferences/>
[30550]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>
[30747]440 <target name="test-compile" depends="test-init,dist">
441 <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpath="${groovy.jar}"/>
[30550]442 <sequential>
[30562]443 <groovyc srcdir="${plugin.test.dir}/unit" destdir="${plugin.test.dir}/build/unit" encoding="UTF-8">
[30550]444 <classpath>
[30747]445 <fileset refid="plugin.requires.jars"/>
[30562]446 <path refid="test.classpath"/>
[30550]447 </classpath>
[30562]448 <javac target="1.7" source="1.7" debug="on" encoding="UTF-8">
[30550]449 <compilerarg value="-Xlint:all"/>
450 <compilerarg value="-Xlint:-serial"/>
451 </javac>
452 </groovyc>
453 </sequential>
454 </target>
[31038]455 <target name="test" depends="dist, test-clean, test-compile"
[30747]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" />
[30550]458 <sequential>
[30562]459 <echo message="Running unit tests with JUnit"/>
[30550]460 <jacoco:coverage destfile="${plugin.test.dir}/jacoco.exec">
[30556]461 <junit printsummary="yes" fork="true" forkmode="once" dir="${basedir}">
[30562]462 <jvmarg value="-Dfile.encoding=UTF-8"/>
463 <sysproperty key="josm.home" value="${plugin.test.dir}/config/unit-josm.home"/>
[30550]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>
[30747]468 <fileset refid="plugin.requires.jars"/>
[30550]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">
[30562]475 <fileset dir="${plugin.test.dir}/build/unit" includes="**/*Test.class"/>
[30550]476 </batchtest>
477 </junit>
478 </jacoco:coverage>
479 </sequential>
[30562]480 </target>
[31281]481
[28807]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>
[29004]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
[29006]501 * clean Cleanup automatical created files
[31281]502 * test Run unit tests (if any)
[29004]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>
[26341]512</project>
513
Note: See TracBrowser for help on using the repository browser.