<?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.
  -->

<!--
 |
 | Download Eclipse, the Eclipse test-framework, and the Abbot SWT for usage with the GEP testsuite
 |
 | TODO: Move many of these tasks to the antrun task in the various pom.xml files (i.e., each plugin)
 |
 |
 | @version $Rev$ $Date$
 |
 -->
<project name="TestsuiteArtifacts" default="common" >

    <!-- expected input properties:
        1. download_to   - The directory to download eclipse_zip to.
        2. extract_to    - The directory to extract  ecslipe_zip to.
        3. LOCAL_M2_REPO - Local M2 repo for various jars...
      -->
    <fail message="required download_to property not set.">
        <condition>
            <not>
                <isset property="download_to" />
            </not>
        </condition>
    </fail>
    <fail message="required extract_to property not set.">
        <condition>
            <not>
                <isset property="extract_to" />
            </not>
        </condition>
    </fail>
    <fail message="required LOCAL_M2_REPO property not set.">
        <condition>
            <not>
                <isset property="LOCAL_M2_REPO" />
            </not>
        </condition>
    </fail>

    <property name="test_eclipse"                   value="${extract_to}/"/>
    <property name="test_framework_url"             value="http://download.eclipse.org/eclipse/downloads/drops/R-3.6-201006080911/eclipse-test-framework-3.6.zip" />
    <property name="test_framework"                 value="eclipse-test-framework-3.6.zip"/>

    <property name="abbot_swt_url"                  value="http://downloads.sourceforge.net/abbot"/>
    <property name="abbot_swt_version"              value="0.1.0.20080305_1254"/>
    <property name="abbot_swt"                      value="abbot.swt-${abbot_swt_version}.zip"/>
    <property name="abbot_protocol"                 value="?modtime=12047243638&amp;protocol=http"/>

    <property name="gep_version"                    value="3.0.0"/>

    <property name="protocol"                       value="&amp;r=1&amp;protocol=http"/>

    <target name="common" description="Download artifacts common to all OS'es">
        <antcall target="cleanup"/>
        <!-- note that ../../eclipse/build.xml also deletes ${test_eclipse}, like cleanup -->
        <ant antfile="../../eclipse/build.xml">
            <property name="extract_to"   value="${test_eclipse}" />
        </ant>
        <antcall target="test-framework"/>
        <antcall target="abbot"/>
        <antcall target="gep-plugins"/>
        <antcall target="gep-features"/>
    </target>

    <target name="cleanup" description="Cleanup from previous invocations of the testsuite">
        <!--
        ##############################################################################################
        ##                                                                                          ##
        ## Cannot repeatedly unzip into the test_eclipse as it will corrupt the Eclipse plugin      ##
        ## registry. So delete it even though clean may not have been specified on the mvn command. ##
        ##                                                                                          ##
        ##############################################################################################
        -->
        <delete dir="${test_eclipse}" quiet="true"/>
    </target>

    <target name="test-framework" description="JUnit Plugin Tests and Automated Testing Framework artifact">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${test_framework}                                                </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${test_framework_url}                                                   </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>

        <mkdir dir="${download_to}"/>
        <get src="${test_framework_url}"
             dest="${download_to}/${test_framework}"
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>

        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${test_framework}                                                  </echo>
        <echo>##                                                                               </echo>
        <echo>## To: ${test_eclipse}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${test_eclipse}"/>
        <unzip src="${download_to}/${test_framework}"
               dest="${test_eclipse}"
               overwrite="true"/>
    </target>

    <target name="abbot" description="Download Abbot SWT plugin artifacts">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${abbot_swt}                                                     </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${abbot_swt_url}                                                        </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${download_to}"/>
        <get src="${abbot_swt_url}/${abbot_swt}${abbot_protocol}"
             dest="${download_to}/${abbot_swt}"
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>

		<!--
		Replace the MANIFEST.MF files of abbot.swt and abbot.swt.eclipse with new MF files in which
		the junit version is 4.8.1
		-->

		<mkdir dir="${basedir}/temp"/>
		<unzip src="${download_to}/${abbot_swt}"
		       dest="${basedir}/temp"/>

		<mkdir dir="${basedir}/temp/plugins/abbot.swt.temp"/>
		<unzip src="${basedir}/temp/plugins/abbot.swt_${abbot_swt_version}.jar"
			   dest="${basedir}/temp/plugins/abbot.swt.temp"/>
		<copy file="${basedir}/metadata_abbot_swt/MANIFEST.MF"
		      tofile="${basedir}/temp/plugins/abbot.swt.temp/META-INF/MANIFEST.MF"
		      overwrite="true"/>
		<zip destfile="${basedir}/temp/plugins/abbot.swt_${abbot_swt_version}.jar"
		     basedir="${basedir}/temp/plugins/abbot.swt.temp"
			 includes="**"
			 update="true"/>

		<mkdir dir="${basedir}/temp/plugins/abbot.swt.eclipse.temp"/>
		<unzip src="${basedir}/temp/plugins/abbot.swt.eclipse_${abbot_swt_version}.jar"
			   dest="${basedir}/temp/plugins/abbot.swt.eclipse.temp"/>
		<copy file="${basedir}/metadata_abbot_swt_eclipse/MANIFEST.MF"
			  tofile="${basedir}/temp/plugins/abbot.swt.eclipse.temp/META-INF/MANIFEST.MF"
		      overwrite="true"/>
		<zip destfile="${basedir}/temp/plugins/abbot.swt.eclipse_${abbot_swt_version}.jar"
		     basedir="${basedir}/temp/plugins/abbot.swt.eclipse.temp"
			 includes="**"
		     update="true"/>

		<delete dir="${basedir}/temp/plugins/abbot.swt.temp"/>
		<delete dir="${basedir}/temp/plugins/abbot.swt.eclipse.temp"/>

		<zip destfile="${download_to}/${abbot_swt}"
		     basedir="${basedir}/temp"
		     includes="**"
		     update="true"/>

		<delete dir="${basedir}/temp"/>


        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${abbot_swt}                                                       </echo>
        <echo>##                                                                               </echo>
        <echo>## To: ${test_eclipse}/eclipse                                                    </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${test_eclipse}"/>
        <unzip src="${download_to}/${abbot_swt}"
               dest="${test_eclipse}/eclipse"
               overwrite="true"/>

        <!--
         |
         | Copy the SWT jars to the local maven repo
         |
         -->
        <mkdir dir="${LOCAL_M2_REPO}/abbot/abbot.swt/0.1.0.20080305_1254"/>
        <copy file="${test_eclipse}/eclipse/plugins/abbot.swt_0.1.0.20080305_1254.jar"
              tofile="${LOCAL_M2_REPO}/abbot/abbot.swt/0.1.0.20080305_1254/abbot.swt-0.1.0.20080305_1254.jar"
              failonerror="true" />
        <mkdir dir="${LOCAL_M2_REPO}/abbot/abbot.swt.eclipse/0.1.0.20080305_1254"/>
        <copy file="${test_eclipse}/eclipse/plugins/abbot.swt.eclipse_0.1.0.20080305_1254.jar"
              tofile="${LOCAL_M2_REPO}/abbot/abbot.swt.eclipse/0.1.0.20080305_1254/abbot.swt.eclipse-0.1.0.20080305_1254.jar"
              failonerror="true" />
        <!--
         |
         | Copy the SWT jars to the Eclipse plugins in the local maven repo
         |
         -->
        <copy file="${test_eclipse}/eclipse/plugins/abbot.swt_0.1.0.20080305_1254.jar"
              tofile="${LOCAL_M2_REPO}/eclipse/eclipse/plugins/abbot.swt-0.1.0.20080305_1254.jar"
              failonerror="true" />
        <copy file="${test_eclipse}/eclipse/plugins/abbot.swt.eclipse_0.1.0.20080305_1254.jar"
              tofile="${LOCAL_M2_REPO}/eclipse/eclipse/plugins/abbot.swt.eclipse-0.1.0.20080305_1254.jar"
              failonerror="true" />
    </target>


    <target name="gep-plugins" description="Copy the GEP plugin(s) into the test_eclipse installation">
        <!--
        |
        | Copy the GEP plugins to the launcher Eclipse plugins directory
        |
        -->
        <mkdir dir="${test_eclipse}"/>
        <copy todir="${test_eclipse}/eclipse/plugins">
	    <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.jaxbmodel.common/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.j2ee.v11.jaxbmodel/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.jee.v21.jaxbmodel/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v30.jaxbmodel/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.runtime.common/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.runtime.v30/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.runtime.v22/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.runtime.v21/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.runtime.v20/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.runtime.v11/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.core/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.ui/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.schemas/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v30.core/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v22.core/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v30.ui/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v22.ui/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v21.core/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v21.ui/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v20.core/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v20.ui/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v11.core/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v11.schemas/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.st.v11.ui/${gep_version}">
                <include name="**/*.jar"/>
            </fileset>
        </copy>
    </target>

    <target name="gep-features" description="Unzip the GEP latest feature to the launcher Eclipse features directory">
        <!--
        |
        | Unzip the GEP latest feature to the launcher Eclipse features directory (for one branding testcase)
        |
        -->
        <mkdir dir="${test_eclipse}"/>
        <unzip src="${LOCAL_M2_REPO}/org/apache/geronimo/devtools/org.apache.geronimo.v30.feature/${gep_version}/org.apache.geronimo.v30.feature-${gep_version}.jar"
               dest="${test_eclipse}/eclipse/features/org.apache.geronimo.v30.feature_${gep_version}"
               overwrite="true"/>
    </target>

</project>
