lib/xcode/install.rb in xcode-install-0.2.0 vs lib/xcode/install.rb in xcode-install-0.3.0

- old
+ new

@@ -16,15 +16,15 @@ cookie_string end def download_seedlist - # categories: Applications%2CDeveloper%20Tools%2CiOS%2COS%20X%2COS%20X%20Server%2CSafari JSON.parse(page.evaluate_script("$.ajax({data: { start: \"0\", limit: \"1000\", " + "sort: \"dateModified\", dir: \"DESC\", searchTextField: \"\", " + - "searchCategories: \"\", search: \"false\" } , type: 'POST', " + - "url: '/downloads/seedlist.action', async: false})")['responseText']) + "searchCategories: \"\", search: \"false\" } , type: 'GET', " + + "url: '/services-account/QH65B2/downloadws/listDownloads.action', " + + "async: false})")['responseText']) end end module Helper def self.is_test? @@ -121,10 +121,18 @@ end FileUtils.rm_f(dmgPath) if clean end + def install_version(version, switch = true, clean = true) + return if version.nil? + dmg_path = get_dmg(version) + raise Informative, "Failed to download Xcode #{version}." if dmg_path.nil? + + install_dmg(dmg_path, "-#{version.split(' ')[0]}", switch, clean) + end + def list_current majors = list_versions.map { |v| v.split('.')[0] }.select { |v| v.length == 1 }.uniq list_versions.select { |v| v.start_with?(majors.last) }.join("\n") end @@ -144,11 +152,11 @@ def symlinks_to File.absolute_path(File.readlink(current_symlink), SYMLINK_PATH.dirname) if current_symlink end - :private + private 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') @@ -160,10 +168,21 @@ def enable_developer_mode `sudo /usr/sbin/DevToolsSecurity -enable` `sudo /usr/sbin/dseditgroup -o edit -t group -a staff _developer` end + def get_dmg(version) + if ENV.key?("XCODE_INSTALL_CACHE_DIR") + cache_path = Pathname.new(ENV["XCODE_INSTALL_CACHE_DIR"]) + Pathname.new("xcode-#{version}.dmg") + if cache_path.exist? + return cache_path + end + end + + return download(version) + end + def get_seedlist @xcodes = parse_seedlist(devcenter.download_seedlist) names = @xcodes.map(&:name) @xcodes += prereleases.reject { |pre| names.include?(pre.name) } @@ -178,10 +197,10 @@ def installed `mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null`.split("\n") end def parse_seedlist(seedlist) - seedlist['data'].select { + seedlist['downloads'].select { |t| /^Xcode [0-9]/.match(t['name']) }.map { |x| Xcode.new(x) }.reject { |x| x.version < MINIMUM_VERSION }.sort { |a,b| a.dateModified <=> b.dateModified }.select { |x| x.url.end_with?('.dmg') } end