<?xml version="1.0"?>
<project default="create-doc" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">

	<property name="toolsdir" location="C:/JAVA-DEV/" />
		
		
	<!-- C:\JAVA-DEV\apache-fop-1.1 -->

	<taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop">
		<classpath>
			<fileset dir="${toolsdir}/fop-2.2/fop">
				<include name="build/*.jar" />
				<include name="lib/*.jar" />
			</fileset>
		</classpath>
	</taskdef>

	<!-- External Syntax Higlighter for docbook xsl -->
	<path id="xslthl.path">
		<pathelement location="${toolsdir}/xslthl-2.1.3/xslthl-2.1.3.jar" />
	</path>


	<property name="current-loc" location="." />
	<property name="workspace" location=".." />

	<property name="htmldir" value="${current-loc}/doc/html" />
	<property name="docbookdir" value="${toolsdir}/docbook-xsl-1.79.1/" />

	<property name="fo.stylesheet" value="${docbookdir}/fo/docbook.xsl" />
	<property name="fo.stylesheet.hl" value="${docbookdir}/fo/docbook.xsl" />
	<property name="html.stylesheet.hl" value="${docbookdir}/html/docbook.xsl" />
	<property name="html.chunked.stylesheet.hl" value="${docbookdir}/html/docbook.xsl" />
	<property name="eclipse.stylesheet" value="${docbookdir}/eclipse/eclipse.xsl" />
	<property name="html.stylesheet" value="${docbookdir}/html/docbook.xsl" />
	<property name="javahelp.stylesheet" value="${docbookdir}/javahelp/javahelp.xsl" />
	<property name="xhtml5.stylesheet" value="${docbookdir}/xhtml5/docbook.xsl" />

	<property name="docbooksource" value="${current-loc}/doc" />
	<property name="xalan" value="org.apache.xalan.processor.TransformerFactoryImpl" />
	<property name="web.dir" value="${current-loc}/web" />
	<property name="build.dir" value="${current-loc}/build/classes" />
	<property name="bin.dir" value="${current-loc}/bin" />
	<property name="delivery.dir" value="c:/TEMP/_DELIVERY_AREA" />
	<property name="name" value="XServices" />


	<!-- XSLT Chunking Properties -->
	<property name="base.dir" value="${htmldir}" />

	<target name="merge">
		<!-- XInclude support comes with Eclipse XML Tools Project,
			the Ant target needs to be executed in the Eclispe Workspace JRE
			in order to get found. Any custom project specific runtime
			may not work.
		-->
		<xsl.xinclude in="${docbooksource}/BruteXServices_User_Guide.xml" out="${docbooksource}/BruteXServices_User_Guide.dbk" />
	</target>

	<target name="clean-doc">
		<delete dir="${htmldir}" />
		<mkdir dir="${htmldir}" />
	</target>

	<target name="create-doc" depends="clean-doc, merge">
		<xslt force="true" style="${html.stylesheet.hl}" in="${docbooksource}/BruteXServices_User_Guide.dbk" out="${htmldir}/index.html">
			<factory name="${xalan}" />
			<classpath refid="xslthl.path" />
			<param name="highlight.xslthl.config" expression="file:///${docbookdir}/highlighting/xslthl-config.xml" />
			<param name="highlight.source" expression="1" />
			<param name="html.stylesheet" expression="style.css" />
		</xslt>
		<copy file="${docbooksource}/style.css" overwrite="true" tofile="${htmldir}/style.css" />
	</target>

	<!--
	    - target: chunks-html
	    - description: Iterates through a directory and transforms
	    - .xml files into seperate .html files using the DocBook XSL.
	  -->
	<target name="build-chunks" depends="clean-doc, merge" description="chunk HTML from DocBook XML">
		<xslt style="${html.chunked.stylesheet.hl}" extension=".html" basedir="${docbooksource}" destdir="${htmldir}">
			<factory name="${xalan}" />
			<classpath refid="xslthl.path" />
			<include name="**/*.dbk" />
			<param name="base.dir" expression="${htmldir}/" />
			<param name="use.id.as.filename" expression="1" />
			<param name="html.stylesheet" expression="styles.css" />
			<param name="section.autolabel" expression="1" />
			<param name="html.cleanup" expression="1" />
			<param name="chunk.first.selection" expression="1" />
			<param name="navig.showtitles" expression="1" />
			<param name="highlight.xslthl.config" expression="file:///${docbookdir}/highlighting/xslthl-config.xml" />
			<param name="highlight.source" expression="1" />
		</xslt>
		<copy file="${docbooksource}/style.css" overwrite="true" tofile="${htmldir}/style.css" />
	</target>


	<target name="build-pdf" depends="merge" description="PDF from DocBook XML">
		<!-- Convert DocBook Files into FO -->
		<xslt style="${fo.stylesheet.hl}" extension=".fo" basedir="${docbooksource}" destdir="${htmldir}">
			<include name="BruteXServices_User_Guide.dbk" />
			<classpath refid="xslthl.path" />
			<param name="fop1.extensions" expression="1" />
			<param name="section.autolabel" expression="1" />
			<param name="chapter.autolabel" expression="1" />
			<param name="appendix.autolabel" expression="1" />
			<param name="section.label.includes.component.label" expression="1" />
			<param name="highlight.xslthl.config" expression="file:///${docbookdir}/highlighting/xslthl-config.xml" />
			<param name="highlight.source" expression="1" />
			<param name="paper.type" expression="A4" />
		</xslt>

		<!-- Convert FO Files into pdf -->
		<fop format="application/pdf" outdir="${htmldir}">
			<fileset dir="${htmldir}">
				<include name="**/*.fo" />
			</fileset>
		</fop>
	</target>

	<target name="build-html5" depends="clean-doc, merge" description="Generates HTML5 files">

		<xslt style="${xhtml5.stylesheet}" extension=".html" basedir="${docbooksource}" destdir="${htmldir}">
			<include name="**/*.dbk" />
			<param name="html.stylesheet" expression="style.css" />
			<param name="docbook.css.source" expression="" />
			<param name="section.autolabel" expression="1" />
			<param name="make.clean.html" expression="1" />
		</xslt>
	</target>

	<!--
	    - target: build-javahelp
	    - description: Iterates through a directory and transforms
	    - .xml files into .html files using the DocBook XSL.
	    -->
	<target name="build-javahelp" depends="clean-doc, merge" description="JavaHelp from DocBook XML">
		<xslt style="${javahelp.stylesheet}" extension=".html" basedir="${docbooksource}" destdir="${htmldir}">
			<include name="**/*.dbk" />
			<outputproperty name="indent" value="yes" />
		</xslt>
	</target>


	<target name="build-eclipse" depends="clean-doc, merge" description="Eclipse help from DocBook XML">
	    <xslt style="${eclipse.stylesheet}" basedir="${docbooksource}" destdir="${htmldir}">
	      <include name="**/*.dbk" />
	    </xslt>
	  </target>






	<!-- ================================= 
	          target: resolve              
	     ================================= -->
	<target name="resolve" description="--> retrieve dependencies with ivy">
		<ivy:retrieve />
	</target>

	<target name="build-war">
		<ivy:retrieve pattern="c://TEMP/lib/default/[artifact]-[revision].[ext]" conf="master" />
		<jar 	destfile="${bin.dir}/XServices.jar" 
				basedir="${build.dir}"
				includes="net/**/*"/>
			
		
		<war destfile="${delivery.dir}\\${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
			<fileset dir="${web.dir}/">
				<include name="**/*.*" />
			</fileset>
			<lib dir="c://TEMP/lib/default">
				<!--<exclude name="portlet.jar"/>-->
			</lib>
			<lib dir="${bin.dir}" />
			<classes dir="${build.dir}">
				<!--We already packed all classes into a jar,
					so put only remaining config files into 
					classes
				-->
				<exclude name="net/**/*"/>
			</classes>
		</war>
		<tstamp>
			<format property="build.version" pattern="yyyyMMddhhmmss" />
		</tstamp>
		<mkdir dir="${delivery.dir}\\${name}\\${name}-${build.version}" />
		<move file="${delivery.dir}\\${name}.war" toFile="${delivery.dir}\\${name}\\${name}-${build.version}\\${name}.war" />
		<copy todir="${delivery.dir}\\${name}\\${name}-${build.version}\\html">
			<fileset dir="${htmldir}">
			</fileset>
		</copy>
		<echo>Distribution: ${delivery.dir}\\${name}\\${name}-${build.version} </echo>
	</target>
	
	<target name="hot-deploy" depends="build-war">
		<copy file="${delivery.dir}\\${name}\\${name}-${build.version}\\${name}.war" toFile="C://JAVA-DEV//Tomcat//apache-tomcat-8.5.30 -localtest//webapps//XServices.war" />
	</target>
</project>
