<?xml version="1.0" encoding="iso-8859-1" ?>
<!-- $Id: build.xml 1415 2010-03-31 14:31:10Z euzenat $ -->

<project name="align" default="compile" basedir=".">

  <!-- this is useful but introduces, Xlint:path warnings -->
  <path id="classpath">
    <fileset dir="./lib">
      <include name="**/*.jar"/>
    </fileset>
  </path>
    
  <!-- tested -->
  <target name="usage" depends="init">
    <echo>ant _target_ _options_

      usage: this message
      init: sets necessary variables
      upgrade: retrieve necessary libraries from other projects (local)
      compile: incrementaly compiles sources
      compileall: recompiles all sources
      lint: compiles all sources with bug flags on
      jar: archives compiled code
      test: performs unit tests
      zip: creates a new zip file
      javadoc: generates documentation
      release: releases a new version
      cover: check test coverage
      analyse: perform static analysis
      svnbranch: copy the version under svn
      clean: clean-up before release

	-Dversion=${version}
    </echo>
  </target>

  <target name="bind">
    <tstamp><format locale="fr,fr" pattern="dd/MM/yyyy" property="TODAY"/></tstamp>
    <property file="../build.properties"/>
    <!-- default values -->
    <property name="doing" value="running"/>
    <property name="version" value="4.0"/>
    <property name="date" value="${TODAY}"/>
    <property name="login" value="${user.name}"/>
    <property name="debug" value="off"/>
    <property name="rep" value="svn+ssh://scm.gforge.inria.fr/svn/alignapi"/>
    <!-- This should now be handled by GForge -->
    <property name="tooldir"  value="tools" />
    <property name="libdir"  value="lib" />
    <property name="classpath"  value="classes"/>
    
    <filter token="DATE" value="${date}"/>
    <filter token="VERS" value="${version}"/>
  </target>

  <!-- tested -->
  <target name="init" depends="bind">
    <property name="jarclasspath" value="owlapi30/owlapi-bin.jar ontosim/ontosim.jar getopt/getopt.jar log4j/commons-logging.jar log4j/log4j.jar log4j/slf4j-api.jar log4j/slf4j-log4j.jar jwnl/jwnl.jar jena/jena.jar jena/iri.jar jena/icu4j.jar xerces/xercesImpl.jar xerces/resolver.jar align.jar ontowrap.jar procalign.jar"/>

  </target>

  <target name="upgrade">
    <copy file="../ontosim/lib/ontosim.jar" todir="lib/ontosim" filtering="false"/>
    <echo message="mappingapi is only updated from its directory"/>
  </target>

  <!-- tested -->
  <target name="compile" depends="init">
    <echo message="Compiling..."/>
    <property name="javacargs" value="-deprecation" />
    <mkdir dir="classes"/>
    <javac deprecation="yes" nowarn="no" verbose="no" srcdir="src" destdir="classes" encoding="iso8859-15">
      <compilerarg value="${javacargs}"/>
      <classpath refid="classpath"/>
    </javac>
  </target>

  <!-- tested -->
  <target name="compileall" depends="init">
    <echo message="Erasing..."/>
    <delete>
      <fileset dir="." includes="classes/**/*.class"/>
    </delete>
    <antcall target="cleanjar"/>
    <antcall target="jar"/>
    <ant dir="plugins/neon" target="compileall" />
    <ant dir="plugins/webcontent" target="compileall" />
  </target>

  <!-- tested -->
  <target name="lint" depends="init">
    <echo message="Setting property..."/>
    <!-- values: cast,deprecation,divzero,empty,unchecked[3],fallthrough,path[5],serial,finally,overrides,all,none -->
    <!--property name="javacargs" value="-Xlint:cast" /-->
    <property name="javacargs" value="-Xlint:all" />
    <antcall target="compileall"/>
  </target>

  <!--target name="analyse" depends="jar">
    // Use Checkstyle
    <taskdef resource="checkstyletask.properties"
             classpath="${tooldir}/checkstyle/checkstyle-all-5.0.jar"/>
    // I must have a checks.xml
    <checkstyle config="docs/sun_checks.xml">
      <fileset dir="src" includes="**/*.java"/>
      // let see if we can put a css
      <formatter type="xml" toFile="test/html/checkstyle.xml"/>
    </checkstyle>
    // Use FindBugs
    <taskdef name="findbugs" classpath="${tooldir}/findbugs/findbugs-ant.jar" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/>
    <findbugs home="test/html/"
	      output="xml"
	      outputFile="bcel-fb.xml" >
      //<auxClasspath path="${basedir}/lib/Regex.jar" />
      <sourcePath path="src" />
      <class location="lib/align.jar" />
    </findbugs>
    // Use PMD
    <taskdef name="pmd" classpath="${tooldir}/pmd/pmd-ant.jar" classname="net.sourceforge.pmd.ant.PMDTask"/>
    <pmd shortFilenames="true">
      <ruleset>rulesets/favorites.xml</ruleset>
      <ruleset>basic</ruleset>
      <formatter type="html" toFile="pmd_report.html" linkPrefix="http://pmd.sourceforge.net/xref/"/>
      <fileset dir="/usr/local/j2sdk1.4.1_01/src/">
	<include name="java/lang/*.java"/>
      </fileset>
    </pmd>
  </target-->

  <!-- cover: emma seems really difficult
  <taskdef resource="emma_ant.properties" classpathref="emma.lib" /-->

  <!-- tested -->
  <target name="jar" depends="compile">
    <echo message="Jarchiving..."/>
    <copy file="distrib/LICENSE.TXT" tofile="classes/LICENSE.TXT" filtering="true"/>
    <delete file="lib/align.jar"/>
    <jar jarfile="lib/align.jar">
      <manifest>
	<attribute name="Built-Date" value="${TODAY}"/>
	<attribute name="Specification-Title" value="Alignment API"/>
	<attribute name="Specification-Version" value="${version}"/>
      </manifest>
      <fileset dir="classes" includes="org/semanticweb/owl/align/*.class"/>
      <fileset dir="classes" includes="LICENSE.TXT"/>
    </jar>
    <delete file="lib/ontowrap.jar"/>
    <jar jarfile="lib/ontowrap.jar">
      <manifest>
	<attribute name="Built-Date" value="${TODAY}"/>
	<attribute name="Specification-Title" value="Ontology wrapper"/>
	<attribute name="Specification-Version" value="${version}"/>
      </manifest>
      <fileset dir="classes" includes="fr/inrialpes/exmo/ontowrap/**/*.class"/>
      <fileset dir="classes" includes="LICENSE.TXT"/>
    </jar>
    <delete file="lib/procalign.jar"/>
    <jar jarfile="lib/procalign.jar">
      <manifest>
	<attribute name="Built-Date" value="${TODAY}"/>
        <attribute name="Main-Class" value="fr.inrialpes.exmo.align.util.Procalign"/>
        <attribute name="Class-Path" value="${jarclasspath}"/>
	<attribute name="Implementation-Title" value="Alignment API implementation"/>
	<attribute name="Implementation-Version" value="${version}"/> 
      </manifest>
      <fileset dir="classes" includes="fr/inrialpes/exmo/align/util/**/*.class"/>
      <fileset dir="classes" includes="fr/inrialpes/exmo/align/parser/**/*.class"/>
      <fileset dir="classes" includes="fr/inrialpes/exmo/align/impl/**/*.class"/>
      <fileset dir="classes" includes="fr/inrialpes/exmo/align/ling/**/*.class"/>
      <fileset dir="classes" includes="LICENSE.TXT"/>
    </jar>
    <delete file="lib/alignsvc.jar"/>
    <copy file="src/fr/inrialpes/exmo/align/service/aserv.wsdl" tofile="classes/fr/inrialpes/exmo/align/service/aserv.wsdl" filtering="false"/>
    <jar jarfile="lib/alignsvc.jar">
      <manifest>
	<attribute name="Built-Date" value="${TODAY}"/>
        <attribute name="Main-Class" value="fr.inrialpes.exmo.align.service.AlignmentService"/>
        <attribute name="Class-Path" value="procalign.jar jade/jade.jar jade/iiop.jar jade/http.jar jdbc/mysql-connector-java.jar jdbc/postgresql-jdbc4.jar servlet/servlet-api.jar jetty/jetty.jar jetty/jetty-util.jar xerces/xercesImpl.jar"/>
	<attribute name="Implementation-Title" value="Alignment server"/>
	<attribute name="Implementation-Version" value="${version}"/> 
      </manifest>
      <fileset dir="classes" includes="fr/inrialpes/exmo/align/service/**/*.class"/>
      <fileset dir="classes" includes="fr/inrialpes/exmo/align/service/**/*.wsdl"/>
      <fileset dir="classes" includes="fr/inrialpes/exmo/queryprocessor/**/*.class"/>
      <fileset dir="classes" includes="LICENSE.TXT"/>
    </jar>
  </target>

  <!-- tested -->
  <target name="cleanjar" depends="init">
    <echo message="Erasing..."/>
    <delete file="lib/align.jar"/>
    <delete file="lib/ontowrap.jar"/>
    <delete file="lib/alignsvc.jar"/>
    <delete file="lib/procalign.jar"/>
  </target>

  <!-- tested -->
  <target name="aserv" depends="init">
    <echo message="Setting property..."/>
    <jar jarfile="lib/aserv.jar">
      <manifest>
	<attribute name="Built-Date" value="${TODAY}"/>
        <attribute name="Main-Class" value="fr.inrialpes.exmo.align.service.AlignmentService"/>
	<!-- usually each MANIFEST knows what it needs, add here -->
	<!--  semanticmapper-0.2.jar jwnl.jar sboa.jar TaxoMap.jar AROMA_aserv.jaroyster2.jar, semanticmapper-0.2.jar, sboalgorithms.jar -->
        <attribute name="Class-Path" value="alignsvc.jar ontosim.jar"/>
	<attribute name="Implementation-Title" value="Alignment server custom launcher"/>
	<attribute name="Implementation-Version" value="${version}"/> 
      </manifest>
    </jar>
  </target>

  <!-- tested -->
  <target name="test" depends="init">
    <echo message="Testing..."/>
    <taskdef name="testng" classpath="${tooldir}/testng/testng.jar" classname="org.testng.TestNGAntTask" />

    <javac srcdir="test/src" destdir="test/classes" debug="on"
	   classpath="tools/testng/testng.jar" encoding="iso8859-15">
      <classpath refid="classpath"/>
    </javac>
    <!-- possible groups: raw=impl+serv+io+onto+omwg, full=raw+ling+sem -->
    <!-- ling requires WordNet and takes ages initialising it -->
    <testng groups="raw"
	    sourcedir="test/src"
	    outputDir="test/html"  verbose="1"
	    haltOnFailure="false" failureProperty="failed">
      <classpath>
        <path refid="classpath"/>
        <pathelement location="test/classes"/>
      </classpath>
      <!--xmlfileset dir="${test14.dir}" includes="testng.xml"/-->
      <classfileset dir="test" includes="classes/**/*.class"/>
    </testng>
    <fail if="failed" message="For results: open test/html/index.html" />
  </target>

  <!-- tested -->
  <target name="cleantest" depends="init">
    <echo message="Cleaning tests..."/>
    <delete>
      <fileset dir="test/classes" includes="**/*.class"/>
      <fileset dir="test/output" includes="**/*.*"/>
      <fileset dir="test/html" includes="**/*.html,**/*.xml,**/*.css"/>
    </delete>
    <delete dir="test/html/Ant suite"/>
  </target>

  <!-- tested -->
  <target name="javadoc" depends="init">
   <echo message="Javadocing..."/>
   <javadoc
      destdir="javadoc"
      author="true"
      version="true"
      Use="true" Splitindex="true" private="true"
      Windowtitle="Alignment API and Server"
      doctitle="Alignment API and Server ${version}" 
      header="Alignment API and Server ${version}"
      bottom="(C) INRIA &amp; friends, 2003-2010"
      >
     <classpath refid="classpath"/>
     <packageset dir="src" defaultexcludes="yes">
       <include name="org/semanticweb/owl/align/**"/>
       <include name="fr/inrialpes/**"/>
       <include name="org/ivml/alimo/**"/>
       <!--exclude name="org/semanticweb/owl/**"/-->
     </packageset>
     <!-- This works but the classpath is not set correctly -->
     <!--packageset dir="plugins/neon/src" defaultexcludes="yes">
	 <include name="fr/inrialpes/**"/>
     </packageset-->
     <link href="http://java.sun.com/j2se/1.5.0/docs/api"/>
    </javadoc>
  </target>

  <!-- tested -->
  <target name="release" depends="init">
    <echo message="Releasing version ${version}" />
    <copy file="distrib/LICENSE.TXT" tofile="LICENSE.TXT" filtering="true"/>
    <antcall target="zip"/>
    <!-- This should now go to GForge -->
    <!--copy file="${FTPDir}/align-${version}.zip" tofile="${WebDir}/align.zip" /-->
    <echo message="Please upload the released file to Gforge" />
    <echo message="svn copy svn+ssh://euzenat@scm.gforge.inria.fr/svn/alignapi/trunk svn+ssh://euzenat@scm.gforge.inria.fr/svn/alignapi/tags/version-${version} -m 'release ${version}'"/>
    <delete file="LICENSE.TXT"/>
  </target>

  <!-- tested -->
  <target name="zip" depends="init">
    <echo message="Ziping..."/>
    <!--echo message="Are you sure that everything is OK (update/ci/compile)?"/-->
    <antcall target="clean"/>
    <!-- Unfortunately commit is not functional -->
    <!--antcall target="commit"/-->
    <antcall target="compileall"/>
    <antcall target="jar"/>
    <antcall target="test"/>
    <antcall target="cleantest"/>
    <antcall target="javadoc"/>
    <ant dir="plugins/neon" target="jar">
      <property name="version" value="${version}"/>
    </ant>
    <!-- may be useful to change directory -->
    <zip zipfile="${FTPDir}/align-${version}.zip">
      <fileset dir=".">
	<include name="**/*"/>
	<exclude name="**/.svn"/>
	<exclude name="plugins/neon/lib"/>
      </fileset>
    </zip>
  </target>

  <target name="svnCommit">
    <property name="source-root" value="/usr/src"/>
    <property name="repository.URL" value="http://sources.example.com"/>
    <java classname="org.tmatesoft.svn.cli.SVN"
      dir="${source-root}/TESTREPO" fork="true">
      <arg value="commit"/>
      <arg value="--username"/>
      <arg value="admin"/>
      <arg value="--password"/>
      <arg value="admin"/>
      <arg value="-m"/> 
      <arg value='"Testing"'/>
      <arg value="${repository.URL}/TESTING"/>
      <classpath>
        <pathelement location="${antroot}/LIB/ganymed.jar" />
        <pathelement location="${antroot}/LIB/javasvn.jar" />
        <pathelement location="${antroot}/LIB/javasvn-cli.jar" />
      </classpath>
    </java>
  </target>

  <!-- This is for testing purposes, but has been found to work -->
  <target name="status" depends="init">
    <java classname="org.tmatesoft.svn.cli.SVN" dir="." fork="true">
      <arg value="status" />
      <classpath refid="classpath"/>
    </java>
  </target>

  <!-- not tested yet -->
  <target name="update" depends="init">
    <java classname="org.tmatesoft.svn.cli.SVN" dir="." fork="true"
         failonerror="true">
      <sysproperty key="javasvn.ssh2.key" 
                   value="/Volumes/Khata/.ssh/id_dsa" />
      <!--sysproperty key="javasvn.ssh2.username" value="${login}" />
      <sysproperty key="javasvn.ssh2.passphrase" value="aa" /-->
      <arg value="update" />
      <classpath refid="classpath"/>
    </java>
  </target>

  <!-- not tested yet -->
  <target name="commit" depends="update">
    <java classname="org.tmatesoft.svn.cli.SVN" dir="." fork="true">
      <arg value="commit" />
      <arg value="--username" />
      <arg value="${login}" />
      <arg value="-m" />
      <arg value='"Pre-release ${version}"' />
      <classpath refid="classpath"/>
    </java>
  </target>

  <!-- not tested yet -->
  <target name="svnbranch" depends="">
    <java classname="org.tmatesoft.svn.cli.SVN" dir="." fork="true">
      <arg value="copy" />
      <arg value="--username" />
      <arg value="${login}" />
      <arg value="${rep}/trunk" />
      <arg value="${rep}/tags/version-${version}" />
      <arg value="-m" />
      <arg value='"Release ${version}"' />
      <classpath refid="classpath"/>
    </java>
  </target>

  <!-- tested -->
  <target name="clean">
    <echo message="Cleaning..."/>
    <antcall target="cleantest"/>
    <ant dir="plugins/neon" target="clean" />
    <ant dir="plugins/webcontent" target="clean" />
    <delete dir="examples/aligns"/>
    <delete>
      <fileset dir="classes" includes="**/*.class"/>
      <fileset dir="examples" includes="**/*.class"/>
      <fileset dir="examples/omwg" includes="wine?.xml"/>
      <fileset dir="examples" includes="**/*.jar"/>
      <fileset dir="html/tutorial" includes="**/*.class"/>
    </delete>
  </target>

</project>
