<project name="com.openexchange.contactcollector" default="install" basedir=".">

    <!-- Customizable values -->
    <property name="destdir" value=""/>
    <property name="prefix" value="/opt/open-xchange"/>

    <!-- Constants -->
    <property name="tmp.dir" value="tmp"/>
    <property name="lib.dir" value="lib"/>

    <property file="META-INF/MANIFEST.MF"/>
    <property file="build.properties"/>

    <property name="version" value="${Bundle-Version}"/>
    <property name="bundle.name" value="${Bundle-SymbolicName}.jar"/>
    <property name="composite.name" value="open-xchange-contactcollector-${version}"/>

    <!-- Install Constants -->
    <property name="bundlesdir" value="${prefix}/bundles"/>
    <property name="bundle.d" value="${prefix}/etc/groupware/osgi/bundle.d"/>

    <!-- Bundle dependencies -->
    <property name="commonBundle" value="com.openexchange.common"/>

    <!-- JAR names for classpath -->
    <property name="osgijar" value="org.eclipse.osgi_3.3.0.v20070530.jar"/>
    <property name="commonsloggingjar" value="org.apache.commons.logging_1.0.4.v200706111724.jar"/>
    <property name="globaljar" value="com.openexchange.global.jar"/>
    <property name="serverjar" value="com.openexchange.server.jar"/>
	<property name="threadpooljar" value="com.openexchange.threadpool.jar"/>
    <property name="mailjar" value="mail-1.4.2.jar" />

    <!-- Classpath -->
    <path id="project.classpath">
        <pathelement location="${bundlesdir}/${osgijar}"/>
        <pathelement location="${bundlesdir}/${commonsloggingjar}"/>
        <pathelement location="${bundlesdir}/${globaljar}"/>
        <pathelement location="${bundlesdir}/${serverjar}"/>
    	<pathelement location="${bundlesdir}/${threadpooljar}"/>
        <pathelement location="${bundlesdir}/${commonBundle}/lib/${mailjar}" />
    </path>

    <!-- Compile -->
    <target name="prepare">
        <mkdir dir="${output..}"/>
        <mkdir dir="${tmp.dir}"/>
    </target>

    <target name="compile" depends="prepare">
        <javac srcdir="${source..}" destdir="${output..}" debug="true"
            encoding="US-ASCII" source="1.5" compiler="javac1.5" target="1.5">
            <classpath refid="project.classpath"/>
        </javac>
    </target>

    <target name="jar" depends="prepare,compile">
        <jar jarfile="${tmp.dir}/${bundle.name}"
            manifest="META-INF/MANIFEST.MF">
            <fileset dir="${output..}"/>
        </jar>
    </target>

    <!-- Install -->
    <target name="install">
        <antcall target="installJar"/>
        <antcall target="installConfig"/>
    </target>

    <target name="installConfig">
        <mkdir dir="${destdir}/${bundle.d}"/>
        <echo file="${destdir}/${bundle.d}/${Bundle-SymbolicName}.ini"
            message="${bundlesdir}/${bundle.name}@start${line.separator}"/>
    </target>

    <target name="installJar" depends="jar">
        <mkdir dir="${destdir}/${bundlesdir}"/>
        <copy todir="${destdir}/${bundlesdir}">
            <fileset dir="${tmp.dir}">
                <include name="${bundle.name}"/>
            </fileset>
        </copy>
    </target>

    <!-- Dist -->
    <target name="dist" depends="clean">
        <property name="dist-package" value="dist-package"/>
        <delete dir="${dist-package}"/>
        <mkdir dir="${dist-package}/${composite.name}"/>
        <copy todir="${dist-package}/${composite.name}">
            <fileset dir=".">
                <exclude name="**${dist-package}/**"/>
                <exclude name="**debian/**"/>
                <exclude name="**CVS/**"/>
                <exclude name="Todo"/>
            </fileset>
        </copy>
        <tar destfile="../${composite.name}.tar.gz"
            basedir="${dist-package}"
            includes="${composite.name}/"
             compression="gzip"/>        <!-- dpkg-source does not like anything else -->
        <delete dir="${dist-package}"/>
    </target>

    <target name="clean">
        <delete dir="${output..}"/>
        <delete dir="${tmp.dir}"/>
    </target>

</project>
