<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements. See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership. The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License. You may obtain a copy of the License at
 
    http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied. See the License for the
  specific language governing permissions and limitations
  under the License.
-->
<project name="org.apache.qpid.management.ui" default="build.update.jar" basedir=".">

    <property name="basews" value="${ws}"/>
    <property name="baseos" value="${os}"/>
    <property name="basearch" value="${arch}"/>
    <property name="basenl" value="${nl}"/>

    <!-- Compiler settings. -->
    <property name="javacFailOnError" value="false"/>
    <property name="javacDebugInfo" value="on"/>
    <property name="javacVerbose" value="false"/>
    <property name="logExtension" value=".log"/>
    <property name="compilerArg" value=""/>
    <property name="javacSource" value="1.5"/>
    <property name="javacTarget" value="1.5"/>
    <path id="path_bootclasspath">
        <fileset dir="${java.home}/lib">
            <include name="*.jar"/>
        </fileset>
    </path>
    <property name="bootclasspath" refid="path_bootclasspath"/>
    <property name="bundleJavacSource" value="${javacSource}"/>
    <property name="bundleJavacTarget" value="${javacTarget}"/>
    <property name="bundleBootClasspath" value="${bootclasspath}"/>
    <property name="pluginName" value="org.apache.qpid.management.ui"/>
    <property name="distName" value="qpidmc"/>
    <property name="version" value="0.1.0"/>

    <target name="init" depends="properties">
        <condition property="pluginTemp" value="${buildTempFolder}/plugins">
            <isset property="buildTempFolder"/>
        </condition>
        <property name="pluginTemp" value="${basedir}"/>
        <condition property="build.result.folder" value="${pluginTemp}/eclipse-plugin">
            <isset property="buildTempFolder"/>
        </condition>
        <property name="build.result.folder" value="${basedir}"/>
        <property name="temp.folder" value="${basedir}/temp.folder"/>
        <property name="plugin.destination" value="${basedir}"/>
        <property name="target.folder" value="${basedir}/target"/>
        <property name="compile.folder" value="${target.folder}/classes"/>
        <property name="plugins.folder" value="${basedir}/plugins"/>
    </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: org.apache.qpid.management.ui 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 destfile="${plugins.folder}/${pluginName}_${version}.jar" basedir="${temp.folder}/${pluginName}" filesonly="false" whenempty="skip" update="false"/>
        <delete dir="${temp.folder}"/>
    </target>

    <target name="compile" depends="init" unless="compile" description="Create jar: org.apache.qpid.management.ui compile.">
        <delete dir="${temp.folder}/compile.bin"/>
        <mkdir dir="${temp.folder}/compile.bin"/>
        <path id="compile.classpath">
            <pathelement path="plugins/org.eclipse.ui_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.core.runtime_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.osgi_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.equinox.common_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.core.jobs_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.core.runtime.compatibility.registry_3.2.0/runtime_registry_compatibility.jar"/>
            <pathelement path="plugins/org.eclipse.equinox.registry_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.equinox.preferences_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.core.contenttype_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.core.runtime.compatibility.auth_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.swt_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.swt.win32.win32.x86_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.jface_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.core.commands_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.ui.workbench_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.ui.workbench.compatibility_3.2.0/compatibility.jar"/>
            <pathelement path="plugins/com.ibm.icu_3.4.4.1.jar"/>
            <pathelement path="plugins/org.eclipse.help_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.core.expressions_3.2.0.jar"/>
            <pathelement path="plugins/org.eclipse.ui.forms_3.2.0.jar"/>
        </path>
        <!-- compile the source code -->
        <javac destdir="${temp.folder}/compile.bin" failonerror="${javacFailOnError}" verbose="${javacVerbose}" debug="${javacDebugInfo}" includeAntRuntime="no" bootclasspath="${bundleBootClasspath}" source="${bundleJavacSource}" target="${bundleJavacTarget}"     >
            <compilerarg line="${compilerArg}" compiler="${build.compiler}"/>
            <classpath refid="compile.classpath" />
            <src path="src/main/java/"          />
            <!--compilerarg value="@${basedir}/javaCompiler...args" compiler="org.eclipse.jdt.core.JDTCompilerAdapter" -->
            <compilerarg line="-log '${temp.folder}/compile.bin${logExtension}'" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        </javac>
        <!-- Copy necessary resources -->
        <copy todir="${temp.folder}/compile.bin" failonerror="true" overwrite="false">
            <fileset dir="src/main/java/" excludes="**/*.java, **/package.htm*"         />
        </copy>
        <mkdir dir="${build.result.folder}"/>
        <copy todir="${target.folder}/classes" failonerror="true" overwrite="false">
            <fileset dir="${temp.folder}/compile.bin"           />
        </copy>
        <delete dir="${temp.folder}/compile.bin"/>
    </target>

    <target name="src.zip" depends="init" unless="src.zip">
        <mkdir dir="${build.result.folder}"/>
        <zip destfile="${build.result.folder}/src.zip" filesonly="false" whenempty="skip" update="false">
            <fileset dir="src/main/java/" includes="**/*.java"          />
        </zip>
    </target>

    <target name="build.jars" depends="init" description="Build all the jars for the plug-in: org.apache.qpid.management.ui.">
        <available property="compile" file="${target.folder}/classes"/>
        <antcall target="compile"/>
    </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.bin.parts" depends="init" if="destination.temp.folder">
        <mkdir dir="${destination.temp.folder}/${pluginName}"/>
        <copy todir="${destination.temp.folder}/${pluginName}" failonerror="true" overwrite="false">
            <fileset dir="${target.folder}/classes" includes="**"/>
        </copy>
        <copy todir="${destination.temp.folder}/${pluginName}" failonerror="true" overwrite="false">
            <fileset dir="${basedir}" includes="plugin.xml,META-INF/,icons/,plugin.properties,splash.bmp"/>
        </copy>
    </target>

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

    <target name="gather.logs" depends="init" if="destination.temp.folder">
        <mkdir dir="${destination.temp.folder}/${pluginName}_${version}"/>
        <copy file="${temp.folder}/compile.bin${logExtension}" todir="${destination.temp.folder}/${pluginName}_${version}" failonerror="false" overwrite="false"/>
    </target>

    <target name="clean" depends="init" description="Clean the plug-in: org.apache.qpid.management.ui of all the zips, jars and logs created.">
        <delete dir="${target.folder}/classes"/>
        <delete file="${build.result.folder}/src.zip"/>
        <delete file="${plugins.folder}/${pluginName}_${version}.jar"/>
        <delete file="${target.folder}/${pluginName}_${version}.zip"/>
        <delete file="${target.folder}/${distName}_${version}.zip"/>
        <delete dir="${temp.folder}"/>
    </target>

    <target name="build.zip" depends="init" description="Create a zip containing all the elements for the plug-in: org.apache.qpid.management.ui.">
        <delete dir="${temp.folder}"/>
        <mkdir dir="${temp.folder}"/>
        <antcall target="build.update.jar"/>
        <antcall target="build.sources"/>
        <antcall target="gather.sources">
            <param name="destination.temp.folder" value="${temp.folder}/plugins/${pluginName}_${version}/"/>
        </antcall>
        <delete>
            <fileset dir="${temp.folder}" includes="**/*.bin${logExtension}"/>
        </delete>
        <copy todir="${temp.folder}/plugins" failonerror="true" overwrite="false">
            <fileset dir="${plugins.folder}" includes="${pluginName}_${version}.jar"/>
        </copy>
        <zip destfile="${target.folder}/${pluginName}_${version}.zip" basedir="${temp.folder}" filesonly="true" whenempty="skip" update="false"/>
        <delete dir="${temp.folder}"/>
    </target>
    
    <target name="dist" depends="init" description="Create a zip containing all the elements for deploying the plug-in: org.apache.qpid.management.ui.">
        <antcall target="clean"/>
        <antcall target="build.update.jar"/>
        <antcall target="build.sources"/>
        <antcall target="gather.sources">
            <param name="destination.temp.folder" value="${temp.folder}/${distName}"/>
        </antcall>
        <copy todir="${temp.folder}/${distName}/plugins" failonerror="true" overwrite="false">
            <fileset dir="${plugins.folder}" includes="**"  />
        </copy>
        <copy todir="${temp.folder}/${distName}/bin" failonerror="true" overwrite="false">
            <fileset dir="${basedir}/bin" includes="**" />
        </copy>
        <copy todir="${temp.folder}/${distName}" failonerror="true" overwrite="false">
            <fileset dir="${basedir}" includes="startup.jar,plugin.xml,META-INF/,icons/,plugin.properties,splash.bmp"/>
        </copy>
        <copy todir="${temp.folder}/${distName}/configuration" failonerror="true" overwrite="false">
            <fileset dir="${basedir}/configuration" includes="**"/>
        </copy>
        
        <delete>
            <fileset dir="${temp.folder}" includes="**/*.bin${logExtension}"/>
        </delete>
        <zip destfile="${target.folder}/${distName}_${version}.zip" basedir="${temp.folder}" filesonly="true" whenempty="skip" update="false"/>
        <delete dir="${temp.folder}"/>
    </target>

</project>
