<project default="usage">

    <!-- updated for forrest 0.9 -->
    <!-- check https://forrest.apache.org/docs_0_90/your-project.html#invoking_from_ant -->
    <!-- TODO: cp forrest/lib/core/xml-commons-resolver-*.jar $ANT_HOME/lib -->

    <property environment="env"/>
    <property name="build.site" location="build/site"/>

    <target name="usage">
        <echo message="Run 'ant -projecthelp' for usage."/>
    </target>

    <!-- documentation targets -->

    <target name="docs" depends="docs-1.x, docs-trunk"
        description="Builds javadocs for multiple versions of XmlBeans.">
    </target>

    <target name="docs-1.x">
        <ant dir="../branches/1.x" target="docs">
        </ant>
        <copy todir="src/documentation/content/docs/1.0.4">
            <fileset dir="../branches/1.x/build/docs"/>
        </copy>
    </target>

    <target name="docs-trunk">
        <ant dir="../trunk" target="docs">
        </ant>
        <copy todir="src/documentation/content/docs/3.0.0">
            <fileset dir="../trunk/build/docs"/>
        </copy>
    </target>

    <!-- samples targets -->

    <target name="samples"
        description="Builds samples archives">
        <ant dir="../trunk/samples" target="dist">
        </ant>
        <copy todir="src/documentation/content/samples">
            <fileset dir="../trunk/samples/build"/>
        </copy>
    </target>

    <target name="site" depends="-check-forrest-installed"
            description="Builds website documentation">
        <exec executable="${env.FORREST_HOME}/bin/forrest"/>


        <!-- Apache Forrest is dead, so we cannot expect fixes there
            however it does not handle "https" in "credits" currently
            if the *.xml file is in a sub-directory, see Apache Forrest
            code at main/webapp/skins/pelt/xslt/html/site-to-xhtml.xsl:350

            So we need to replace the links afterwards to have a fully "https"
            website and avoid browser warning about a "mixed content"
            website -->
        <echo>Fix https in ${build.site}</echo>
        <replace dir="${build.site}"
                 token="http://www.apache.org/events/current-event-125x125.png"
                 value="https://www.apache.org/events/current-event-125x125.png"
                 summary="true"
                 includes="**/*.html"/>
        <replace dir="${build.site}"
                 token="http://www.google.com/search"
                 value="https://www.google.com/search"
                 summary="true"
                 includes="**/*.html"/>
        <replace dir="${build.site}"
                 token="http://validator.w3.org/"
                 value="https://validator.w3.org/"
                 summary="true"
                 includes="**/*.html"/>
        <replace dir="${build.site}"
                 token="http://jigsaw.w3.org/"
                 value="https://jigsaw.w3.org/"
                 summary="true"
                 includes="**/*.html"/>

        <fixcrlf srcdir="${build.site}" includes="**/*.html,**/*.css" eol="unix" eof="remove" />

        <touch>
            <fileset dir="${build.site}"/>
        </touch>
    </target>

    <target name="-check-forrest-installed" unless="env.FORREST_HOME">
        <echo>Please install Apache Forrest (see
            &lt;https://forrest.apache.org/index.html&gt;) and set the
            FORREST_HOME environment variable!
        </echo>
        <fail message="Apache Forrest is not installed."/>
    </target>


</project>
