<?xml version="1.0" encoding="utf-8"?>
<!-- ** build.xml - main ant file for JOSM
**
** To build run
**    ant clean
**    ant dist
** This will create 'josm-custom.jar' in directory 'dist'. See also
**   https://josm.openstreetmap.de/wiki/DevelopersGuide/CreateBuild
**
-->
<project xmlns:as="antlib:org.codehaus.mojo.animal_sniffer" name="josm" default="dist" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
    <property name="test.dir" location="test"/>
    <property name="src.dir" location="src"/>
    <property name="build.dir" location="build"/>
    <property name="javacc.home" location="tools"/>
    <property name="mapcss.dir" location="${src.dir}/org/openstreetmap/josm/gui/mappaint/mapcss"/>
    <property name="imagerytypes.dir" location="${src.dir}/org/openstreetmap/josm/data/imagery/types"/>
    <!-- build parameter: compression level (ant -Dclevel=N)
             N ranges from 0 (no compression) to 9 (maximum compression)
             default: 9 -->
    <condition property="clevel" value="${clevel}" else="9">
        <isset property="clevel"/>
    </condition>
    <!-- For Windows-specific stuff -->
    <condition property="isWindows">
        <os family="Windows"/>
    </condition>

    <!--
      ** Used by Eclipse ant builder for updating
      ** the REVISION file used by JOSM
    -->
    <target name="create-revision-eclipse">
        <property name="revision.dir" value="bin"/>
        <antcall target="create-revision"/>
    </target>
    <!--
      ** Initializes the REVISION.XML file from SVN information
    -->
    <target name="init-svn-revision-xml">
        <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.success">
            <equals arg1="${svn.info.result}" arg2="0" />
        </condition>
    </target>
    <!--
      ** Initializes the REVISION.XML file from git information
    -->
    <target name="init-git-revision-xml" unless="svn.info.success">
        <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false">
            <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="HEAD"/>
        </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="&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;"/>
    </target>
    <!--
      ** Creates the REVISION file to be included in the distribution
    -->
    <target name="create-revision" depends="init-svn-revision-xml, init-git-revision-xml">
        <property name="revision.dir" value="${build.dir}"/>
        <xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
        <delete file="REVISION.XML"/>
        <tstamp>
            <format property="build.tstamp" pattern="yyyy-MM-dd HH:mm:ss"/>
        </tstamp>
        <property name="version.entry.commit.revision" value="UNKNOWN"/>
        <property name="version.entry.commit.date" value="UNKNOWN"/>
        <mkdir dir="${revision.dir}"/>
        <!-- add Build-Name: ... when making special builds, e.g. DEBIAN -->
        <echo file="${revision.dir}/REVISION">
