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

Last change on this file since 30294 was 30161, checked in by simon04, 6 years ago

JOSM: allow plugins to be built from a Git mirror - see #josm9450

File size: 14.3 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 information
173    -->
174    <target name="init-git-revision-xml" unless="svn.info.success">
175        <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false">
176            <arg value="log"/>
177            <arg value="-1"/>
178            <arg value="--grep=git-svn-id"/>
179            <!--
180            %B:  raw body (unwrapped subject and body)
181            %n:  new line
182            %ai: author date, ISO 8601 format
183            -->
184            <arg value="--pretty=format:%B%n%ai"/>
185            <arg value="HEAD"/>
186        </exec>
187        <replaceregexp file="REVISION.XML" flags="s"
188                       match=".*git-svn-id: [^@]*@([0-9]+).*(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
189                       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;"/>
190    </target>
191    <target name="revision" depends="init-svn-revision-xml, init-git-revision-xml">
192      <xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
193      <delete file="REVISION.XML"/>
194    </target>
195    <!--
196    **********************************************************
197    ** clean - clean up the build environment
198    **********************************************************
199    -->
200    <target name="clean">
201        <delete dir="${plugin.build.dir}"/>
202        <delete file="${plugin.jar}"/>
203    </target>
204    <!--
205    **********************************************************
206    ** install - install the plugin in your local JOSM installation
207    **********************************************************
208    -->
209    <target name="install" depends="dist">
210        <property environment="env"/>
211        <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">
212            <and>
213                <os family="windows"/>
214            </and>
215        </condition>
216        <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
217    </target>
218    <!--
219    ************************** Publishing the plugin ***********************************
220    -->
221    <!--
222    ** extracts the JOSM release for the JOSM version in ../core and saves it in the
223    ** property ${coreversion.info.entry.revision}
224    **
225    -->
226    <target name="core-info">
227        <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
228            <env key="LANG" value="C"/>
229            <arg value="info"/>
230            <arg value="--xml"/>
231            <arg value="../../core"/>
232        </exec>
233        <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
234        <echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
235        <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
236        <delete file="core.info.xml"/>
237    </target>
238    <!--
239    ** commits the source tree for this plugin
240    -->
241    <target name="commit-current">
242        <echo>Commiting the plugin source with message '${commit.message}' ...</echo>
243        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
244            <env key="LANG" value="C"/>
245            <arg value="commit"/>
246            <arg value="-m"/>
247            <arg value="${commit.message}"/>
248            <arg value="."/>
249        </exec>
250    </target>
251    <!--
252    ** updates (svn up) the source tree for this plugin
253    -->
254    <target name="update-current">
255        <echo>Updating plugin source ...</echo>
256        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
257            <env key="LANG" value="C"/>
258            <arg value="up"/>
259            <arg value="."/>
260        </exec>
261        <echo>Updating ${plugin.jar} ...</echo>
262        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
263            <env key="LANG" value="C"/>
264            <arg value="up"/>
265            <arg value="../dist/${plugin.jar}"/>
266        </exec>
267    </target>
268    <!--
269    ** commits the plugin.jar
270    -->
271    <target name="commit-dist">
272        <echo>
273    ***** Properties of published ${plugin.jar} *****
274    Commit message    : '${commit.message}'
275    Plugin-Mainversion: ${plugin.main.version}
276    JOSM build version: ${coreversion.info.entry.revision}
277    Plugin-Version    : ${version.entry.commit.revision}
278    ***** / Properties of published ${plugin.jar} *****
279
280    Now commiting ${plugin.jar} ...
281    </echo>
282        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
283            <env key="LANG" value="C"/>
284            <arg value="-m"/>
285            <arg value="${commit.message}"/>
286            <arg value="commit"/>
287            <arg value="${plugin.jar}"/>
288        </exec>
289    </target>
290    <!-- ** make sure svn is present as a command line tool ** -->
291    <target name="ensure-svn-present">
292        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">
293            <env key="LANG" value="C"/>
294            <arg value="--version"/>
295        </exec>
296        <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">
297            <!-- return code not set at all? Most likely svn isn't installed -->
298            <condition>
299                <not>
300                    <isset property="svn.exit.code"/>
301                </not>
302            </condition>
303        </fail>
304        <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">
305            <!-- error code from SVN? Most likely svn is not what we are looking on this system -->
306            <condition>
307                <isfailure code="${svn.exit.code}"/>
308            </condition>
309        </fail>
310    </target>
311
312    <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
313    </target>
314
315    <target name="runjosm" depends="install">
316        <java jar="${josm}" fork="true">
317        </java>
318    </target>
319
320    <target name="profilejosm" depends="install">
321        <nbprofiledirect>
322        </nbprofiledirect>
323        <java jar="${josm}" fork="true">
324            <jvmarg value="${profiler.info.jvmargs.agent}"/>
325        </java>
326    </target>
327    <!--
328    ** shows a help text
329    -->
330    <target name="help">
331        <echo>
332    You can use following targets:
333    * dist        This default target builds the plugin jar file
334    * clean       Cleanup automatical created files
335    * publish     Checkin source code, build jar and checkin plugin jar
336                  (requires proper entry for SVN commit message!)
337    * install     Install the plugin in current system
338    * runjosm     Install plugin and start josm
339    * profilejosm Install plugin and start josm in profiling mode
340   
341    There are other targets, which usually should not be called manually.
342        </echo>
343    </target>
344</project>
345
Note: See TracBrowser for help on using the repository browser.