Skip to content

Commit 8ac1ed3

Browse files
author
Josh Holtz
authored
Merge pull request #393 from pietbrauer/sort-by-most-recent
Sort Xcode version by most recent
2 parents 1a0623c + 62f9898 commit 8ac1ed3

File tree

7 files changed

+83
-57
lines changed

7 files changed

+83
-57
lines changed

lib/xcode/install.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def seedlist
214214
current_xcode.installed = cached_installed_versions.include?(current_xcode.version)
215215
end
216216

217-
all_xcodes.sort_by(&:version)
217+
all_xcodes.sort_by { |seed| [seed.version, -seed.date_modified] }.reverse
218218
end
219219

220220
def install_dmg(dmg_path, suffix = '', switch = true, clean = true)
@@ -712,7 +712,7 @@ def verify_app_cert
712712
#
713713
# Sample object:
714714
# <XcodeInstall::Xcode:0x007fa1d451c390
715-
# @date_modified=2015,
715+
# @date_modified=1573661580,
716716
# @name="6.4",
717717
# @path="/Developer_Tools/Xcode_6.4/Xcode_6.4.dmg",
718718
# @url=
@@ -735,7 +735,7 @@ class Xcode
735735

736736
def initialize(json, url = nil, release_notes_url = nil)
737737
if url.nil?
738-
@date_modified = json['dateModified'].to_i
738+
@date_modified = DateTime.strptime(json['dateModified'], '%m/%d/%y %H:%M').strftime('%s').to_i
739739
@name = json['name'].gsub(/^Xcode /, '')
740740
@path = json['files'].first['remotePath']
741741
url_prefix = 'https://developer.apple.com/devcenter/download.action?path='
@@ -767,6 +767,7 @@ def ==(other)
767767

768768
def self.new_prerelease(version, url, release_notes_path)
769769
new('name' => version,
770+
'dateModified' => '01/01/70 00:00',
770771
'files' => [{ 'remotePath' => url.split('=').last }],
771772
'release_notes_path' => release_notes_path)
772773
end

spec/fixtures/xcode.json

+30-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
{"active":true,"availableInMemberSite":true,"categories":[{"active":null,"dateCreated":1052825460000,"dateModified":1079108316000,"enabled":true,"id":187,"name":"Developer Tools","sortOrder":28}],"dateAvailable":null,"dateCreated":1413472373000,"dateDisabled":null,"dateModified":1413472373000,"description":"This package enables UNIX-style development via Terminal by installing command line developer tools, as well as Mac OS X SDK frameworks and headers. Many useful tools are included, such as the Apple LLVM compiler, linker, and Make. If you use Xcode, these tools are also embedded within the Xcode IDE.","files":[{"active":true,"dateCreated":1413472373000,"dateModified":1413472373000,"fileSize":107698152,"format":{"active":null,"dateCreated":1066327569000,"dateModified":null,"description":"Disk Image","extension":".dmg","id":12},"id":33285,"name":"Command Line Tools for OSX 10.9 for Xcode 6.1","remotePath":"/Developer_Tools/command_line_tools_os_x_10.9_for_xcode__xcode_6.1/command_line_tools_for_osx_10.9_for_xcode_6.1.dmg","sortOrder":1,"state":"ENABLED"}],"id":21958,"name":"Command Line Tools (OS X 10.9) for Xcode - Xcode 6.1","prerelease":false,"releasedSeed":true,"state":"ENABLED"}
1+
{
2+
"name": "Xcode 9.3",
3+
"description": "This is the complete Xcode developer toolset for Apple Watch, Apple TV, iPhone, iPad, and Mac. It includes the Xcode IDE, iOS Simulator, and all required tools and frameworks for building iOS, watchOS, tvOS and macOS apps.",
4+
"isReleased": 1,
5+
"datePublished": "03/23/18 09:47",
6+
"dateCreated": "11/01/19 12:00",
7+
"dateModified": "11/01/19 12:58",
8+
"categories": [
9+
{
10+
"id": 187,
11+
"name": "Developer Tools",
12+
"sortOrder": 28
13+
}
14+
],
15+
"files": [
16+
{
17+
"filename": "Xcode 9.3.xip",
18+
"displayName": "Xcode 9.3",
19+
"remotePath": "/Developer_Tools/Xcode_9.3/Xcode_9.3.xip",
20+
"fileSize": 5235094775,
21+
"sortOrder": 0,
22+
"dateCreated": "11/01/19 19:00",
23+
"dateModified": "11/01/19 19:58",
24+
"fileFormat": {
25+
"extension": ".xip",
26+
"description": "XIP"
27+
}
28+
}
29+
]
30+
}

