<project name="OpenSwing" default="all" basedir=".">
	<!-- created by Nicola Benaglia           -->
	<!-- set global properties for this build -->
	<property file="${basedir}/build.properties" />
	
	<!-- set signature properties for this build -->
	<property file="${basedir}/signature.properties" />

	<target name="init" description="Initialize the build">
		<echo>Init...</echo>
		<mkdir dir="${build}"/>
		<mkdir dir="${build}/${classes}"/>
		<mkdir dir="${build}/${jars}"/>
		<mkdir dir="${build}/${source-jars}"/>
		<mkdir dir="${build}/${signedlib}"/>
	</target>

	<target name="compile-core" depends="init"
		description="Compile the Java source code" unless="eclipse.running">
		<echo>Compiling Openswing Core Sources...</echo>
		<javac destdir="${build}/${classes}"
			   optimize="${javac.optimize}" 
			   debug="${javac.debug}"
			   deprecation="${javac.deprecation}" 
			   nowarn="on">
			<classpath id="comp-openswing-core">
				<fileset dir="${lib}" includes="**/*.jar" />
			</classpath>
			<src path="${src}" />
		</javac>
	</target>

	<target name="allclasses" depends="common,client,server,allsrc"></target>


	<target name="allsrc" depends="srccommon,srcclient,srcserver"></target>


	<target name="client" description="Compile the client jar" depends="compile-core">
		<echo>Creating clientos.jar...</echo>

		<jar jarfile="${build}/jars/clientos.jar">
			<!-- Include only Openswing -->
			<fileset dir="${build}/${classes}">
				<exclude name="com/**"/>
				<exclude name="**/java/**"/>
				<exclude name="**/server/**"/>
			</fileset>
			
			<!-- Include images folder -->
			<fileset dir="${images}/.." includes="${images}/**" excludes="**/Thumbs.db" />
		</jar>
		
		<copy todir="${lib}">
			<fileset dir="${build}/${jars}">
				<include name="clientos.jar" />
			</fileset>
		</copy>
		
	<!-- 	<copy todir="${build}/${signedlib}">
			<fileset dir="${build}/${jars}">
				<include name="clientos.jar" />
			</fileset>
		</copy>   -->
	</target>

    	<target name="common" description="Compile the common jar" depends="compile-core">
		<echo>Creating commonos.jar...</echo>

		<jar jarfile="${build}/jars/commonos.jar">
			<!-- Include only Openswing -->
			<fileset dir="${build}/${classes}">
				<exclude name="com/**"/>
				<exclude name="**/client/**"/>
				<exclude name="**/server/**"/>
			</fileset>
		</jar>
		
		<copy todir="${lib}">
			<fileset dir="${build}/${jars}">
				<include name="commonos.jar" />
			</fileset>
		</copy>

	</target>

	<target name="server" description="Compile the server jar" depends="compile-core">
		<echo>Creating serveros.jar...</echo>

		<jar jarfile="${build}/${jars}/serveros.jar">
			<fileset dir="${build}/${classes}">
				<exclude name="com/**"/>
				<exclude name="**/java/**"/>
				<exclude name="**/client/**"/>
			</fileset>
		</jar>
		
		<copy todir="${lib}">
			<fileset dir="${build}/${jars}">
				<include name="serveros.jar" />
			</fileset>
		</copy>
		
