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

    <target name="init">
        <property name="galileo_url"            value="http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR2/"/>
        <property name="galileo_jee_win32"      value="eclipse-jee-galileo-SR2-win32.zip"/>
        <property name="galileo_jee_linux"      value="eclipse-jee-galileo-SR2-linux-gtk.tar"/>
        <property name="galileo_jee_linux-x86_64" value="eclipse-jee-galileo-SR2-linux-gtk-x86_64.tar"/>
        <property name="galileo_jee_macos"      value="eclipse-jee-galileo-SR2-macosx-carbon.tar"/>
        <property name="galileo_jee_linux_gz"   value="${galileo_jee_linux}.gz"/>
        <property name="galileo_jee_linux-x86_64_gz" value="${galileo_jee_linux-x86_64}.gz"/>
        <property name="galileo_jee_macos_gz"   value="${galileo_jee_macos}.gz"/>
        <property name="protocol"               value="&amp;r=1&amp;protocol=http"/>
        <property name="test_eclipse"           value="${basedir}/../launcher/eclipse/"/>
        <property name="test_framework_url"     value="http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.5-200906111540/"/>
        <property name="test_framework"         value="eclipse-test-framework-3.5.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="2.2.1"/>
    </target>

    <target name="win32" depends="init,common" description="Download Windows-specific artifact(s)">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${galileo_jee_win32}                                             </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${galileo_url}                                                          </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${galileo_url}${galileo_jee_win32}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_win32}" 
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${galileo_jee_win32}                                               </echo>
        <echo>##                                                                               </echo>
        <echo>## To: ${test_eclipse}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${test_eclipse}"/>
        <unzip src="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_win32}" 
               dest="${test_eclipse}"
               overwrite="true"/>
    </target>

    <target name="linux" depends="init,common" description="Download Linux-specific artifact(s)">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${galileo_jee_linux_gz}                                          </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${galileo_url}                                                          </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${galileo_url}${galileo_jee_linux_gz}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_linux_gz}" 
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${galileo_jee_linux_gz}                                            </echo>
        <echo>##                                                                               </echo>
        <echo>## To: ${test_eclipse}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir  dir="${test_eclipse}"/>
        <gunzip src="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_linux_gz}"/>
        <untar  src="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_linux}" 
                dest="${test_eclipse}"
                overwrite="true"/>
    </target>

    <target name="linux-x86_64" depends="init,common" description="Download Linux-specific artifact(s)">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${galileo_jee_linux-x86_64_gz}                                   </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${galileo_url}                                                          </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${galileo_url}${galileo_jee_linux-x86_64_gz}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_linux-x86_64_gz}"
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${galileo_jee_linux-x86_64_gz}                                     </echo>
	<echo>##                                                                               </echo>
        <echo>## To: ${test_eclipse}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
	<mkdir  dir="${test_eclipse}"/>
        <gunzip src="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_linux-x86_64_gz}"/>
        <untar  src="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_linux-x86_64}"
		dest="${test_eclipse}"
                overwrite="true"/>
    </target>

    <target name="macos" depends="init,common" description="Download Mac-specific artifact(s)">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${galileo_jee_macos_gz}                                          </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${galileo_url}                                                          </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${galileo_url}${galileo_jee_macos_gz}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_macos_gz}" 
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${galileo_jee_macos_gz}                                            </echo>
        <echo>##                                                                               </echo>
        <echo>## To: ${test_eclipse}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir  dir="${test_eclipse}"/>
        <gunzip src="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_macos_gz}"/>
        <untar  src="${LOCAL_M2_REPO}/eclipse-downloads/${galileo_jee_macos}" 
                dest="${test_eclipse}"
                overwrite="true"/>
    </target>

    <target name="common" depends="init" description="Download artifacts common to all OS'es">
        <antcall target="cleanup"/>
        <antcall target="test-framework"/>
        <antcall target="abbot"/>
        <antcall target="gep-plugins"/>
        <antcall target="gep-features"/>
    </target>

    <target name="cleanup" depends="init" description="Cleanup from previous invocatins 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" depends="init" 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="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${test_framework_url}${test_framework}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${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="${LOCAL_M2_REPO}/eclipse-downloads/${test_framework}"
               dest="${test_eclipse}"
               overwrite="true"/>
    </target>

    <target name="abbot" depends="init" 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="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${abbot_swt_url}${abbot_swt}${abbot_protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${abbot_swt}" 
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <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="${LOCAL_M2_REPO}/eclipse-downloads/${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" depends="init" 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.jee.v21.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.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.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.v22.core/${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>
        </copy>
    </target>

    <target name="gep-features" depends="init" 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.v22.feature/${gep_version}/org.apache.geronimo.v22.feature-${gep_version}.jar"
               dest="${test_eclipse}eclipse/features/org.apache.geronimo.v22.feature_${gep_version}"
               overwrite="true"/>
    </target>
    
    <target name="skip" description="Skip the build.xml">                                             
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Skip testsuite\eclipse\build.xml                                              </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
    </target>

</project>
