Class: XcodeInstall::Installer
- Inherits:
-
Object
- Object
- XcodeInstall::Installer
- Defined in:
- lib/xcode/install.rb
Instance Attribute Summary collapse
-
#xcodes ⇒ Object
readonly
Returns the value of attribute xcodes.
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #current_symlink ⇒ Object
- #download(version) ⇒ Object
- #exist?(version) ⇒ Boolean
-
#initialize ⇒ Installer
constructor
A new instance of Installer.
- #install_components(xcode_path) ⇒ Object
- #install_dmg(dmgPath, suffix = '', switch = true, clean = true) ⇒ Object
- #install_version(version, switch = true, clean = true, install = true) ⇒ Object
- #installed?(version) ⇒ Boolean
- #installed_versions ⇒ Object
- #list ⇒ Object
- #list_current ⇒ Object
- #rm_list_cache ⇒ Object
- #symlink(version) ⇒ Object
- #symlinks_to ⇒ Object
Constructor Details
#initialize ⇒ Installer
Returns a new instance of Installer.
34 35 36 |
# File 'lib/xcode/install.rb', line 34 def initialize FileUtils.mkdir_p(CACHE_DIR) end |
Instance Attribute Details
#xcodes ⇒ Object (readonly)
Returns the value of attribute xcodes.
32 33 34 |
# File 'lib/xcode/install.rb', line 32 def xcodes @xcodes end |
Instance Method Details
#cache_dir ⇒ Object
38 39 40 |
# File 'lib/xcode/install.rb', line 38 def cache_dir CACHE_DIR end |
#current_symlink ⇒ Object
42 43 44 |
# File 'lib/xcode/install.rb', line 42 def current_symlink File.symlink?(SYMLINK_PATH) ? SYMLINK_PATH : nil end |
#download(version) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/xcode/install.rb', line 46 def download(version) return unless exist?(version) xcode = seedlist.find { |x| x.name == version } dmg_file = Pathname.new(File.basename(xcode.path)) result = Curl.new.fetch(xcode.url, CACHE_DIR, spaceship., dmg_file) result ? CACHE_DIR + dmg_file : nil end |
#exist?(version) ⇒ Boolean
55 56 57 |
# File 'lib/xcode/install.rb', line 55 def exist?(version) list_versions.include?(version) end |
#install_components(xcode_path) ⇒ Object
59 60 61 |
# File 'lib/xcode/install.rb', line 59 def install_components(xcode_path) `#{xcode_path}/Contents/MacOS/Xcode -installComponents` end |
#install_dmg(dmgPath, suffix = '', switch = true, clean = true) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/xcode/install.rb', line 73 def install_dmg(dmgPath, suffix = '', switch = true, clean = true) xcode_path = "/Applications/Xcode#{suffix}.app" `hdiutil mount -nobrowse -noverify #{dmgPath}` puts 'Please authenticate for Xcode installation...' source = Dir.glob('/Volumes/Xcode/Xcode*.app').first if source.nil? $stderr.puts <<-HELP No `Xcode.app` found in DMG. Please remove #{dmgPath} if you suspect a corrupted download or run `xcode-install update` to see if the version you tried to install has been pulled by Apple. If none of this is true, please open a new GH issue. HELP return end `sudo ditto "#{source}" "#{xcode_path}"` `umount "/Volumes/Xcode"` enable_developer_mode `sudo xcodebuild -license` unless xcode_license_approved? install_components(xcode_path) if switch `sudo rm -f #{SYMLINK_PATH}` unless current_symlink.nil? `sudo ln -sf #{xcode_path} #{SYMLINK_PATH}` unless SYMLINK_PATH.exist? `sudo xcode-select --switch #{xcode_path}` puts `xcodebuild -version` end FileUtils.rm_f(dmgPath) if clean end |
#install_version(version, switch = true, clean = true, install = true) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/xcode/install.rb', line 107 def install_version(version, switch = true, clean = true, install = true) return if version.nil? dmg_path = get_dmg(version) fail Informative, "Failed to download Xcode #{version}." if dmg_path.nil? install_dmg(dmg_path, "-#{version.split(' ')[0]}", switch, clean) if install end |
#installed?(version) ⇒ Boolean
63 64 65 |
# File 'lib/xcode/install.rb', line 63 def installed?(version) installed_versions.map(&:version).include?(version) end |
#installed_versions ⇒ Object
67 68 69 70 71 |
# File 'lib/xcode/install.rb', line 67 def installed_versions @installed ||= installed.map { |x| InstalledXcode.new(x) }.sort do |a, b| Gem::Version.new(a.version) <=> Gem::Version.new(b.version) end end |
#list ⇒ Object
121 122 123 |
# File 'lib/xcode/install.rb', line 121 def list list_versions.join("\n") end |
#list_current ⇒ Object
115 116 117 118 119 |
# File 'lib/xcode/install.rb', line 115 def list_current stable_majors = list_versions.reject { |v| /beta/i =~ v }.map { |v| v.split('.')[0] }.map { |v| v.split(' ')[0] } latest_stable_major = stable_majors.select { |v| v.length == 1 }.uniq.sort.last.to_i list_versions.select { |v| v.split('.')[0].to_i >= latest_stable_major }.sort.join("\n") end |
#rm_list_cache ⇒ Object
125 126 127 |
# File 'lib/xcode/install.rb', line 125 def rm_list_cache FileUtils.rm_f(LIST_FILE) end |
#symlink(version) ⇒ Object
129 130 131 132 133 |
# File 'lib/xcode/install.rb', line 129 def symlink(version) xcode = installed_versions.find { |x| x.version == version } `sudo rm -f #{SYMLINK_PATH}` unless current_symlink.nil? `sudo ln -sf #{xcode.path} #{SYMLINK_PATH}` unless xcode.nil? || SYMLINK_PATH.exist? end |
#symlinks_to ⇒ Object
135 136 137 |
# File 'lib/xcode/install.rb', line 135 def symlinks_to File.absolute_path(File.readlink(current_symlink), SYMLINK_PATH.dirname) if current_symlink end |