source: subversion/applications/editors/josm/plugins/build-common.xml @ 30306

Last change on this file since 30306 was 30306, checked in by simon04, 5 years ago

JOSM: allow plugins to be built from a Git (non-SVN) mirror

File size: 15.5 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">
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    </target>
215    <target name="revision" depends="init-svn-revision-xml, init-git-svn-revision-xml, init-git-revision-xml">
216      <xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
217      <delete file="REVISION.XML"/>
218    </target>
219    <!--
220    **********************************************************
221    ** clean - clean up the build environment
222    **********************************************************
223    -->
224    <target name="clean">
225        <delete dir="${plugin.build.dir}"/>
226        <delete file="${plugin.jar}"/>
227    </target>
228    <!--
229    **********************************************************
230    ** install - install the plugin in your local JOSM installation
231    **********************************************************
232    -->
233    <target name="install" depends="dist">
234        <property environment="env"/>
235        <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">
236            <and>
237                <os family="windows"/>
238            </and>
239        </condition>
240        <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
241    </target>
242    <!--
243    ************************** Publishing the plugin ***********************************
244    -->
245    <!--
246    ** extracts the JOSM release for the JOSM version in ../core and saves it in the
247    ** property ${coreversion.info.entry.revision}
248    **
249    -->
250    <target name="core-info">
251        <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
252            <env key="LANG" value="C"/>
253            <arg value="info"/>
254            <arg value="--xml"/>
255            <arg value="../../core"/>
256        </exec>
257        <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
258        <echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
259        <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
260        <delete file="core.info.xml"/>
261    </target>
262    <!--
263    ** commits the source tree for this plugin
264    -->
265    <target name="commit-current">
266        <echo>Commiting the plugin source with message '${commit.message}' ...</echo>
267        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
268            <env key="LANG" value="C"/>
269            <arg value="commit"/>
270            <arg value="-m"/>
271            <arg value="${commit.message}"/>
272            <arg value="."/>
273        </exec>
274    </target>
275    <!--
276    ** updates (svn up) the source tree for this plugin
277    -->
278    <target name="update-current">
279        <echo>Updating plugin source ...</echo>
280        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
281            <env key="LANG" value="C"/>
282            <arg value="up"/>
283            <arg value="."/>
284        </exec>
285        <echo>Updating ${plugin.jar} ...</echo>
286        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
287            <env key="LANG" value="C"/>
288            <arg value="up"/>
289            <arg value="../dist/${plugin.jar}"/>
290        </exec>
291    </target>
292    <!--
293    ** commits the plugin.jar
294    -->
295    <target name="commit-dist">
296        <echo>
297    ***** Properties of published ${plugin.jar} *****
298    Commit message    : '${commit.message}'
299    Plugin-Mainversion: ${plugin.main.version}
300    JOSM build version: ${coreversion.info.entry.revision}
301    Plugin-Version    : ${version.entry.commit.revision}
302    ***** / Properties of published ${plugin.jar} *****
303
304    Now commiting ${plugin.jar} ...
305    </echo>
306        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
307            <env key="LANG" value="C"/>
308            <arg value="-m"/>
309            <arg value="${commit.message}"/>
310            <arg value="commit"/>
311            <arg value="${plugin.jar}"/>
312        </exec>
313    </target>
314    <!-- ** make sure svn is present as a command line tool ** -->
315    <target name="ensure-svn-present">
316        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">
317            <env key="LANG" value="C"/>
318            <arg value="--version"/>
319        </exec>
320        <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">
321            <!-- return code not set at all? Most likely svn isn't installed -->
322            <condition>
323                <not>
324                    <isset property="svn.exit.code"/>
325                </not>
326            </condition>
327        </fail>
328        <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">
329            <!-- error code from SVN? Most likely svn is not what we are looking on this system -->
330            <condition>
331                <isfailure code="${svn.exit.code}"/>
332            </condition>
333        </fail>
334    </target>
335
336    <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
337    </target>
338
339    <target name="runjosm" depends="install">
340        <java jar="${josm}" fork="true">
341        </java>
342    </target>
343
344    <target name="profilejosm" depends="install">
345        <nbprofiledirect>
346        </nbprofiledirect>
347        <java jar="${josm}" fork="true">
348            <jvmarg value="${profiler.info.jvmargs.agent}"/>
349        </java>
350    </target>
351    <!--
352    ** shows a help text
353    -->
354    <target name="help">
355        <echo>
356    You can use following targets:
357    * dist        This default target builds the plugin jar file
358    * clean       Cleanup automatical created files
359    * publish     Checkin source code, build jar and checkin plugin jar
360                  (requires proper entry for SVN commit message!)
361    * install     Install the plugin in current system
362    * runjosm     Install plugin and start josm
363    * profilejosm Install plugin and start josm in profiling mode
364   
365    There are other targets, which usually should not be called manually.
366        </echo>
367    </target>
368</project>
369
Note: See TracBrowser for help on using the repository browser.