<?xml version="1.0"?>
<project name="Create a single package with all modules" default="jar" basedir=".">

	<property name="target_path" value="deploy" />
	<property name="version" value="liner2.4-rc2" />	
	<property name="version_path" value="${target_path}/${version}" />

	<target name="jar-corpus">
        <exec dir="modules/g419-corpus" executable="ant"><arg line="jar"/></exec>
		<copy file="modules/g419-corpus/g419-corpus.jar" todir="./lib"></copy>
	</target>

	<target name="jar-liner2-api">
        <exec dir="modules/g419-liner2-api" executable="ant"><arg line="jar"/></exec>
		<copy file="modules/g419-liner2-api/g419-liner2-api.jar" todir="./lib"></copy>
	</target>

	<target name="jar-liner2-cli">
        <exec dir="modules/g419-liner2-cli" executable="ant"><arg line="jar"/></exec>
		<copy file="modules/g419-liner2-cli/g419-liner2-cli.jar" todir="./lib"></copy>
	</target>

    <target name="jar-liner2-daemon">
        <exec dir="modules/g419-liner2-daemon" executable="ant"><arg line="jar"/></exec>
        <copy file="modules/g419-liner2-daemon/g419-liner2-daemon.jar" todir="./lib"></copy>
    </target>

    <target name="jar-tools">
        <exec dir="modules/g419-tools" executable="ant"><arg line="jar"/></exec>
        <copy file="modules/g419-tools/g419-tools.jar" todir="./lib"></copy>
    </target>

	<target name="jar-liner2-api-all" depends="jar-corpus,jar-liner2-api"></target>
	
	<target name="jar-liner2-cli-all" depends="jar-corpus,jar-liner2-api,jar-liner2-cli"></target>

    <target name="jar-liner2-daemon-all" depends="jar-corpus,jar-liner2-api,jar-liner2-daemon"></target>
		
	<target name="jar" depends="jar-corpus,jar-liner2-api,jar-liner2-cli,jar-liner2-daemon,jar-tools"></target>

	<target name="deploy" depends="jar">
		<delete dir="${version_path}"/>
		<mkdir dir="${version_path}"/>
		<mkdir dir="${version_path}/lib"/>
		
		<copy todir="${version_path}/lib" >  
			<fileset dir="./lib">
				<include name="commons-cli-1.2.jar"/>
				<include name="commons-io-2.4.jar"/>
				<include name="commons-lang3-3.3.2.jar"/>
				<include name="CRF++-0.57.tar.gz"/>
				<include name="g419-corpus.jar"/>
				<include name="g419-tools.jar"/>
				<include name="g419-liner2-api.jar"/>
				<include name="g419-liner2-cli.jar"/>
				<include name="ini4j-0.5.0.jar"/>
				<include name="liblinear-1.92.jar"/>
				<include name="maltparser-1.7.1.jar"/>
				<include name="mysql-connector-java-5.1.10.jar"/>
				<include name="nlog4j-1.2.25.jar"/>
				<include name="princetonAdapter.jar"/>
				<include name="weka-3.6.9.jar"/>
			</fileset>
		</copy>
		
		<copy todir="${version_path}">
			<fileset dir="./resources">
				<include name="README"/>
				<include name="INSTALL"/>
				<include name="LICENSE"/>
			</fileset>
		</copy>

		<copy todir="${version_path}">
			<fileset dir=".">
				<include name="liner2-cli"/>
			</fileset>
		</copy>
		<chmod file="${version_path}/liner2-cli" perm="a+x"/>
	</target>
	
	<target name="deploy-src" depends="deploy">
		<mkdir dir="${version_path}/modules"/>
		<mkdir dir="${version_path}/resources"/>
		
		<copy todir="${version_path}/lib" >  
			<fileset dir="./lib">
				<include name="g419-liner2-daemon.jar"/>
				<include name="ant-contrib-1.0b3.jar"/>
			</fileset>
		</copy>
		
		<copy todir="${version_path}">
			<fileset dir=".">
				<include name="liner2-daemon"/>
			</fileset>
		</copy>

		<copy todir="${version_path}">
			<fileset dir=".">
				<include name="build.xml"/>
			</fileset>
		</copy>
		<chmod file="${version_path}/liner2-daemon" perm="ugo+x"/>

		<copy todir="${version_path}/modules" >
		    <fileset dir="./modules">
		      <exclude name="**/*.jar"/>
		    </fileset>			
		</copy>

		<copy todir="${version_path}/resources" >
		    <fileset dir="./resources"/>
		</copy>

	</target>	

	<!-- Create command liner2 linking to current instance of Liner2. --> 	
	<target name="install">
		<property name="liner2-cli" location="liner2-cli"/>
		<echo file="/usr/local/bin/liner2-cli">#!/bin/bash
${liner2-cli} $@
		</echo>
		<chmod file="/usr/local/bin/liner2-cli" perm="ugo+x"/>
		<echo message="/usr/local/bin/liner2-cli was created"/>
		<echo message="Now you can use `liner2-cli [parameters]`."/>
	</target>

</project>
