lib/xcode/install.rb in xcode-install-0.3.3 vs lib/xcode/install.rb in xcode-install-0.9.0

- old
+ new

@@ -1,9 +1,8 @@ require 'fileutils' require 'pathname' require 'spaceship' -require 'nokogiri' require 'rubygems/version' require 'xcode/install/command' require 'xcode/install/version' module XcodeInstall @@ -55,10 +54,14 @@ def exist?(version) list_versions.include?(version) end + def install_components(xcode_path) + `#{xcode_path}/Contents/MacOS/Xcode -installComponents` + end + def installed?(version) installed_versions.map(&:version).include?(version) end def installed_versions @@ -73,19 +76,24 @@ `hdiutil mount -nobrowse -noverify #{dmgPath}` puts 'Please authenticate for Xcode installation...' source = Dir.glob('/Volumes/Xcode/Xcode*.app').first if source.nil? - puts 'No `Xcode.app` found in DMG.' + $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? @@ -130,11 +138,20 @@ private def spaceship @spaceship ||= begin - Spaceship.login(ENV["XCODE_INSTALL_USER"], ENV["XCODE_INSTALL_PASSWORD"]) + begin + Spaceship.login(ENV["XCODE_INSTALL_USER"], ENV["XCODE_INSTALL_PASSWORD"]) + rescue Spaceship::Client::InvalidUserCredentialsError + $stderr.puts <<-HELP +Please provide your Apple developer account credentials via the +XCODE_INSTALL_USER and XCODE_INSTALL_PASSWORD environment variables. +HELP + exit(1) + end + if ENV.key?("XCODE_INSTALL_TEAM_ID") Spaceship.client.team_id = ENV["XCODE_INSTALL_TEAM_ID"] end Spaceship.client end @@ -179,10 +196,15 @@ xcodes end def installed + unless (`mdutil -s /` =~ /disabled/).nil? + $stderr.puts 'Please enable Spotlight indexing for /Applications.' + exit(1) + end + `mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null`.split("\n") end def parse_seedlist(seedlist) seeds = seedlist['downloads'].select do |t| @@ -200,13 +222,13 @@ installed = installed_versions.map(&:version) seedlist.map(&:name).reject { |x| installed.include?(x) } end def prereleases - page = Nokogiri::HTML.parse(spaceship.send(:request, :get, '/xcode/downloads/').body) - links = page.xpath('//a').select { |link| link['href'].end_with?('.dmg') } + body=spaceship.send(:request, :get, '/xcode/downloads/').body + links=body.scan(/<a.+?href="(.+?.dmg)".*>(.*)<\/a>/) - links.map { |pre| Xcode.new_prelease(pre.text.strip.gsub(/.*Xcode /, ''), pre['href']) } + links.map { |pre| Xcode.new_prelease(pre[1].strip.gsub(/.*Xcode /, ''), pre[0]) } end def seedlist @xcodes = Marshal.load(File.read(LIST_FILE)) if LIST_FILE.exist? && xcodes.nil? xcodes || fetch_seedlist