spec/fixtures/xcode_63.json

+28-44
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,30 @@
11
{
2-
"active": true,
3-
"availableInMemberSite": true,
4-
"categories": [
5-
{
6-
"active": null,
7-
"dateCreated": 1052825460000,
8-
"dateModified": 1079108316000,
9-
"enabled": true,
10-
"id": 187,
11-
"name": "Developer Tools",
12-
"sortOrder": 28
13-
}
14-
],
15-
"dateAvailable": null,
16-
"dateCreated": 1425695047000,
17-
"dateDisabled": null,
18-
"dateModified": 1425943753000,
19-
"description": "This is the complete Xcode developer toolset for Mac, iPhone, and iPad. It includes the Xcode IDE, iOS Simulator, and all required tools and frameworks for building OS X and iOS apps.",
20-
"files": [
21-
{
22-
"active": true,
23-
"dateCreated": 1425696402000,
24-
"dateModified": 1425929405000,
25-
"fileSize": 2778059898,
26-
"format": {
27-
"active": null,
28-
"dateCreated": 1066327569000,
29-
"dateModified": null,
30-
"description": "Disk Image",
31-
"extension": ".dmg",
32-
"id": 12
33-
},
34-
"id": 35240,
35-
"name": "Xcode 6.3",
36-
"remotePath": "/Developer_Tools/Xcode_6.2/Xcode_6.2.dmg",
37-
"sortOrder": null,
38-
"state": "ENABLED"
39-
}
40-
],
41-
"id": 23600,
42-
"name": "Xcode 6.3",
43-
"prerelease": false,
44-
"releasedSeed": true,
45-
"state": "ENABLED"
2+
"name": "Xcode 6.3",
3+
"description": "This is the complete Xcode developer toolset for Apple Watch, iPhone, iPad, and Mac. It includes the Xcode IDE, iOS Simulator, and all required tools and frameworks for building OS X and iOS apps.",
4+
"isReleased": 1,
5+
"datePublished": "04/08/15 14:36",
6+
"dateCreated": "12/11/19 13:41",
7+
"dateModified": "12/11/19 14:28",
8+
"categories": [
9+
{
10+
"id": 187,
11+
"name": "Developer Tools",
12+
"sortOrder": 28
13+
}
14+
],
15+
"files": [
16+
{
17+
"filename": "Xcode 6.3.dmg",
18+
"displayName": "Xcode 6.3",
19+
"remotePath": "/Developer_Tools/Xcode_6.3/Xcode_6.3.dmg",
20+
"fileSize": 2685818165,
21+
"sortOrder": 0,
22+
"dateCreated": "12/11/19 21:41",
23+
"dateModified": "12/11/19 22:28",
24+
"fileFormat": {
25+
"extension": ".dmg",
26+
"description": "Disk Image"
27+
}
28+
}
29+
]
4630
}

spec/fixtures/yolo.json

+1-1
Large diffs are not rendered by default.

spec/installer_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ module XcodeInstall
108108

