<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except in
compliance with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<project name="pivot-site" default="build" basedir=".">

    <!-- Properties that affect the directories that are created as part of the build -->
    <property name="folder.trunk" location="trunk"/>
    <property name="folder.deploy" location="deploy"/>

    <!-- Dynamic properties -->
    <property file="${folder.trunk}/build.properties"/>


    <!-- Ant argument check -->
    <fail unless="version">
    <![CDATA[
    Error:

    Usage: ant [-Dfolder.trunk=pathtotrunk] [target]

    Parameters:
      folder.trunk    This specifies the file system location of the pivot trunk. 
	                  The site pulls the current Pivot version, 
                      the demos, and the tutorials from this location. 
                      If unspecified, it will default to 'trunk', meaning that 
                      you can either check the trunk out into this folder, 
                      or you can create a symbolic link named 'trunk' that 
                      links to the trunk.

    ]]>
    </fail>


    <!-- Transform macro -->
    <macrodef name="transform">
        <attribute name="stylesheet"/>
        <attribute name="destdir" default="${folder.deploy}"/>
        <element name="nested-elements" implicit="true"/>

        <sequential>
            <xslt force="true"
                useImplicitFileset="false"
                extension=".html"
                destdir="@{destdir}"
                style="@{stylesheet}">
                <param name="version" expression="${version}"/>
                <param name="trunk" expression="${folder.trunk}"/>
                <nested-elements/>
            </xslt>
        </sequential>
    </macrodef>


    <!-- Removes build artifacts -->
    <target name="clean" description="Removes build artifacts">
        <delete dir="${folder.deploy}"/>
    </target>

    <!-- Builds the site -->
    <target name="build" description="Builds the site">
        <!-- perform XSLT transformations -->
        <transform stylesheet="xsl/index.xsl">
            <fileset dir="www" includes="index.xml"/>
        </transform>

        <transform stylesheet="xsl/auxilliary.xsl">
            <fileset dir="www" includes="**/*.xml" excludes="index.xml"/>
        </transform>

        <transform stylesheet="xsl/demos/index.xsl" destdir="${folder.deploy}/demos">
            <fileset dir="${folder.trunk}/demos/www" includes="index.xml"/>
        </transform>

        <transform stylesheet="xsl/demos/auxilliary.xsl" destdir="${folder.deploy}/demos">
            <fileset dir="${folder.trunk}/demos/www" includes="**/*.xml" excludes="index.xml"/>
        </transform>

        <transform stylesheet="xsl/tutorials/index.xsl" destdir="${folder.deploy}/tutorials">
            <fileset dir="${folder.trunk}/tutorials/www" includes="index.xml"/>
        </transform>

        <transform stylesheet="xsl/tutorials/auxilliary.xsl" destdir="${folder.deploy}/tutorials">
            <fileset dir="${folder.trunk}/tutorials/www" includes="**/*.xml" excludes="index.xml"/>
        </transform>
        <copy todir="${folder.deploy}/tutorials">
            <fileset dir="${folder.trunk}/tutorials/www">
                <include name="**/*.png"/>
                <include name="**/*.jpg"/>
            </fileset>
        </copy>

        <!-- Copy static resource files -->
        <copy todir="${folder.deploy}">
            <fileset dir="www" excludes="**/*.xml"/>
        </copy>

        <!-- Generate API documentation -->
        <javadoc packagenames="org.apache.pivot.*" destdir="${folder.deploy}/${version}/docs/api"
            author="true" version="true" use="true"
            classpath="${java.class.path}"
		>
            <classpath>
                <fileset dir="${folder.trunk}/web-server/lib" includes="**/*.jar"/>
                <fileset dir="${folder.trunk}/wtk/lib" includes="**/*.jar"/>
                <fileset dir="${java.home}/lib" includes="**/*.jar"/>
            </classpath>

            <packageset dir="${folder.trunk}/charts/src" includes="**/*"/>
            <packageset dir="${folder.trunk}/core/src" includes="**/*"/>
            <packageset dir="${folder.trunk}/web/src" includes="**/*"/>
            <packageset dir="${folder.trunk}/web-server/src" includes="**/*"/>
            <packageset dir="${folder.trunk}/wtk/src" includes="**/*"/>
            <packageset dir="${folder.trunk}/wtk-terra/src" includes="**/*"/>

            <link href="http://download.oracle.com/javase/6/docs/api"/>
            <link href="http://download.oracle.com/javaee/5/api/"/>

            <header>
			</header>
        </javadoc>
    </target>

</project>
