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

- old
+ new

@@ -1,52 +1,13 @@ -require 'fastlane_core' -require 'fastlane_core/developer_center/developer_center' +require 'fileutils' +require 'pathname' +require 'spaceship' require 'nokogiri' require 'rubygems/version' require 'xcode/install/command' require 'xcode/install/version' -module CredentialsManager - class PasswordManager - alias_method :old_ask_for_login, :ask_for_login - - def ask_for_login - puts "\nXcodeInstall needs your developer AppleID credentials to access the DevCenter." - - old_ask_for_login - end - end -end - -module FastlaneCore - class DeveloperCenter - def cookies - cookie_string = '' - - page.driver.cookies.each do |_key, cookie| - cookie_string << "#{cookie.name}=#{cookie.value};" - end - - cookie_string - end - - def download_seedlist - JSON.parse(page.evaluate_script("$.ajax({data: { start: \"0\", limit: \"1000\", " \ - "sort: \"dateModified\", dir: \"DESC\", searchTextField: \"\", " \ - "searchCategories: \"\", search: \"false\" } , type: 'GET', " \ - "url: '/services-account/QH65B2/downloadws/listDownloads.action', " \ - 'async: false})')['responseText']) - end - end - - module Helper - def self.is_test? - true - end - end -end - module XcodeInstall class Curl COOKIES_PATH = Pathname.new('/tmp/curl-cookies.txt') def fetch(url, directory = nil, cookies = nil, output = nil) @@ -86,11 +47,11 @@ 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, devcenter.cookies, dmg_file) + result = Curl.new.fetch(xcode.url, CACHE_DIR, spaceship.cookie, dmg_file) result ? CACHE_DIR + dmg_file : nil end def exist?(version) list_versions.include?(version) @@ -133,16 +94,16 @@ end FileUtils.rm_f(dmgPath) if clean end - def install_version(version, switch = true, clean = true) + 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) + install_dmg(dmg_path, "-#{version.split(' ')[0]}", switch, clean) if install end 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 @@ -167,19 +128,25 @@ File.absolute_path(File.readlink(current_symlink), SYMLINK_PATH.dirname) if current_symlink end private + def spaceship + @spaceship ||= begin + Spaceship.login(ENV["XCODE_INSTALL_USER"], ENV["XCODE_INSTALL_PASSWORD"]) + if ENV.key?("XCODE_INSTALL_TEAM_ID") + Spaceship.client.team_id = ENV["XCODE_INSTALL_TEAM_ID"] + end + Spaceship.client + end + end + CACHE_DIR = Pathname.new("#{ENV['HOME']}/Library/Caches/XcodeInstall") LIST_FILE = CACHE_DIR + Pathname.new('xcodes.bin') MINIMUM_VERSION = Gem::Version.new('4.3') SYMLINK_PATH = Pathname.new('/Applications/Xcode.app') - def devcenter - @devcenter ||= FastlaneCore::DeveloperCenter.new - end - def enable_developer_mode `sudo /usr/sbin/DevToolsSecurity -enable` `sudo /usr/sbin/dseditgroup -o edit -t group -a staff _developer` end @@ -191,11 +158,19 @@ download(version) end def fetch_seedlist - @xcodes = parse_seedlist(devcenter.download_seedlist) + @xcodes = parse_seedlist(spaceship.send(:request, :get, '/services-account/QH65B2/downloadws/listDownloads.action', { + start: "0", + limit: "1000", + sort: "dateModified", + dir: "DESC", + searchTextField: "", + searchCategories: "", + search: "false", + }).body) names = @xcodes.map(&:name) @xcodes += prereleases.reject { |pre| names.include?(pre.name) } File.open(LIST_FILE, 'w') do |f| @@ -225,10 +200,10 @@ installed = installed_versions.map(&:version) seedlist.map(&:name).reject { |x| installed.include?(x) } end def prereleases - page = Nokogiri::HTML.parse(devcenter.download_file('/xcode/downloads/')) + page = Nokogiri::HTML.parse(spaceship.send(:request, :get, '/xcode/downloads/').body) links = page.xpath('//a').select { |link| link['href'].end_with?('.dmg') } links.map { |pre| Xcode.new_prelease(pre.text.strip.gsub(/.*Xcode /, ''), pre['href']) } end