<?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 Helios artifacts and unzip them into the user's local maven repo     
 |                                                                                             
 |                                                                                             
 | @version $Rev$ $Date$
 -->
<project name="HeliosArtifacts">   

    <condition property="is64bitJDK">
        <!--We only check JVM bit model here.It works fine even 32-bit JVM is used on 64-bit OS -->
        <equals arg1="${sun.arch.data.model}" arg2="64" />
    </condition>

    <target name="init">
        <property name="helios_url"                     value="http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/helios/R"/>
        <property name="helios_jee_win32"               value="eclipse-jee-helios-win32.zip"/>
        <property name="helios_jee_win64"               value="eclipse-jee-helios-win32_64.zip"/>
        <property name="helios_jee_linux"               value="eclipse-jee-helios-linux-gtk.tar"/>
        <property name="helios_jee_linux-x86_64"        value="eclipse-jee-helios-linux-gtk-x86_64.tar"/>
        <property name="helios_jee_macos"               value="eclipse-jee-helios-macosx-cocoa.tar"/>
        <property name="helios_jee_linux_gz"            value="${helios_jee_linux}.gz"/>
        <property name="helios_jee_linux-x86_64_gz"     value="${helios_jee_linux-x86_64}.gz"/>
        <property name="helios_jee_macos_gz"            value="${helios_jee_macos}.gz"/>
        <property name="protocol"                       value="&amp;r=1&amp;protocol=http"/>
    </target>

    <target name="win" depends="init" description="Download Windows-specific artifact(s)">
           <antcall target="win64"></antcall>
           <antcall target="win32"></antcall>
    </target>

    <target name="win32" unless="is64bitJDK" description="Download Windows 32-bit-specific artifact(s)">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${helios_jee_win32}                                              </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${helios_url}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${helios_url}/${helios_jee_win32}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_win32}" 
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${helios_jee_win32}                                                </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <delete dir="${LOCAL_M2_REPO}/eclipse" quiet="true"/> 
        <mkdir dir="${LOCAL_M2_REPO}/eclipse"/>
        <unzip src="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_win32}" 
               dest="${LOCAL_M2_REPO}/eclipse"
               overwrite="true"/>
    </target>

    <target name="win64" if="is64bitJDK" description="Download Windows 64-bit-specific artifact(s)">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${helios_jee_win64}                                              </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${helios_url}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${helios_url}/${helios_jee_win64}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_win64}" 
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${helios_jee_win64}                                                </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <delete dir="${LOCAL_M2_REPO}/eclipse" quiet="true"/> 
        <mkdir dir="${LOCAL_M2_REPO}/eclipse"/>
        <unzip src="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_win64}" 
               dest="${LOCAL_M2_REPO}/eclipse"
               overwrite="true"/>
    </target>

    <target name="linux" depends="init" description="Download Linux-specific artifact(s)">
        <antcall target="linux_x86"></antcall>
        <antcall target="linux-x86_64"></antcall>
    </target>

    <target name="linux_x86" unless="is64bitJDK" description="Download Linux 32-bit-specific artifact(s)">
	
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${helios_jee_linux_gz}                                           </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${helios_url}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${helios_url}/${helios_jee_linux_gz}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_linux_gz}" 
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${helios_jee_linux_gz}                                             </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <delete dir="${LOCAL_M2_REPO}/eclipse" quiet="true"/> 
        <mkdir  dir="${LOCAL_M2_REPO}/eclipse"/>
        <gunzip src="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_linux_gz}"/>
        <untar  src="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_linux}" 
                dest="${LOCAL_M2_REPO}/eclipse"
                overwrite="true"/>
    </target>

    <target name="linux-x86_64" if="is64bitJDK" description="Download Linux 64-bit-specific artifact(s)">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${helios_jee_linux-x86_64_gz}                                    </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${helios_url}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${helios_url}/${helios_jee_linux-x86_64_gz}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_linux-x86_64_gz}"
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${helios_jee_linux-x86_64_gz}                                      </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <delete dir="${LOCAL_M2_REPO}/eclipse" quiet="true"/> 
        <mkdir  dir="${LOCAL_M2_REPO}/eclipse"/>
        <gunzip src="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_linux-x86_64_gz}"/>
        <untar  src="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_linux-x86_64}"
                dest="${LOCAL_M2_REPO}/eclipse"
                overwrite="true"/>
    </target>

    <target name="macos" depends="init" description="Download Mac-specific artifact(s)">
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Downloading: ${helios_jee_macos_gz}                                           </echo>
        <echo>##                                                                               </echo>
        <echo>## From: ${helios_url}                                                           </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <mkdir dir="${LOCAL_M2_REPO}/eclipse-downloads"/>
        <get src="${helios_url}/${helios_jee_macos_gz}${protocol}"
             dest="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_macos_gz}" 
             verbose="true"
             ignoreerrors="true"
             usetimestamp="true"/>
        <echo>#################################################################################</echo>
        <echo>##                                                                               </echo>
        <echo>## Unzipping: ${helios_jee_macos_gz}                                             </echo>
        <echo>##                                                                               </echo>
        <echo>#################################################################################</echo>
        <delete dir="${LOCAL_M2_REPO}/eclipse" quiet="true"/> 
        <mkdir  dir="${LOCAL_M2_REPO}/eclipse"/>
        <gunzip src="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_macos_gz}"/>
        <untar  src="${LOCAL_M2_REPO}/eclipse-downloads/${helios_jee_macos}" 
                dest="${LOCAL_M2_REPO}/eclipse"
                overwrite="true"/>
    </target>

</project>
