Module: Sweet::Downloader

Defined in:
lib/sweet/swt/downloader.rb

Class Method Summary collapse

Class Method Details

.download_swt(opts = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sweet/swt/downloader.rb', line 5

def self.download_swt(opts = {})
  require 'rubygems'
  require 'open-uri'
  require 'zippy'
  require 'fileutils'

  platform = system_qualifier(opts)
  puts "Downloading SWT #{platform}"

  # TODO support other SWT versions
  open("http://mirrors.ibiblio.org/pub/mirrors/eclipse/eclipse/downloads/drops/R-3.5.2-201002111343/swt-3.5.2-#{platform}.zip") do |remote|
    Zippy.open(remote.path) do |zip|
      FileUtils.mkdir_p File.dirname(Sweet::SWT_JAR)
      File.open(Sweet::SWT_JAR, 'wb') do |f|
        f.write zip['swt.jar']
      end
    end
  end
end

.system_qualifier(opts = {}) ⇒ Object

TODO integrate user input to all feasible platforms



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sweet/swt/downloader.rb', line 26

def self.system_qualifier(opts = {})
  props = Java.java.lang.System.properties
  os = (opts[:os] || props['os.name']).downcase

  arch = (opts[:arch] || props['os.arch']).downcase
  arch = 'x86' if arch =~ /..86$/

  wish_tk = opts[:tk]
  tk = case os
  when *%w{linux solaris sunos}
    os = 'solaris' if os == 'sunos'
    %w{gtk motif}.member?(wish_tk) ? wish_tk : 'gtk'
  when 'mac os x'
    os = 'macosx'
    arch = nil if arch != 'x86_64'
    %w{carbon cocoa}.member?(wish_tk) ? wish_tk : 'cocoa'
  when 'qnx'
    arch = 'x86'
    'photon'
  when 'aix'
    arch = 'ppc'
    'motif'
  when 'hp-ux'
    os = 'hpux'
    arch = 'ia64_32'
    'motif'
  when 'windows vista'
    os = 'win32'
    arch = 'x86' if wish_tk == 'wpf'
    %w{wpf win32}.member?(wish_tk) ? wish_tk : 'win32'
  when /windows/
    os = 'win32' # returns win32 as tk also
  end

  [tk, os, arch].compact.join('-')
end