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

Last change on this file since 30410 was 30309, checked in by bastik, 11 years ago

plugin build: add another fallback when plugin is not under version control (set revision as UNKNOWN)

File size: 16.1 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=".">
14
15 <property name="josm" location="../../core/dist/josm-custom.jar"/>
16 <property name="plugin.build.dir" value="build"/>
17 <property name="plugin.src.dir" value="src"/>
18 <property name="plugin.lib.dir" value="lib"/>
19 <!-- this is the directory where the plugin jar is copied to -->
20 <property name="plugin.dist.dir" value="../../dist"/>
21 <property name="ant.build.javac.target" value="1.6"/>
22 <property name="ant.build.javac.source" value="1.6"/>
23 <property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/>
24
25 <!--
26 **********************************************************
27 ** init - initializes the build
28 **********************************************************
29 -->
30 <target name="init">
31 <mkdir dir="${plugin.build.dir}"/>
32 </target>
33 <!--
34 **********************************************************
35 ** compile - compiles the source tree
36 **********************************************************
37 -->
38 <target name="compile" depends="init">
39 <echo message="compiling sources for ${plugin.jar} ..."/>
40 <javac srcdir="src" debug="true" destdir="${plugin.build.dir}" includeantruntime="false" encoding="UTF-8">
41 <compilerarg value="-Xlint:deprecation"/>
42 <compilerarg value="-Xlint:unchecked"/>
43 <classpath>
44 <pathelement location="${josm}"/>
45 <fileset dir="${plugin.lib.dir}" erroronmissingdir="no">
46 <include name="**/*.jar"/>
47 </fileset>
48 </classpath>
49 </javac>
50 </target>
51 <!--
52 **********************************************************
53 ** setup-dist - copies files for distribution
54 **********************************************************
55 -->
56 <target name="setup-dist-default">
57 <copy todir="${plugin.build.dir}/resources" failonerror="no" includeemptydirs="no">
58 <fileset dir="resources"/>
59 </copy>
60 <copy todir="${plugin.build.dir}/images" failonerror="no" includeemptydirs="no">
61 <fileset dir="images"/>
62 </copy>
63 <copy todir="${plugin.build.dir}/data" failonerror="no" includeemptydirs="no">
64 <fileset dir="data"/>
65 </copy>
66 <copy todir="${plugin.build.dir}">
67 <fileset dir=".">
68 <include name="README"/>
69 <include name="LICENSE*"/>
70 <include name="*GPL*"/>
71 </fileset>
72 </copy>
73 </target>
74 <target name="setup-dist">
75 <antcall target="setup-dist-default" />
76 </target>
77 <!--
78 **********************************************************
79 ** dist - creates the plugin jar
80 **********************************************************
81 -->
82 <target name="dist" depends="compile,revision">
83 <echo message="creating ${ant.project.name}.jar ... "/>
84 <antcall target="setup-dist" />
85 <delete file="MANIFEST" failonerror="no"/>
86 <manifest file="MANIFEST" mode="update">
87 <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
88 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
89 <attribute name="Plugin-Class" value="${plugin.class}" />
90 <attribute name="Plugin-Description" value="${plugin.description}" />
91 <attribute name="Plugin-Date" value="${version.entry.commit.date}" />
92 <attribute name="Author" value="${plugin.author}"/>
93 </manifest>
94 <antcall target="add-manifest-attribute">
95 <param name="manifest.attribute" value="Plugin-Link"/>
96 <param name="propery.name" value="plugin.link"/>
97 <param name="propery.value" value="${plugin.link}"/>
98 </antcall>
99 <antcall target="add-manifest-attribute">
100 <param name="manifest.attribute" value="Plugin-Icon"/>
101 <param name="propery.name" value="plugin.icon"/>
102 <param name="propery.value" value="${plugin.icon}"/>
103 </antcall>
104 <antcall target="add-manifest-attribute">
105 <param name="manifest.attribute" value="Plugin-Early"/>
106 <param name="propery.name" value="plugin.early"/>
107 <param name="propery.value" value="${plugin.early}"/>
108 </antcall>
109 <antcall target="add-manifest-attribute">
110 <param name="manifest.attribute" value="Plugin-Requires"/>
111 <param name="propery.name" value="plugin.requires"/>
112 <param name="propery.value" value="${plugin.requires}"/>
113 </antcall>
114 <antcall target="add-manifest-attribute">
115 <param name="manifest.attribute" value="Plugin-Stage"/>
116 <param name="propery.name" value="plugin.stage"/>
117 <param name="propery.value" value="${plugin.stage}"/>
118 </antcall>
119 <antcall target="additional-manifest" />
120 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}" manifest="MANIFEST">
121 <zipgroupfileset dir="${plugin.lib.dir}" includes="*.jar" erroronmissingdir="no"/>
122 </jar>
123 <delete file="MANIFEST" failonerror="no"/>
124 <antcall target="post-dist" />
125 </target>
126 <target name="post-dist">
127 <!-- to be overidden by plugins that need to perform additional tasks on resulting jar -->
128 </target>
129 <target name="add-manifest-attribute" depends="check-manifest-attribute" if="have-${propery.name}">
130 <manifest file="MANIFEST" mode="update">
131 <attribute name="${manifest.attribute}" value="${propery.value}" />
132 </manifest>
133 </target>
134 <!-- target to add additional entries, empty in commons -->
135 <target name="additional-manifest">
136 </target>
137 <target name="check-manifest-attribute">
138 <condition property="have-${propery.name}">
139 <and>
140 <isset property="${propery.name}"/>
141 <not>
142 <equals arg1="${propery.value}" arg2=""/>
143 </not>
144 <not>
145 <equals arg1="${propery.value}" arg2="..."/>
146 </not>
147 </and>
148 </condition>
149 </target>
150 <!--
151 **********************************************************
152 ** revision - extracts the current revision number for the
153 ** file build.number and stores it in the XML property
154 ** version.*
155 **********************************************************
156 -->
157 <!--
158 ** Initializes the REVISION.XML file from SVN information
159 -->
160 <target name="init-svn-revision-xml">
161 <exec append="false" output="REVISION.XML" executable="svn" failifexecutionfails="false" resultproperty="svn.info.result">
162 <env key="LANG" value="C"/>
163 <arg value="info"/>
164 <arg value="--xml"/>
165 <arg value="."/>
166 </exec>
167 <condition property="svn.info.success">
168 <equals arg1="${svn.info.result}" arg2="0" />
169 </condition>
170 </target>
171 <!--
172 ** Initializes the REVISION.XML file from git-svn information.
173 Obtains the revision from the git-svn-id field.
174 -->
175 <target name="init-git-svn-revision-xml" unless="svn.info.success">
176 <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false" resultproperty="git.svn.info.result">
177 <arg value="log"/>
178 <arg value="-1"/>
179 <arg value="--grep=git-svn-id"/>
180 <!--
181 %B: raw body (unwrapped subject and body)
182 %n: new line
183 %ai: author date, ISO 8601 format
184 -->
185 <arg value="--pretty=format:%B%n%ai"/>
186 <arg value="HEAD"/>
187 </exec>
188 <replaceregexp file="REVISION.XML" flags="s"
189 match=".*git-svn-id: [^@]*@([0-9]+).*(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
190 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;"/>
191 <condition property="git.svn.fail">
192 <not>
193 <and>
194 <equals arg1="${git.svn.info.result}" arg2="0" />
195 <length file="REVISION.XML" when="greater" length="1" />
196 </and>
197 </not>
198 </condition>
199 </target>
200 <!--
201 ** Initializes the REVISION.XML file from git (w/o svn) information.
202 Uses Unix date as revision number.
203 -->
204 <target name="init-git-revision-xml" if="git.svn.fail">
205 <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false" resultproperty="git.info.result">
206 <arg value="log"/>
207 <arg value="-1"/>
208 <arg value="--pretty=format:%at%n%ai"/>
209 <arg value="HEAD"/>
210 </exec>
211 <replaceregexp file="REVISION.XML" flags="s"
212 match="\s*(\d*)\s+(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
213 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;"/>
214 <condition property="git.fail">
215 <not>
216 <and>
217 <equals arg1="${git.info.result}" arg2="0" />
218 <length file="REVISION.XML" when="greater" length="1" />
219 </and>
220 </not>
221 </condition>
222 </target>
223 <target name="init-revision-fallback" if="git.fail">
224 <tstamp>
225 <format property="current.time" pattern="yyyy-MM-dd'T'HH:mm:ss.SSS" />
226 </tstamp>
227 <echo file="REVISION.XML"><![CDATA[<info><entry><commit revision="UNKNOWN"><date>${current.time}</date></commit></entry></info>]]></echo>
228 </target>
229 <target name="revision" depends="init-svn-revision-xml, init-git-svn-revision-xml, init-git-revision-xml, init-revision-fallback">
230 <xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
231 <delete file="REVISION.XML"/>
232 </target>
233 <!--
234 **********************************************************
235 ** clean - clean up the build environment
236 **********************************************************
237 -->
238 <target name="clean">
239 <delete dir="${plugin.build.dir}"/>
240 <delete file="${plugin.jar}"/>
241 </target>
242 <!--
243 **********************************************************
244 ** install - install the plugin in your local JOSM installation
245 **********************************************************
246 -->
247 <target name="install" depends="dist">
248 <property environment="env"/>
249 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">
250 <and>
251 <os family="windows"/>
252 </and>
253 </condition>
254 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
255 </target>
256 <!--
257 ************************** Publishing the plugin ***********************************
258 -->
259 <!--
260 ** extracts the JOSM release for the JOSM version in ../core and saves it in the
261 ** property ${coreversion.info.entry.revision}
262 **
263 -->
264 <target name="core-info">
265 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
266 <env key="LANG" value="C"/>
267 <arg value="info"/>
268 <arg value="--xml"/>
269 <arg value="../../core"/>
270 </exec>
271 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
272 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
273 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
274 <delete file="core.info.xml"/>
275 </target>
276 <!--
277 ** commits the source tree for this plugin
278 -->
279 <target name="commit-current">
280 <echo>Commiting the plugin source with message '${commit.message}' ...</echo>
281 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
282 <env key="LANG" value="C"/>
283 <arg value="commit"/>
284 <arg value="-m"/>
285 <arg value="${commit.message}"/>
286 <arg value="."/>
287 </exec>
288 </target>
289 <!--
290 ** updates (svn up) the source tree for this plugin
291 -->
292 <target name="update-current">
293 <echo>Updating plugin source ...</echo>
294 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
295 <env key="LANG" value="C"/>
296 <arg value="up"/>
297 <arg value="."/>
298 </exec>
299 <echo>Updating ${plugin.jar} ...</echo>
300 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
301 <env key="LANG" value="C"/>
302 <arg value="up"/>
303 <arg value="../dist/${plugin.jar}"/>
304 </exec>
305 </target>
306 <!--
307 ** commits the plugin.jar
308 -->
309 <target name="commit-dist">
310 <echo>
311 ***** Properties of published ${plugin.jar} *****
312 Commit message : '${commit.message}'
313 Plugin-Mainversion: ${plugin.main.version}
314 JOSM build version: ${coreversion.info.entry.revision}
315 Plugin-Version : ${version.entry.commit.revision}
316 ***** / Properties of published ${plugin.jar} *****
317
318 Now commiting ${plugin.jar} ...
319 </echo>
320 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
321 <env key="LANG" value="C"/>
322 <arg value="-m"/>
323 <arg value="${commit.message}"/>
324 <arg value="commit"/>
325 <arg value="${plugin.jar}"/>
326 </exec>
327 </target>
328 <!-- ** make sure svn is present as a command line tool ** -->
329 <target name="ensure-svn-present">
330 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">
331 <env key="LANG" value="C"/>
332 <arg value="--version"/>
333 </exec>
334 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">
335 <!-- return code not set at all? Most likely svn isn't installed -->
336 <condition>
337 <not>
338 <isset property="svn.exit.code"/>
339 </not>
340 </condition>
341 </fail>
342 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">
343 <!-- error code from SVN? Most likely svn is not what we are looking on this system -->
344 <condition>
345 <isfailure code="${svn.exit.code}"/>
346 </condition>
347 </fail>
348 </target>
349
350 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
351 </target>
352
353 <target name="runjosm" depends="install">
354 <java jar="${josm}" fork="true">
355 </java>
356 </target>
357
358 <target name="profilejosm" depends="install">
359 <nbprofiledirect>
360 </nbprofiledirect>
361 <java jar="${josm}" fork="true">
362 <jvmarg value="${profiler.info.jvmargs.agent}"/>
363 </java>
364 </target>
365 <!--
366 ** shows a help text
367 -->
368 <target name="help">
369 <echo>
370 You can use following targets:
371 * dist This default target builds the plugin jar file
372 * clean Cleanup automatical created files
373 * publish Checkin source code, build jar and checkin plugin jar
374 (requires proper entry for SVN commit message!)
375 * install Install the plugin in current system
376 * runjosm Install plugin and start josm
377 * profilejosm Install plugin and start josm in profiling mode
378
379 There are other targets, which usually should not be called manually.
380 </echo>
381 </target>
382</project>
383
Note: See TracBrowser for help on using the repository browser.