Skip to content

Prepare for change in package identity semantics #3032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4e40988
Add PackageIdentity
mattt Nov 4, 2020
3a1835d
Remove testPackageReference, which is superceded by PackageIdentityTests
mattt Nov 4, 2020
75525f8
Remove PackageReference.PackageIdentity typealias
mattt Nov 7, 2020
fbc78a6
Delegate PackageReference implementations to PackageIdentity without …
mattt Nov 7, 2020
1ffb6c1
Remove redundant calls to PackageReference.computeIdentity
mattt Nov 7, 2020
4f46e74
Replace PackageReference.computeDefaultName delegated calls to Packag…
mattt Nov 7, 2020
8024f1c
Refactor Workspace dependency resolution to use PackageIdentity
mattt Nov 7, 2020
b6d5cb4
Update implementation of ManifestLoader to use PackageIdentity
mattt Nov 7, 2020
31ff495
Update implementation of PackageGraph.load to use PackageIdentity
mattt Nov 7, 2020
53ee0d9
Update implementation of ManifestLoader to use PackageIdentity
mattt Nov 7, 2020
41a3c53
Update implementation of packge override diagnostics to use PackageId…
mattt Nov 7, 2020
47f828e
Remove unnecessary call to PackageReference.computeIdentity in create…
mattt Nov 7, 2020
0ff2a3e
Remove unused method PackageReference.computeIdentity
mattt Nov 7, 2020
e68cadd
Update PackageIdentity to account for URL port component
mattt Nov 9, 2020
2e76236
Update PackageIdentity to account for URL query and fragment components
mattt Nov 9, 2020
5d4409b
Refactor computePackageURLs() to avoid PackageIdentity awkwardness
mattt Nov 11, 2020
eb068aa
Update PackageIdentity to support implicit and explicit file URLs
mattt Nov 12, 2020
e7be0fd
Update PackageIdentity to support http URLs
mattt Nov 12, 2020
b652538
Update PackageIdentity to support ftp and ftps URLs
mattt Nov 12, 2020
dec3dc8
Update PackageIdentity to handle tilde expansion
mattt Nov 12, 2020
5cd5443
Update PackageIdentity to handle percent encoding
mattt Nov 12, 2020
01c0ee4
Add testInternationalizedDomainName
mattt Nov 12, 2020
64d22e9
Reorganize PackageIdentityTests
mattt Nov 12, 2020
6397d4f
Update PackageIdentity to be case and normalization insensitive
mattt Nov 12, 2020
d39264e
Use aPath instead of hardcoded string for identifier in testArtifactD…
mattt Nov 12, 2020
844286b
Add documentation comments for PackageIdentity
mattt Nov 12, 2020
dd8dd76
Update PackageIdentity to support any valid URL scheme
mattt Nov 12, 2020
85a496d
Annotate implementation of PackageIdentity initializer
mattt Nov 12, 2020
57babb4
Add FIXME comment in createResolvedPackages
mattt Nov 12, 2020
d1054e2
Formatting
mattt Nov 12, 2020
c3fbf4e
Add PackageReference.Identity typealias
mattt Nov 12, 2020
5b87153
Remove PackageIdentity conformance to ExpressibleByStringLiteral
mattt Nov 16, 2020
8eb7467
Prepend leading slash for file URLs and paths
mattt Nov 16, 2020
5f081cb
Merge branch 'main' into package-identity
mattt Nov 16, 2020
e341e83
Fix ManifestLoader test failure
mattt Nov 16, 2020
2b98adf
Replace remaining instances of PackageReference.computeIdentity -> le…
mattt Nov 16, 2020
87c1e0f
Revert private interface use of PackageIdentity
mattt Nov 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions Sources/PackageCollections/PackageCollections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public struct PackageCollections: PackageCollectionsProtocol {
init(configuration: Configuration,
storage: Storage,
collectionProviders: [PackageCollectionsModel.CollectionSourceType: PackageCollectionProvider],
metadataProvider: PackageMetadataProvider) {
metadataProvider: PackageMetadataProvider)
{
self.configuration = configuration
self.storage = storage
self.collectionProviders = collectionProviders
Expand All @@ -38,7 +39,8 @@ public struct PackageCollections: PackageCollectionsProtocol {

public func listCollections(identifiers: Set<PackageCollectionsModel.CollectionIdentifier>? = nil,
in profile: PackageCollectionsModel.Profile? = nil,
callback: @escaping (Result<[PackageCollectionsModel.Collection], Error>) -> Void) {
callback: @escaping (Result<[PackageCollectionsModel.Collection], Error>) -> Void)
{
let profile = profile ?? .default

self.storage.collectionsProfiles.listSources(in: profile) { result in
Expand Down Expand Up @@ -70,7 +72,8 @@ public struct PackageCollections: PackageCollectionsProtocol {
}

public func refreshCollections(in profile: PackageCollectionsModel.Profile? = nil,
callback: @escaping (Result<[PackageCollectionsModel.CollectionSource], Error>) -> Void) {
callback: @escaping (Result<[PackageCollectionsModel.CollectionSource], Error>) -> Void)
{
let profile = profile ?? .default

self.storage.collectionsProfiles.listSources(in: profile) { result in
Expand Down Expand Up @@ -99,7 +102,8 @@ public struct PackageCollections: PackageCollectionsProtocol {
public func addCollection(_ source: PackageCollectionsModel.CollectionSource,
order: Int? = nil,
to profile: PackageCollectionsModel.Profile? = nil,
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void) {
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void)
{
let profile = profile ?? .default

if let errors = source.validate() {
Expand All @@ -120,7 +124,8 @@ public struct PackageCollections: PackageCollectionsProtocol {

public func removeCollection(_ source: PackageCollectionsModel.CollectionSource,
from profile: PackageCollectionsModel.Profile? = nil,
callback: @escaping (Result<Void, Error>) -> Void) {
callback: @escaping (Result<Void, Error>) -> Void)
{
let profile = profile ?? .default

self.storage.collectionsProfiles.remove(source: source, from: profile) { result in
Expand Down Expand Up @@ -148,7 +153,8 @@ public struct PackageCollections: PackageCollectionsProtocol {

public func moveCollection(_ source: PackageCollectionsModel.CollectionSource,
to order: Int, in profile: PackageCollectionsModel.Profile? = nil,
callback: @escaping (Result<Void, Error>) -> Void) {
callback: @escaping (Result<Void, Error>) -> Void)
{
let profile = profile ?? .default

self.storage.collectionsProfiles.move(source: source, to: order, in: profile, callback: callback)
Expand All @@ -158,7 +164,8 @@ public struct PackageCollections: PackageCollectionsProtocol {
// The collection is not required to be in the configured list.
// If not found locally (storage), the collection will be fetched from the source.
public func getCollection(_ source: PackageCollectionsModel.CollectionSource,
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void) {
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void)
{
if let errors = source.validate() {
return callback(.failure(MultipleErrors(errors)))
}
Expand Down Expand Up @@ -204,7 +211,8 @@ public struct PackageCollections: PackageCollectionsProtocol {

public func getPackageMetadata(_ reference: PackageReference,
profile: PackageCollectionsModel.Profile? = nil,
callback: @escaping (Result<PackageCollectionsModel.PackageMetadata, Error>) -> Void) {
callback: @escaping (Result<PackageCollectionsModel.PackageMetadata, Error>) -> Void)
{
let profile = profile ?? .default

// first find in storage
Expand Down Expand Up @@ -280,7 +288,8 @@ public struct PackageCollections: PackageCollectionsProtocol {
private func refreshCollectionFromSource(source: PackageCollectionsModel.CollectionSource,
order _: Int? = nil,
profile _: PackageCollectionsModel.Profile? = nil,
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void) {
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void)
{
if let errors = source.validate() {
return callback(.failure(MultipleErrors(errors)))
}
Expand All @@ -298,7 +307,7 @@ public struct PackageCollections: PackageCollectionsProtocol {
}

func findPackage(
identifier: PackageReference.PackageIdentity,
identifier: PackageReference.Identity,
profile: PackageCollectionsModel.Profile? = nil,
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult.Item, Error>) -> Void
) {
Expand Down Expand Up @@ -356,7 +365,8 @@ public struct PackageCollections: PackageCollectionsProtocol {
}

internal static func mergedPackageMetadata(package: PackageCollectionsModel.Collection.Package,
basicMetadata: PackageCollectionsModel.PackageBasicMetadata?) -> PackageCollectionsModel.Package {
basicMetadata: PackageCollectionsModel.PackageBasicMetadata?) -> PackageCollectionsModel.Package
{
var versions = package.versions.map { packageVersion -> PackageCollectionsModel.Package.Version in
.init(version: packageVersion.version,
packageName: packageVersion.packageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public protocol PackageCollectionsStorage {
/// - identifier: The package identifier
/// - collectionIdentifiers: Optional. The identifiers of the `PackageCollection`s
/// - callback: The closure to invoke when result becomes available
func findPackage(identifier: PackageReference.PackageIdentity,
func findPackage(identifier: PackageReference.Identity,
collectionIdentifiers: [PackageCollectionsModel.CollectionIdentifier]?,
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult.Item, Error>) -> Void)

Expand Down Expand Up @@ -135,7 +135,8 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
}

func put(collection: PackageCollectionsModel.Collection,
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void) {
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void)
{
self.queue.async {
do {
let query = "INSERT OR IGNORE INTO PACKAGES_COLLECTIONS VALUES (?, ?);"
Expand All @@ -157,7 +158,8 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
}

func remove(identifier: PackageCollectionsModel.CollectionIdentifier,
callback: @escaping (Result<Void, Error>) -> Void) {
callback: @escaping (Result<Void, Error>) -> Void)
{
self.queue.async {
do {
let query = "DELETE FROM PACKAGES_COLLECTIONS WHERE key == ?;"
Expand All @@ -176,7 +178,8 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
}

func get(identifier: PackageCollectionsModel.CollectionIdentifier,
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void) {
callback: @escaping (Result<PackageCollectionsModel.Collection, Error>) -> Void)
{
self.queue.async {
do {
let query = "SELECT value FROM PACKAGES_COLLECTIONS WHERE key == ? LIMIT 1;"
Expand All @@ -199,7 +202,8 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
}

func list(identifiers: [PackageCollectionsModel.CollectionIdentifier]? = nil,
callback: @escaping (Result<[PackageCollectionsModel.Collection], Error>) -> Void) {
callback: @escaping (Result<[PackageCollectionsModel.Collection], Error>) -> Void)
{
self.queue.async {
do {
var blobs = [Data]()
Expand Down Expand Up @@ -240,14 +244,16 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
// FIXME: implement this
func searchPackages(identifiers: [PackageCollectionsModel.CollectionIdentifier]? = nil,
query: String,
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult, Error>) -> Void) {
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult, Error>) -> Void)
{
fatalError("not implemented")
}

// FIXME: this is PoC for search, need a more performant version of this
func findPackage(identifier: PackageReference.PackageIdentity,
func findPackage(identifier: PackageReference.Identity,
collectionIdentifiers: [PackageCollectionsModel.CollectionIdentifier]?,
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult.Item, Error>) -> Void) {
callback: @escaping (Result<PackageCollectionsModel.PackageSearchResult.Item, Error>) -> Void)
{
self.list(identifiers: collectionIdentifiers) { result in
switch result {
case .failure(let error):
Expand All @@ -273,7 +279,8 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
func searchTargets(identifiers: [PackageCollectionsModel.CollectionIdentifier]? = nil,
query: String,
type: PackageCollectionsModel.TargetSearchType,
callback: @escaping (Result<PackageCollectionsModel.TargetSearchResult, Error>) -> Void) {
callback: @escaping (Result<PackageCollectionsModel.TargetSearchResult, Error>) -> Void)
{
fatalError("not implemented")
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/PackageCollections/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ internal extension Result {

// Model Extension

extension PackageReference {
public extension PackageReference {
/// Initializes a `PackageReference` from `RepositorySpecifier`
init(repository: RepositorySpecifier, kind: PackageReference.Kind = .remote) {
self.init(
identity: PackageReference.computeIdentity(packageURL: repository.url),
identity: repository.url,
path: repository.url,
kind: kind
)
Expand Down
Loading