<!-- 		<copy todir="${signedlib}">
			<fileset dir="${build}/${jars}">
				<include name="serveros.jar" />
			</fileset>
		</copy>  -->
	</target>

	<target name="srcclient" description="Create source client jar" depends="init">
		<jar jarfile="${build}/${source-jars}/${client-source-jar-file}">
			<fileset dir="${src}">
				<exclude name="com/**"/>
				<exclude name="**/java/**"/>
				<exclude name="**/server/**"/>
			</fileset>
		</jar>
	</target>

	<target name="srccommon" description="Create source common jar" depends="init">
		<jar jarfile="${build}/${source-jars}/${common-source-jar-file}">
			<fileset dir="${src}">
				<exclude name="com/**"/>
				<exclude name="**/client/**"/>
				<exclude name="**/server/**"/>
			</fileset>
		</jar>
	</target>

	<target name="srcserver" description="Create source server jar" depends="init">
		<jar jarfile="${build}/${source-jars}/${server-source-jar-file}">
			<fileset dir="${src}">
				<exclude name="com/**"/>
				<exclude name="**/java/**"/>
				<exclude name="**/client/**"/>
			</fileset>
		</jar>
	</target>


	<!-- this target will invoke: common,client,server,srccommon,srclient,srcserver -->
	<target name="signlib" description="Sign all libraries" depends="srcclient, client, srccommon, common, srcserver, server">
		<copy todir="${build}/${signedlib}">
			<fileset dir="${lib}">
				<include name="hsqldb.jar" />
				<include name="poi-2.0-RC2-20040102.jar" />
				<include name="itext-1.4.8.jar" />
				<include name="clientos.jar" />
				<include name="commonos.jar" />
				<include name="serveros.jar" />
				<include name="pooler.jar" />
				<include name="jcalendar.jar" />
				<include name="jnlp.jar" />
				<include name="jnlp-servlet.jar" />
				<include name="hessian-3.1.5.jar" />
			</fileset>
		</copy>
		<echo>${alias}</echo>
		<echo>${storepass}</echo>
		<echo>${keystore}</echo>
		<signjar jar="${build}/${signedlib}/hsqldb.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/poi-2.0-RC2-20040102.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/itext-1.4.8.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/clientos.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/commonos.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/serveros.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/pooler.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/jcalendar.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/jnlp.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/jnlp-servlet.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
		<signjar jar="${build}/${signedlib}/hessian-3.1.5.jar" alias="${alias}" storepass="${storepass}" keystore="${keystore}" />
	</target>


	<!-- this target will invoke: common,client,server,srclient,srcserver,signlib,demo5,demo10,demo18 -->
	<target name="all" depends="signlib,demo5,demo10,demo18" />


	<!-- invoke "signlib" before -->
	<target name="demo10">
		<mkdir dir="${tmp}" />
		<mkdir dir="${webapps}/demo10/" />
		<copy todir="${tmp}/demo10">
			<fileset dir="${classes}/demo10">
				<include name="**/*.class" />
			</fileset>
		</copy>
		<jar jarfile="${classes}/demo10/demo10.jar" basedir="${tmp}" />
		<delete dir="${tmp}" />
		<signjar jar="${classes}/demo10/demo10.jar" alias="${alias}"
			storepass="${storepass}" keystore="${keystore}" />
		<copy todir="${webapps}/demo10">
			<fileset dir="${classes}/demo10">
				<include name="demo10.jar" />
				<include name="demo10.jnlp" />
			</fileset>
		</copy>
		<copy todir="${webapps}/demo10">
			<fileset dir="${signedlib}">
				<include name="looks-2.0.1.jar" />
				<include name="hsqldb.jar" />
				<include name="poi-2.0-RC2-20040102.jar" />
				<include name="itext-1.4.8.jar" />
				<include name="clientos.jar" />
				<include name="commonos.jar" />
				<include name="serveros.jar" />
				<include name="pooler.jar" />
				<include name="jcalendar.jar" />
				<include name="jnlp.jar" />
				<include name="OfficeLnFs_2.7.jar" />
			</fileset>
		</copy>
	</target>


	<!-- invoke "signlib" before -->
	<target name="demo5">
		<mkdir dir="${tmp}" />
		<copy todir="${webapps}/demo5">
			<fileset dir="${signedlib}">
				<include name="clientos.jar" />
				<include name="itext-1.4.8.jar" />
				<include name="commonos.jar" />
				<include name="jcalendar.jar" />
				<include name="jnlp.jar" />
				<include name="hessian-3.1.5.jar" />
			</fileset>
			<fileset dir="${classes}/demo5">
				<include name="demo5.jnlp" />
				<include name="demo5.jsp" />
			</fileset>
		</copy>
		<copy todir="${tmp}/demo5/">
			<fileset dir="${classes}/demo5/">
				<include name="**/java/*.class" />
				<include name="**/client/*.class" />
			</fileset>
		</copy>
		<copy todir="${tmp}/">
			<fileset dir="${classes}/demo5/">
				<include name="Resources_*.xml" />
			</fileset>
		</copy>
		<jar jarfile="${tmp}/demo5client.jar" basedir="${tmp}" />
		<signjar jar="${tmp}/demo5client.jar" alias="${alias}"
			storepass="${storepass}" keystore="${keystore}" />
		<copy todir="${webapps}/demo5">
			<fileset dir="${tmp}">
				<include name="demo5client.jar" />
			</fileset>
		</copy>
		<delete dir="${tmp}" />
		<mkdir dir="${tmp}" />
		<copy todir="${webapps}/demo5/WEB-INF/lib">
			<fileset dir="${signedlib}">
                <include name="commonos.jar"/>
				<include name="serveros.jar" />
				<include name="hsqldb.jar" />
				<include name="pooler.jar" />
				<include name="log4j-1.2.7.jar" />
				<include name="poi-2.0-RC2-20040102.jar" />
				<include name="itext-1.4.8.jar" />
				<include name="jnlp-servlet.jar" />
				<include name="hessian-3.1.5.jar" />
			</fileset>
		</copy>
		<copy todir="${webapps}/demo5/WEB-INF">
			<fileset dir="${classes}/demo5/">
				<include name="web.xml" />
			</fileset>
		</copy>
		<copy todir="${tmp}/demo5/">
			<fileset dir="${classes}/demo5/">
				<include name="**/java/*.class" />
				<include name="**/server/*.class" />
			</fileset>
		</copy>
		<jar jarfile="${tmp}/demo5server.jar" basedir="${tmp}" />
		<copy todir="${webapps}/demo5/WEB-INF/classes">
			<fileset dir="${classes}/demo5/">
				<include name="Resources_*.xml" />
				<include name="pooler.ini" />
			</fileset>
		</copy>
		<copy todir="${webapps}/demo5/WEB-INF/lib">
			<fileset dir="${tmp}">
				<include name="demo5server.jar" />
			</fileset>
		</copy>
		<delete dir="${tmp}" />
		<jar jarfile="${classes}/demo5/demo5.war"
			basedir="${webapps}/demo5/" />
		<delete dir="${webapps}/demo5/" />
		<copy todir="${webapps}">
			<fileset dir="${classes}/demo5/">
				<include name="demo5.war" />
			</fileset>
		</copy>
	</target>


	<!-- invoke "signlib" before -->
	<target name="demo18">
		<mkdir dir="${tmp}" />
		<copy todir="${webapps}/demo18">
			<fileset dir="${signedlib}">
				<include name="poi-2.0-RC2-20040102.jar" />
				<include name="clientos.jar" />
				<include name="commonos.jar" />
				<include name="jcalendar.jar" />
				<include name="jnlp.jar" />
				<include name="hessian-3.1.5.jar" />
			</fileset>
			<fileset dir="${classes}/demo18">
				<include name="demo18.jnlp" />
				<include name="demo18login.jnlp" />
			</fileset>
		</copy>
		<copy todir="${tmp}/demo18/">
			<fileset dir="${classes}/demo18/">
				<include name="**/java/*.class" />
				<include name="**/client/*.class" />
			</fileset>
		</copy>
		<copy todir="${tmp}/">
			<fileset dir="${classes}/demo18/">
				<include name="Resources_*.xml" />
			</fileset>
		</copy>
		<jar jarfile="${tmp}/demo18client.jar" basedir="${tmp}" />
		<signjar jar="${tmp}/demo18client.jar" alias="${alias}"
			storepass="${storepass}" keystore="${keystore}" />
		<copy todir="${webapps}/demo18">
			<fileset dir="${tmp}">
				<include name="demo18client.jar" />
			</fileset>
		</copy>
		<delete dir="${tmp}" />
		<mkdir dir="${tmp}" />
		<copy todir="${webapps}/demo18/WEB-INF/lib">
			<fileset dir="${signedlib}">
                <include name="commonos.jar"/>
				<include name="serveros.jar" />
				<include name="hsqldb.jar" />
				<include name="pooler.jar" />
				<include name="log4j-1.2.7.jar" />
				<include name="poi-2.0-RC2-20040102.jar" />
				<include name="itext-1.4.8.jar" />
				<include name="jnlp-servlet.jar" />
				<include name="hessian-3.1.5.jar" />
			</fileset>
		</copy>
		<copy todir="${webapps}/demo18/WEB-INF">
			<fileset dir="${classes}/demo18/">
				<include name="web.xml" />
				<include name="controller-servlet.xml" />
				<include name="applicationContext.xml" />
				<include name="jdbc.properties" />
				<include name="dataAccessContext-local.xml" />
			</fileset>
		</copy>
		<copy todir="${tmp}/demo18/">
			<fileset dir="${classes}/demo18/">
				<include name="**/java/*.class" />
				<include name="**/server/*.class" />
			</fileset>
		</copy>
		<jar jarfile="${tmp}/demo18server.jar" basedir="${tmp}" />
		<copy todir="${webapps}/demo18/WEB-INF/classes">
			<fileset dir="${classes}/demo18/">
				<include name="Resources_*.xml" />
			</fileset>
		</copy>
		<copy todir="${webapps}/demo18/WEB-INF/lib">
			<fileset dir="${tmp}">
				<include name="demo18server.jar" />
			</fileset>
		</copy>
		<delete dir="${tmp}" />
		<jar jarfile="${classes}/demo18/demo18.war"
			basedir="${webapps}/demo18/" />
		<delete dir="${webapps}/demo18/" />
		<copy todir="${webapps}">
			<fileset dir="${classes}/demo18/">
				<include name="demo18.war" />
			</fileset>
		</copy>
	</target>


</project>
