<?xml version="1.0" encoding="UTF-8"?>
<project name="ol" default="usage">

    <description>
        OpenLayers Dev Utilities
    </description>
    
    <property name="ol.home" location=".."/>
    <property name="plovr.version" value="4b3caf2b7d84"/>
    <property name="plovr.jar" location="${ol.home}/bin/plovr-${plovr.version}.jar"/>
    <property name="main.json" location="${ol.home}/main.json"/>
    <property name="build.json" location="${ol.home}/api.json"/>

    <target name="usage">
        <echo>
        Available commands:
        
        serve - Run the library server
        build - Builds a minified version of the library or an application
        doc   - Generate the reference docs
        </echo>
    </target>

    <condition property="plovr.exists">
        <available file="${plovr.jar}" type="file"/>
    </condition>
    
    <target name="deps" unless="plovr.exists">
        <get src="http://plovr.googlecode.com/files/plovr-${plovr.version}.jar"
            dest="${plovr.jar}"/>
    </target>
    
    <target name="serve" depends="deps">
        <java jar="${plovr.jar}" fork="true">
            <arg value="serve"/>
            <arg value="${main.json}"/>
        </java>
    </target>

    <target name="checkpath">
        <condition property="build.json.set">
            <isset property="build.json"/>
        </condition>
        <fail message="Missing build config." unless="build.json.set"/>
        <property name="build.json.fullpath" location="${build.json}"/>
        <condition property="build.json.exists">
            <available file="${build.json.fullpath}" type="file"/>
        </condition>
    </target>

    <target name="build" depends="deps, checkpath">
        <fail message="Build config '${build.json.fullpath}' doesn't exist." unless="build.json.exists"/>
        <java jar="${plovr.jar}" fork="true">
            <arg value="build"/>
            <arg value="${build.json}"/>
        </java>
    </target>
    
    <target name="doc" depends="deps">
        <java jar="${plovr.jar}" fork="true">
            <arg value="jsdoc"/>
            <arg value="${main.json}"/>
        </java>
    </target>

</project>
