<project name="JCSP" basedir="." default="all">

<property name="src" location="src"/>
<property name="build" location="jartemp"/>
<property name="jcsp-version" value="1.1-rc4"/>
<property name="dist"  location="dist/jcsp-${jcsp-version}"/>
<property name="copyright" value="Copyright 1997-2008 P.D.Austin and P.H.Welch - All Rights Reserved"/>
<!-- Use ant-contrib: -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

	
<selector id="jcsp-net-lang-files">
	<!--lang is the tricky package:-->
		
	<or>
		<!-- Picks up Rejectable channels and ChannelDataRejectedException: -->
		<filename name="org/jcsp/lang/*Reject*"/>
	</or>
</selector>
	
<selector id="jcsp-core-fileset">
	<and>
		<or>
			<filename name="org/jcsp/awt/**/*"/>
			<filename name="org/jcsp/plugNplay/**/*"/>	
			<filename name="org/jcsp/util/**/*"/>	
	
			<filename name="org/jcsp/lang/**/*"/>
		</or>
		<not>
			<selector refid="jcsp-net-lang-files"/>
		</not>		
	</and>
</selector>	

<selector id="jcsp-net-fileset">
	<or>
		<filename name="org/jcsp/net/**/*"/>	
		<selector refid="jcsp-net-lang-files"/>
	</or>
</selector>
	
<dirset dir="${src}" id="jcsp-demos-dirset">
	<include name="jcsp-demos/**/*"/>
	<exclude name="jcsp-demos/net2/**"/>
</dirset>
	
<selector id="jcsp-demos-util-fileset">
	<filename name="org/jcsp/demos/util/*"/>
</selector>
	
<selector id="jar-files-only">
	<and>
		<filename name="**/*.java" negate="true"/>
		<filename name="**/doc-files" negate="true"/>
		<filename name="**/doc-files/*" negate="true"/>
		<filename name="**/package.html" negate="true"/>
		<filename name="*.svn*" negate="true"/>
	</and>
</selector>
	
<selector id="doc-files">
	<or>
		<filename name="**/doc-files"/>
		<filename name="**/doc-files/*"/>
	</or>
</selector>
	
<selector id="source-files-only">
	<filename name="**/*.java"/>
</selector>
	
<target name="jcsp-build">
	<mkdir dir="${build}"/>
	<javac srcdir="${src}" destdir="${build}" source="1.3" target="1.3" excludes="org/jcsp/test/**,jcsp-demos/**" deprecation="on">
	</javac>
	<copy todir="${build}">
		<fileset dir="${src}"/>
	</copy>
</target>

<target name="jcsp-core-jar" depends="jcsp-build">
	<mkdir dir="${dist}"/>
	<jar destfile="${dist}/jcsp-core.jar" basedir="${build}" >
		<and>
			<selector refid="jcsp-core-fileset"/>
			<selector refid="jar-files-only"/>
		</and>
	</jar>
</target>
	
<!-- No longer used; we have just the core jar, and the everything jar

<target name="jcsp-net-jar" depends="jcsp-build">
	<mkdir dir="${dist}"/>
	<jar destfile="${dist}/jcsp-net.jar" basedir="${build}" >
		<and>
			<selector refid="jcsp-net-fileset"/>
			<selector refid="jar-files-only"/>
		</and>
	</jar>
</target>
-->
	
<target name="jcsp-jar" depends="jcsp-build">
	<mkdir dir="${dist}"/>
	<jar destfile="${dist}/jcsp.jar" basedir="${build}" >
		<and>
			<or>
				<selector refid="jcsp-core-fileset"/>
				<selector refid="jcsp-net-fileset"/>
			</or>
			<selector refid="jar-files-only"/>
		</and>
	</jar>
</target>
	
<target name="jcsp-demos-test" depends="jcsp-jar,jcsp-demos-util-jar">
	<foreach target="build-demo-then-clean" param="dir">
		<path>
			<dirset refid="jcsp-demos-dirset"/>
		</path>
	</foreach>
</target>

<path id="jcsp-jar-cp">
  <fileset dir="${dist}" includes="*.jar"/>
</path>

<target name="build-demo-then-clean">
	<javac srcdir="${dir}" destdir="${dir}" includes="*.java" deprecation="on" classpathref="jcsp-jar-cp">
	</javac>
	<delete>
		<fileset dir="${dir}" includes="*.class"/>
	</delete>
</target>
	
<target name="jcsp-demos-src-jar">
	<mkdir dir="${dist}"/>
	<jar destfile="${dist}/jcsp-demos-src.jar" basedir="${src}">
		<and>
			<selector refid="jcsp-demos-fileset"/>
			<selector refid="source-files-only"/>
		</and>
	</jar>
</target>
	
<target name="jcsp-demos-util-jar" depends="jcsp-build,jcsp-core-jar">
	<mkdir dir="${dist}"/>
	<jar destfile="${dist}/jcsp-demos-util.jar" basedir="${build}">
		<and>
			<selector refid="jcsp-demos-util-fileset"/>
			<selector refid="jar-files-only"/>
		</and>
	</jar>
</target>
	