# automatically generated by JOSM build.xml - do not edit
Revision: ${version.entry.commit.revision}
Is-Local-Build: true
Build-Date: ${build.tstamp}
</echo>
    </target>
    <!--
      ** Check internal XML files against their XSD
    -->
    <target name="check-schemas" unless="check-schemas.notRequired">
        <schemavalidate file="data/defaultpresets.xml" >
            <schema namespace="http://josm.openstreetmap.de/tagging-preset-1.0" file="data/tagging-preset.xsd" />
        </schemavalidate>
    </target>
    <!--
      ** Main target that builds JOSM and checks XML against schemas
    -->
    <target name="dist" depends="compile,create-revision,check-schemas">
        <echo>Revision ${version.entry.commit.revision}</echo>
        <copy file="CONTRIBUTION" todir="build"/>
        <copy file="README" todir="build"/>
        <copy file="LICENSE" todir="build"/>
        <!-- create josm-custom.jar -->
        <delete file="dist/josm-custom.jar"/>
        <jar destfile="dist/josm-custom.jar" basedir="build" level="${clevel}">
            <!-- add attribute excludes="**/*BZip2*,**/*Bzip2*" to create a non-bzip2 supporting jar -->
            <manifest>
                <attribute name="Main-class" value="JOSM"/>
                <attribute name="Main-Version" value="${version.entry.commit.revision} SVN"/>
                <attribute name="Main-Date" value="${version.entry.commit.date}"/>
                <attribute name="Permissions" value="all-permissions"/>
                <attribute name="Codebase" value="josm.openstreetmap.de"/>
                <attribute name="Application-Name" value="JOSM - Java OpenStreetMap Editor"/>
            </manifest>
            <zipfileset dir="images" prefix="images"/>
            <zipfileset dir="data" prefix="data"/>
            <zipfileset dir="styles" prefix="styles"/>
            <zipfileset dir="${src.dir}/org/openstreetmap/gui/jmapviewer/images" prefix="org/openstreetmap/gui/jmapviewer/images"/>
        </jar>
    </target>
    <!-- Mac OS X target -->
    <target name="mac">
        <!-- Using https://bitbucket.org/infinitekind/appbundler to create mac application bundle -->
        <taskdef name="bundleapp" classname="com.oracle.appbundler.AppBundlerTask" classpath="tools/appbundler-1.0ea.jar"/>
        <!-- create MacOS X application bundle -->
        <bundleapp outputdirectory="${bundle.outdir}" name="JOSM" displayname="JOSM" executablename="JOSM" identifier="org.openstreetmap.josm"
                   mainclassname="org.openstreetmap.josm.gui.MainApplication"
                   copyright="JOSM, and all its integral parts, are released under the GNU General Public License v2 or later"
                   applicationCategory="public.app-category.utilities"
                   shortversion="${version.entry.commit.revision} SVN"
                   version="${version.entry.commit.revision} SVN"
                   icon="macosx/JOSM.app/Contents/Resources/JOSM.icns"
                   highResolutionCapable="true">

            <arch name="x86_64"/>
            <arch name="i386"/>

            <classpath file="${bundle.jar}"/>

            <option value="-Xmx1024m"/>

            <option value="-Xdock:icon=Contents/Resources/JOSM.icns"/>
            <option value="-Xdock:name=JOSM"/>

            <!-- OSX specific options, optional -->
            <option value="-Dapple.laf.useScreenMenuBar=true"/>
            <option value="-Dcom.apple.macos.use-file-dialog-packages=true"/>
            <option value="-Dcom.apple.macos.useScreenMenuBar=true"/>
            <option value="-Dcom.apple.mrj.application.apple.menu.about.name=JOSM"/>
            <option value="-Dcom.apple.smallTabs=true"/>
        </bundleapp>
        
        <!-- appbundler lacks the possibility of defining our own keys or using a template, so update the .plist manually -->
        <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="tools/xmltask.jar"/>
        
        <xmltask source="${bundle.outdir}/JOSM.app/Contents/Info.plist" dest="${bundle.outdir}/JOSM.app/Contents/Info.plist" indent="false">
            <!-- remove empty CFBundleDocumentTypes definition -->
            <remove path="/plist/dict/key[text()='CFBundleDocumentTypes']|/plist/dict/key[text()='CFBundleDocumentTypes']/following-sibling::array[1]"/>
            <!-- insert our own keys -->
            <insert position="before" path="/plist/dict/key[1]" file="macosx/JOSM.app/Contents/Info.plist_template.xml" />
        </xmltask>
        
        <!-- create ZIP file with MacOS X application bundle -->
        <zip destfile="${bundle.outdir}/josm-custom-macosx.zip" update="true">
            <zipfileset dir="." includes="CONTRIBUTION README LICENSE"/>
            <zipfileset dir="${bundle.outdir}" includes="JOSM.app/**/*" filemode="755" />
        </zip>
    </target>
    <target name="distmac" depends="dist">
        <antcall target="mac">
            <param name="bundle.outdir" value="dist"/>
            <param name="bundle.jar" value="dist/josm-custom.jar"/>
        </antcall>
    </target>
    <!-- Windows target -->
    <target name="distwin" depends="dist">
        <exec dir="windows" executable="./josm-setup-unix.sh">
            <arg value="${version.entry.commit.revision}"/>
            <arg value="../dist/josm-custom.jar"/>
        </exec>
    </target>
    <target name="javacc" depends="init" unless="javacc.notRequired">
        <mkdir dir="${mapcss.dir}/parsergen"/>
        <exec append="false" executable="java" failifexecutionfails="true">
            <arg value="-cp"/>
            <arg value="${javacc.home}/javacc.jar"/>
            <arg value="javacc"/>
            <arg value="-DEBUG_PARSER=false"/>
            <arg value="-DEBUG_TOKEN_MANAGER=false"/>
            <arg value="-JDK_VERSION=1.7"/>
            <arg value="-GRAMMAR_ENCODING=UTF-8"/>
            <arg value="-OUTPUT_DIRECTORY=${mapcss.dir}/parsergen"/>
            <arg value="${mapcss.dir}/MapCSSParser.jj"/>
        </exec>
    </target>
    <target name="-jaxb_win" if="isWindows">
        <property name="xjc" value="${java.home}\..\bin\xjc.exe" />
    </target>
    <target name="-jaxb_nix" unless="isWindows">
        <property name="xjc" value="${java.home}/../bin/xjc" />
    </target>
    <target name="jaxb" depends="init, -jaxb_win, -jaxb_nix" unless="jaxb.notRequired">
        <exec executable="${xjc}" failonerror="true">
            <arg value="-d"/>
            <arg value="${src.dir}"/>
            <arg value="-encoding"/>
            <arg value="UTF-8"/>
            <arg value="data_nodist/wms-cache.xsd"/>
        </exec>
    </target>
    <target name="compile" depends="init,javacc,jaxb">
        <!-- COTS -->
        <javac srcdir="${src.dir}" includes="com/**,oauth/**,org/apache/commons/**,org/glassfish/**" nowarn="on" encoding="iso-8859-1"
            destdir="build" target="1.7" source="1.7" debug="on" includeAntRuntime="false" createMissingPackageInfoClass="false">
            <!-- get rid of "internal proprietary API" warning -->
            <compilerarg value="-XDignore.symbol.file"/>
            <exclude name="org/apache/commons/compress/compressors/lzma/**"/>
            <exclude name="org/apache/commons/compress/compressors/xz/**"/>
            <exclude name="org/apache/commons/compress/compressors/CompressorStreamFactory.java"/>
            <exclude name="org/apache/commons/compress/compressors/deflate/**"/>
            <exclude name="org/apache/commons/compress/compressors/gzip/**"/>
            <exclude name="org/apache/commons/compress/compressors/lzw/**"/>
            <exclude name="org/apache/commons/compress/compressors/pack200/**"/>
            <exclude name="org/apache/commons/compress/compressors/snappy/**"/>
            <exclude name="org/apache/commons/compress/compressors/z/**"/>
            <exclude name="org/apache/commons/jcs/admin/**"/>
            <exclude name="org/apache/commons/jcs/auxiliary/disk/jdbc/**"/>
            <exclude name="org/apache/commons/jcs/auxiliary/remote/**"/>
            <exclude name="org/apache/commons/jcs/utils/servlet/**"/>
            <exclude name="org/apache/commons/logging/impl/AvalonLogger.java"/>
            <exclude name="org/apache/commons/logging/impl/Jdk13LumberjackLogger.java"/>
            <exclude name="org/apache/commons/logging/impl/Log4JLogger.java"/>
            <exclude name="org/apache/commons/logging/impl/LogKitLogger.java"/>
            <exclude name="org/apache/commons/logging/impl/ServletContextCleaner.java"/>
        </javac>
        <!-- JMapViewer/JOSM -->
        <javac srcdir="${src.dir}" excludes="com/**,oauth/**,org/apache/commons/**,org/glassfish/**,org/openstreetmap/gui/jmapviewer/Demo.java" 
            destdir="build" target="1.7" source="1.7" debug="on" includeantruntime="false" createMissingPackageInfoClass="false" encoding="UTF-8">
            <compilerarg value="-Xlint:cast"/>
            <compilerarg value="-Xlint:deprecation"/>
            <compilerarg value="-Xlint:dep-ann"/>
            <compilerarg value="-Xlint:divzero"/>
            <compilerarg value="-Xlint:empty"/>
            <compilerarg value="-Xlint:finally"/>
            <compilerarg value="-Xlint:overrides"/>
            <!--<compilerarg value="-Xlint:rawtypes"/>-->
            <compilerarg value="-Xlint:static"/>
            <compilerarg value="-Xlint:try"/>
            <compilerarg value="-Xlint:unchecked"/>
            <!-- Undocumented argument to ignore "Sun internal proprietary API" warning, see http://stackoverflow.com/a/13862308/2257172 -->
            <compilerarg value="-XDignore.symbol.file"/>
        </javac>
        <copy todir="build" failonerror="no" includeemptydirs="no">
            <fileset dir="resources"/>
        </copy>
    </target>
    <target name="init">
        <uptodate property="javacc.notRequired" targetfile="${mapcss.dir}/parsergen/MapCSSParser.java" >
            <srcfiles dir="${mapcss.dir}" includes="MapCSSParser.jj"/>
        </uptodate>
        <uptodate property="jaxb.notRequired" targetfile="${src.dir}/org/openstreetmap/josm/data/imagery/types/package-info.java" >
            <srcfiles dir="data_nodist" includes="wms-cache.xsd"/>
        </uptodate>
        <mkdir dir="build"/>
        <mkdir dir="dist"/>
    </target>
    <target name="javadoc">
        <javadoc destdir="javadoc" 
                sourcepath="${src.dir}"
                encoding="UTF-8"    
                packagenames="org.openstreetmap.josm.*,org.openstreetmap.gui.jmapviewer.*"
                windowtitle="JOSM"
                use="true"
                private="true"
                linksource="true"
                author="false">
            <link href="http://docs.oracle.com/javase/7/docs/api"/>
            <doctitle><![CDATA[<h2>JOSM - Javadoc</h2>]]></doctitle>
            <bottom><![CDATA[<a href="https://josm.openstreetmap.de/">JOSM</a>]]></bottom>
        </javadoc>
    </target>
    <target name="clean">
        <delete dir="build"/>
        <delete dir="dist"/>
        <delete dir="${mapcss.dir}/parsergen"/>
        <delete dir="${imagerytypes.dir}"/>
    </target>
    <path id="test.classpath">
        <fileset dir="${test.dir}/lib">
            <include name="**/*.jar"/>
        </fileset>
        <pathelement path="dist/josm-custom.jar"/>
        <pathelement path="tools/groovy-all-2.4.3.jar"/>
    </path>
    <macrodef name="init-test-preferences">
        <attribute name="testfamily"/>
        <sequential>
            <copy file="${test.dir}/config/preferences.template.xml" tofile="${test.dir}/config/@{testfamily}-josm.home/preferences.xml"/>
            <replace file="${test.dir}/config/@{testfamily}-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_USERNAME@" value="${osm.username}"/>
            <replace file="${test.dir}/config/@{testfamily}-josm.home/preferences.xml" encoding="UTF-8" token="@OSM_PASSWORD@" value="${osm.password}"/>
        </sequential>
    </macrodef>
    <target name="test-init">
        <mkdir dir="${test.dir}/build"/>
        <mkdir dir="${test.dir}/build/unit"/>
        <mkdir dir="${test.dir}/build/functional"/>
        <mkdir dir="${test.dir}/build/performance"/>
        <mkdir dir="${test.dir}/report"/>
        <init-test-preferences testfamily="unit"/>
        <init-test-preferences testfamily="functional"/>
        <init-test-preferences testfamily="performance"/>
    </target>
    <target name="test-clean">
        <delete dir="${test.dir}/build"/>
        <delete dir="${test.dir}/report"/>
        <delete file="${test.dir}/jacoco.exec" />
        <delete file="${test.dir}/config/unit-josm.home/preferences.xml" />
        <delete file="${test.dir}/config/functional-josm.home/preferences.xml" />
        <delete file="${test.dir}/config/performance-josm.home/preferences.xml" />
        <delete dir="${test.dir}/config/unit-josm.home/cache" failonerror="false"/>
        <delete dir="${test.dir}/config/functional-josm.home/cache" failonerror="false"/>
        <delete dir="${test.dir}/config/performance-josm.home/cache" failonerror="false"/>
    </target>
    <macrodef name="call-groovyc">
        <attribute name="testfamily"/>
        <element name="cp-elements"/>
        <sequential>
            <groovyc srcdir="${test.dir}/@{testfamily}" destdir="${test.dir}/build/@{testfamily}" encoding="UTF-8">
                <classpath>
                    <cp-elements/>
                </classpath>
                <javac target="1.7" source="1.7" debug="on" encoding="UTF-8">
                    <compilerarg value="-Xlint:all"/>
                    <compilerarg value="-Xlint:-serial"/>
                </javac>
            </groovyc>
        </sequential>
    </macrodef>
    <target name="test-compile" depends="test-init,dist">
        <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpath="tools/groovy-all-2.4.3.jar"/>
        <call-groovyc testfamily="unit">
            <cp-elements>
                <path refid="test.classpath"/>
            </cp-elements>
        </call-groovyc>
        <call-groovyc testfamily="functional">
            <cp-elements>
                <path refid="test.classpath"/>
                <pathelement path="${test.dir}/build/unit"/>
            </cp-elements>
        </call-groovyc>
        <call-groovyc testfamily="performance">
            <cp-elements>
                <path refid="test.classpath"/>
                <pathelement path="${test.dir}/build/unit"/>
            </cp-elements>
        </call-groovyc>
    </target>
    <macrodef name="call-junit">
        <attribute name="testfamily"/>
        <sequential>
            <echo message="Running @{testfamily} tests with JUnit"/>
            <jacoco:coverage destfile="${test.dir}/jacoco.exec">
                <junit printsummary="yes" fork="true" forkmode="once">
                    <jvmarg value="-Dfile.encoding=UTF-8"/>
                    <sysproperty key="josm.home" value="${test.dir}/config/@{testfamily}-josm.home"/>
                    <sysproperty key="josm.test.data" value="${test.dir}/data"/>
                    <sysproperty key="java.awt.headless" value="true"/>
                    <sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
                    <classpath>
                        <path refid="test.classpath"/>
                        <pathelement path="${test.dir}/build/unit"/>
                        <pathelement path="${test.dir}/build/@{testfamily}"/>
                        <pathelement path="${test.dir}/config"/>
                    </classpath>
                    <formatter type="plain"/>
                    <formatter type="xml"/>
                    <batchtest fork="yes" todir="${test.dir}/report">
                        <fileset dir="${test.dir}/build/@{testfamily}" includes="**/*Test.class"/>
                    </batchtest>
                </junit>
            </jacoco:coverage>
        </sequential>
    </macrodef>
    <target name="test" depends="test-compile" 
        description="Run unit, functional and performance tests. OSM API (TEST) account shall be set with -Dosm.username and -Dosm.password">
        <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="tools/jacocoant.jar" />
        <call-junit testfamily="unit"/>
        <call-junit testfamily="functional"/>
        <call-junit testfamily="performance"/>
    </target>
    <target name="test-html" depends="test" description="Generate HTML test reports">
        <!-- May require additional ant dependencies like ant-trax package -->
        <junitreport todir="${test.dir}/report">
            <fileset dir="${test.dir}/report">
                <include name="TEST-*.xml"/>
            </fileset>
            <report todir="${test.dir}/report/html"/>
        </junitreport>
        <jacoco:report>
            <executiondata>
                <file file="${test.dir}/jacoco.exec"/>
            </executiondata>
            <structure name="JOSM Test Coverage">
                <classfiles>
                    <fileset dir="${build.dir}" includes="org/openstreetmap/"/>
                </classfiles>
                <sourcefiles encoding="UTF-8">
                    <fileset dir="${src.dir}" includes="org/openstreetmap/"/>
                </sourcefiles>
            </structure>
            <html destdir="${test.dir}/report/jacoco"/>
        </jacoco:report>
    </target>
    <target name="dist-optimized" depends="dist">
        <taskdef resource="proguard/ant/task.properties" classpath="tools/proguard.jar"/>
        <proguard>
        -injars dist/josm-custom.jar
        -outjars dist/josm-custom-optimized.jar

        -libraryjars ${java.home}/lib/rt.jar
        -libraryjars ${java.home}/lib/jce.jar

        -dontoptimize
        -dontobfuscate

        # These options probably are not necessary (and make processing a bit slower)
        -dontskipnonpubliclibraryclasses
        -dontskipnonpubliclibraryclassmembers

        -keepclasseswithmembers public class org.openstreetmap.josm.gui.MainApplication {
            public static void main(java.lang.String[]);
        }
        -keepclasseswithmembers public class org.openstreetmap.josm.gui.MainApplet

        -keep class JOSM
        -keep class * extends org.openstreetmap.josm.io.FileImporter
        -keep class * extends org.openstreetmap.josm.io.FileExporter
        -keep class org.w3._2001.xmlschema.Adapter1
        -keep class org.openstreetmap.josm.actions.search.SearchCompiler$Never
        -keep class org.apache.commons.logging.impl.*

        -keepclassmembers enum  * {
            public static **[] values();
            public static ** valueOf(java.lang.String);
        }

        # Keep unused public methods (can be useful for plugins)
        -keepclassmembers class * {
            public protected *;
        }

        # Disable annoying [proguard] Note: the configuration keeps the entry point '...', but not the descriptor class '...'.
        # This note should not be a problem as we don't use obfuscation
        -dontnote
        </proguard>
    </target>
    <target name="check-plugins" depends="dist-optimized">
        <echo message="Check of plugins binary compatibility (needs ant 1.8)"/>
        <local name="dir"/>
        <local name="plugins"/>
        <property name="dir" value="plugin-check"/>
        <typedef uri="antlib:org.codehaus.mojo.animal_sniffer">
            <classpath path="tools/animal-sniffer-ant-tasks-1.14.jar"/>
        </typedef>
        <mkdir dir="${dir}"/>
        <!-- List of deprecated plugins -->
        <loadfile property="deprecated-plugins" srcFile="${src.dir}/org/openstreetmap/josm/plugins/PluginHandler.java">
            <filterchain>
                <linecontains>
                    <contains value="new DeprecatedPlugin("/>
                </linecontains>
                <tokenfilter>
                    <replaceregex pattern=".*new DeprecatedPlugin\(&quot;(.+?)&quot;.*" replace="\1|" flags="gi"/>
                </tokenfilter>
                <striplinebreaks/>
                <tokenfilter>
                    <replaceregex pattern="\|$" replace="" flags="gi"/>
                </tokenfilter>
            </filterchain>
        </loadfile>
        <!-- Download list of plugins -->
        <loadresource property="plugins">
            <url url="https://josm.openstreetmap.de/plugin"/>
            <filterchain>
                <linecontainsregexp negate="true">
                    <regexp pattern="^\t.*"/>
                </linecontainsregexp>
                <linecontainsregexp negate="true">
                    <regexp pattern="${deprecated-plugins}"/>
                </linecontainsregexp>
                <tokenfilter>
                    <replaceregex pattern="^.*;" replace="" flags="gi"/>
                </tokenfilter>
            </filterchain>
        </loadresource>
        <!-- Delete files that are not in plugin list (like old plugins) -->
        <loadresource property="file-list">
            <propertyresource name="plugins"/>
            <filterchain>
                <tokenfilter>
                    <replaceregex pattern="^.*/(.*)$" replace="\1\|" flags=""/>
                </tokenfilter>
                <striplinebreaks/>
                <tokenfilter>
                    <replaceregex pattern="\|$" replace="" flags="gi"/>
                </tokenfilter>    
            </filterchain>
        </loadresource>
        <delete>
            <restrict>
                <fileset dir="${dir}"/>
                <not>
                    <name regex="${file-list}"/>
                </not>
            </restrict>
        </delete>
        <!-- Download plugins -->
        <copy todir="${dir}" flatten="true">
            <resourcelist>
                <string value="${plugins}"/>
            </resourcelist>
        </copy>
        <!-- Check plugins -->
        <as:build-signatures destfile="${dir}/api.sig">
            <path>
                <fileset file="dist/josm-custom-optimized.jar"/>
                <fileset file="${java.home}/lib/rt.jar"/>
                <fileset file="${java.home}/lib/jce.jar"/>
            </path>
        </as:build-signatures>
        <as:check-signature signature="${dir}/api.sig">
            <ignore classname="au.edu.*"/>
            <ignore classname="au.com.*"/>
            <ignore classname="com.*"/>
            <ignore classname="de.miethxml.*"/>
            <ignore classname="javafx.*"/>
            <ignore classname="javax.*"/>
            <ignore classname="jogamp.*"/>
            <ignore classname="junit.*"/>
            <ignore classname="net.sf.*"/>
            <ignore classname="nu.xom.*"/>
            <ignore classname="org.apache.*"/>
            <ignore classname="org.codehaus.*"/>
            <ignore classname="org.dom4j.*"/>
            <ignore classname="org.hsqldb.*"/>
            <ignore classname="org.ibex.*"/>
            <ignore classname="org.iso_relax.*"/>
            <ignore classname="org.jaitools.*"/>
            <ignore classname="org.jaxen.*"/>
            <ignore classname="org.jdom2.*"/>
            <ignore classname="org.jgraph.*"/>
            <ignore classname="org.joda.time.*"/>
            <ignore classname="org.jvnet.staxex.*"/>
            <ignore classname="org.kxml2.*"/>
            <ignore classname="org.objectweb.*"/>
            <ignore classname="org.python.*"/>
            <ignore classname="org.slf4j.*"/>
            <!-- plugins used by another ones -->
            <ignore classname="org.openstreetmap.josm.plugins.geotools.*"/>
            <ignore classname="org.openstreetmap.josm.plugins.jna.*"/>
            <ignore classname="org.openstreetmap.josm.plugins.jts.*"/>
            <ignore classname="org.openstreetmap.josm.plugins.log4j.*"/>
            <ignore classname="org.openstreetmap.josm.plugins.utilsplugin2.*"/>
            <path path="${dir}"/>
        </as:check-signature>
    </target>

    <target name="checkstyle">
        <taskdef resource="checkstyletask.properties" classpath="tools/checkstyle/checkstyle-6.7-all.jar"/>
        <checkstyle config="tools/checkstyle/josm_checks.xml">
            <fileset dir="${basedir}/src/org/openstreetmap/josm" includes="**/*.java" 
            	excludes="data/imagery/types/*.java,gui/mappaint/mapcss/parsergen/*.java"/>
            <fileset dir="${basedir}/test" includes="**/*.java"/>
            <formatter type="xml" toFile="checkstyle-josm.xml"/>
        </checkstyle>
    </target>

    <target name="findbugs" depends="dist">
        <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="tools/findbugs/findbugs-ant.jar"/>
        <path id="findbugs-classpath">
            <fileset dir="tools/findbugs/">
                <include name="*.jar"/>
            </fileset>
        </path>
        <property name="findbugs-classpath" refid="findbugs-classpath"/>
        <findbugs output="xml"
                outputFile="findbugs-josm.xml"
                classpath="${findbugs-classpath}"
                pluginList=""
                excludeFilter="tools/findbugs/josm-filter.xml"
                effort="max"
                >
            <sourcePath path="${basedir}/src" />
            <class location="${basedir}/dist/josm-custom.jar" />
        </findbugs>
    </target>
    <target name="run" depends="dist">
        <java jar="dist/josm-custom.jar" fork="true">
            <arg value="--set=expert=true"/>
            <arg value="--set=remotecontrol.enabled=true"/>
            <arg value="--set=debug.edt-checker.enable=false"/>
            <jvmarg value="-Djosm.home=/tmp/.josm/"/>
        </java>
    </target>
</project>
