<?xml version="1.0" encoding="UTF-8"?>
<project name="net.sf.colorer" default="gather" basedir=".">

  <property name="bootclasspath" value=""/>
  <property name="eclipse.ws" value='win32'/>
  <property name="ws" value="${eclipse.ws}"/>
  <property name="os" value="win32"/>
  <property name="arch" value="x86"/>
  <property name="javacFailOnError" value="true"/>
  <property name="javacDebugInfo" value="on"/>
  <property name="javacVerbose" value="true"/>

  <target name="init" depends="properties">
    <property name="plugin" value="net.sf.colorer"/>

    <property name='eclipseplugin-version' value='_0.5.0'/>
    <property name='eclipseplugin-name' value='EclipseColorer-take5${eclipseplugin-version}'/>
    <property name='eclipsedir-name' value='net.sf.colorer${eclipseplugin-version}'/>

    <property name="version.suffix" value="${eclipseplugin-version}"/>
    <property name="full.name" value="${plugin}${version.suffix}"/>
    <property name="zip.name" value="${eclipseplugin-name}"/>
    <property name="temp.folder" value="${basedir}/temp.folder"/>
    <property name="plugin.destination" value="${basedir}/distr"/>
    <property name="build.result.folder" value="${basedir}"/>
    <property name='eclipse.dir' value='../..'/>
    <property name='eclipse.plugins' value='${eclipse.dir}/plugins'/>
    <property name='eclipse.ver' value='2.1.0'/>
  </target>

  <target name="properties" if="eclipse.running">
    <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
  </target>

  <target name="build.update.jar" depends="init" description="Build the plug-in: net.sf.colorer for an update site.">
    <delete dir="${temp.folder}"/>
    <mkdir dir="${temp.folder}"/>
    <antcall target="build.jars"/>
    <antcall target="gather.bin.parts">
      <param name="destination.temp.folder" value="${temp.folder}/"/>
    </antcall>
    <zip zipfile="${plugin.destination}/${full.name}.jar" basedir="${temp.folder}/${full.name}" filesonly="false" update="no"/>
    <delete dir="${temp.folder}"/>
  </target>

  <target name="gather.bin.parts" depends="init" if="destination.temp.folder">
    <mkdir dir="${destination.temp.folder}/${full.name}"/>
    <copy file="${build.result.folder}/colorer.jar" todir="${destination.temp.folder}/${full.name}"/>
    <copy todir="${destination.temp.folder}/${full.name}">
      <fileset dir="." includes="plugin.properties,plugin.xml,plugin_ru.prop,plugin_ru.properties"/><!-- toc.xml -->
      <fileset dir="." includes="icons/**/*.gif"/>
      <fileset dir="${plugin.destination}" includes='ColorerDemo.bat,LINUX,MACOS,README,TODO,WHATSNEW,ColorerDemo.sh'/>
    </copy>
  </target>

  <target name="colorer.jar" depends="init" unless="colorer.jar" description="Create jar: colorer.jar.">
    <property name="destdir" value="${temp.folder}/colorer.jar.bin"/>
    <delete dir="${temp.folder}/colorer.jar.bin"/>
    <mkdir dir="${temp.folder}/colorer.jar.bin"/>
    <!-- compile the source code -->
    <javac destdir="${temp.folder}/colorer.jar.bin" failonerror="${javacFailOnError}" verbose="${javacVerbose}" debug="${javacDebugInfo}" includeAntRuntime="no" bootclasspath="${bootclasspath}" classpath="${eclipse.plugins}/org.eclipse.core.boot_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.core.boot_${eclipse.ver}/boot.jar;${eclipse.plugins}/org.eclipse.core.runtime_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.core.runtime_${eclipse.ver}/runtime.jar;${eclipse.plugins}/org.apache.xerces_4.0.7/bin;${eclipse.plugins}/org.apache.xerces_4.0.7/xmlParserAPIs.jar;${eclipse.plugins}/org.apache.xerces_4.0.7/xercesImpl.jar;${eclipse.plugins}/org.eclipse.core.resources_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.core.resources_${eclipse.ver}/resources.jar;${eclipse.plugins}/org.eclipse.core.resources.win32_${eclipse.ver}/resources.jar;${eclipse.plugins}/org.eclipse.ui_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.ui_${eclipse.ver}/ui.jar;${eclipse.plugins}/org.eclipse.update.core_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.update.core_${eclipse.ver}/updatecore.jar;${eclipse.plugins}/org.eclipse.update.core.win32_${eclipse.ver}/updatecore.jar;${eclipse.plugins}/org.eclipse.help_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.help_${eclipse.ver}/help.jar;${eclipse.plugins}/org.apache.lucene_1.2.1/bin;${eclipse.plugins}/org.apache.lucene_1.2.1/parser.jar;${eclipse.plugins}/org.apache.lucene_1.2.1/lucene-1.2.jar;${eclipse.plugins}/org.eclipse.help.appserver_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.help.appserver_${eclipse.ver}/appserver.jar;${eclipse.plugins}/org.eclipse.swt_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.swt_${eclipse.ver}/ws/${ws}/swt.jar;${eclipse.plugins}/org.eclipse.swt.${ws}_${eclipse.ver}/ws/${ws}/swt.jar;${eclipse.plugins}/org.eclipse.text_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.text_${eclipse.ver}/text.jar;${eclipse.plugins}/org.eclipse.jface_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.jface_${eclipse.ver}/jface.jar;${eclipse.plugins}/org.eclipse.jface.text_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.jface.text_${eclipse.ver}/jfacetext.jar;${eclipse.plugins}/org.eclipse.ui.views_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.ui.views_${eclipse.ver}/views.jar;${eclipse.plugins}/org.eclipse.ui.workbench_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.ui_${eclipse.ver}/workbench.jar;${eclipse.plugins}/org.eclipse.ui.workbench_${eclipse.ver}/workbench.jar;${eclipse.plugins}/org.eclipse.ui.workbench.texteditor_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.ui.workbench.texteditor_${eclipse.ver}/texteditor.jar;${eclipse.plugins}/org.eclipse.ui.editors_${eclipse.ver}/bin;${eclipse.plugins}/org.eclipse.ui.editors_${eclipse.ver}/editors.jar">
      <src path="src/"/>
    </javac>
    <!-- copy necessary resources -->
    <copy todir="${temp.folder}/colorer.jar.bin">
      <fileset dir="src/" excludes="**/*.java"/>
    </copy>
    <mkdir dir="${build.result.folder}"/>
    <jar jarfile="${build.result.folder}/colorer.jar" basedir="${temp.folder}/colorer.jar.bin"/>
    <delete dir="${temp.folder}/colorer.jar.bin"/>
  </target>

  <target name="src.zip" depends="init" unless="colorer.jar">
    <mkdir dir="${build.result.folder}"/>
    <zip zipfile="${build.result.folder}/src.zip" filesonly="false" update="no">
      <fileset dir="." includes="src/**/*.java, src/**/*.prop*, src/**/*.htm*, plugin*, build.*, .*, javadoc.xml"/>
    </zip>
  </target>

  <target name="build.jars" depends="init" description="Build all the jars for the plug-in: net.sf.colorer.">
    <uptodate property="colorer.jar" targetfile="${build.result.folder}/colorer.jar">
      <srcfiles dir= "src" includes="**/*.java"/>
    </uptodate>
    <antcall target="colorer.jar"/>
  </target>

  <target name="build.sources" depends="init">
    <available property="src.zip" file="${build.result.folder}/src.zip"/>
    <antcall target="src.zip"/>
  </target>

  <target name="gather.sources" depends="init" if="destination.temp.folder">
    <mkdir dir="${destination.temp.folder}/${full.name}"/>
    <copy file="${build.result.folder}/src.zip" todir="${destination.temp.folder}/${full.name}"/>
  </target>

  <target name="gather.logs" depends="init" if="destination.temp.folder">
    <mkdir dir="${destination.temp.folder}/${full.name}"/>
    <copy file="${temp.folder}/colorer.jar.bin.log" todir="${destination.temp.folder}/${full.name}"/>
  </target>

  <target name="clean" depends="init" description="Clean the plug-in: net.sf.colorer of all the zips, jars and logs created.">
    <delete file="${build.result.folder}/colorer.jar"/>
    <delete file="${build.result.folder}/src.zip"/>
    <delete file="${plugin.destination}/${full.name}.jar"/>
    <delete file="${plugin.destination}/${full.name}.zip"/>
    <delete dir="${temp.folder}"/>
  </target>

  <target name="refresh" depends="init" if="eclipse.running">
    <eclipse.convertPath fileSystemPath="C:\Program Files\eclipse\workspace\net.sf.colorer\" property="resourcePath"/>
    <eclipse.refreshLocal resource="${resourcePath}" depth="infinite"/>
  </target>

  <target name="gather" depends="init" description="Create a directory, containing all the elements for the plug-in: net.sf.colorer.">
    <antcall target="build.jars"/>
    <antcall target="build.sources"/>
    <antcall target="gather.bin.parts">
      <param name="destination.temp.folder" value="${temp.folder}/"/>
    </antcall>
    <antcall target="gather.sources">
      <param name="destination.temp.folder" value="${temp.folder}/"/>
    </antcall>
    <delete>
      <fileset dir="${temp.folder}" includes="**/*.bin.log"/>
    </delete>
  </target>
  <target name="zip.folder" depends="init">
    <zip zipfile="${plugin.destination}/${zip.name}.zip" basedir="${temp.folder}" filesonly="true" update="no" excludes="**/*.bin.log"/>
  </target>

</project>
