Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode 8 support #142

Merged
merged 4 commits into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

# Offense count: 11
Metrics/AbcSize:
Max: 36
Max: 39

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 212
Max: 226

# Offense count: 3
Metrics/CyclomaticComplexity:
Expand All @@ -22,7 +22,7 @@ Metrics/CyclomaticComplexity:
# Offense count: 10
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 30
Max: 40

# Offense count: 1
# Configuration parameters: CountKeywordArgs.
Expand All @@ -31,4 +31,4 @@ Metrics/ParameterLists:

# Offense count: 2
Metrics/PerceivedComplexity:
Max: 8
Max: 9
65 changes: 45 additions & 20 deletions lib/xcode/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,31 @@ def installed_versions
end

def install_dmg(dmg_path, suffix = '', switch = true, clean = true)
prompt = "Please authenticate for Xcode installation.\nPassword: "
xcode_path = "/Applications/Xcode#{suffix}.app"

mount_dir = mount(dmg_path)
source = Dir.glob(File.join(mount_dir, 'Xcode*.app')).first

if source.nil?
out = <<-HELP
if dmg_path.extname == '.xip'
`xar -x -f #{dmg_path} --exclude 'Metadata'`
`sudo -p "#{prompt}" ditto -x Content /Applications`
`sudo -p "#{prompt}" mv /Applications/Xcode-beta.app "#{xcode_path}"`
FileUtils.rm_f('Content')
else
mount_dir = mount(dmg_path)
source = Dir.glob(File.join(mount_dir, 'Xcode*.app')).first

if source.nil?
out = <<-HELP
No `Xcode.app` found in DMG. Please remove #{dmg_path} 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.tr("\n", ' ')
return
end
$stderr.puts out.tr("\n", ' ')
return
end

prompt = "Please authenticate for Xcode installation.\nPassword: "
`sudo -p "#{prompt}" ditto "#{source}" "#{xcode_path}"`
`umount "/Volumes/Xcode"`
`sudo -p "#{prompt}" ditto "#{source}" "#{xcode_path}"`
`umount "/Volumes/Xcode"`
end

unless verify_integrity(xcode_path)
`sudo rm -f #{xcode_path}`
Expand Down Expand Up @@ -258,7 +265,8 @@ def list_versions
end

def prereleases
body = spaceship.send(:request, :get, '/xcode/download/').body
body = spaceship.send(:request, :get, '/download/').body

links = body.scan(%r{<a.+?href="(.+?.dmg)".*>(.*)</a>})
links = links.map do |link|
parent = link[0].scan(%r{path=(/.*/.*/)}).first.first
Expand All @@ -269,7 +277,16 @@ def prereleases
link + [nil]
end
end
links.map { |pre| Xcode.new_prerelease(pre[1].strip.gsub(/.*Xcode /, ''), pre[0], pre[2]) }
links = links.map { |pre| Xcode.new_prerelease(pre[1].strip.gsub(/.*Xcode /, ''), pre[0], pre[2]) }

if links.count == 0
version = body.scan(/Xcode.* beta/).last.sub(/<.*?>/, '').gsub(/.*Xcode /, '')
link = body.scan(%r{<button .*"(.+?.xip)".*</button>}).first.first
notes = body.scan(%r{<a.+?href="(/go/\?id=xcode-.+?)".*>(.*)</a>}).first.first
links << Xcode.new(version, link, notes)
end

links
end

def seedlist
Expand Down Expand Up @@ -472,13 +489,21 @@ class Xcode
attr_reader :version
attr_reader :release_notes_url

def initialize(json)
@date_modified = json['dateModified'].to_i
@name = json['name'].gsub(/^Xcode /, '')
@path = json['files'].first['remotePath']
url_prefix = 'https://developer.apple.com/devcenter/download.action?path='
@url = "#{url_prefix}#{@path}"
@release_notes_url = "#{url_prefix}#{json['release_notes_path']}" if json['release_notes_path']
def initialize(json, url = nil, release_notes_url = nil)
if url.nil?
@date_modified = json['dateModified'].to_i
@name = json['name'].gsub(/^Xcode /, '')
@path = json['files'].first['remotePath']
url_prefix = 'https://developer.apple.com/devcenter/download.action?path='
@url = "#{url_prefix}#{@path}"
@release_notes_url = "#{url_prefix}#{json['release_notes_path']}" if json['release_notes_path']
else
@name = json
@path = url.split('/').last
url_prefix = 'https://developer.apple.com/'
@url = "#{url_prefix}#{url}"
@release_notes_url = "#{url_prefix}#{release_notes_url}"
end

begin
@version = Gem::Version.new(@name.split(' ')[0])
Expand Down