Skip to content

Commit dc436c0

Browse files
authored
Add package identity support to package collection (#6166)
rdar://99717156
1 parent aabbe18 commit dc436c0

File tree

9 files changed

+152
-41
lines changed

9 files changed

+152
-41
lines changed

Fixtures/Collections/JSON/good.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"packages": [
1212
{
1313
"url": "https://www.example.com/repos/RepoOne.git",
14+
"identity": "repos.one",
1415
"summary": "Package One",
1516
"keywords": ["sample package"],
1617
"readmeURL": "https://www.example.com/repos/RepoOne/README",

Fixtures/Collections/JSON/good_signed.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"packages": [
1212
{
1313
"url": "https://www.example.com/repos/RepoOne.git",
14+
"identity": "repos.one",
1415
"summary": "Package One",
1516
"keywords": ["sample package"],
1617
"readmeURL": "https://www.example.com/repos/RepoOne/README",

Sources/PackageCollections/Providers/JSONPackageCollectionProvider.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -264,7 +264,8 @@ struct JSONPackageCollectionProvider: PackageCollectionProvider {
264264
serializationOkay = false
265265
}
266266

267-
return .init(identity: .init(url: package.url),
267+
// If package identity is set, use that. Otherwise create one from URL.
268+
return .init(identity: package.identity.map { PackageIdentity.plain($0) } ?? PackageIdentity(url: package.url),
268269
location: package.url.absoluteString,
269270
summary: package.summary,
270271
keywords: package.keywords,

Sources/PackageCollections/Storage/SQLitePackageCollectionsStorage.swift

Lines changed: 113 additions & 27 deletions
Large diffs are not rendered by default.

Sources/PackageCollectionsModel/Formats/v1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ To begin, define the top-level metadata about the collection:
2828
Each item in the `packages` array is a package object with the following properties:
2929

3030
* `url`: The URL of the package. Currently only Git repository URLs are supported. URL should be HTTPS and may contain `.git` suffix.
31+
* `identity`: The [identity](https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#36-package-identification) of the package if published to registry. **Optional.**
3132
* `summary`: A description of the package. **Optional.**
3233
* `keywords`: An array of keywords that the package is associated with. **Optional.**
3334
* `readmeURL`: The URL of the package's README. **Optional.**

Sources/PackageCollectionsModel/PackageCollectionModel+v1.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -81,6 +81,9 @@ extension PackageCollectionModel.V1.Collection {
8181
public struct Package: Equatable, Codable {
8282
/// The URL of the package. Currently only Git repository URLs are supported.
8383
public let url: URL
84+
85+
/// Package identity for registry (https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#36-package-identification).
86+
public let identity: String?
8487

8588
/// A description of the package.
8689
public let summary: String?
@@ -100,13 +103,15 @@ extension PackageCollectionModel.V1.Collection {
100103
/// Creates a `Package`
101104
public init(
102105
url: URL,
106+
identity: String? = nil,
103107
summary: String?,
104108
keywords: [String]?,
105109
versions: [PackageCollectionModel.V1.Collection.Package.Version],
106110
readmeURL: URL?,
107111
license: PackageCollectionModel.V1.License?
108112
) {
109113
self.url = url
114+
self.identity = identity
110115
self.summary = summary
111116
self.keywords = keywords
112117
self.versions = versions

Tests/PackageCollectionsModelTests/PackageCollectionModelTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -22,6 +22,7 @@ class PackageCollectionModelTests: XCTestCase {
2222
let packages = [
2323
Model.Collection.Package(
2424
url: URL(string: "https://package-collection-tests.com/repos/foobar.git")!,
25+
identity: "foo.bar",
2526
summary: "Package Foobar",
2627
keywords: ["test package"],
2728
versions: [
@@ -67,6 +68,7 @@ class PackageCollectionModelTests: XCTestCase {
6768
let packages = [
6869
Model.Collection.Package(
6970
url: URL(string: "https://package-collection-tests.com/repos/foobar.git")!,
71+
identity: "foo.bar",
7072
summary: "Package Foobar",
7173
keywords: ["test package"],
7274
versions: [

Tests/PackageCollectionsTests/JSONPackageCollectionProviderTests.swift

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -57,7 +57,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
5757
XCTAssertEqual(collection.packages.count, 2)
5858

5959
let package = collection.packages.first!
60-
XCTAssertEqual(package.identity, .init(urlString: "https://www.example.com/repos/RepoOne.git"))
60+
XCTAssertEqual(package.identity, PackageIdentity.plain("repos.one"))
6161
XCTAssertEqual(package.location, "https://www.example.com/repos/RepoOne.git")
6262
XCTAssertEqual(package.summary, "Package One")
6363
XCTAssertEqual(package.keywords, ["sample package"])
@@ -78,6 +78,8 @@ class JSONPackageCollectionProviderTests: XCTestCase {
7878
XCTAssertEqual(version.license, .init(type: .Apache2_0, url: URL(string: "https://www.example.com/repos/RepoOne/LICENSE")!))
7979
XCTAssertNotNil(version.createdAt)
8080
XCTAssertFalse(collection.isSigned)
81+
82+
XCTAssertEqual(collection.packages[1].identity, .init(urlString: "https://www.example.com/repos/RepoTwo.git"))
8183

8284
// "1.8.3" is originally "v1.8.3"
8385
XCTAssertEqual(["2.1.0", "1.8.3"], collection.packages[1].versions.map { $0.version.description })
@@ -102,7 +104,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
102104
XCTAssertEqual(collection.packages.count, 2)
103105

104106
let package = collection.packages.first!
105-
XCTAssertEqual(package.identity, .init(urlString: "https://www.example.com/repos/RepoOne.git"))
107+
XCTAssertEqual(package.identity, PackageIdentity.plain("repos.one"))
106108
XCTAssertEqual(package.location, "https://www.example.com/repos/RepoOne.git")
107109
XCTAssertEqual(package.summary, "Package One")
108110
XCTAssertEqual(package.keywords, ["sample package"])
@@ -121,6 +123,8 @@ class JSONPackageCollectionProviderTests: XCTestCase {
121123
XCTAssertEqual(version.verifiedCompatibility!.first!.swiftVersion, SwiftLanguageVersion(string: "5.1")!)
122124
XCTAssertEqual(version.license, .init(type: .Apache2_0, url: URL(string: "https://www.example.com/repos/RepoOne/LICENSE")!))
123125
XCTAssertFalse(collection.isSigned)
126+
127+
XCTAssertEqual(collection.packages[1].identity, .init(urlString: "https://www.example.com/repos/RepoTwo.git"))
124128

125129
// "1.8.3" is originally "v1.8.3"
126130
XCTAssertEqual(["2.1.0", "1.8.3"], collection.packages[1].versions.map { $0.version.description })
@@ -403,7 +407,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
403407
XCTAssertEqual(collection.packages.count, 2)
404408

405409
let package = collection.packages.first!
406-
XCTAssertEqual(package.identity, .init(urlString: "https://www.example.com/repos/RepoOne.git"))
410+
XCTAssertEqual(package.identity, PackageIdentity.plain("repos.one"))
407411
XCTAssertEqual(package.location, "https://www.example.com/repos/RepoOne.git")
408412
XCTAssertEqual(package.summary, "Package One")
409413
XCTAssertEqual(package.keywords, ["sample package"])
@@ -428,6 +432,8 @@ class JSONPackageCollectionProviderTests: XCTestCase {
428432
XCTAssertTrue(signature.isVerified)
429433
XCTAssertEqual("Sample Subject", signature.certificate.subject.commonName)
430434
XCTAssertEqual("Sample Issuer", signature.certificate.issuer.commonName)
435+
436+
XCTAssertEqual(collection.packages[1].identity, .init(urlString: "https://www.example.com/repos/RepoTwo.git"))
431437

432438
// "1.8.3" is originally "v1.8.3"
433439
XCTAssertEqual(["2.1.0", "1.8.3"], collection.packages[1].versions.map { $0.version.description })
@@ -471,7 +477,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
471477
XCTAssertEqual(collection.createdBy?.name, "Jane Doe")
472478
XCTAssertEqual(collection.packages.count, 2)
473479
let package = collection.packages.first!
474-
XCTAssertEqual(package.identity, .init(urlString: "https://www.example.com/repos/RepoOne.git"))
480+
XCTAssertEqual(package.identity, PackageIdentity.plain("repos.one"))
475481
XCTAssertEqual(package.location, "https://www.example.com/repos/RepoOne.git")
476482
XCTAssertEqual(package.summary, "Package One")
477483
XCTAssertEqual(package.keywords, ["sample package"])
@@ -496,6 +502,8 @@ class JSONPackageCollectionProviderTests: XCTestCase {
496502
XCTAssertFalse(signature.isVerified)
497503
XCTAssertEqual("Sample Subject", signature.certificate.subject.commonName)
498504
XCTAssertEqual("Sample Issuer", signature.certificate.issuer.commonName)
505+
506+
XCTAssertEqual(collection.packages[1].identity, .init(urlString: "https://www.example.com/repos/RepoTwo.git"))
499507
}
500508
}
501509

@@ -607,7 +615,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
607615
XCTAssertEqual(collection.createdBy?.name, "Jane Doe")
608616
XCTAssertEqual(collection.packages.count, 2)
609617
let package = collection.packages.first!
610-
XCTAssertEqual(package.identity, .init(urlString: "https://www.example.com/repos/RepoOne.git"))
618+
XCTAssertEqual(package.identity, PackageIdentity.plain("repos.one"))
611619
XCTAssertEqual(package.location, "https://www.example.com/repos/RepoOne.git")
612620
XCTAssertEqual(package.summary, "Package One")
613621
XCTAssertEqual(package.keywords, ["sample package"])
@@ -630,6 +638,8 @@ class JSONPackageCollectionProviderTests: XCTestCase {
630638
XCTAssertTrue(signature.isVerified)
631639
XCTAssertEqual("Sample Subject", signature.certificate.subject.commonName)
632640
XCTAssertEqual("Sample Issuer", signature.certificate.issuer.commonName)
641+
642+
XCTAssertEqual(collection.packages[1].identity, .init(urlString: "https://www.example.com/repos/RepoTwo.git"))
633643
}
634644
}
635645

@@ -675,7 +685,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
675685
XCTAssertEqual(collection.createdBy?.name, "Jane Doe")
676686
XCTAssertEqual(collection.packages.count, 2)
677687
let package = collection.packages.first!
678-
XCTAssertEqual(package.identity, .init(urlString: "https://www.example.com/repos/RepoOne.git"))
688+
XCTAssertEqual(package.identity, PackageIdentity.plain("repos.one"))
679689
XCTAssertEqual(package.location, "https://www.example.com/repos/RepoOne.git")
680690
XCTAssertEqual(package.summary, "Package One")
681691
XCTAssertEqual(package.keywords, ["sample package"])
@@ -700,6 +710,8 @@ class JSONPackageCollectionProviderTests: XCTestCase {
700710
XCTAssertTrue(signature.isVerified)
701711
XCTAssertEqual("Sample Subject", signature.certificate.subject.commonName)
702712
XCTAssertEqual("Sample Issuer", signature.certificate.issuer.commonName)
713+
714+
XCTAssertEqual(collection.packages[1].identity, .init(urlString: "https://www.example.com/repos/RepoTwo.git"))
703715
}
704716
}
705717

@@ -750,7 +762,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
750762
XCTAssertEqual(collection.createdBy?.name, "Jane Doe")
751763
XCTAssertEqual(collection.packages.count, 2)
752764
let package = collection.packages.first!
753-
XCTAssertEqual(package.identity, .init(urlString: "https://www.example.com/repos/RepoOne.git"))
765+
XCTAssertEqual(package.identity, PackageIdentity.plain("repos.one"))
754766
XCTAssertEqual(package.location, "https://www.example.com/repos/RepoOne.git")
755767
XCTAssertEqual(package.summary, "Package One")
756768
XCTAssertEqual(package.keywords, ["sample package"])
@@ -775,6 +787,8 @@ class JSONPackageCollectionProviderTests: XCTestCase {
775787
XCTAssertTrue(signature.isVerified)
776788
XCTAssertEqual("Sample Subject", signature.certificate.subject.commonName)
777789
XCTAssertEqual("Sample Issuer", signature.certificate.issuer.commonName)
790+
791+
XCTAssertEqual(collection.packages[1].identity, .init(urlString: "https://www.example.com/repos/RepoTwo.git"))
778792
}
779793
}
780794

Tests/PackageCollectionsTests/Utility.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -105,7 +105,7 @@ func makeMockPackage(id: String) -> PackageCollectionsModel.Package {
105105
createdAt: Date())
106106
}
107107

108-
return PackageCollectionsModel.Package(identity: .init(urlString: "https://\(id)"),
108+
return PackageCollectionsModel.Package(identity: PackageIdentity.plain("test-\(id).\(id)"),
109109
location: "https://\(id)",
110110
summary: "\(id) description",
111111
keywords: (0 ..< Int.random(in: 1 ... 3)).map { "keyword \($0)" },

0 commit comments

Comments
 (0)