<?xml version="1.0" encoding="utf-8"?>
<project name="josm-plugins" default="dist" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless">
    <target name="compile_josm" unless="skip-josm">
        <ant dir="../core" target="dist"/>
    </target>
    <target name="compile_josm_test" unless="skip-josm">
        <ant dir="../core" target="test-compile"/>
    </target>
    <!-- For Java specific stuff by version -->
    <condition property="isJava21"><matches string="${ant.java.version}" pattern="2[1-9]|[3-9][0-9]" /></condition>
    <condition property="isJava17"><matches string="${ant.java.version}" pattern="1[7-9]|[2-9][0-9]" /></condition>
    <!-- Specific plugins -->
    <property name="java21_plugins" value="FIT/build.xml
                                            MicrosoftStreetside/build.xml" />
    <property name="java17_plugins" value="cadastre-fr/build.xml
                                            javafx/build.xml
                                            ImageIO/build.xml
                                            Mapillary/build.xml
                                            MapRoulette/build.xml
                                            pmtiles/build.xml
                                            todo/build.xml"/>
    <property name="ordered_plugins" value="jackson/build.xml
                                            jaxb/build.xml
                                            jna/build.xml
                                            jts/build.xml
                                            ejml/build.xml
                                            utilsplugin2/build.xml
                                            log4j/build.xml
                                            apache-commons/build.xml
                                            apache-http/build.xml
                                            geotools/build.xml
                                            austriaaddresshelper/build.xml"/>
    <macrodef name="iterate">
        <attribute name="target"/>
        <sequential>
            <subant target="@{target}" inheritall="true">
                <filelist dir="." files="${ordered_plugins}"/>
                <filelist dir="." files="${java17_plugins}" if:set="isJava17"/>
                <filelist dir="." files="${java21_plugins}" if:set="isJava21"/>
                <fileset  dir="." includes="*/build.xml" excludes="00_*/build.xml *.wip/build.xml ${ordered_plugins} ${java17_plugins} ${java21_plugins} "/>
            </subant>
        </sequential>
    </macrodef>
    <target name="clean">
        <iterate target="clean"/>
    </target>
    <target name="compile">
        <iterate target="compile"/>
    </target>
    <target name="dist" depends="compile_josm">
        <mkdir dir="../dist"/>
        <iterate target="dist"/>
        <property name="skip-dist" value="true"/>
        <property name="skip-compile" value="true"/>
        <property name="skip-revision" value="true"/>
    </target>
    <target name="install" depends="dist">
        <iterate target="install"/>
    </target>
    <target name="test" depends="compile_josm_test">
        <iterate target="test"/>
    </target>
    <target name="checkstyle">
        <iterate target="checkstyle"/>
    </target>
    <target name="spotbugs">
        <iterate target="spotbugs"/>
    </target>
    <target name="javadoc">
        <iterate target="javadoc"/>
    </target>
</project>
