<project name="repository" default="build">

   <path id="path.common" path="${basedir}/../../common"/>
   <property name="dir.common" refid="path.common"/>
   <import file="${dir.common}/common.xml"/>

   <target name="compile-java" depends="common.compile-java">
      <antcall target="compile-jibx" />
   </target>

   <target name="compile-jibx" depends="init">
      <bind verbose="false" load="true" binding="${file.jibx.binding.m2}">
         <classpathset dir="${dir.classes}"/>
      </bind>
      <bind verbose="false" load="true" binding="${file.jibx.binding.systeminfo}">
	     <classpathset dir="${dir.classes}"/>
	  </bind>
   </target>

   <target name="build-single-jar" depends="common.compile-java" description="Build an self-contained executable jar" >
      <property name="dir.one-jar" value="${dir.build}/one-jar" />
      <!-- extract the one-jar file -->
      <unjar src="${dir.common.lib}/one-jar/one-jar-boot-0.95.jar" dest="${dir.one-jar}" overwrite="true" />
      <!-- remove unwanted files -->
      <delete >
         <fileset dir="${dir.one-jar}">
            <include name="**/*.java" />
            <include name="**/boot-manifest.mf" />
         </fileset>
      </delete>
      <!-- copy required jars into lib folder -->
      <copy todir="${dir.one-jar}/lib" flatten="false">
         <fileset dir="${dir.common.lib}" includes="**/*.jar" />
         <fileset dir="${dir.project.core}/build/dist" includes="${dir.name.core}.jar" />
         <fileset dir="${dir.project.core}/source/java" includes="**/*log4j.properties" />
         <fileset dir="${dir.project.repository}/build/dist" includes="${dir.name.repository}.jar" />
      </copy>
      <!-- delete target one-jar -->
      <delete file="${dir.dist}/alfresco-repository.jar" />
      <!-- build the one-jar -->
      <jar destfile="${dir.dist}/alfresco-repository.jar" manifest="${dir.one-jar}/META-INF/MANIFEST.MF" update="false" >
         <fileset dir="${dir.one-jar}">
            <include name="**/*" />
         </fileset>
      </jar>
   </target>

   <target name="build-tck" depends="package-jar" description="Builds the JCR TCK war file">
      <war warfile="${dir.dist}/${tck.file.name.war}" webxml="${dir.src.webinf}\JCRTCK\web.xml">
         <fileset dir="${dir.src.web}" excludes="WEB-INF/**" />
         <webinf dir="${dir.project.installer}" includes="licenses/**"/>
         <webinf dir="${dir.src.webinf}" includes="${webinf.includes}" excludes="${webinf.excludes}"/>
         <lib dir="${dir.common.lib}" includes="${webinf.lib.includes}" excludes="${tck.webinf.lib.excludes}" />
         <lib dir="${dir.common.lib}/jibx" includes="*.jar" />
         <lib dir="${dir.common.lib}/openoffice" includes="*.jar" />
         <lib dir="${dir.common.lib}/jmagick" includes="*.jar" />
         <lib dir="${dir.common.lib}/commons" includes="*.jar" />
         <lib dir="${dir.common.lib}/jgroups" includes="*.jar" />
         <lib dir="${dir.common.lib}/swarmcache" includes="*.jar" />
         <lib dir="${dir.dist}" includes="${file.name.jar}" />
         <lib dir="${dir.project.core}/build/dist" includes="${dir.name.core}.jar" />
         <lib dir="${dir.project.repository}/build/dist" includes="${dir.name.repository}.jar" />
         <classes dir="${dir.config.repository}"/>
         <classes dir="${dir.config.jcr}"/>
         <classes file="${dir.project.core}/source/java/log4j.properties" prefix="WEB-INF/classes"/>
      </war>
   </target>

   <target name="deploy-tck" depends="build-tck">
      <copy file="${dir.dist}/${tck.file.name.war}" todir="${tck.dir.deploy}/bin/tck-webapp/webapps" />
   </target>

   <target name="start-tck" depends="init">
      <exec dir="${tck.dir.deploy}/bin/tck-webapp" executable="cmd.exe" spawn="true">
         <arg line="/k start server.bat -debug socket" />
      </exec>
   </target>

</project>
