<project name="keycloak-dist" basedir=".">
    <target name="jboss">
        <unzip src="${org.jboss.as:jboss-as-dist:zip}" dest="${project.build.directory}"/>
        <chmod perm="755">
            <fileset dir="${project.build.directory}/jboss-as-${jboss.version}/bin">
                <include name="**/*.sh"/>
            </fileset>
        </chmod>
        <move todir="${build.target.dir}" overwrite="true">
            <fileset dir="${project.build.directory}/jboss-as-${jboss.version}">
                <include name="**/*"/>
            </fileset>
        </move>
        <delete dir="${project.build.directory}/jboss-as-${jboss.version}"/>
    </target>

    <target name="resteasy-modules">
        <get src="http://sourceforge.net/projects/resteasy/files/Resteasy%20JAX-RS/${resteasy.version}/resteasy-jaxrs-${resteasy.version}-all.zip"
             dest="${project.build.directory}" skipexisting="true"/>
        <unzip src="${project.build.directory}/resteasy-jaxrs-${resteasy.version}-all.zip"
               dest="${project.build.directory}">
            <patternset>
                <include name="resteasy-jaxrs-${resteasy.version}/resteasy-jboss-modules-${resteasy.version}.zip"/>
            </patternset>
            <mapper type="flatten"/>
        </unzip>
        <unzip src="${project.build.directory}/resteasy-jboss-modules-${resteasy.version}.zip"
               dest="${build.target.dir}/modules"/>
    </target>

    <target name="keycloak-server">
        <copy file="${org.keycloak:keycloak-server:war}"
              tofile="${build.target.dir}/standalone/deployments/auth-server.war" overwrite="true"/>
    </target>

    <target name="all" depends="jboss, resteasy-modules, keycloak-server"/>
</project>
