<?xml version="1.0"?>
<project name="YACY - SOAP API" default="dist">
    <description>
            A SOAP API for YaCy
    </description>

    <property name="addonShortName" value="Soap"/>
	<property name="addonVersion" value="0.1"/>
    <property name="addonLongName" value="${addonShortName}Addon"/>    	
   	<property name="addonArchive" location="${release}/${addonLongName}_${addonVersion}.tgz"/>
   	
	<property name="clientStub" location="${release}/SOAP_CLIENT" />
   	<property name="clientStubSrc" location="${clientStub}/source" />
   	<property name="clientStubBuild" location="${clientStub}/classes" />
    	
  	<!-- defining the classpath that should be used for compiling -->   
  	<path id="soap.class.path">
	  	  <pathelement location="${build}" />	
  		
  	      <!-- libs needed for the yacy thread/object-pools -->
  	      <pathelement location="${lib}/commons-collections.jar" />
  	      <pathelement location="${lib}/commons-pool.jar" />      		
	  	
		  <!-- all needed libs -->  	
 		  <pathelement location="${libx}/axis.jar" />  	  		    	
 		  <pathelement location="${libx}/axis-ant.jar" />
 		  <pathelement location="${libx}/commons-discovery.jar" />   		  
 		  <pathelement location="${libx}/commons-logging.jar" />   		     		  
 		  <pathelement location="${libx}/jaxrpc.jar" />   		     		  
 		  <pathelement location="${libx}/saaj.jar" />   		     		  
 		  <pathelement location="${libx}/wsdl4j.jar" />    
  		
  		  <!-- optional libraries needed for soap attachments -->
  		  <pathelement location="${libx}/gnumail.jar" />
  		  <pathelement location="${libx}/activation.jar" />
  		  <pathelement location="${libx}/inetlib.jar" />
  	</path>	
	
	
    <target name="compile">
  	  <javac srcdir="${src}/de/anomic/soap/" 
  	  		destdir="${build}" 
  	  		source="${javacSource}" 
  	  		target="${javacTarget}" 
  	  		debug="true" 
  	  		debuglevel="lines,vars,source"
	  	    classpathref="soap.class.path">
  	  </javac>    	
    </target>
	

    <target name="zip" depends="compile">
  	  <tar destfile="${addonArchive}" compression="gzip">
  	  	<tarfileset dir="${libx}" 
  	  				includes="axis.jar,axis-ant.jar,commons-discovery.jar,commons-logging.jar,jaxrpc.jar,saaj.jar,wsdl4j.jar,gnumail.jar,activation.jar,inetlib.jar" 
  	  				prefix="${releaseDir}/libx/"
			  		dirmode="755" mode="644"/>
  	  	<tarfileset dir="${src}/de/anomic/soap/" 
  	  				prefix="${releaseDir}/source/de/anomic/soap/"
			  	  	dirmode="755" mode="644"/>
  	  	<tarfileset dir="${build}/de/anomic/soap/" 
  	  				prefix="${releaseDir}/classes/de/anomic/soap/"
			  	  	dirmode="755" mode="644"/>			  	  					  	  		
  	  </tar>    	
    </target>	

    <target name="copy" depends="compile">
        <copy todir="${release}/libx/">
             <fileset dir="${libx}" includes="axis.jar,axis-ant.jar,commons-discovery.jar,commons-logging.jar,jaxrpc.jar,saaj.jar,wsdl4j.jar,gnumail.jar,activation.jar,inetlib.jar"/> 
        </copy>
        <copy todir="${release}/source/de/anomic/soap/">
             <fileset dir="${src}/de/anomic/soap/" includes="**/*"/> 
        </copy>        
        <copy todir="${release}/classes/de/anomic/soap/">
             <fileset dir="${build}/de/anomic/soap/" includes="**/*"/> 
        </copy>         
    </target>  
 
    
    <target name="dist" depends="compile,zip" description="Compile and zip the addon"/>        
	
	<target name="genClientStubFiles">
		<!-- ensure that the temp directory exists -->
		<mkdir dir="${clientStubSrc}"/>	
	
		<!-- define the foreach task -->
		<taskdef name="foreach" classname="org.apache.axis.tools.ant.foreach.ForeachTask" classpathref="soap.class.path"/>
	
		<!-- loop through the wsdl files -->
      	<foreach target="genClientStubFileFromWSDL">
        	<param name="wsdlFileName">
            	<fileset dir="${src}/de/anomic/soap/services/" includes="*.wsdl"/>
        	</param>
       </foreach>
	</target>

	<!-- generates client stub classes for a soap service -->
	<target name="genClientStubFileFromWSDL" description="Generate YaCy SOAP client stub java files from wsdl">
		<!-- define the wasdl2java task -->
		<taskdef name="axis-wsdl2java" classname="org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask" classpathref="soap.class.path"/>		
		
		<axis-wsdl2java 
		  output="${clientStubSrc}"
		  url="file:///${wsdlFileName}" >
		    <mapping
		      namespace="http://axis.apache.org/ns/interop"
		      package="interop" />
		  </axis-wsdl2java>		
	</target>
	
	<target name="compileClientStubClasses" depends="genClientStubFiles" description="Compile YaCy SOAP client stube classes">
	  <mkdir dir="${clientStubBuild}"/>	
  	  <javac srcdir="${clientStubSrc}" 
  	  		destdir="${clientStubBuild}" 
  	  		source="${javacSource}" 
  	  		target="${javacTarget}" 
  	  		debug="true" 
  	  		debuglevel="lines,vars,source"
	  	    classpathref="soap.class.path">
  	  </javac> 	
	</target>
	
	<target name="buildClientStubJar" depends="compileClientStubClasses">
	  <!-- delete old jar file -->
	  <delete file="${}/yacySoapClient.jar" />
		
	  <!-- copy all source and class files into the jar -->
	  <jar destfile="${clientStub}/yacySoapClient.jar">
	    <fileset dir="${clientStubSrc}"/>
	    <fileset dir="${clientStubBuild}"/>	  		  	
	  </jar>
		
	  <!-- remove old temp directories -->
 	  <delete dir="${clientStubSrc}"/>
 	  <delete dir="${clientStubBuild}"/>			
	</target>
</project>