From 1637a30b37bcb65f804ab852f991a019e6818a70 Mon Sep 17 00:00:00 2001 From: Gabriel Jacoby-Cooper Date: Mon, 15 May 2023 09:03:58 -0700 Subject: [PATCH] Add support for new version of APNSwift (#51) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update Package.swift * Update Swift tools minimum version * Rename to “VaporAPNS” * Fix directory structure * Rename tests target * Update minimum platform versions * Fix imports and exports * Delete interactions with removed APNSwift features * Export APNSCore * Remove exports * Fix imports in tests file * Fix tests --------- Co-authored-by: Kyle Browning --- Package.swift | 20 +++++++++---------- Sources/APNS/Exports.swift | 5 ----- .../{APNS => VaporAPNS}/APNSContainerID.swift | 0 .../{APNS => VaporAPNS}/APNSContainers.swift | 10 +++++----- .../Application+APNS.swift | 5 +++-- .../{APNS => VaporAPNS}/Docs.docc/index.md | 0 .../{APNS => VaporAPNS}/Request+APNS.swift | 2 +- .../APNSTests.swift | 11 ++-------- 8 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 Sources/APNS/Exports.swift rename Sources/{APNS => VaporAPNS}/APNSContainerID.swift (100%) rename Sources/{APNS => VaporAPNS}/APNSContainers.swift (92%) rename Sources/{APNS => VaporAPNS}/Application+APNS.swift (95%) rename Sources/{APNS => VaporAPNS}/Docs.docc/index.md (100%) rename Sources/{APNS => VaporAPNS}/Request+APNS.swift (88%) rename Tests/{APNSTests => VaporAPNSTests}/APNSTests.swift (94%) diff --git a/Package.swift b/Package.swift index a796313..5f4a5d9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,26 +1,26 @@ -// swift-tools-version:5.6 +// swift-tools-version:5.7 import PackageDescription let package = Package( - name: "apns", + name: "vapor-apns", platforms: [ - .macOS(.v12), - .iOS(.v15) + .macOS(.v13), + .iOS(.v16) ], products: [ - .library(name: "APNS", targets: ["APNS"]), + .library(name: "VaporAPNS", targets: ["VaporAPNS"]), ], dependencies: [ - .package(url: "https://github.com/swift-server-community/APNSwift.git", from: "5.0.0-beta.2"), + .package(url: "https://github.com/swift-server-community/APNSwift.git", from: "5.0.0-beta.3"), .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"), ], targets: [ - .target(name: "APNS", dependencies: [ - .product(name: "APNSwift", package: "apnswift"), + .target(name: "VaporAPNS", dependencies: [ + .product(name: "APNS", package: "apnswift"), .product(name: "Vapor", package: "vapor"), ]), - .testTarget(name: "APNSTests", dependencies: [ - .target(name: "APNS"), + .testTarget(name: "VaporAPNSTests", dependencies: [ + .target(name: "VaporAPNS"), .product(name: "XCTVapor", package: "vapor"), ]), ] diff --git a/Sources/APNS/Exports.swift b/Sources/APNS/Exports.swift deleted file mode 100644 index 82d5e9c..0000000 --- a/Sources/APNS/Exports.swift +++ /dev/null @@ -1,5 +0,0 @@ -#if !BUILDING_DOCC - -@_exported import APNSwift - -#endif \ No newline at end of file diff --git a/Sources/APNS/APNSContainerID.swift b/Sources/VaporAPNS/APNSContainerID.swift similarity index 100% rename from Sources/APNS/APNSContainerID.swift rename to Sources/VaporAPNS/APNSContainerID.swift diff --git a/Sources/APNS/APNSContainers.swift b/Sources/VaporAPNS/APNSContainers.swift similarity index 92% rename from Sources/APNS/APNSContainers.swift rename to Sources/VaporAPNS/APNSContainers.swift index cbdddba..13a1093 100644 --- a/Sources/APNS/APNSContainers.swift +++ b/Sources/VaporAPNS/APNSContainers.swift @@ -1,6 +1,8 @@ import Vapor -import APNSwift +import APNS +import Foundation import NIO +import NIOConcurrencyHelpers public typealias APNSGenericClient = APNSClient @@ -24,7 +26,7 @@ public class APNSContainers { private var containers: [ID: Container] private var defaultID: ID? - private var lock: Lock + private var lock: NIOLock init() { self.containers = [:] @@ -52,7 +54,6 @@ extension APNSContainers { responseDecoder: JSONDecoder, requestEncoder: JSONEncoder, byteBufferAllocator: ByteBufferAllocator = .init(), - backgroundActivityLogger: Logger, as id: ID, isDefault: Bool? = nil ) { @@ -66,8 +67,7 @@ extension APNSContainers { eventLoopGroupProvider: eventLoopGroupProvider, responseDecoder: responseDecoder, requestEncoder: requestEncoder, - byteBufferAllocator: byteBufferAllocator, - backgroundActivityLogger: backgroundActivityLogger + byteBufferAllocator: byteBufferAllocator ) ) diff --git a/Sources/APNS/Application+APNS.swift b/Sources/VaporAPNS/Application+APNS.swift similarity index 95% rename from Sources/APNS/Application+APNS.swift rename to Sources/VaporAPNS/Application+APNS.swift index cf4e769..e544a01 100644 --- a/Sources/APNS/Application+APNS.swift +++ b/Sources/VaporAPNS/Application+APNS.swift @@ -1,4 +1,5 @@ -import APNSwift +import APNS +import NIOConcurrencyHelpers import Vapor extension Application { @@ -9,7 +10,7 @@ extension Application { public struct APNS { // Synchronize access across threads. - private var lock: Lock + private var lock: NIOLock struct ContainersKey: StorageKey, LockKey { typealias Value = APNSContainers diff --git a/Sources/APNS/Docs.docc/index.md b/Sources/VaporAPNS/Docs.docc/index.md similarity index 100% rename from Sources/APNS/Docs.docc/index.md rename to Sources/VaporAPNS/Docs.docc/index.md diff --git a/Sources/APNS/Request+APNS.swift b/Sources/VaporAPNS/Request+APNS.swift similarity index 88% rename from Sources/APNS/Request+APNS.swift rename to Sources/VaporAPNS/Request+APNS.swift index 58dde20..3733ea6 100644 --- a/Sources/APNS/Request+APNS.swift +++ b/Sources/VaporAPNS/Request+APNS.swift @@ -1,4 +1,4 @@ -import APNSwift +import APNS import Vapor extension Request { diff --git a/Tests/APNSTests/APNSTests.swift b/Tests/VaporAPNSTests/APNSTests.swift similarity index 94% rename from Tests/APNSTests/APNSTests.swift rename to Tests/VaporAPNSTests/APNSTests.swift index bfc52f3..8f215e4 100644 --- a/Tests/APNSTests/APNSTests.swift +++ b/Tests/VaporAPNSTests/APNSTests.swift @@ -1,4 +1,5 @@ import APNS +import VaporAPNS import XCTVapor class APNSTests: XCTestCase { @@ -29,7 +30,6 @@ class APNSTests: XCTestCase { eventLoopGroupProvider: .createNew, responseDecoder: JSONDecoder(), requestEncoder: JSONEncoder(), - backgroundActivityLogger: app.logger, as: .default ) @@ -45,8 +45,7 @@ class APNSTests: XCTestCase { topic: "MY_TOPC", payload: Payload() ), - deviceToken: "98AAD4A2398DDC58595F02FA307DF9A15C18B6111D1B806949549085A8E6A55D", - deadline: .distantFuture + deviceToken: "98AAD4A2398DDC58595F02FA307DF9A15C18B6111D1B806949549085A8E6A55D" ) return .ok } @@ -75,7 +74,6 @@ class APNSTests: XCTestCase { eventLoopGroupProvider: .createNew, responseDecoder: JSONDecoder(), requestEncoder: JSONEncoder(), - backgroundActivityLogger: app.logger, as: .default ) @@ -105,7 +103,6 @@ class APNSTests: XCTestCase { eventLoopGroupProvider: .createNew, responseDecoder: JSONDecoder(), requestEncoder: JSONEncoder(), - backgroundActivityLogger: app.logger, as: .custom ) @@ -140,7 +137,6 @@ class APNSTests: XCTestCase { eventLoopGroupProvider: .createNew, responseDecoder: JSONDecoder(), requestEncoder: JSONEncoder(), - backgroundActivityLogger: app.logger, as: .default, isDefault: true ) @@ -155,7 +151,6 @@ class APNSTests: XCTestCase { eventLoopGroupProvider: .createNew, responseDecoder: JSONDecoder(), requestEncoder: JSONEncoder(), - backgroundActivityLogger: app.logger, as: .custom, isDefault: true ) @@ -192,7 +187,6 @@ class APNSTests: XCTestCase { eventLoopGroupProvider: .createNew, responseDecoder: JSONDecoder(), requestEncoder: JSONEncoder(), - backgroundActivityLogger: app.logger, as: .default, isDefault: true ) @@ -207,7 +201,6 @@ class APNSTests: XCTestCase { eventLoopGroupProvider: .createNew, responseDecoder: JSONDecoder(), requestEncoder: JSONEncoder(), - backgroundActivityLogger: app.logger, as: .custom )