109109
xcodes = [
110110
XcodeInstall::Xcode.new('name' => '11.4 beta 2',
111+
'dateModified' => '12/11/19 14:28',
111112
'files' => [{
112113
'remotePath' => '/Developer_Tools/Xcode_11.4_beta_2/Xcode_11.4_beta_2.xip'
113114
}]),
114115
XcodeInstall::Xcode.new('name' => '11.4',
116+
'dateModified' => '12/15/19 11:28',
115117
'files' => [{
116118
'remotePath' => '/Developer_Tools/Xcode_11.4/Xcode_11.4.xip'
117119
}])

spec/json_spec.rb

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module XcodeInstall
66
fixture = Pathname.new('spec/fixtures/xcode.json').read
77
xcode = Xcode.new(JSON.parse(fixture))
88

9-
xcode.date_modified.should == 1_413_472_373_000
10-
xcode.name.should == 'Command Line Tools (OS X 10.9) for Xcode - Xcode 6.1'
11-
xcode.url.should == 'https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/command_line_tools_os_x_10.9_for_xcode__xcode_6.1/command_line_tools_for_osx_10.9_for_xcode_6.1.dmg'
9+
xcode.date_modified.should == 1_572_613_080
10+
xcode.name.should == '9.3'
11+
xcode.url.should == 'https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/Xcode_9.3/Xcode_9.3.xip'
1212
end
1313

1414
it 'can parse list of all Xcodes' do
@@ -19,7 +19,17 @@ module XcodeInstall
1919
installer.stubs(:installed_versions).returns([])
2020
installer.stubs(:xcodes).returns(seedlist)
2121

22-
installer.list.should == "6.1\n6.1.1\n6.2"
22+
versions = [
23+
'4.3 for Lion', '4.3.1 for Lion', '4.3.2 for Lion', '4.3.3 for Lion', '4.4.1', '4.5', '4.6.2', '4.6', '4.6.1', '4.6.3',
24+
'5.0.1', '5', '5.0.2', '5.1', '5.1.1',
25+
'6.0.1', '6.1', '6.1.1', '6.2', '6.3', '6.3.1', '6.3.2', '6.4',
26+
'7', '7.0.1', '7.1', '7.1.1', '7.2.1', '7.2', '7.3', '7.3.1',
27+
'8', '8.1', '8.2', '8.2.1', '8.3.2', '8.3.3', '8.3',
28+
'9', '9.0.1', '9.1', '9.2', '9.3', '9.3.1', '9.4', '9.4.1',
29+
'10', '10.1', '10.2.1', '10.2', '10.3',
30+
'11', '11.1', '11.2', '11.2.1', '11.3 beta', '11.3', '11.3.1', '11.4 beta', '11.4', '11.4 beta 3', '11.4 beta 2', '11.4.1', '11.5 beta 2', '11.5', '11.5 GM Seed', '11.5 beta'
31+
]
32+
installer.list.split("\n").should == versions
2333
end
2434

2535
it 'raises informative error when account is not registered as a developer' do

spec/list_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,27 @@ def fake_installed_xcodes(*names)
4343
it 'lists all versions' do
4444
fake_xcodes '1', '2.3', '2.3.1', '2.3.2', '3 some', '4 beta', '10 beta'
4545
fake_installed_xcodes
46-
installer.list.should == "1\n2.3\n2.3.1\n2.3.2\n3 some\n4 beta\n10 beta"
46+
installer.list.should == "1\n2.3.2\n2.3.1\n2.3\n3 some\n4 beta\n10 beta"
4747
end
4848
end
4949

5050
describe '#list_annotated' do
5151
it 'lists all versions with annotations' do
5252
fake_xcodes '1', '2.3', '2.3.1', '2.3.2', '3 some', '4.3.1 for Lion', '9.4.1', '10 beta'
5353
fake_installed_xcodes '2.3', '4.3.1 for Lion', '10 beta'
54-
installer.list.should == "1\n2.3 (installed)\n2.3.1\n2.3.2\n3 some\n4.3.1 for Lion (installed)\n9.4.1\n10 beta (installed)"
54+
installer.list.should == "1\n2.3.2\n2.3.1\n2.3 (installed)\n3 some\n4.3.1 for Lion (installed)\n9.4.1\n10 beta (installed)"
5555
end
5656

5757
it 'distinguish between beta and official_version' do
5858
fake_xcodes '11.4', '11.4 beta'
5959
fake_installed_xcodes '11.4'
60-
installer.list.should == "11.4 (installed)\n11.4 beta"
60+
installer.list.should == "11.4 beta\n11.4 (installed)"
6161
end
6262

6363
it 'distinguish each beta versions' do
6464
fake_xcodes '11.4 beta', '11.4 beta 3'
6565
fake_installed_xcodes '11.4 beta'
66-
installer.list.should == "11.4 beta (installed)\n11.4 beta 3"
66+
installer.list.should == "11.4 beta 3\n11.4 beta (installed)"
6767
end
6868
end
6969
end

0 commit comments

Comments
 (0)