-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathbuild-common.xml
859 lines (842 loc) · 44.8 KB
/
build-common.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
<?xml version="1.0" encoding="utf-8"?>
<!--
** Template for the build targets common to all plugins
** ====================================================
**
** To override a property, add it to the plugin build.xml _before_
** this template has been imported.
** To override a target, add it _after_ this template has been imported.
**
** Paths are relative to the build.xml that imports this template.
**
-->
<project name="plugin_common" basedir="." xmlns:jacoco="antlib:org.jacoco.ant" xmlns:if="ant:if" xmlns:unless="ant:unless" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:mvn="antlib:org.apache.maven.resolver.ant" >
<property name="josm" location="../../core/dist/josm-custom.jar"/>
<property name="josm.ivy" location="../../core/ivy.xml"/>
<property name="josm.ivysettings" location="../../core/ivysettings.xml"/>
<property name="josm.test.build.dir" location="../../core/test/build"/>
<property name="core.tools.ivy" location="../00_core_tools/ivy.xml"/>
<property name="plugin.tools.dir" location="../00_tools"/>
<property name="plugin.build.dir" location="build"/>
<property name="plugin.test.dir" location="test"/>
<property name="plugin.src.dir" location="src"/>
<property name="plugin.resources.dir" location="resources"/>
<property name="plugin.doc.dir" location="javadoc"/>
<property name="plugin.lib.dir" location="lib"/>
<!-- this is the directory where the plugin jar is copied to -->
<property name="plugin.dist.dir" location="../../dist"/>
<property name="java.lang.version" value="11" />
<property name="javadoc.executable" value="javadoc" />
<property name="manifest" value="MANIFEST"/>
<property name="manifest.unixoid" value="MANIFEST-unixoid"/>
<property name="manifest.windows" value="MANIFEST-windows"/>
<property name="manifest.osx" value="MANIFEST-osx"/>
<property name="plugin.jar" location="${plugin.dist.dir}/${ant.project.name}.jar"/>
<property name="plugin.unixoid.jar" location="${plugin.dist.dir}/${ant.project.name}-unixoid.jar"/>
<property name="plugin.windows.jar" location="${plugin.dist.dir}/${ant.project.name}-windows.jar"/>
<property name="plugin.osx.jar" location="${plugin.dist.dir}/${ant.project.name}-osx.jar"/>
<property name="plugin.sources.jar" location="${plugin.dist.dir}/${ant.project.name}-sources.jar"/>
<property name="plugin.javadoc.jar" location="${plugin.dist.dir}/${ant.project.name}-javadoc.jar"/>
<property name="ivy.home" location="${user.home}/.ant"/>
<property name="ivy.jar.dir" location="${ivy.home}/lib"/>
<property name="ivy.jar.file" location="${ivy.jar.dir}/ivy.jar"/>
<property name="ivy.version" value="2.5.1"/>
<property name="maven.artifact.resolver.version" value="1.5.1"/>
<property name="maven.artifact.resolver.parent.dir" value="${user.home}/.m2/repository/org/apache/maven/resolver/maven-resolver-ant-tasks/${maven.artifact.resolver.version}/"/>
<property name="maven.artifact.resolver.jar.file" value="${maven.artifact.resolver.parent.dir}/maven-resolver-ant-tasks-${maven.artifact.resolver.version}-uber.jar"/>
<property name="jacoco.inclbootstrapclasses" value="false" />
<property name="jacoco.inclnolocationclasses" value="false" />
<property name="junit.printsummary" value="on" />
<!-- For platform-specific stuff -->
<condition property="isWindows"><os family="Windows"/></condition>
<condition property="isUnix"><os family="Unix"/></condition>
<condition property="isMac"><os family="Mac"/></condition>
<!-- For Java specific stuff by version -->
<condition property="isJava14"><matches string="${ant.java.version}" pattern="1[4-9]|[2-9][0-9]" /></condition>
<condition property="isJava15"><matches string="${ant.java.version}" pattern="1[5-9]|[2-9][0-9]" /></condition>
<condition property="isJava17"><matches string="${ant.java.version}" pattern="1[7-9]|[2-9][0-9]" /></condition>
<condition property="isJava21"><matches string="${ant.java.version}" pattern="2[1-9]|[3-9][0-9]" /></condition>
<!-- set the javadoc location -->
<property name="javadoc.link" value="https://docs.oracle.com/en/java/javase/11/docs/api/" unless:set="isJava17"/>
<property name="javadoc.link" value="https://docs.oracle.com/en/java/javase/17/docs/api/" if:set="isJava17" unless:set="isJava21"/>
<property name="javadoc.link" value="https://docs.oracle.com/en/java/javase/21/docs/api/" if:set="isJava21"/>
<!-- Disable jacoco on Java 21+ (Jacoco does not yet support Java 21+) -->
<condition property="coverageByDefault">
<not>
<isset property="isJava21"/>
</not>
</condition>
<target name="-jaxb_windows" if="isWindows">
<property name="xjc" value="${plugin.tools.dir}${file.separator}jaxb-ri${file.separator}bin${file.separator}xjc.bat" />
</target>
<target name="-jaxb_linux" unless="isWindows">
<property name="xjc" value="${plugin.tools.dir}${file.separator}jaxb-ri${file.separator}bin${file.separator}xjc.sh" />
</target>
<!-- To be overriden in plugin build file before inclusion if other plugins are required -->
<fileset id="plugin.requires.jars" dir="${plugin.dist.dir}" includes="nothing"/>
<fileset id="jaxb.jars" dir="${plugin.tools.dir}/jaxb-ri/lib" includes="**/*.jar"/>
<path id="plugin.classpath">
<pathelement location="${josm}"/>
<fileset dir="${plugin.lib.dir}" erroronmissingdir="no">
<include name="**/*.jar"/>
<exclude name="**/*-sources.jar"/>
<exclude name="**/*-javadoc.jar"/>
<exclude name="**/*-unixoid.jar" unless="isUnix"/>
<exclude name="**/*-windows.jar" unless="isWindows"/>
<exclude name="**/*-osx.jar" unless="isMac"/>
</fileset>
<fileset refid="plugin.requires.jars"/>
<fileset refid="jaxb.jars"/>
</path>
<!--
**********************************************************
** init - initializes the build
**********************************************************
-->
<target name="init">
<mkdir dir="${plugin.build.dir}"/>
</target>
<!--
**********************************************************
** compile - compiles the source tree
**********************************************************
-->
<target name="pre-compile">
<!-- to be overridden by plugins that need to perform additional tasks before compiling -->
</target>
<target name="compile" depends="init, pre-compile, resolve-tools" unless="skip-compile">
<condition property="plugin.classpath.actual.defined">
<isreference refid="plugin.classpath.actual" type="path"/>
</condition>
<path id="plugin.classpath.actual" unless:set="plugin.classpath.actual.defined">
<path refid="plugin.classpath"/>
</path>
<echo message="compiling sources for ${plugin.jar} ..."/>
<path id="jdk.boot.classpath">
<path refid="errorprone_javac.classpath"/>
<fileset refid="jaxb.jars"/>
</path>
<javac srcdir="${plugin.src.dir}" debug="true" destdir="${plugin.build.dir}" includeantruntime="false"
encoding="UTF-8" release="${java.lang.version}" fork="yes">
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" unless:set="noErrorProne"/>
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED" unless:set="noErrorProne"/>
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED" unless:set="noErrorProne"/>
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" unless:set="noErrorProne"/>
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED" unless:set="noErrorProne"/>
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED" unless:set="noErrorProne"/>
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" unless:set="noErrorProne"/>
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED" unless:set="noErrorProne"/>
<compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED" unless:set="noErrorProne"/>
<compilerarg line="-XDcompilePolicy=simple"/>
<compilerarg value="-processorpath"/>
<compilerarg pathref="errorprone.classpath"/>
<compilerarg value="-Xlint:deprecation"/>
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-Xplugin:ErrorProne -Xep:StringSplitter:OFF -Xep:ReferenceEquality:OFF -Xep:InsecureCryptoUsage:OFF -Xep:FutureReturnValueIgnored:OFF -Xep:JdkObsolete:OFF -Xep:EqualsHashCode:OFF -Xep:JavaUtilDate:OFF -Xep:DoNotCallSuggester:OFF -Xep:BanSerializableRead:OFF" />
<compilerarg line="-Xmaxwarns 1000"/>
<classpath refid="plugin.classpath.actual"/>
</javac>
</target>
<!--
**********************************************************
** setup-dist - copies files for distribution
**********************************************************
-->
<target name="setup-dist-default">
<copy todir="${plugin.build.dir}/resources" failonerror="no" includeemptydirs="no">
<fileset dir="${plugin.resources.dir}"/>
</copy>
<copy todir="${plugin.build.dir}/images" failonerror="no" includeemptydirs="no">
<fileset dir="images"/>
</copy>
<copy todir="${plugin.build.dir}/data" failonerror="no" includeemptydirs="no">
<fileset dir="data"/>
</copy>
<copy todir="${plugin.build.dir}">
<fileset dir=".">
<include name="README"/>
<include name="LICENSE*"/>
<include name="*GPL*"/>
<exclude name="*.md"/>
</fileset>
</copy>
</target>
<target name="setup-dist">
<antcall target="setup-dist-default" />
</target>
<!--
**********************************************************
** dist - creates the plugin jars
**********************************************************
-->
<target name="dist" depends="compile,javadoc,revision" unless="skip-dist">
<echo message="creating ${ant.project.name}.jar ... "/>
<antcall target="setup-dist" />
<delete failonerror="no">
<fileset dir="." includes="${manifest}*" />
</delete>
<manifest file="${manifest}" mode="update">
<attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
<attribute name="Plugin-Version" value="${version.entry.commit.revision}" unless:set="plugin.version"/>
<attribute name="Plugin-Version" value="${plugin.version}" if:set="plugin.version"/>
<attribute name="Plugin-Class" value="${plugin.class}" />
<attribute name="Plugin-Description" value="${plugin.description}" />
<attribute name="Plugin-Date" value="${version.entry.commit.date}" />
<attribute name="Author" value="${plugin.author}"/>
</manifest>
<antcall target="add-manifest-attribute">
<param name="manifest.attribute" value="Plugin-Link"/>
<param name="property.name" value="plugin.link"/>
<param name="property.value" value="${plugin.link}"/>
</antcall>
<antcall target="add-manifest-attribute">
<param name="manifest.attribute" value="Plugin-Icon"/>
<param name="property.name" value="plugin.icon"/>
<param name="property.value" value="${plugin.icon}"/>
</antcall>
<antcall target="add-manifest-attribute">
<param name="manifest.attribute" value="Plugin-Early"/>
<param name="property.name" value="plugin.early"/>
<param name="property.value" value="${plugin.early}"/>
</antcall>
<antcall target="add-manifest-attribute">
<param name="manifest.attribute" value="Plugin-Provides"/>
<param name="property.name" value="plugin.provides"/>
<param name="property.value" value="${plugin.provides}"/>
</antcall>
<antcall target="add-manifest-attribute">
<param name="manifest.attribute" value="Plugin-Requires"/>
<param name="property.name" value="plugin.requires"/>
<param name="property.value" value="${plugin.requires}"/>
</antcall>
<antcall target="add-manifest-attribute">
<param name="manifest.attribute" value="Plugin-Stage"/>
<param name="property.name" value="plugin.stage"/>
<param name="property.value" value="${plugin.stage}"/>
</antcall>
<antcall target="add-manifest-attribute">
<param name="manifest.attribute" value="Plugin-Canloadatruntime"/>
<param name="property.name" value="plugin.canloadatruntime"/>
<param name="property.value" value="${plugin.canloadatruntime}"/>
</antcall>
<antcall target="add-manifest-attribute">
<param name="manifest.attribute" value="Plugin-Minimum-Java-Version"/>
<param name="property.name" value="plugin.minimum.java.version"/>
<param name="property.value" value="${plugin.minimum.java.version}"/>
</antcall>
<antcall target="additional-manifest" />
<antcall target="build-jar" />
<jar destfile="${plugin.sources.jar}" basedir="${plugin.src.dir}" level="9"/>
<jar destfile="${plugin.javadoc.jar}" basedir="${plugin.doc.dir}" level="9"/>
<delete failonerror="no">
<fileset dir="." includes="${manifest}*" />
</delete>
<antcall target="post-dist" />
</target>
<target name="build-jar">
<jar destfile="${plugin.jar}" basedir="${plugin.build.dir}" manifest="${manifest}" manifestencoding="UTF-8" duplicate="preserve" level="9">
<restrict>
<not><or>
<name name="META-INF/maven/*"/>
<name name="META-INF/DEPENDENCIES"/>
<name name="META-INF/LICENSE"/>
<name name="META-INF/NOTICE"/>
<name name="META-INF/*.RSA"/>
<name name="META-INF/*.SF"/>
<name name="module-info.class"/>
</or></not>
<archives>
<zips>
<fileset dir="${plugin.lib.dir}" includes="*.jar" excludes="*-sources.jar, *-javadoc.jar" erroronmissingdir="no"/>
</zips>
</archives>
</restrict>
</jar>
</target>
<target name="post-dist">
<!-- to be overridden by plugins that need to perform additional tasks on resulting jar -->
</target>
<target name="add-manifest-attribute" depends="check-manifest-attribute" if="have-${property.name}">
<manifest file="${manifest}" mode="update">
<attribute name="${manifest.attribute}" value="${property.value}" />
</manifest>
</target>
<!-- target to add additional entries, empty in commons -->
<target name="additional-manifest">
</target>
<target name="check-manifest-attribute">
<condition property="have-${property.name}">
<and>
<isset property="${property.name}"/>
<not>
<equals arg1="${property.value}" arg2=""/>
</not>
<not>
<equals arg1="${property.value}" arg2="..."/>
</not>
</and>
</condition>
</target>
<target name="pre-javadoc">
<!-- to be overridden by plugins that need to perform additional tasks before generating javadoc -->
</target>
<target name="javadoc" depends="pre-javadoc,pre-compile" unless="skip-javadoc">
<mkdir dir="${plugin.doc.dir}"/>
<javadoc destdir="${plugin.doc.dir}"
executable="${javadoc.executable}"
encoding="UTF-8"
windowtitle="JOSM-${ant.project.name}"
use="true"
private="true"
linksource="true"
author="false">
<classpath refid="plugin.classpath" unless:set="plugin.classpath.dependencies"/>
<classpath refid="plugin.classpath.dependencies" if:set="plugin.classpath.dependencies"/>
<sourcepath>
<pathelement path="${plugin.src.dir}" />
<pathelement path="gen" />
<pathelement path="includes" />
</sourcepath>
<link href="${javadoc.link}"/>
<link href="https://josm.openstreetmap.de/doc"/>
<doctitle><![CDATA[<h2>JOSM-${ant.project.name} - Javadoc</h2>]]></doctitle>
<bottom><![CDATA[<a href="https://josm.openstreetmap.de/wiki/Plugins">JOSM Plugins</a>]]></bottom>
<arg line="-tag license:X" />
<arg value="-html5" />
<arg value="--add-exports" unless:set="noJavaFX" />
<arg value="javafx.graphics/com.sun.javafx.application=ALL-UNNAMED" unless:set="noJavaFX" />
</javadoc>
</target>
<!--
**********************************************************
** revision - extracts the current revision number for the
** file build.number and stores it in the XML property
** version.*
**********************************************************
-->
<!--
** Initializes the REVISION.XML file from SVN information
-->
<target name="init-svn-revision-xml" unless="skip-revision">
<exec append="false" output="REVISION.XML" executable="svn" failifexecutionfails="false" resultproperty="svn.info.result">
<env key="LANG" value="C"/>
<arg value="info"/>
<arg value="--xml"/>
<arg value="."/>
</exec>
<condition property="svn.info.fail">
<not>
<and>
<equals arg1="${svn.info.result}" arg2="0" />
<length file="REVISION.XML" when="greater" length="1" />
</and>
</not>
</condition>
</target>
<!--
** Initializes the REVISION.XML file from git-svn information.
Obtains the revision from the git-svn-id field.
-->
<target name="init-git-svn-revision-xml" if="svn.info.fail" unless="skip-revision">
<exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false" resultproperty="git.svn.info.result">
<arg value="log"/>
<arg value="-1"/>
<arg value="--grep=git-svn-id"/>
<!--
%B: raw body (unwrapped subject and body)
%n: new line
%ai: author date, ISO 8601 format
-->
<arg value="--pretty=format:%B%n%ai"/>
<arg value="."/>
</exec>
<replaceregexp file="REVISION.XML" flags="s"
match=".*git-svn-id: [^@]*@([0-9]+).*(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
replace="<info><entry><commit revision="\1"><date>\2</date></commit></entry></info>"/>
<condition property="git.svn.fail">
<not>
<and>
<equals arg1="${git.svn.info.result}" arg2="0" />
<length file="REVISION.XML" when="greater" length="1" />
</and>
</not>
</condition>
</target>
<!--
** Initializes the REVISION.XML file from git (w/o svn) information.
Uses Unix date as revision number.
-->
<target name="init-git-revision-xml" if="git.svn.fail" unless="skip-revision">
<exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false" resultproperty="git.info.result">
<arg value="log"/>
<arg value="-1"/>
<arg value="--pretty=format:%at%n%ai"/>
<arg value="."/>
</exec>
<replaceregexp file="REVISION.XML" flags="s"
match="\s*(\d*)\s+(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
replace="<info><entry><commit revision="\1"><date>\2</date></commit></entry></info>"/>
<condition property="git.fail">
<not>
<and>
<equals arg1="${git.info.result}" arg2="0" />
<length file="REVISION.XML" when="greater" length="1" />
</and>
</not>
</condition>
</target>
<target name="init-revision-fallback" if="git.fail" unless="skip-revision">
<tstamp>
<format property="current.time" pattern="yyyy-MM-dd'T'HH:mm:ss.SSS" />
</tstamp>
<echo file="REVISION.XML"><![CDATA[<info><entry><commit revision="UNKNOWN"><date>${current.time}</date></commit></entry></info>]]></echo>
</target>
<target name="revision" depends="init-svn-revision-xml, init-git-svn-revision-xml, init-git-revision-xml, init-revision-fallback" unless="skip-revision">
<xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
<delete file="REVISION.XML"/>
</target>
<!--
**********************************************************
** clean - clean up the build environment
**********************************************************
-->
<target name="clean">
<delete dir="${plugin.build.dir}"/>
<delete dir="${plugin.doc.dir}"/>
<delete file="${plugin.jar}"/>
<delete file="${plugin.sources.jar}"/>
<delete file="${plugin.javadoc.jar}"/>
</target>
<!--
**********************************************************
** install - install the plugin in your local JOSM installation
**********************************************************
-->
<target name="install" depends="dist">
<property environment="env"/>
<condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins">
<and>
<os family="windows"/>
</and>
</condition>
<condition property="josm.plugins.dir" value="${user.home}/Library/JOSM/plugins">
<and>
<os family="mac"/>
</and>
</condition>
<condition property="josm.plugins.dir" value="${user.home}/.local/share/JOSM/plugins">
<and>
<not><os family="windows"/></not>
<not><os family="mac"/></not>
</and>
</condition>
<copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
</target>
<!--
************************** Publishing the plugin ***********************************
-->
<!--
** extracts the JOSM release for the JOSM version in ../core and saves it in the
** property ${coreversion.info.entry.revision}
**
-->
<target name="core-info">
<exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
<env key="LANG" value="C"/>
<arg value="info"/>
<arg value="--xml"/>
<arg value="../../core"/>
</exec>
<xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
<echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
<echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
<delete file="core.info.xml"/>
</target>
<!--
** commits the source tree for this plugin
-->
<target name="commit-current">
<echo>Commiting the plugin source with message '${commit.message}' ...</echo>
<exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
<env key="LANG" value="C"/>
<arg value="commit"/>
<arg value="-m"/>
<arg value="${commit.message}"/>
<arg value="."/>
</exec>
</target>
<!--
** updates (svn up) the source tree for this plugin
-->
<target name="update-current">
<echo>Updating plugin source ...</echo>
<exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
<env key="LANG" value="C"/>
<arg value="up"/>
<arg value="."/>
</exec>
<echo>Updating ${plugin.jar} ...</echo>
<exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
<env key="LANG" value="C"/>
<arg value="up"/>
<arg value="${plugin.jar}"/>
</exec>
</target>
<!--
** commits the plugin.jar
-->
<target name="commit-dist">
<echo>
***** Properties of published ${plugin.jar} *****
Commit message : '${commit.message}'
Plugin-Mainversion: ${plugin.main.version}
JOSM build version: ${coreversion.info.entry.revision}
Plugin-Version : ${version.entry.commit.revision}
***** / Properties of published ${plugin.jar} *****
Now committing ${plugin.jar} ...
</echo>
<exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
<env key="LANG" value="C"/>
<arg value="-m"/>
<arg value="${commit.message}"/>
<arg value="commit"/>
<arg value="${plugin.jar}"/>
</exec>
</target>
<!-- ** make sure svn is present as a command line tool ** -->
<target name="ensure-svn-present">
<exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">
<env key="LANG" value="C"/>
<arg value="--version"/>
</exec>
<fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">
<!-- return code not set at all? Most likely svn isn't installed -->
<condition>
<not>
<isset property="svn.exit.code"/>
</not>
</condition>
</fail>
<fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">
<!-- error code from SVN? Most likely svn is not what we are looking on this system -->
<condition>
<isfailure code="${svn.exit.code}"/>
</condition>
</fail>
</target>
<target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
</target>
<macrodef name="init-test-preferences">
<sequential>
<copy file="../00_core_test_config/preferences.template.xml" tofile="../00_core_test_config/unit-josm.home/preferences.xml"/>
<replace file="../00_core_test_config/unit-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_USERNAME@" value="${osm.username}"/>
<replace file="../00_core_test_config/unit-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_PASSWORD@" value="${osm.password}"/>
</sequential>
</macrodef>
<target name="check-test">
<available file="${plugin.test.dir}" type="dir" property="test.present"/>
</target>
<target name="test-init" depends="check-test" if="test.present" unless="skip-test">
<mkdir dir="${plugin.test.dir}/build"/>
<mkdir dir="${plugin.test.dir}/build/unit"/>
<mkdir dir="${plugin.test.dir}/report"/>
<init-test-preferences/>
<ivy:settings file="${josm.ivysettings}" id="ivy.core.settings"/>
<ivy:resolve settingsRef="ivy.core.settings" file="${josm.ivy}" conf="test,jacocoant"/>
<!-- The following ivy:retrieve calls are for IDEs without Ivy support; since we don't have sync=true, these may not have the "latest" versions -->
<!--
<ivy:retrieve settingsRef="ivy.core.settings" pattern="../00_core_test_lib/[artifact].[ext]" conf="test"/>
<ivy:retrieve settingsRef="ivy.core.settings" pattern="../00_core_tools/[conf].[ext]" conf="jacocoant"/>
-->
<ivy:cachepath settingsRef="ivy.core.settings" pathid=".local.test.classpath" conf="test" />
<ivy:cachepath settingsRef="ivy.core.settings" pathid="jacocotest.classpath" conf="test,jacocoant"/>
<ivy:cachepath settingsRef="ivy.core.settings" pathid="jmockit.classpath" file="${josm.ivy}" conf="jmockit" transitive="false"/>
<ivy:cachepath settingsRef="ivy.core.settings" pathid="jacocoant.classpath" file="${josm.ivy}" conf="jacocoant"/>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="${toString:jacocoant.classpath}"/>
<path id="test.classpath">
<!-- JMockit must be included before JUnit in the classpath -->
<path refid="jmockit.classpath"/>
<path refid="jacocotest.classpath"/>
<path refid=".local.test.classpath"/>
<fileset dir="${plugin.test.dir}/lib" erroronmissingdir="no">
<include name="**/*.jar"/>
<exclude name="**/*-sources.jar"/>
<exclude name="**/*-javadoc.jar"/>
</fileset>
<fileset dir="lib" erroronmissingdir="no">
<include name="**/*.jar"/>
<exclude name="**/*-sources.jar"/>
<exclude name="**/*-javadoc.jar"/>
</fileset>
<pathelement path="${plugin.resources.dir}"/>
<pathelement path="${plugin.test.dir}/data"/>
<pathelement path="${josm.test.build.dir}/unit"/>
<pathelement path="${josm}"/>
<pathelement path="${plugin.jar}"/>
</path>
</target>
<target name="test-clean">
<delete dir="${plugin.test.dir}/build"/>
<delete dir="${plugin.test.dir}/report"/>
<delete file="${plugin.test.dir}/jacoco.exec" />
<delete file="../00_core_test_config/unit-josm.home/preferences.xml" />
<delete dir="../00_core_test_config/unit-josm.home/cache" failonerror="false"/>
</target>
<target name="test-compile" depends="test-init,dist" if="test.present" unless="skip-test">
<sequential>
<javac debug="on" includeantruntime="false" srcdir="${plugin.test.dir}/unit" destdir="${plugin.test.dir}/build/unit" encoding="UTF-8"
release="${java.lang.version}">
<classpath>
<fileset refid="plugin.requires.jars"/>
<path refid="test.classpath"/>
</classpath>
<compilerarg value="-Xlint:all"/>
<compilerarg value="-Xlint:-serial"/>
</javac>
</sequential>
</target>
<target name="test" depends="dist, test-clean, test-compile" if="test.present" unless="skip-test"
description="Run unit tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
<sequential>
<echo message="Running unit tests with JUnit"/>
<jacoco:agent destfile="${plugin.test.dir}/jacoco.exec" enabled="${coverageByDefault}"
inclbootstrapclasses="${jacoco.inclbootstrapclasses}" inclnolocationclasses="${jacoco.inclnolocationclasses}"
property="jacocoagent" if:true="${coverageByDefault}"/>
<junitlauncher printsummary="${junit.printsummary}">
<classpath>
<fileset refid="plugin.requires.jars"/>
<path refid="test.classpath"/>
<pathelement path="${plugin.test.dir}/build/unit"/>
</classpath>
<testclasses outputDir="${plugin.test.dir}/report">
<fileset dir="${plugin.test.dir}/build/unit" includes="**/*Test.class"/>
<fork>
<jvmarg value="${jacocoagent}" if:set="jacocoagent" />
<jvmarg value="-Dfile.encoding=UTF-8"/>
<jvmarg value="-javaagent:${toString:jmockit.classpath}"/>
<jvmarg value="-Djunit.jupiter.extensions.autodetection.enabled=true"/>
<jvmarg value="-Djunit.jupiter.execution.parallel.enabled=true"/>
<jvmarg value="--add-opens" />
<jvmarg value="java.base/java.lang.reflect=ALL-UNNAMED" />
<jvmarg value="--add-opens" />
<jvmarg value="java.desktop/javax.imageio.spi=ALL-UNNAMED" />
<jvmarg value="--add-exports" />
<jvmarg value="java.desktop/com.sun.imageio.spi=ALL-UNNAMED" />
<jvmarg value="-XX:+ShowCodeDetailsInExceptionMessages" if:set="isJava14" unless:set="isJava15" />
<sysproperty key="josm.home" value="../00_core_test_config/unit-josm.home"/>
<sysproperty key="josm.test.data" value="${plugin.test.dir}/data"/>
<sysproperty key="java.awt.headless" value="true"/>
<sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
<sysproperty key="junit.jupiter.execution.parallel.enabled" value="${junit.jupiter.execution.parallel.enabled}" if:set="junit.jupiter.execution.parallel.enabled"/>
<sysproperty key="junit.jupiter.execution.parallel.mode.default" value="${junit.jupiter.execution.parallel.mode.default}" if:set="junit.jupiter.execution.parallel.mode.default"/>
<sysproperty key="junit.jupiter.execution.parallel.mode.classes.default" value="${junit.jupiter.execution.parallel.mode.classes.default}" if:set="junit.jupiter.execution.parallel.mode.classes.default"/>
</fork>
<listener type="legacy-plain" />
<listener type="legacy-xml" />
</testclasses>
</junitlauncher>
</sequential>
</target>
<target name="checkstyle" depends="resolve-tools">
<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties">
<classpath refid="checkstyle.classpath"/>
</taskdef>
<checkstyle config="${basedir}/../checkstyle-config.xml">
<fileset dir="${basedir}/src" includes="**/*.java" excludes="boofcv/**/*.java,
com/google/**/*.java,
crosby/**/*.java,
edu/princeton/**/*.java,
net/boplicity/**/*.java,
org/apache/**/*.java,
org/dinopolis/**/*.java,
org/kaintoch/**/*.java,
org/marvinproject/**/*.java,
org/netbeans/**/*.java,
org/openstreetmap/josm/plugins/dataimport/io/tcx/**/*.java,
org/openstreetmap/josm/plugins/ohe/parser/**/*.java,
org/openstreetmap/josm/plugins/pdfimport/pdfbox/operators/**/*.java
org/openstreetmap/josm/plugins/roadsigns/javacc/**/*.java,
org/osgeo/**/*.java,
"/>
<fileset dir="${basedir}/test" includes="**/*.java" erroronmissingdir="false"/>
<formatter type="plain"/>
<formatter type="xml" toFile="checkstyle-josm-${ant.project.name}.xml"/>
</checkstyle>
</target>
<target name="spotbugs" depends="compile,resolve-tools">
<taskdef name="spotbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="${toString:spotbugs.classpath}"/>
<spotbugs output="xml"
outputFile="spotbugs-josm-${ant.project.name}.xml"
classpath="${toString:spotbugs.classpath}"
pluginList=""
excludeFilter="../spotbugs-filter.xml"
effort="less"
reportLevel="low"
nested="false"
jvmargs="-Xmx1024m"
>
<auxClasspath refid="plugin.classpath" unless:set="plugin.classpath.dependencies"/>
<auxClasspath refid="plugin.classpath.dependencies" if:set="plugin.classpath.dependencies"/>
<sourcePath path="${basedir}/src" />
<class location="${plugin.build.dir}" />
</spotbugs>
</target>
<target name="runjosm" depends="install">
<java jar="${josm}" fork="true"/>
</target>
<target name="profilejosm" depends="install">
<nbprofiledirect>
</nbprofiledirect>
<java jar="${josm}" fork="true">
<jvmarg value="${profiler.info.jvmargs.agent}"/>
</java>
</target>
<!--
** shows a help text
-->
<target name="help">
<echo>
You can use following targets:
* dist This default target builds the plugin jar file
* clean Cleanup automatically created files
* test Run unit tests (if any)
* publish Checkin source code, build jar and checkin plugin jar
(requires proper entry for SVN commit message!)
* install Install the plugin in current system
* runjosm Install plugin and start josm
* profilejosm Install plugin and start josm in profiling mode
There are other targets, which usually should not be called manually.
</echo>
</target>
<!--
** Ivy tasks
-->
<target name="is-ivy">
<condition property="isIvy">
<available file="ivy.xml"/>
</condition>
</target>
<target name="download-ivy">
<mkdir dir="${ivy.jar.dir}"/>
<get src="https://josm.openstreetmap.de/nexus/content/repositories/public/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar"
dest="${ivy.jar.file}"
usetimestamp="true"/>
</target>
<target name="init-ivy" depends="download-ivy">
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<target name="resolve-tools" depends="init-ivy" description="Resolves tools using Apache Ivy">
<ivy:settings file="${josm.ivysettings}"/>
<ivy:resolve file="${core.tools.ivy}"/>
<ivy:cachepath file="${core.tools.ivy}" pathid="errorprone.classpath" conf="errorprone"/>
<ivy:cachepath file="${core.tools.ivy}" pathid="errorprone_javac.classpath" conf="errorprone_javac"/>
<ivy:cachepath file="${core.tools.ivy}" pathid="checkstyle.classpath" conf="checkstyle"/>
<ivy:cachepath file="${core.tools.ivy}" pathid="spotbugs.classpath" conf="spotbugs"/>
</target>
<target name="clean_ivy">
<delete failonerror="false">
<fileset dir="${plugin.lib.dir}">
<include name="**/*.jar"/>
<exclude name="**/*-custom.jar" />
</fileset>
</delete>
</target>
<target name="fetch-dependencies-ivy" depends="clean_ivy, init-ivy, is-ivy" if="isIvy">
<echo>fetching dependencies with ivy</echo>
<available property="plugin.ivysettings.exists" file="ivy_settings.xml"/>
<ivy:settings file="ivy_settings.xml" if:set="plugin.ivysettings.exists"/>
<ivy:settings file="${josm.ivysettings}" unless:set="plugin.ivysettings.exists"/>
<ivy:resolve />
<ivy:retrieve pattern="${plugin.lib.dir}/[artifact]-[revision](-[classifier]).[ext]" conf="default" />
</target>
<target name="ivy-checkdepsupdate" description="Display dependency updates on the console" depends="fetch-dependencies-ivy">
<ivy:checkdepsupdate/>
</target>
<!--
** Maven tasks
-->
<target name="is-maven" depends="is-ivy">
<condition property="isMaven">
<and>
<available file="pom.xml"/>
<not>
<isset property="isIvy"/>
</not>
</and>
</condition>
</target>
<target name="download-maven" depends="is-maven" if="isMaven">
<mkdir dir="${maven.artifact.resolver.parent.dir}"/>
<get src="https://josm.openstreetmap.de/nexus/content/repositories/public/org/apache/maven/resolver/maven-resolver-ant-tasks/${maven.artifact.resolver.version}/maven-resolver-ant-tasks-${maven.artifact.resolver.version}-uber.jar"
dest="${maven.artifact.resolver.jar.file}"
usetimestamp="true"/>
</target>
<target name="init-maven" depends="is-maven,download-maven" if="isMaven">
<path id="maven.lib.path">
<fileset dir="${maven.artifact.resolver.parent.dir}" includes="*.jar"/>
</path>
<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml" classpathref="maven.lib.path"/>
</target>
<target name="fetch-dependencies-maven" depends="is-maven,init-maven,clean_ivy" if="isMaven">
<mvn:pom file="pom.xml"/>
<mvn:pom file="pom.xml" id="pom"/>
<!-- This stanza is necessary since the maven resolver doesn't read repo settings from the pom.xml file -->
<!-- resolver.repositories makes it global -->
<mvn:remoterepos id="resolver.repositories">
<mvn:remoterepo id="JOSM" url="https://josm.openstreetmap.de/nexus/content/repositories/public/" />
<mvn:remoterepo id="JOSM-snapshots" url="https://josm.openstreetmap.de/nexus/content/repositories/snapshots/" snapshots="true" />
</mvn:remoterepos>
<mkdir dir="${plugin.lib.dir}"/>
<mvn:resolve>
<!-- For some reason, compile time josm-unittest dependencies get included -->
<mvn:dependencies pomRef="pom">
<mvn:exclusion groupId="org.openstreetmap.josm" artifactId="josm-unittest"/>
<mvn:exclusion groupId="org.junit.platform"/>
<mvn:exclusion groupId="org.junit.vintage"/>
<mvn:exclusion groupId="org.junit.jupiter"/>
</mvn:dependencies>
<mvn:files refid="lib.files" dir="${plugin.lib.dir}" layout="{artifactId}-{version}-{classifier}.{extension}" scopes="compile,!test"/>
</mvn:resolve>
<mvn:resolve>
<mvn:path refid="classpath.provided" scopes="provided"/>
</mvn:resolve>
<mvn:resolve>
<mvn:path refid="testlib.classpath" classpath="test"/>
</mvn:resolve>
<mvn:resolve>
<mvn:dependencies>
<mvn:dependency groupId="org.jacoco" artifactId="org.jacoco.ant" version="${pom.properties.jacoco.version}" classifier="nodeps" type="jar" scope="test"/>
</mvn:dependencies>
<mvn:path refid="jacocotest.classpath" classpath="test"/>
</mvn:resolve>
<mvn:resolve>
<mvn:dependencies>
<mvn:dependency groupId="com.puppycrawl.tools" artifactId="checkstyle" version="${pom.properties.checkstyle.version}" scope="compile"/>
</mvn:dependencies>
<mvn:path refid="checkstyle.classpath" classpath="compile"/>
</mvn:resolve>
<mvn:resolve>
<mvn:dependencies>
<mvn:dependency groupId="com.github.spotbugs" artifactId="spotbugs" version="${pom.properties.spotbugs.version}" scope="compile"/>
<mvn:dependency groupId="com.github.spotbugs" artifactId="spotbugs-ant" version="${pom.properties.spotbugs.version}" scope="compile"/>
</mvn:dependencies>
<mvn:path refid="spotbugs.classpath" classpath="compile"/>
</mvn:resolve>
<condition property="classpath.provided.present">
<isreference refid="classpath.provided" type="path"/>
</condition>
<path id="plugin.classpath.actual" unless:set="classpath.provided.present">
<path refid="plugin.classpath"/>
</path>
<path id="plugin.classpath.actual" if:set="classpath.provided.present">
<path refid="plugin.classpath"/>
<path refid="classpath.provided"/>
</path>
</target>
<target name="fetch_dependencies" depends="fetch-dependencies-ivy,fetch-dependencies-maven">
<!-- We can depend upon ivy and/or maven right now. -->
</target>
</project>