@@ -287,7 +287,15 @@ public final class XcodeInstaller {
287
287
288
288
private func downloadXcode( version: Version , dataSource: DataSource , downloader: Downloader , willInstall: Bool ) -> Promise < ( Xcode , URL ) > {
289
289
return firstly { ( ) -> Promise < Version > in
290
- loginIfNeeded ( ) . map { version }
290
+ if dataSource == . apple {
291
+ return loginIfNeeded ( ) . map { version }
292
+ } else {
293
+ guard let xcode = self . xcodeList. availableXcodes. first ( withVersion: version) else {
294
+ throw Error . unavailableVersion ( version)
295
+ }
296
+
297
+ return validateADCSession ( path: xcode. downloadPath) . map { version }
298
+ }
291
299
}
292
300
. then { version -> Promise < Version > in
293
301
if self . xcodeList. shouldUpdate {
@@ -297,14 +305,6 @@ public final class XcodeInstaller {
297
305
return Promise . value ( version)
298
306
}
299
307
}
300
- . then { version -> Promise < Version > in
301
- // This request would've already been made if the Apple data source were being used.
302
- // That's not the case for the Xcode Releases data source.
303
- // We need the cookies from its response in order to download Xcodes though,
304
- // so perform it here first just to be sure.
305
- Current . network. dataTask ( with: URLRequest . downloads)
306
- . map { _ in version }
307
- }
308
308
. then { version -> Promise < ( Xcode , URL ) > in
309
309
guard let xcode = self . xcodeList. availableXcodes. first ( withVersion: version) else {
310
310
throw Error . unavailableVersion ( version)
@@ -334,7 +334,11 @@ public final class XcodeInstaller {
334
334
. map { return ( xcode, $0) }
335
335
}
336
336
}
337
-
337
+
338
+ func validateADCSession( path: String ) -> Promise < Void > {
339
+ return Current . network. dataTask ( with: URLRequest . downloadADCAuth ( path: path) ) . asVoid ( )
340
+ }
341
+
338
342
func loginIfNeeded( withUsername providedUsername: String ? = nil , shouldPromptForPassword: Bool = false ) -> Promise < Void > {
339
343
return firstly { ( ) -> Promise < Void > in
340
344
return Current . network. validateSession ( )
@@ -626,11 +630,15 @@ public final class XcodeInstaller {
626
630
}
627
631
628
632
func update( dataSource: DataSource ) -> Promise < [ Xcode ] > {
629
- return firstly { ( ) -> Promise < Void > in
630
- loginIfNeeded ( )
631
- }
632
- . then { ( ) -> Promise < [ Xcode ] > in
633
- self . xcodeList. update ( dataSource: dataSource)
633
+ if dataSource == . apple {
634
+ return firstly { ( ) -> Promise < Void > in
635
+ loginIfNeeded ( )
636
+ }
637
+ . then { ( ) -> Promise < [ Xcode ] > in
638
+ self . xcodeList. update ( dataSource: dataSource)
639
+ }
640
+ } else {
641
+ return self . xcodeList. update ( dataSource: dataSource)
634
642
}
635
643
}
636
644
0 commit comments