<!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.    
-->
<project name="filter-framework" default="publish" xmlns:ivy="antlib:org.apache.ivy.ant">
    <!-- some variables used -->
    <property name="lib.dir" value="lib" />
    <property name="build.dir" value="build" />
    <property name="distrib.dir" location="distrib" />
    <property name="src.dir" value="src" />
	<property name="test.dir" value="test" />
	<property name="build.test.dir" value="${build.dir}/test-classes" />
	<property name="report.test.dir" value="${build.dir}/test-report" />
	<property name="revision" value="1.3" />
	
	<property name="ivy.local.default.root" location="${user.home}/.ivy2/local"/>
	
    <!-- paths used for compilation and run  -->
    <path id="compile.path.id">
        <fileset dir="${lib.dir}/cc-impl" />
	</path>
	
    <path id="test.path.id">
        <path location="${build.dir}" />
    	 <path location="${build.test.dir}" />
        <fileset dir="${lib.dir}/test" />
	</path>
    
    <!-- ================================= 
          target: resolve              
         ================================= -->
    <target name="resolve" description="--> retreive dependencies with ivy">
    	<!-- conf="*" will copie artifacts defined for each conf in a dir matching conf name -->
		<ivy:retrieve pattern="${ivy.lib.dir}/[conf]/[artifact]-[revision].[ext]"/>
    </target>
	
	<!-- ================================= 
          target: build
         ================================= -->
    <target name="build" depends="clean, resolve" description="--> compile and jar project">
        <mkdir dir="${build.dir}" />
		<mkdir dir="${distrib.dir}"/>
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="compile.path.id" includeAntRuntime="false"/>
    	<jar destfile="${distrib.dir}/filter-api.jar" >
    		<fileset dir="${build.dir}">
    			<include name="filter/*.class"/>
    		</fileset>
    	</jar>
    	<jar destfile="${distrib.dir}/filter-hmimpl.jar" >
    		<fileset dir="${build.dir}">
    			<include name="filter/hmimpl/*.class"/>
    		</fileset>
    	</jar>    
    	<jar destfile="${distrib.dir}/filter-ccimpl.jar" >
    		<fileset dir="${build.dir}">
    			<include name="filter/ccimpl/*.class"/>
    		</fileset>
    	</jar>        	
    </target>
	
    <!-- ================================= 
          target: test              
         ================================= -->	
	<target name="test" depends="build" description="--> compile and test the project">	
		<mkdir dir="${report.test.dir}"/>
		<mkdir dir="${build.test.dir}"/>
		
		<javac srcdir="${test.dir}" destdir="${build.test.dir}" classpathref="test.path.id"/>
		<junit printsummary="yes" fork="yes" haltonfailure="yes" >
			<classpath refid="test.path.id"/>	
			<formatter type="plain"/>
			<batchtest todir="${report.test.dir}" >
			    <fileset dir="${build.test.dir}">
			    	<include name="**/**Test.*"/>
			    </fileset>	
			</batchtest>
		</junit>
	</target>
    <!-- ================================= 
          target: publish              
         ================================= -->	
    <target name="publish" depends="test" description="--> compile test and publish this project in the local ivy repository">
        <property name="revision" value="${revision}"/>
		<ivy:publish artifactspattern="${distrib.dir}/[artifact].[ext]" 
			           resolver="local"
			           pubrevision="${revision}" 
			           status="release"/>
        <echo message="project ${ant.project.name} released with version ${revision}" />
    </target>	
    <!-- ================================= 
          target: clean              
         ================================= -->
    <target name="clean" description="--> clean the project">
        <delete includeemptydirs="true">
            <fileset dir="${basedir}">
            	<exclude name="src/**" />
            	<exclude name="test/**" />
            	<exclude name="build.xml" />
                <exclude name="ivy.xml" />
            	<exclude name=".*" />
        	</fileset>
    	</delete>
    </target>
	
    <!-- ================================= 
          target: clean-cache              
         ================================= -->
	<target name="clean-cache" description="--> clean the ivy cache">
		<ivy:cleancache />
	</target>

    <!-- ================================= 
      target: clean-local              
     ================================= -->
	<target name="clean-local" description="--> clean the local user repository">
		<delete dir="${ivy.local.default.root}"/>
	</target>

	    
    <!-- ================================= 
          target: report              
         ================================= -->
    <target name="report" depends="resolve" description="--> generates a report of dependencies">
        <ivy:report todir="${build.dir}"/>
    </target>
</project>
