<project name="osgi-test" default="testAll">

	<!--
    This build file is intended for testing purposes. It does not
    actually package or create any files with a lifespan beyond that
    of the current test cycle.
    
		This build file is usually run indirectly via Maven.
		
		When running this build file through Ant directly, you must
		define the currentVersion property on the command line, e.g.:
		
		ant  -DcurrentVersion=1.5.4-SNAPSHOT	
	-->
	
  <!-- We skip the test if the maven.test.skip system property is set
       to true. See also http://jira.qos.ch/browse/LBCLASSIC-191 -->

	<echo message="compile classpath: ${currentVersion}" />
	<echo message="test classpath:    ${test_classpath}" />



  <property name="iBundleJar" value="target/iBundle.jar"/>
  <property name="bundlesDir" value="bundle"/>


	<echo message="===============================" />
	<echo message="basedir:           ${basedir}" />
	<echo message="===============================" />
            
  <path id="basicCP">
    <pathelement location="${org.apache.felix:org.apache.felix.main:jar}" />    
    <pathelement location="target/classes/" />
    <pathelement location="target/test-classes" />  
    <!--		
      <pathelement location="${org.slf4j:slf4j-api:jar}" />
      <pathelement location="../logback-core/target/classes/" />
      <pathelement location="../logback-core/target/test-classes/" />	
    -->
	</path >


	<path id="minimal">
		<pathelement location="target/test-classes/" />
	</path >

  <target name="copySLF4J_JAR">
    <echo>Copying ${org.slf4j:slf4j-api:jar} to lib/</echo>
    <delete>
      <fileset dir="../logback-examples/lib/" includes="slf4j-*SNAPSHOT.jar" />
    </delete>
    <copy file="${org.slf4j:slf4j-api:jar}" todir="lib/" />
  </target>

	<target name="init" depends="copySLF4J_JAR">
		<mkdir dir="target/unit-reports" />
	</target>

  <target name="createIBundle" unless="maven.test.skip">
    <mkdir dir="${bundlesDir}"/>
    <jar destFile="${iBundleJar}" 
         manifest="src/IBUNDLE-META-INF/MANIFEST.MF"
         basedir="target/test-classes/"
         includes="integrator/**.class"/>
                   
  </target>

	<target name="testAll" depends="init, createIBundle, logback" unless="maven.test.skip">
	</target>


  <macrodef name="prepareOSGiHarness">
    <attribute name="binding"/>
    <sequential>
      <delete>
        <fileset dir="${bundlesDir}" includes="*.jar"/>
      </delete>
      <copy file="${iBundleJar}" todir="${bundlesDir}"/>
      <copy file="lib/slf4j-api-${slf4j.version}.jar" todir="${bundlesDir}"/>
      <copy file="../logback-core/target/logback-core-${currentVersion}.jar" todir="${bundlesDir}"/>
      <copy file="target/logback-classic-${currentVersion}.jar" todir="${bundlesDir}"/>
      <echo>value of binding = @{binding}</echo>
    </sequential>
  </macrodef>


   <!-- for some reason if mvn is invoked from the parent directory, junit gets
        invoked from the parent dir, which messes up theses tests. Hence, the
        fork="yes" dir="${basedir}" -->

	<target name="logback" unless="maven.test.skip">
    <prepareOSGiHarness binding="logback"/>
    <junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes">    
      <classpath refid="basicCP"/>
      <formatter type="plain" />
      <test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" />
    </junit>
	</target>
  
</project>