<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	

    See test results in target/unit-reports 
	-->
	
  <!-- We skip the test if the maven.test.skip system property is set
       to true. See also http://jira.qos.ch/browse/LBCLASSIC-191 -->

<!--
  <property name="slf4j.version" value="1.7.20"/>
  <property name="org.slf4j:slf4j-api:jar" value="c:/Users/ceki/.m2/repository/org/slf4j/slf4j-api/1.7.20/slf4j-api-1.7.20.jar"/>

  <property name="org.apache.felix:org.apache.felix.main:jar" value="c:/Users/ceki/.m2/repository/org/apache/felix/org.apache.felix.main/2.0.2/org.apache.felix.main-2.0.2.jar" />
-->

  <echo message="currentVersion: ${currentVersion}" />
  <echo message="slfj4:  ${org.slf4j:slf4j-api:jar}" />
  <echo message="felix:  ${org.apache.felix:org.apache.felix.main:jar}" />



  <property name="iBundleJar" value="target/iBundle.jar"/>
  <!-- jar in the folder named "bundle" are auto-deployed by Felix -->	
  <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" />  
  </path >


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

  <target name="copySLF4J_JAR">
    <echo>Making lib/ folder in case it does not already exist.</echo>
  	<mkdir dir="lib/"/>
    <echo>Copying ${org.slf4j:slf4j-api:jar} to lib/</echo>
    <!-- sneak in a cleanup procedure of the ../logback-examples/lib/ folder-->
    <delete quiet="true">
      <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">
    <echo message="in init"/>
		<mkdir dir="target/unit-reports" />
	</target>

  <target name="createIBundle" unless="maven.test.skip">
    <echo message="Making folder ${bundlesDir}"/>
    <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 these 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>
