<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: build.xml,v 1.16 2009-01-23 15:32:34 jean-gui Exp $ -->
<project default="jar" name="W3C CSS Validator">

  <!-- =================================================================== -->
  <!-- User-overrideable properties                                      -->
  <!-- =================================================================== -->

  <property name="servlet.lib" value="/jigsaw/classes/servlet.jar"/>

  <!-- =================================================================== -->
  <!-- Project-wide properties                                           -->
  <!-- =================================================================== -->
  <!-- Overriding those properties works too, but is not advisable. -->

  <property name="app.name" value="css-validator"/>
  <property name="jar.file" value="${app.name}.jar"/>
  <property name="war.file" value="${app.name}.war"/>

  <!-- =================================================================== -->
  <!-- Targets                                                             -->
  <!-- =================================================================== -->

	<path id="build.class.path">
		<pathelement location="${servlet.lib}"/>
    <fileset dir="/jigsaw/classes">
        <include name="*.jar"/>
    </fileset>
	</path>

  <target name="prepare.check">
    <condition property="prepare.run">
      <and>
        <available file="/jigsaw/classes/jigsaw.jar"/>
        <available file="/jigsaw/classes/commons-collections-3.2.1.jar"/>
        <available file="/jigsaw/classes/commons-lang-2.4.jar"/>
        <available file="/jigsaw/classes/velocity-1.6.1.jar"/>
        <available file="/jigsaw/classes/xercesImpl.jar"/>
        <available file="/jigsaw/classes/xml-apis.jar"/>
        <available file="/jigsaw/classes/tagsoup-1.2.jar"/>
      </and>
    </condition>
  </target>


  <target name="prepare" description="Downloads necessary libs" depends="prepare.check" unless="prepare.run">
    <mkdir dir="lib"/>
    <mkdir dir="tmp"/>

    <get dest="tmp/jigsaw_2.2.6.tar.gz" src="http://jigsaw.w3.org/Distrib/jigsaw_2.2.6.tar.gz" usetimestamp="true"/>
    <get dest="tmp/commons-collections-3.2.1-bin.tar.gz" src="http://www.apache.org/dist/commons/collections/binaries/commons-collections-3.2.1-bin.tar.gz" usetimestamp="true"/>
    <get dest="tmp/commons-lang-2.4-bin.tar.gz" src="http://www.apache.org/dist/commons/lang/binaries/commons-lang-2.4-bin.tar.gz" usetimestamp="true"/>
    <get dest="tmp/velocity-1.6.1.tar.gz" src="http://www.apache.org/dist/velocity/engine/1.6.1/velocity-1.6.1.tar.gz" usetimestamp="true"/>
    <get dest="tmp/Xerces-J-bin.2.9.1.tar.gz" src="http://www.apache.org/dist/xerces/j/Xerces-J-bin.2.9.1.tar.gz" usetimestamp="true"/>

    <untar compression="gzip" src="tmp/jigsaw_2.2.6.tar.gz" dest="tmp"/>
    <untar compression="gzip" src="tmp/commons-collections-3.2.1-bin.tar.gz" dest="tmp"/>
    <untar compression="gzip" src="tmp/commons-lang-2.4-bin.tar.gz" dest="tmp"/>
    <untar compression="gzip" src="tmp/velocity-1.6.1.tar.gz" dest="tmp"/>
    <untar compression="gzip" src="tmp/Xerces-J-bin.2.9.1.tar.gz" dest="tmp"/>

    <copy file="tmp/Jigsaw/classes/jigsaw.jar" tofile="lib/jigsaw.jar"/>
    <copy file="tmp/commons-collections-3.2.1/commons-collections-3.2.1.jar" tofile="lib/commons-collections-3.2.1.jar"/>
    <copy file="tmp/commons-lang-2.4/commons-lang-2.4.jar" tofile="lib/commons-lang-2.4.jar"/>
    <copy file="tmp/velocity-1.6.1/velocity-1.6.1.jar" tofile="lib/velocity-1.6.1.jar"/>
    <copy file="tmp/xerces-2_9_1/xercesImpl.jar" tofile="lib/xercesImpl.jar"/>
    <copy file="tmp/xerces-2_9_1/xml-apis.jar" tofile="lib/xml-apis.jar"/>
    <get dest="lib/tagsoup-1.2.jar" src="http://home.ccil.org/~cowan/XML/tagsoup/tagsoup-1.2.jar"/>
  </target>

	<target name="build" description="Builds the validator" depends="prepare">
		<mkdir dir="./build"/>
		<javac classpathref="build.class.path" destdir="./build" encoding="UTF-8"
           debug="yes" includes="org/w3c/**" srcdir="." source="1.5" target="1.5"/>
		<copy todir="./build">
      <fileset dir="./">
        <include name="org/**"/>
        <exclude name="**/*.java"/>
        <exclude name="**/*.class"/>
      </fileset>
		</copy>
	</target>

	<target name="jigsaw" description="Builds the validator for Jigsaw" depends="prepare">
		<mkdir dir="./build"/>
		<javac classpathref="build.class.path" destdir="/Jigsaw/Jigsaw/WWW/servlet/css-validator" encoding="UTF-8"
           debug="yes" source="1.5" target="1.5">
			<src path="./org/w3c"/>
		</javac>
		<copy todir="/Jigsaw/Jigsaw/WWW/servlet/css-validator">
      <fileset dir="./">
        <include name="org/**"/>
        <include name="html/**"/>
        <include name="images/**"/>
        <include name="scripts/**"/>
        <include name="style/**"/>
        <include name="tabtastic/**"/>
        <include name="*.*"/>
        <exclude name="CVS/*.*"/>
        <exclude name="**/Makefile"/>
        <exclude name="**/.cvsignore"/>
        <exclude name="**/*.java"/>
        <exclude name="**/*.class"/>
      </fileset>
		</copy>
	</target>

	<target name="javadoc" description="Generates API docs">
		<mkdir dir="./javadoc"/>
		<javadoc
			packagenames="org.w3c.*"
			sourcepath="./"
			destdir="./javadoc"
			author="true"
			version="true"
			windowtitle="W3C CSS Validator API"/>
	</target>

	<target name="jar" depends="build" description="Creates the lib archive">
		<delete file="${jar.file}"/>
		<jar jarfile="${jar.file}" basedir="build" excludes="org/**/*.java">
			<include name="org/**"/>
			<manifest>
        <attribute name="Main-Class" value="org.w3c.css.css.CssValidator"/>
        <attribute name="Class-path" value=". lib/commons-collections-3.2.1.jar lib/commons-lang-2.4.jar lib/jigsaw.jar lib/tagsoup-1.2.jar lib/velocity-1.6.1.jar lib/xercesImpl.jar lib/xml-apis.jar"/>
			</manifest>
		</jar>
	</target>

	<target name="war" depends="build" description="Creates the webapp module">
		<delete file="${war.file}"/>
		<war warfile="${war.file}" webxml="web.xml" basedir="." includes="*html*,favicon.ico,images/**,style/**,scripts/**,tabtastic/**" excludes="html,css-validator.*">
      <classes dir="build"/>
      <lib dir="/jigsaw/classes"/>
		</war>
	</target>

  <target name="clean" description="Cleans up generated files">
    <delete file="${jar.file}"/>
    <delete file="${war.file}"/>
    <delete dir="./build"/>
    <delete dir="./javadoc"/>
    <delete dir="./tmp"/>
  </target>

</project>
