@@ -290,7 +290,15 @@ public final class XcodeInstaller {
290
290
291
291
private func downloadXcode( version: Version , dataSource: DataSource , downloader: Downloader , willInstall: Bool ) -> Promise < ( Xcode , URL ) > {
292
292
return firstly { ( ) -> Promise < Version > in
293
- loginIfNeeded ( ) . map { version }
293
+ if dataSource == . apple {
294
+ return loginIfNeeded ( ) . map { version }
295
+ } else {
296
+ guard let xcode = self . xcodeList. availableXcodes. first ( withVersion: version) else {
297
+ throw Error . unavailableVersion ( version)
298
+ }
299
+
300
+ return validateADCSession ( path: xcode. downloadPath) . map { version }
301
+ }
294
302
}
295
303
. then { version -> Promise < Version > in
296
304
if self . xcodeList. shouldUpdate {
@@ -300,14 +308,6 @@ public final class XcodeInstaller {
300
308
return Promise . value ( version)
301
309
}
302
310
}
303
- . then { version -> Promise < Version > in
304
- // This request would've already been made if the Apple data source were being used.
305
- // That's not the case for the Xcode Releases data source.
306
- // We need the cookies from its response in order to download Xcodes though,
307
- // so perform it here first just to be sure.
308
- Current . network. dataTask ( with: URLRequest . downloads)
309
- . map { _ in version }
310
- }
311
311
. then { version -> Promise < ( Xcode , URL ) > in
312
312
guard let xcode = self . xcodeList. availableXcodes. first ( withVersion: version) else {
313
313
throw Error . unavailableVersion ( version)
@@ -337,7 +337,11 @@ public final class XcodeInstaller {
337
337
. map { return ( xcode, $0) }
338
338
}
339
339
}
340
-
340
+
341
+ func validateADCSession( path: String ) -> Promise < Void > {
342
+ return Current . network. dataTask ( with: URLRequest . downloadADCAuth ( path: path) ) . asVoid ( )
343
+ }
344
+
341
345
func loginIfNeeded( withUsername providedUsername: String ? = nil , shouldPromptForPassword: Bool = false ) -> Promise < Void > {
342
346
return firstly { ( ) -> Promise < Void > in
343
347
return Current . network. validateSession ( )
@@ -645,11 +649,15 @@ public final class XcodeInstaller {
645
649
}
646
650
647
651
func update( dataSource: DataSource ) -> Promise < [ Xcode ] > {
648
- return firstly { ( ) -> Promise < Void > in
649
- loginIfNeeded ( )
650
- }
651
- . then { ( ) -> Promise < [ Xcode ] > in
652
- self . xcodeList. update ( dataSource: dataSource)
652
+ if dataSource == . apple {
653
+ return firstly { ( ) -> Promise < Void > in
654
+ loginIfNeeded ( )
655
+ }
656
+ . then { ( ) -> Promise < [ Xcode ] > in
657
+ self . xcodeList. update ( dataSource: dataSource)
658
+ }
659
+ } else {
660
+ return self . xcodeList. update ( dataSource: dataSource)
653
661
}
654
662
}
655
663
0 commit comments