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, progress, url = nil) ⇒ Object
- #exist?(version) ⇒ Boolean
-
#initialize ⇒ Installer
constructor
A new instance of Installer.
- #install_dmg(dmgPath, suffix = '', switch = true, clean = true) ⇒ Object
- #install_version(version, switch = true, clean = true, install = true, progress = true, url = nil) ⇒ Object
- #installed?(version) ⇒ Boolean
- #installed_versions ⇒ Object
- #list ⇒ Object
- #list_current ⇒ Object
- #open_release_notes_url(version) ⇒ Object
- #rm_list_cache ⇒ Object
- #symlink(version) ⇒ Object
- #symlinks_to ⇒ Object
Constructor Details
#initialize ⇒ Installer
Returns a new instance of Installer.
35 36 37 |
# File 'lib/xcode/install.rb', line 35 def initialize FileUtils.mkdir_p(CACHE_DIR) end |
Instance Attribute Details
#xcodes ⇒ Object (readonly)
Returns the value of attribute xcodes.
33 34 35 |
# File 'lib/xcode/install.rb', line 33 def xcodes @xcodes end |
Instance Method Details
#cache_dir ⇒ Object
39 40 41 |
# File 'lib/xcode/install.rb', line 39 def cache_dir CACHE_DIR end |
#current_symlink ⇒ Object
43 44 45 |
# File 'lib/xcode/install.rb', line 43 def current_symlink File.symlink?(SYMLINK_PATH) ? SYMLINK_PATH : nil end |
#download(version, progress, url = nil) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/xcode/install.rb', line 47 def download(version, progress, url = nil) return unless exist?(version) || url xcode = seedlist.find { |x| x.name == version } dmg_file = Pathname.new(File.basename(url || xcode.path)) result = Curl.new.fetch(url || xcode.url, CACHE_DIR, spaceship., dmg_file, progress) result ? CACHE_DIR + dmg_file : nil end |
#exist?(version) ⇒ Boolean
56 57 58 |
# File 'lib/xcode/install.rb', line 56 def exist?(version) list_versions.include?(version) end |
#install_dmg(dmgPath, suffix = '', switch = true, clean = true) ⇒ Object
70 71 72 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 106 107 |
# File 'lib/xcode/install.rb', line 70 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? out <<-HELP No `Xcode.app` found in DMG. Please remove #{dmgPath} if you suspect a corrupted download or run `xcversion 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 $stderr.puts out.gsub("\n", ' ') return end `sudo ditto "#{source}" "#{xcode_path}"` `umount "/Volumes/Xcode"` if not verify_integrity(xcode_path) `sudo rm -f #{xcode_path}` return end enable_developer_mode InstalledXcode.new(xcode_path).approve_license 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, progress = true, url = nil) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/xcode/install.rb', line 109 def install_version(version, switch = true, clean = true, install = true, progress = true, url = nil) dmg_path = get_dmg(version, progress, url) fail Informative, "Failed to download Xcode #{version}." if dmg_path.nil? install_dmg(dmg_path, "-#{version.split(' ')[0]}", switch, clean) if install open_release_notes_url(version) end |
#installed?(version) ⇒ Boolean
60 61 62 |
# File 'lib/xcode/install.rb', line 60 def installed?(version) installed_versions.map(&:version).include?(version) end |
#installed_versions ⇒ Object
64 65 66 67 68 |
# File 'lib/xcode/install.rb', line 64 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
130 131 132 |
# File 'lib/xcode/install.rb', line 130 def list list_versions.join("\n") end |
#list_current ⇒ Object
124 125 126 127 128 |
# File 'lib/xcode/install.rb', line 124 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 |
#open_release_notes_url(version) ⇒ Object
118 119 120 121 122 |
# File 'lib/xcode/install.rb', line 118 def open_release_notes_url(version) return if version.nil? xcode = seedlist.find { |x| x.name == version } `open #{xcode.release_notes_url}` unless xcode.nil? || xcode.release_notes_url.nil? end |
#rm_list_cache ⇒ Object
134 135 136 |
# File 'lib/xcode/install.rb', line 134 def rm_list_cache FileUtils.rm_f(LIST_FILE) end |
#symlink(version) ⇒ Object
138 139 140 141 142 |
# File 'lib/xcode/install.rb', line 138 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
144 145 146 |
# File 'lib/xcode/install.rb', line 144 def symlinks_to File.absolute_path(File.readlink(current_symlink), SYMLINK_PATH.dirname) if current_symlink end |