<!--
  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="site" default="docs" basedir=".">

	<!-- Initialization properties -->
	<property name="project.name"   value="site"/>

	<!-- The source directory for our XML source documents which are
    to be sytlized and transformed into XHTML. -->
	<property name="docs.src" value="xdocs"/>

	<!-- The destination directory for content generated from our XML
    sources. -->
	<property name="docs.dest" value="docs"/>

	<property name="texen.work" value="target/texen"/>
	<property name="texen.src" value="xdocs/stylesheets/texen"/>

	<path id="classpath">
		<fileset dir="./lib">
			<include name="**/*.jar"/>
		</fileset>
	</path>

	<target name="prepare-texen">
		<available classname="org.apache.velocity.texen.ant.TexenTask" 
            property="TexenTask.present">
			<classpath refid="classpath"/>
		</available>
	</target>

	<target depends="prepare-texen" name="prepare-error-texen" unless="TexenTask.present">
		<echo>
        	  TexenTask is not present! Please check to make sure that 
            velocity.jar is in your classpath.
        </echo>
	</target>

	<target name="prepare">
		<available classname="org.apache.velocity.anakia.AnakiaTask" property="AnakiaTask.present">
			<classpath refid="classpath"/>
		</available>
	</target>

	<target depends="prepare" name="prepare-error" unless="AnakiaTask.present">
		<echo>
            AnakiaTask is not present! Please check to make sure that 
            velocity.jar is in your classpath.
        </echo>
	</target>

	
	<target name="docs" depends="prepare-error" if="AnakiaTask.present">
		<taskdef name="anakia" classname="org.apache.velocity.anakia.AnakiaTask">
			<classpath refid="classpath"/>
		</taskdef>
		<property name="anakia.check.date" value="true"/>
		<anakia basedir="${docs.src}" destdir="${docs.dest}/"
             extension=".html" style="./site.vsl"
             projectFile="stylesheets/project.xml"
             excludes="**/stylesheets/**,**/_template.xml"
             includes="**/*.xml"
             lastModifiedCheck="${anakia.check.date}"
             templatePath="${docs.src}/stylesheets"
             velocityPropertiesFile="build.props"
        >
		</anakia>

		<copy todir="${docs.dest}/" filtering="no">
			<fileset dir="${docs.src}/">
				<!-- 
				   Ignore the Anakia style sheet used for processing
	                of the xdocs, and the unprocessed xdocs themselves,
	                but copy all other content to the directory which is
	                checked out on the server. 
                -->
				<exclude name="**/*.xml"/>
				<exclude name="**/stylesheets/**"/>
				
				<!-- Editor-specific ignores. -->
				<exclude name="**/*~"/>
				<exclude name="**/.#*"/>
			</fileset>
		</copy>
		<echo level="info">
			The build process only rebuilds html files that are older than the corresponding xml file. 
			If a file is not updated, and you think it should be, try deleting the html file and rebuilding.
			
			Or rebuild with the property:  -Danakia.check.date=false
		</echo>

		<antcall target="FixCRLF"></antcall>
	</target>
	
	<target name="checkOS">
		<condition property="os.windows">
			<os family="windows"/>
		</condition>
	</target>
	
	<!-- 
	    Anakia seems to get confused about line-endings in some html files on Windows.
	    This target can be used to restore the line endings.
	-->
	<target name="FixCRLF" description="Fix the line endings of HTML files on Windows" depends="checkOS" if="os.windows">
		<echo level="info" message="Updating CRLF endings"/>
		<fixcrlf srcdir="${docs.dest}" includes="**/*.html"/>
	</target>

	  <target name="clean-docs">
	    <delete includeEmptyDirs="true"> 
	    	<fileset dir="${docs.dest}" excludes=".svn/**"/>
	    </delete>
	  </target>

</project>
