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

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

fix #josm10910 - "ant install" no longer works on OS X and Windows

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