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

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

[josm_plugins] ignore javadoc and sources jars in plugin libs

File size: 21.4 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 <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.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">
270 <and>
271 <os family="windows"/>
272 </and>
273 </condition>
274 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
275 </target>
276 <!--
277 ************************** Publishing the plugin ***********************************
278 -->
279 <!--
280 ** extracts the JOSM release for the JOSM version in ../core and saves it in the
281 ** property ${coreversion.info.entry.revision}
282 **
283 -->
284 <target name="core-info">
285 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
286 <env key="LANG" value="C"/>
287 <arg value="info"/>
288 <arg value="--xml"/>
289 <arg value="../../core"/>
290 </exec>
291 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
292 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
293 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
294 <delete file="core.info.xml"/>
295 </target>
296 <!--
297 ** commits the source tree for this plugin
298 -->
299 <target name="commit-current">
300 <echo>Commiting the plugin source with message '${commit.message}' ...</echo>
301 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
302 <env key="LANG" value="C"/>
303 <arg value="commit"/>
304 <arg value="-m"/>
305 <arg value="${commit.message}"/>
306 <arg value="."/>
307 </exec>
308 </target>
309 <!--
310 ** updates (svn up) the source tree for this plugin
311 -->
312 <target name="update-current">
313 <echo>Updating plugin source ...</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="."/>
318 </exec>
319 <echo>Updating ${plugin.jar} ...</echo>
320 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
321 <env key="LANG" value="C"/>
322 <arg value="up"/>
323 <arg value="../dist/${plugin.jar}"/>
324 </exec>
325 </target>
326 <!--
327 ** commits the plugin.jar
328 -->
329 <target name="commit-dist">
330 <echo>
331 ***** Properties of published ${plugin.jar} *****
332 Commit message : '${commit.message}'
333 Plugin-Mainversion: ${plugin.main.version}
334 JOSM build version: ${coreversion.info.entry.revision}
335 Plugin-Version : ${version.entry.commit.revision}
336 ***** / Properties of published ${plugin.jar} *****
337
338 Now commiting ${plugin.jar} ...
339 </echo>
340 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
341 <env key="LANG" value="C"/>
342 <arg value="-m"/>
343 <arg value="${commit.message}"/>
344 <arg value="commit"/>
345 <arg value="${plugin.jar}"/>
346 </exec>
347 </target>
348 <!-- ** make sure svn is present as a command line tool ** -->
349 <target name="ensure-svn-present">
350 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">
351 <env key="LANG" value="C"/>
352 <arg value="--version"/>
353 </exec>
354 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">
355 <!-- return code not set at all? Most likely svn isn't installed -->
356 <condition>
357 <not>
358 <isset property="svn.exit.code"/>
359 </not>
360 </condition>
361 </fail>
362 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">
363 <!-- error code from SVN? Most likely svn is not what we are looking on this system -->
364 <condition>
365 <isfailure code="${svn.exit.code}"/>
366 </condition>
367 </fail>
368 </target>
369
370 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
371 </target>
372
373 <path id="test.classpath">
374 <fileset dir="../00_core_test_lib">
375 <include name="**/*.jar"/>
376 </fileset>
377 <fileset dir="${plugin.test.dir}/lib" erroronmissingdir="no">
378 <include name="**/*.jar"/>
379 <exclude name="**/*-sources.jar"/>
380 <exclude name="**/*-javadoc.jar"/>
381 </fileset>
382 <fileset dir="lib" erroronmissingdir="no">
383 <include name="**/*.jar"/>
384 <exclude name="**/*-sources.jar"/>
385 <exclude name="**/*-javadoc.jar"/>
386 </fileset>
387 <pathelement path="${josm.test.build.dir}/unit"/>
388 <pathelement path="${josm}"/>
389 <pathelement path="${plugin.jar}"/>
390 <pathelement path="${groovy.jar}"/>
391 </path>
392 <macrodef name="init-test-preferences">
393 <sequential>
394 <copy file="${plugin.test.dir}/config/preferences.template.xml" tofile="${plugin.test.dir}/config/unit-josm.home/preferences.xml"/>
395 <replace file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_USERNAME@" value="${osm.username}"/>
396 <replace file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_PASSWORD@" value="${osm.password}"/>
397 </sequential>
398 </macrodef>
399 <target name="test-init">
400 <mkdir dir="${plugin.test.dir}/build"/>
401 <mkdir dir="${plugin.test.dir}/build/unit"/>
402 <mkdir dir="${plugin.test.dir}/report"/>
403 <init-test-preferences/>
404 </target>
405 <target name="test-clean">
406 <delete dir="${plugin.test.dir}/build"/>
407 <delete dir="${plugin.test.dir}/report"/>
408 <delete file="${plugin.test.dir}/jacoco.exec" />
409 <delete file="${plugin.test.dir}/config/unit-josm.home/preferences.xml" />
410 <delete dir="${plugin.test.dir}/config/unit-josm.home/cache" failonerror="false"/>
411 </target>
412 <target name="test-compile" depends="test-init,dist">
413 <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpath="${groovy.jar}"/>
414 <sequential>
415 <groovyc srcdir="${plugin.test.dir}/unit" destdir="${plugin.test.dir}/build/unit" encoding="UTF-8">
416 <classpath>
417 <fileset refid="plugin.requires.jars"/>
418 <path refid="test.classpath"/>
419 </classpath>
420 <javac target="1.7" source="1.7" debug="on" encoding="UTF-8">
421 <compilerarg value="-Xlint:all"/>
422 <compilerarg value="-Xlint:-serial"/>
423 </javac>
424 </groovyc>
425 </sequential>
426 </target>
427 <target name="test" depends="dist, test-compile"
428 description="Run unit tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
429 <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="../00_core_tools/jacocoant.jar" />
430 <sequential>
431 <echo message="Running unit tests with JUnit"/>
432 <jacoco:coverage destfile="${plugin.test.dir}/jacoco.exec">
433 <junit printsummary="yes" fork="true" forkmode="once" dir="${basedir}">
434 <jvmarg value="-Dfile.encoding=UTF-8"/>
435 <sysproperty key="josm.home" value="${plugin.test.dir}/config/unit-josm.home"/>
436 <sysproperty key="josm.test.data" value="${plugin.test.dir}/data"/>
437 <sysproperty key="java.awt.headless" value="true"/>
438 <sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
439 <classpath>
440 <fileset refid="plugin.requires.jars"/>
441 <path refid="test.classpath"/>
442 <pathelement path="${plugin.test.dir}/build/unit"/>
443 </classpath>
444 <formatter type="plain"/>
445 <formatter type="xml"/>
446 <batchtest fork="yes" todir="${plugin.test.dir}/report">
447 <fileset dir="${plugin.test.dir}/build/unit" includes="**/*Test.class"/>
448 </batchtest>
449 </junit>
450 </jacoco:coverage>
451 </sequential>
452 </target>
453
454 <target name="runjosm" depends="install">
455 <java jar="${josm}" fork="true">
456 </java>
457 </target>
458
459 <target name="profilejosm" depends="install">
460 <nbprofiledirect>
461 </nbprofiledirect>
462 <java jar="${josm}" fork="true">
463 <jvmarg value="${profiler.info.jvmargs.agent}"/>
464 </java>
465 </target>
466 <!--
467 ** shows a help text
468 -->
469 <target name="help">
470 <echo>
471 You can use following targets:
472 * dist This default target builds the plugin jar file
473 * clean Cleanup automatical created files
474 * test Run unit tests (if any)
475 * publish Checkin source code, build jar and checkin plugin jar
476 (requires proper entry for SVN commit message!)
477 * install Install the plugin in current system
478 * runjosm Install plugin and start josm
479 * profilejosm Install plugin and start josm in profiling mode
480
481 There are other targets, which usually should not be called manually.
482 </echo>
483 </target>
484</project>
485
Note: See TracBrowser for help on using the repository browser.