<target name="jcsp-core-javadoc">
	<mkdir dir="${dist}/jcsp-core-doc"/>
	<javadoc 
		destdir="${dist}/jcsp-core-doc" 
		Splitindex="true"
		Windowtitle="CSP for Java (JCSP) ${jcsp-version} API Specification"
		Doctitle="CSP for Java&lt;sup&gt;&lt;font size=\'-2\'&gt;TM&lt;/font&gt;&lt;/sup&gt; (JCSP) ${jcsp-version} API Specification"
		Header="&lt;b&gt;CSP for Java&lt;br&gt;(JCSP) ${jcsp-version}&lt;/b&gt;"	
		bottom="&lt;font size=\'-1\'&gt;&lt;A HREF=\'mailto:jcsp-team@kent.ac.uk\'&gt;Submit a bug or feature to jcsp-team@kent.ac.uk&lt;/A&gt;&lt;br&gt;Version ${jcsp-version} of the JCSP API Specification (${copyright})&lt;br&gt;Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries."
		link="http://java.sun.com/j2se/1.5.0/docs/api"
		Overview="overview.html"
		Author="true"
		additionalparam="-docfilessubdirs"
		packagenames="org.jcsp.lang,org.jcsp.util,org.jcsp.util.ints,org.jcsp.plugNplay,org.jcsp.plugNplay.ints,org.jcsp.awt"
		useexternalfile="yes"
	>		
		<fileset dir="${src}">
			<and>
				<selector refid="jcsp-core-fileset"/>
				<selector refid="source-files-only"/>
			</and>
		</fileset>
	</javadoc>
	
	<copy todir="${dist}/jcsp-core-doc/">
		<fileset dir="${src}">
			<and>
				<selector refid="jcsp-core-fileset"/>
				<selector refid="doc-files"/>
			</and>
		</fileset>
	</copy>
</target>

	<!-- No longer used; we have just the core javadoc, and the everything javadoc
	
	<target name="jcsp-net-javadoc">
		<mkdir dir="${dist}/jcsp-net-doc"/>
		<javadoc 
			destdir="${dist}/jcsp-net-doc" 
			Splitindex="true"
			Use="true"
			link="http://java.sun.com/j2se/1.5.0/docs/api"
			additionalparam="-docfilessubdirs"
			Windowtitle="JCSP (CSP for Java) Networked Libraries"			
			packagenames="org.jcsp.lang,org.jcsp.net,org.jcsp.net.cns,org.jcsp.net.dynamic,org.jcsp.net.remote,org.jcsp.net.security,org.jcsp.net.settings,org.jcsp.net.tcpip,org.jcsp.win32"
			useexternalfile="yes"
		>		
			<fileset dir="${src}">
				<and>
					<selector refid="jcsp-net-fileset"/>
					<selector refid="source-files-only"/>
				</and>
			</fileset>
		</javadoc>
		<copy todir="${dist}/jcsp-net-doc/">
			<fileset dir="${src}">
				<and>
					<selector refid="jcsp-net-fileset"/>
					<selector refid="doc-files"/>
				</and>
			</fileset>
		</copy>
	</target>
	
	-->

	<target name="jcsp-javadoc">
		<mkdir dir="${dist}/jcsp-doc"/>
		<javadoc 
			destdir="${dist}/jcsp-doc" 
			Splitindex="true"
			Windowtitle="CSP for Java (JCSP) ${jcsp-version} API Specification (inc. Network)"
			Doctitle="CSP for Java&lt;sup&gt;&lt;font size=\'-2\'&gt;TM&lt;/font&gt;&lt;/sup&gt; (JCSP) ${jcsp-version} API Specification"
			Header="&lt;b&gt;CSP for Java&lt;br&gt;(JCSP) ${jcsp-version}&lt;/b&gt;"	
			bottom="&lt;font size=\'-1\'&gt;&lt;A HREF=\'mailto:jcsp-team@kent.ac.uk\'&gt;Submit a bug or feature to jcsp-team@kent.ac.uk&lt;/A&gt;&lt;br&gt;Version ${jcsp-version} of the JCSP API Specification (${copyright})&lt;br&gt;Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries."
			link="http://java.sun.com/j2se/1.5.0/docs/api"
			Overview="overview.html"
			Author="true"
			additionalparam="-docfilessubdirs"
			packagenames="org.jcsp.lang,org.jcsp.util,org.jcsp.util.ints,org.jcsp.plugNplay,org.jcsp.plugNplay.ints,org.jcsp.awt,org.jcsp.net,org.jcsp.net.cns,org.jcsp.net.dynamic,org.jcsp.net.remote,org.jcsp.net.security,org.jcsp.net.settings,org.jcsp.net.tcpip,org.jcsp.win32"
			useexternalfile="yes"
		>		
			<fileset dir="${src}">
				<and>
					<or>
						<selector refid="jcsp-core-fileset"/>
						<selector refid="jcsp-net-fileset"/>
					</or>
					<selector refid="source-files-only"/>
				</and>
			</fileset>
		</javadoc>
		<copy todir="${dist}/jcsp-doc/">
			<fileset dir="${src}">
				<selector refid="doc-files"/>
			</fileset>
		</copy>		
	</target>	
	
	<target name="release-jar" depends="all-jars,all-javadoc">
		<copy tofile="${dist}/GNU-LGPL-2.1.txt" file="LICENCE.txt"/>
		<copy tofile="${dist}/README-JCSP-${jcsp-version}.txt" file="README.txt"/>
		<copy todir="${dist}/jcsp-demos">
		  <fileset dir="${src}/jcsp-demos"/>
		</copy>
		<!-- Note that this is meant to be two unescaped "dist"s below: -->
		<jar destfile="dist/jcsp-${jcsp-version}.jar" basedir="dist" includes="jcsp-${jcsp-version}/**"/>
	</target>
	
	<target name="build-all" depends="jcsp-build"/>
	<target name="all-jars" depends="jcsp-core-jar,jcsp-jar"/>
	<target name="all-javadoc" depends="jcsp-core-javadoc,jcsp-javadoc"/>
	<target name="all" depends="all-jars,all-javadoc,release-jar,jcsp-demos-test"/>

	<target name="clean" >
		<delete dir="${build}" />
		<delete dir="${docs}" />
		<delete dir="${dist}" />
	</target>		
	
</project>
