<?xml version="1.0"?>
<project name="relames" basedir="." default="binary">

	<!-- import the global configuration file -->
	<property file="../shared/ant.config"/>
	
	
	<!-- compile Java source files -->
	<target name="binary">
		<mkdir dir="./bin"/>
		<javac
			srcdir="./src"
			destdir="./bin"
			source="1.2" target="1.2"
			debug="on"
			optimize="off">
			
			<classpath path="../msv/bin" />
			<classpath path="../xsdlib/bin" />
			<classpath>
			  <fileset dir="../shared/lib" includes="*.jar" />
			</classpath>
		</javac>
    <!-- copy static resource files -->
    <copy todir="bin">
      <fileset dir="src">
        <include name="META-INF/**/*"/>
      </fileset>
    </copy>
	</target>
	
	
	
	<!-- create a distribution package -->
	<target name="dist">
		<tstamp>
      <format property="YEAR" pattern="yyyy" locale="en"/>
    </tstamp>
		
		<delete	dir="dist" />
		<mkdir	dir="dist/src" />
		
		<!-- copy files -->
		<copy todir="dist/src">
			<fileset dir="src" />
		</copy>
		<copy todir="dist">
			<fileset dir="doc" />
		</copy>
		<fixcrlf	srcdir="dist"
					cr="remove"
					eof="remove"
					includes="*.txt"/>
    <replace dir="dist">
        <include name="**/*.html"/>
        <include name="**/*.txt"/>
        <replacefilter token="@@VERSION@@" value="${DSTAMP}" />
        <replacefilter token="@@YEAR@@" value="${YEAR}" />
    </replace>
		
		<!-- compile files -->
		<mkdir	dir="temp" />
		<javac srcdir="dist/src" destdir="temp" source="1.2" target="1.2" debug="on">
			
			<classpath path="../package/msv.jar"/>
			<classpath>
			  <fileset dir="../shared/lib" includes="*.jar" />
			</classpath>
			<include name="**/*.java" />
		</javac>
		
		<!-- create a time stamp file -->
		<echo file="temp/version.properties">version=${DSTAMP}</echo>
		
		
		<!-- creates binary jar -->
		<jar	jarfile="dist/relames.jar"
				manifest="dist/src/META-INF/MANIFEST.MF"
				compress="false">
				
			<fileset dir="temp" />
			<!-- resource files -->
			<fileset dir="dist/src" includes="**/*.properties" />
			<fileset dir="dist/src" includes="META-INF/**/*" />
		</jar>
		<delete dir="temp" />
		
		<!-- remove the source code for now -->
		<delete dir="dist/src"/>
		
		<!-- copy related jars -->
		<copy file="../package/msv.jar" todir="dist"/>
		<copy file="../package/xsdlib.jar" todir="dist"/>
		<copy file="${isorelax.jar}" todir="dist"/>
		<copy file="${relaxngDatatype.jar}" todir="dist"/>
		<copy file="${xalan.jar}" todir="dist"/>
		<copy file="${xerces.jar}" todir="dist" />
		<copy file="${xmlParserAPIs.jar}" todir="dist" />
	</target>
	
	
	
	<target name="release" depends="dist" description="build the distribution zip file">
    <tstamp />
		<property name="stageName" value="relames-${DSTAMP}"/>
		
		<!-- copy jar file to package dir -->
		<copy file="dist/relames.jar" tofile="../package/relames.jar" />
    
		<!-- creates distribution package -->
		<mkdir dir="../package"/>
		<zip	zipfile="../package/relames.${DSTAMP}.zip">
			<zipfileset dir="dist" includes="**/*.*" prefix="${stageName}" />
		</zip>
	</target>
	
	<target name="clean">
		<delete dir="bin" />
		<delete dir="dist" />
		<delete dir="temp" />
	</target>
</project>
