<!--
 -
 - 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="Eclipse Plugin Binary Release" default="release-bin">

	<!-- check properties that must be set by caller -->
    <target name="check" description="ensure all required properties are set">
    	<condition property="properties.set">
    		<and>
    	        <!-- common properties -->
    		    <isset property ="mcplugin.contents.dir"/>
                <isset property ="mcplugin.manifest"/>
                <isset property ="mcplugin.filename"/>
                <isset property ="bin.dir"/>
                <isset property ="startup.jar"/>
                <isset property ="eclipse.ini"/>
                <isset property ="license.eclipse.txt"/>
                <isset property ="jmxremote.sasl.manifest"/>
                <isset property ="qpidmanagementcommon.manifest"/>
                <!-- platform specific properties -->
                <isset property ="bin.includes"/>
                <isset property ="release.name"/>
                <isset property ="release.subdir"/>
                <isset property ="rcp.libs"/>
                <isset property ="rcp.configuration.dir"/>
    		    <or>
    		        <isset property ="release.zip"/>
    		        <isset property ="release.tar.gz"/>
    		    </or>
        	</and>
            <!-- Optional Properties -->
            <!-- eclipse.executable.companion.library -->
        </condition>

        <fail unless="properties.set" message="required properties not set"/>
    </target>

    <target name="release-bin-prepare">
        <mkdir dir="${release.subdir}"/>
    </target>

    <target name="release-bin-mcplugin-jar">
    	<jar destfile="${release.subdir}/eclipse/plugins/${mcplugin.filename}.jar" basedir="${mcplugin.contents.dir}" manifest="${mcplugin.manifest}"/>
    </target>

    <target name="release-bin-jmxremote-plugin">
        <!-- Copy the jmxremote.sasl plugin's manifest, creating its plugin directory -->
        <copy todir="${release.subdir}/eclipse/plugins/jmxremote.sasl_1.0.1/META-INF" flatten="true" failonerror="true">
            <fileset file="${jmxremote.sasl.manifest}"/>
        </copy>
    </target>

    <target name="release-bin-qpidmanagementcommon-plugin">
        <!-- Copy the management common plugin's manifest, creating its plugin directory -->
        <copy todir="${release.subdir}/eclipse/plugins/qpid-management-common_1.0.0/META-INF" flatten="true" failonerror="true">
            <fileset file="${qpidmanagementcommon.manifest}"/>
        </copy>
        <copy todir="${release.subdir}/eclipse/plugins/qpid-management-common_1.0.0/" flatten="true" failonerror="true">
            <fileset file="${build.lib}/qpid-management-common-${project.version}.jar"/>
        </copy>
    </target>

    <target name="copy-executable" description="Copy eclipse-rcp execuitable" if="eclipse.executable">
 
        <!-- Copy the eclipse rcp executable files -->
        <copy todir="${release.subdir}/eclipse" flatten="true" failonerror="true">
            <fileset file="${eclipse.executable}"/>
        </copy>
        <chmod dir="${release.subdir}/eclipse" perm="u+rx" includes="**/*"/>


    </target>

    <target name="release-bin-rcp-deps" description="copy eclipse-rcp dependencies into module release" 
					depends="copy-executable">    	
        
        <!-- Copy remaining startup & license files -->
        <copy todir="${release.subdir}/eclipse" flatten="true" failonerror="true">
            <fileset file="${startup.jar}"/>
            <fileset file="${eclipse.ini}"/>
            <fileset file="${license.eclipse.txt}"/>
        </copy>

        <echo message="${ecl-swt-linux-gtk-x86}"/>
        <echo message="${management-eclipse-plugin-linux-gtk-x86.libs}"/>
        <echo message="${rcp.libs}"/>
        <!-- Copy the eclipse rcp module libs -->
        <copy todir="${release.subdir}/eclipse/plugins" failonerror="true">

            <fileset dir="${project.root}" includes="${rcp.libs}"/>
            <globmapper from="lib/*" to="*"/>
        </copy>

        <!-- Copy the relevant bin dir files-->    	
        <copy todir="${release.subdir}/bin" failonerror="true">
            <fileset dir="${bin.dir}" includes="${bin.includes}"/>
        </copy>
        <chmod dir="${release.subdir}/bin" perm="u+rx" includes="**/*"/>

        <!-- Copy the relevant configuration dir -->
        <copy todir="${release.subdir}/configuration" failonerror="true">
            <fileset dir="${rcp.configuration.dir}"/>
        </copy>
        <chmod dir="${release.subdir}/configuration" perm="ugo+r" includes="**/*"/>
    </target>
  
    <target name="release-bin-zip" if="release.zip" description="build mc zip archive">
        <zip destfile="${release.zip}">
            <zipfileset dir="${release.subdir}" prefix="${release.name}" filemode="755">
                <include name="bin/*"/>
            </zipfileset>

            <zipfileset dir="${release.subdir}" prefix="${release.name}" filemode="755">
                <include name="eclipse/eclipse*"/>
            </zipfileset>

            <zipfileset dir="${release.subdir}" prefix="${release.name}" filemode="644" dirmode="755">
                <exclude name="bin/**"/>
                <exclude name="eclipse/eclipse*"/>
            </zipfileset>
        </zip>
    </target>    		

    <target name="release-bin-gzip" if="release.tar.gz" description="build mc tar.gz archive">
        <tar destfile="${release.tar.gz}" longfile="gnu">
            <tarfileset dir="${release.subdir}" prefix="${release.name}" filemode="755">
                <include name="bin/*"/>
            </tarfileset>

            <tarfileset dir="${release.subdir}" prefix="${release.name}" filemode="755">
                <include name="eclipse/eclipse*"/>
            </tarfileset>

            <tarfileset dir="${release.subdir}" prefix="${release.name}" filemode="644" dirmode="755">
                <exclude name="bin/**"/>
                <exclude name="eclipse/eclipse*"/>
            </tarfileset>
        </tar>
    </target>

    
    
    <target name="release-bin" depends="check,release-bin-prepare,release-bin-rcp-deps,
        release-bin-mcplugin-jar,release-bin-qpidmanagementcommon-plugin,release-bin-jmxremote-plugin,release-bin-zip,release-bin-gzip"/>
    
</project>
