<project name="OpenEJB-Corba" default="jar" basedir="../">
  <!-- 
  		Contributions by:
  			Daniel S. Haischt <sirabyss@gmx.net>
  	-->

  <property name="build.corba.src" value="${build.src}/corba"/>
  <property name="build.corba.dest" value="${build.dest}/corba"/>
  <property name="dest.corba.javadoc.dir" value="${dest.javadoc.dir}/corba"/>
  <property name="dest.gensrc.dir" value="${build.src}/corba-stubs"/>
  <property name="build.testsuite.dest" value="${build.dest}/testsuite"/>
  
  <!-- Build classpath -->
  <path id="project.classpath">
    <pathelement location="${ejb20.jar}"/>
    <pathelement location="${jta.jar}"/>
    <pathelement location="${jts.jar}"/>
    <pathelement location="${jdbcext.jar}"/>
    <pathelement location="${log4j.jar}"/>
    <pathelement location="${openorb.jar}"/>
    <pathelement location="${openorb.rmi.jar}"/>
    <pathelement location="${openorb.rmi.tools.jar}"/>
    <pathelement location="${openorb.tools.jar}"/>
    <pathelement location="${tyrex.home}/${tyrex.jar}"/>
    <pathelement location="lib/xml-apis-2.4.D1.jar"/>
    <pathelement location="lib/logkit.jar"/>
    <pathelement location="lib/avalon-framework.jar"/>
    <pathelement location="lib/xercesImpl-2.0.2.jar"/>
    <pathelement location="lib/ichilli-tools.jar"/>
    <pathelement location="${junit.jar}"/>
  </path>
  
  
  <!-- ================================================================== -->
  <!-- Prepares the build directory                                       -->
  <!-- ================================================================== -->

  <target name="prepare">
    
    <mkdir dir="${build.corba.src}"/>
    <mkdir dir="${build.corba.dest}"/>
    <mkdir dir="${dest.corba.javadoc.dir}"/>
    <mkdir dir="${dest.gensrc.dir}"/>
    
    <copy todir="${build.corba.src}">
          
      <fileset dir="${src.java.dir}/corba" >
        <include name="**/corba/**"/>
        <include name="**/javax/**"/>
        <exclude name="**/CVS/**"/>
        <exclude name="**/*.class"/>
      </fileset>
      
    </copy>
    
  </target>
  
  <target name="copy.manifest">
  
    <copy todir="${build.corba.dest}">
    
      <fileset dir="${src.java.dir}/etc" >
        <include name="**/LICENSE"/>
        <include name="**/MANIFEST.MF"/>
        <include name="**/README"/>
      </fileset>
    
    </copy>
    
    <copy todir="${build.corba.dest}">
    
      <fileset dir="${final.dir}/src/etc" >
        <include name="**/CHANGELOG"/>
      </fileset>
    
    </copy>
    
    <replace file="${build.corba.dest}/MANIFEST.MF" token="$$VERSION$$" value="${version}"/>
  
  </target>
  
    <target name="copy.i18n">
    
      <copy todir="${build.corba.dest}">
      
        <fileset dir="${src.java.dir}/corba" >
          <include name="**/resources/*.properties"/>
        </fileset>
      
      </copy>
    
    </target>

   <!-- =============================== -->
   <!--                IDL              -->
   <!-- =============================== -->
   <!--<target name="java2idl">
     <echo message="Compiling ${source}..." />
     <java failonerror="true" classname="org.openorb.rmi.compiler.JavaToIdl" fork="true">
       <classpath refid="project.classpath" />
       <classpath location="${build.testsuite.dest}" />
       <arg line="-all -silence -stub -tie -noidl -d ${dest.gensrc.dir} ${source}" />
     </java>
   </target>-->

  <target name="generate-idl-classes">
    <taskdef name="idl-process" classname="org.ichilli.tools.anttasks.openorb.IDLProcess">
        <classpath refid="project.classpath"/>
    </taskdef>

    <idl-process basedir="${build.dest}/testsuite"
             destdir="${dest.gensrc.dir}"
             extension=".java"
             processDependencies="true"
             quiet="true"
             generateStubs="true"
             generateTies="true"
             generateValueTypeDataMethods="true"
             packageName="org.openejb.test"
             verbose="false"
             excludes="**/*Test*.class,**/*Bean*.class"
             includes="**/stateless/*Object.class,**/stateless/*Home.class,
                            **/statefull/*Object.class,**/statefull/*Home.class,
                            **/cmp/*Object.class,**/cmp/*Home.class,
                            **/bmp/*Object.class,**/bmp/*Home.class,
                            **/Calculator*.class,**/Shopping*.class,
                            **/Employee*.class,**/Database*.class">
      <classpath>        
        <pathelement location="${build.testsuite.dest}"/>
        <path refid="project.classpath"/>
      </classpath>
    </idl-process>

    <!--<antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateless.RmiIiopStatelessObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateless.RmiIiopStatelessHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateless.EncStatelessObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateless.EncStatelessHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateless.BeanTxStatelessObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateless.BeanTxStatelessHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateless.BasicStatelessObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateless.BasicStatelessHome" />
    </antcall>

    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateful.RmiIiopStatefulObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateful.RmiIiopStatefulHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateful.EncStatefulObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateful.EncStatefulHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateful.BeanTxStatefulObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateful.BeanTxStatefulHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateful.BasicStatefulObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.stateful.BasicStatefulHome" />
    </antcall>

    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.cmp.RmiIiopCmpObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.cmp.RmiIiopCmpHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.cmp.EncCmpObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.cmp.EncCmpHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.cmp.BasicCmpObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.cmp.BasicCmpHome" />
    </antcall>

    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.bmp.RmiIiopBmpObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.bmp.RmiIiopBmpHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.bmp.EncBmpObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.bmp.EncBmpHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.bmp.BasicBmpObject" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.entity.bmp.BasicBmpHome" />
    </antcall>
    
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.beans.Database" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.beans.DatabaseHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.beans.ShoppingCart" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.beans.ShoppingCartHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.beans.Employee" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.beans.EmployeeHome" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.beans.Calculator" />
    </antcall>
    <antcall target="java2idl" >
      <param name="source" value="org.openejb.test.beans.CalculatorHome" />
    </antcall>-->
  </target>
    
  <target name="compile-idl-classes" depends="generate-idl-classes">
    <javac srcdir="${dest.gensrc.dir}"
           destdir="build/classes/testsuite"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}" >
      <classpath refid="project.classpath" />
       <classpath location="${build.testsuite.dest}" />
    </javac>

  </target>

  <!-- ================================================================== -->
  <!-- Compiles the source directory                                      -->
  <!-- ================================================================== -->
  
  <target name="compile" description="--> compiles the java source files">
    <antcall target="compile.jdk.${ant.java.version}"/>
  </target>
  <target name="compile.jdk.1.1" depends="compile.invalid.jdk"/>
  <target name="compile.jdk.1.2" depends="compile.invalid.jdk"/>
  <target name="compile.jdk.1.3" depends="compile.valid.jdk"/>
  <target name="compile.jdk.1.4" depends="compile.valid.jdk"/>
  
  <target name="compile.invalid.jdk">
    <echo message="The CORBA Adapter requires JDK 1.3 or higher. You are using JDK ${ant.java.version}"/>          
  </target>
  
  <target name="compile.valid.jdk" depends="prepare">
    <javac srcdir="${build.corba.src}"
           destdir="${build.corba.dest}"
           includes="**/corba/**,javax/**"
           debug="${debug}"
           deprecation="${deprecation}">
           
      <classpath>
        <path refid="project.classpath"/>
        <pathelement location="${build.dest}/openejb"/>
      </classpath>
    </javac>
  </target>
  
  
  <!-- ================================================================== -->
  <!-- Compiles the source directory and creates a .jar file              -->
  <!-- ================================================================== -->
  
  <target name="jar"
          depends="compile, compile-idl-classes, copy.manifest, copy.i18n"
          description="--> generates all java archives (default)">
          
    <jar jarfile="dist/${project}_corba-${version}.jar"
         basedir="${build.corba.dest}"
         manifest="${build.corba.dest}/MANIFEST.MF"/>
          
  </target>
  
  <!-- ================================================================== -->
  <!-- Creates the API documentation                                      -->
  <!-- ================================================================== -->
  
  <target name="javadocs"
          depends="compile"
          description="--> generates the API documentation">
          
    <javadoc packagenames="org.openejb.*"
             sourcepath="${build.corba.src}"
             destdir="${dest.corba.javadoc.dir}"
             doctitle="${name} CORBA JavaDoc"
             windowtitle="${name} JavaDoc"
             bottom="${copyright}"
		     package="true"
             author="true"
             version="true"
             noindex="true">
             
      <classpath>
        <path refid="project.classpath"/>
        <pathelement location="${build.dest}/openejb"/>
      </classpath>
             
    </javadoc>         
          
  </target>
  
</project>
