@@ -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) :
@@ -93,6 +104,10 @@ public struct PackageCollections: PackageCollectionsProtocol {
93
104
}
94
105
95
106
public func refreshCollections( callback: @escaping ( Result < [ PackageCollectionsModel . CollectionSource ] , Error > ) -> Void ) {
107
+ guard Self . isSupportedPlatform else {
108
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
109
+ }
110
+
96
111
self . storage. sources. list { result in
97
112
switch result {
98
113
case . failure( let error) :
@@ -115,17 +130,23 @@ public struct PackageCollections: PackageCollectionsProtocol {
115
130
}
116
131
}
117
132
118
- public func refreshCollection(
119
- _ source: PackageCollectionsModel . CollectionSource ,
120
- callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void
121
- ) {
133
+ public func refreshCollection( _ source: PackageCollectionsModel . CollectionSource ,
134
+ callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void ) {
135
+ guard Self . isSupportedPlatform else {
136
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
137
+ }
138
+
122
139
self . refreshCollectionFromSource ( source: source, trustConfirmationProvider: nil , callback: callback)
123
140
}
124
141
125
142
public func addCollection( _ source: PackageCollectionsModel . CollectionSource ,
126
143
order: Int ? = nil ,
127
144
trustConfirmationProvider: ( ( PackageCollectionsModel . Collection , @escaping ( Bool ) -> Void ) -> Void ) ? = nil ,
128
145
callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void ) {
146
+ guard Self . isSupportedPlatform else {
147
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
148
+ }
149
+
129
150
if let errors = source. validate ( ) ? . errors ( ) {
130
151
return callback ( . failure( MultipleErrors ( errors) ) )
131
152
}
@@ -160,6 +181,10 @@ public struct PackageCollections: PackageCollectionsProtocol {
160
181
161
182
public func removeCollection( _ source: PackageCollectionsModel . CollectionSource ,
162
183
callback: @escaping ( Result < Void , Error > ) -> Void ) {
184
+ guard Self . isSupportedPlatform else {
185
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
186
+ }
187
+
163
188
self . storage. sources. remove ( source: source) { result in
164
189
switch result {
165
190
case . failure( let error) :
@@ -173,11 +198,19 @@ public struct PackageCollections: PackageCollectionsProtocol {
173
198
public func moveCollection( _ source: PackageCollectionsModel . CollectionSource ,
174
199
to order: Int ,
175
200
callback: @escaping ( Result < Void , Error > ) -> Void ) {
201
+ guard Self . isSupportedPlatform else {
202
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
203
+ }
204
+
176
205
self . storage. sources. move ( source: source, to: order, callback: callback)
177
206
}
178
207
179
208
public func updateCollection( _ source: PackageCollectionsModel . CollectionSource ,
180
209
callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void ) {
210
+ guard Self . isSupportedPlatform else {
211
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
212
+ }
213
+
181
214
self . storage. sources. update ( source: source) { result in
182
215
switch result {
183
216
case . failure( let error) :
@@ -193,6 +226,10 @@ public struct PackageCollections: PackageCollectionsProtocol {
193
226
// If not found locally (storage), the collection will be fetched from the source.
194
227
public func getCollection( _ source: PackageCollectionsModel . CollectionSource ,
195
228
callback: @escaping ( Result < PackageCollectionsModel . Collection , Error > ) -> Void ) {
229
+ guard Self . isSupportedPlatform else {
230
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
231
+ }
232
+
196
233
if let errors = source. validate ( ) ? . errors ( ) {
197
234
return callback ( . failure( MultipleErrors ( errors) ) )
198
235
}
@@ -212,11 +249,13 @@ public struct PackageCollections: PackageCollectionsProtocol {
212
249
213
250
// MARK: - Packages
214
251
215
- public func findPackages(
216
- _ query: String ,
217
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
218
- callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void
219
- ) {
252
+ public func findPackages( _ query: String ,
253
+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
254
+ callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult , Error > ) -> Void ) {
255
+ guard Self . isSupportedPlatform else {
256
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
257
+ }
258
+
220
259
self . storage. sources. list { result in
221
260
switch result {
222
261
case . failure( let error) :
@@ -235,6 +274,10 @@ public struct PackageCollections: PackageCollectionsProtocol {
235
274
236
275
public func getPackageMetadata( _ reference: PackageReference ,
237
276
callback: @escaping ( Result < PackageCollectionsModel . PackageMetadata , Error > ) -> Void ) {
277
+ guard Self . isSupportedPlatform else {
278
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
279
+ }
280
+
238
281
// first find in storage
239
282
self . findPackage ( identifier: reference. identity) { result in
240
283
switch result {
@@ -266,10 +309,12 @@ public struct PackageCollections: PackageCollectionsProtocol {
266
309
267
310
// MARK: - Targets
268
311
269
- public func listTargets(
270
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
271
- callback: @escaping ( Result < PackageCollectionsModel . TargetListResult , Error > ) -> Void
272
- ) {
312
+ public func listTargets( collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
313
+ callback: @escaping ( Result < PackageCollectionsModel . TargetListResult , Error > ) -> Void ) {
314
+ guard Self . isSupportedPlatform else {
315
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
316
+ }
317
+
273
318
self . listCollections ( identifiers: collections) { result in
274
319
switch result {
275
320
case . failure( let error) :
@@ -281,12 +326,14 @@ public struct PackageCollections: PackageCollectionsProtocol {
281
326
}
282
327
}
283
328
284
- public func findTargets(
285
- _ query: String ,
286
- searchType: PackageCollectionsModel . TargetSearchType ? = nil ,
287
- collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
288
- callback: @escaping ( Result < PackageCollectionsModel . TargetSearchResult , Error > ) -> Void
289
- ) {
329
+ public func findTargets( _ query: String ,
330
+ searchType: PackageCollectionsModel . TargetSearchType ? = nil ,
331
+ collections: Set < PackageCollectionsModel . CollectionIdentifier > ? = nil ,
332
+ callback: @escaping ( Result < PackageCollectionsModel . TargetSearchResult , Error > ) -> Void ) {
333
+ guard Self . isSupportedPlatform else {
334
+ return callback ( . failure( PackageCollectionError . unsupportedPlatform) )
335
+ }
336
+
290
337
let searchType = searchType ?? . exactMatch
291
338
292
339
self . storage. sources. list { result in
@@ -371,10 +418,8 @@ public struct PackageCollections: PackageCollectionsProtocol {
371
418
}
372
419
}
373
420
374
- func findPackage(
375
- identifier: PackageIdentity ,
376
- callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult . Item , Error > ) -> Void
377
- ) {
421
+ func findPackage( identifier: PackageIdentity ,
422
+ callback: @escaping ( Result < PackageCollectionsModel . PackageSearchResult . Item , Error > ) -> Void ) {
378
423
self . storage. sources. list { result in
379
424
switch result {
380
425
case . failure( let error) :
0 commit comments