@@ -14,6 +14,13 @@ import TSCBasic
14
14
15
15
// TODO: is there a better name? this conflicts with the module name which is okay in this case but not ideal in Swift
16
16
public struct PackageCollections : PackageCollectionsProtocol {
17
+ // Check JSONPackageCollectionProvider.isSignatureCheckSupported before updating or removing this
18
+ #if os(macOS) || os(Linux) || os(Windows)
19
+ static let isSupportedPlatform = true
20
+ #else
21
+ static let isSupportedPlatform = false
22
+ #endif
23
+
17
24
private let configuration : Configuration
18
25
private let diagnosticsEngine : DiagnosticsEngine ?
19
26
private let storageContainer : ( storage: Storage , owned: Bool )
@@ -64,6 +71,10 @@ public struct PackageCollections: PackageCollectionsProtocol {
64
71
65
72
public func listCollections( identifiers: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
66
73
callback: @escaping ( Result < [ PackageCollectionsModel . Collection ] , Error > ) -> Void ) {
74
+ guard Self . isSupportedPlatform else {
75
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
76
+ }
77
+
67
78
self . storage. sources. list { result in
68
79
switch result {
69
80
case . failure( let error) :
@@ -115,6 +126,10 @@ public struct PackageCollections: PackageCollectionsProtocol {
115
126
}
116
127
117
128
public func refreshCollections( callback: @escaping ( Result < [ PackageCollectionsModel . CollectionSource ] , Error > ) -> Void ) {
129
+ guard Self . isSupportedPlatform else {
130
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
131
+ }
132
+
118
133
self . storage. sources. list { result in
119
134
switch result {
120
135
case . failure( let error) :
@@ -137,17 +152,23 @@ public struct PackageCollections: PackageCollectionsProtocol {
137
152
}
138
153
}
139
154
140
- public func refreshCollection(
141
- _ source: PackageCollectionsModel . CollectionSource ,
142
- callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
143
- ) {
155
+ public func refreshCollection( _ source: PackageCollectionsModel . CollectionSource ,
156
+ callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void ) {
157
+ guard Self . isSupportedPlatform else {
158
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
159
+ }
160
+
144
161
self . refreshCollectionFromSource ( source: source, trustConfirmationProvider: nil , callback: callback)
145
162
}
146
163
147
164
public func addCollection( _ source: PackageCollectionsModel . CollectionSource ,
148
165
order: Int ? = nil ,
149
166
trustConfirmationProvider: ( ( PackageCollectionsModel . Collection , @escaping ( Bool ) -> Void ) -> Void ) ? = nil ,
150
167
callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void ) {
168
+ guard Self . isSupportedPlatform else {
169
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
170
+ }
171
+
151
172
if let errors = source. validate ( ) ? . errors ( ) {
152
173
return callback ( . failure( MultipleErrors ( errors) ) )
153
174
}
@@ -182,6 +203,10 @@ public struct PackageCollections: PackageCollectionsProtocol {
182
203
183
204
public func removeCollection( _ source: PackageCollectionsModel . CollectionSource ,
184
205
callback: @escaping ( Result < Void , Error > ) -> Void ) {
206
+ guard Self . isSupportedPlatform else {
207
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
208
+ }
209
+
185
210
self . storage. sources. remove ( source: source) { result in
186
211
switch result {
187
212
case . failure( let error) :
@@ -195,11 +220,19 @@ public struct PackageCollections: PackageCollectionsProtocol {
195
220
public func moveCollection( _ source: PackageCollectionsModel . CollectionSource ,
196
221
to order: Int ,
197
222
callback: @escaping ( Result < Void , Error > ) -> Void ) {
223
+ guard Self . isSupportedPlatform else {
224
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
225
+ }
226
+
198
227
self . storage. sources. move ( source: source, to: order, callback: callback)
199
228
}
200
229
201
230
public func updateCollection( _ source: PackageCollectionsModel . CollectionSource ,
202
231
callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void ) {
232
+ guard Self . isSupportedPlatform else {
233
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
234
+ }
235
+
203
236
self . storage. sources. update ( source: source) { result in
204
237
switch result {
205
238
case . failure( let error) :
@@ -215,6 +248,10 @@ public struct PackageCollections: PackageCollectionsProtocol {
215
248
// If not found locally (storage), the collection will be fetched from the source.
216
249
public func getCollection( _ source: PackageCollectionsModel . CollectionSource ,
217
250
callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void ) {
251
+ guard Self . isSupportedPlatform else {
252
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
253
+ }
254
+
218
255
if let errors = source. validate ( ) ? . errors ( ) {
219
256
return callback ( . failure( MultipleErrors ( errors) ) )
220
257
}
@@ -234,11 +271,13 @@ public struct PackageCollections: PackageCollectionsProtocol {
234
271
235
272
// MARK: - Packages
236
273
237
- public func findPackages(
238
- _ query: String ,
239
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
240
- callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void
241
- ) {
274
+ public func findPackages( _ query: String ,
275
+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
276
+ callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void ) {
277
+ guard Self . isSupportedPlatform else {
278
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
279
+ }
280
+
242
281
self . storage. sources. list { result in
243
282
switch result {
244
283
case . failure( let error) :
@@ -257,6 +296,10 @@ public struct PackageCollections: PackageCollectionsProtocol {
257
296
258
297
public func getPackageMetadata( _ reference: PackageReference ,
259
298
callback: @escaping ( Result < PackageCollectionsModel . PackageMetadata , Error > ) -> Void ) {
299
+ guard Self . isSupportedPlatform else {
300
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
301
+ }
302
+
260
303
// first find in storage
261
304
self . findPackage ( identifier: reference. identity) { result in
262
305
switch result {
@@ -288,10 +331,12 @@ public struct PackageCollections: PackageCollectionsProtocol {
288
331
289
332
// MARK: - Targets
290
333
291
- public func listTargets(
292
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
293
- callback: @escaping ( Result < PackageCollectionsModel . TargetListResult , Error > ) -> Void
294
- ) {
334
+ public func listTargets( collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
335
+ callback: @escaping ( Result < PackageCollectionsModel . TargetListResult , Error > ) -> Void ) {
336
+ guard Self . isSupportedPlatform else {
337
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
338
+ }
339
+
295
340
self . listCollections ( identifiers: collections) { result in
296
341
switch result {
297
342
case . failure( let error) :
@@ -303,12 +348,14 @@ public struct PackageCollections: PackageCollectionsProtocol {
303
348
}
304
349
}
305
350
306
- public func findTargets(
307
- _ query: String ,
308
- searchType: PackageCollectionsModel . TargetSearchType ? = nil ,
309
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
310
- callback: @escaping ( Result < PackageCollectionsModel . TargetSearchResult , Error > ) -> Void
311
- ) {
351
+ public func findTargets( _ query: String ,
352
+ searchType: PackageCollectionsModel . TargetSearchType ? = nil ,
353
+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
354
+ callback: @escaping ( Result < PackageCollectionsModel . TargetSearchResult , Error > ) -> Void ) {
355
+ guard Self . isSupportedPlatform else {
356
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
357
+ }
358
+
312
359
let searchType = searchType ?? . exactMatch
313
360
314
361
self . storage. sources. list { result in
@@ -393,10 +440,8 @@ public struct PackageCollections: PackageCollectionsProtocol {
393
440
}
394
441
}
395
442
396
- func findPackage(
397
- identifier: PackageIdentity ,
398
- callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult . Item , Error > ) -> Void
399
- ) {
443
+ func findPackage( identifier: PackageIdentity ,
444
+ callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult . Item , Error > ) -> Void ) {
400
445
self . storage. sources. list { result in
401
446
switch result {
402
447
case . failure( let error) :
0 commit comments