From 93a3f1d34ae692bcb9805c1cbaca05d62725c6b2 Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 01:38:54 +0000 Subject: [PATCH 01/11] Support Swift Package Manager --- .gitignore | 4 +++ JSONRPCKit.xcodeproj/project.pbxproj | 27 ++++++++++--------- .../xcschemes/JSONRPCKit.xcscheme | 4 +-- Package.resolved | 16 +++++++++++ Package.swift | 19 +++++++++++++ .../BatchElementTests.swift | 0 .../BatchFactoryTests.swift | 0 Tests/{ => JSONRPCKitTests}/Info.plist | 0 Tests/{ => JSONRPCKitTests}/TestRequest.swift | 0 9 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 Package.resolved create mode 100644 Package.swift rename Tests/{ => JSONRPCKitTests}/BatchElementTests.swift (100%) rename Tests/{ => JSONRPCKitTests}/BatchFactoryTests.swift (100%) rename Tests/{ => JSONRPCKitTests}/Info.plist (100%) rename Tests/{ => JSONRPCKitTests}/TestRequest.swift (100%) diff --git a/.gitignore b/.gitignore index 8615121..2492f29 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,7 @@ DerivedData # Carthage/Checkouts Carthage/Build + +# Swift Package Manager + +.build diff --git a/JSONRPCKit.xcodeproj/project.pbxproj b/JSONRPCKit.xcodeproj/project.pbxproj index 20d32cb..f03aa3d 100644 --- a/JSONRPCKit.xcodeproj/project.pbxproj +++ b/JSONRPCKit.xcodeproj/project.pbxproj @@ -40,7 +40,7 @@ 7FC654F61D48B6CB004C390C /* Batch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Batch.swift; sourceTree = ""; }; 7FC654F71D48B6CB004C390C /* BatchElement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchElement.swift; sourceTree = ""; }; 7FC654FA1D49DF27004C390C /* BatchFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchFactory.swift; sourceTree = ""; }; - 7FC655001D49EA19004C390C /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 7FC655001D49EA19004C390C /* JSONRPCKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JSONRPCKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 7FC655041D49EA19004C390C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7FC6550B1D49FA20004C390C /* TestRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestRequest.swift; sourceTree = ""; }; CB31EFB91CF6E8FE00DD13DD /* Result.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Result.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -75,7 +75,7 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 7FC655011D49EA19004C390C /* Tests */ = { + 7FC655011D49EA19004C390C /* JSONRPCKitTests */ = { isa = PBXGroup; children = ( 7FC6550B1D49FA20004C390C /* TestRequest.swift */, @@ -83,7 +83,8 @@ 7F359B771D4B1B0500032E8D /* BatchFactoryTests.swift */, 7FC655041D49EA19004C390C /* Info.plist */, ); - path = Tests; + name = JSONRPCKitTests; + path = Tests/JSONRPCKitTests; sourceTree = ""; }; CB63E2391CE22F7E00E22B5C /* Frameworks */ = { @@ -98,7 +99,7 @@ isa = PBXGroup; children = ( CBB0C3501BF0B1D6006A7D41 /* JSONRPCKit */, - 7FC655011D49EA19004C390C /* Tests */, + 7FC655011D49EA19004C390C /* JSONRPCKitTests */, CBB0C34F1BF0B1D6006A7D41 /* Products */, CB63E2391CE22F7E00E22B5C /* Frameworks */, ); @@ -108,7 +109,7 @@ isa = PBXGroup; children = ( CBB0C34E1BF0B1D6006A7D41 /* JSONRPCKit.framework */, - 7FC655001D49EA19004C390C /* Tests.xctest */, + 7FC655001D49EA19004C390C /* JSONRPCKitTests.xctest */, ); name = Products; sourceTree = ""; @@ -144,9 +145,9 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 7FC654FF1D49EA19004C390C /* Tests */ = { + 7FC654FF1D49EA19004C390C /* JSONRPCKitTests */ = { isa = PBXNativeTarget; - buildConfigurationList = 7FC655081D49EA19004C390C /* Build configuration list for PBXNativeTarget "Tests" */; + buildConfigurationList = 7FC655081D49EA19004C390C /* Build configuration list for PBXNativeTarget "JSONRPCKitTests" */; buildPhases = ( 7FC654FC1D49EA19004C390C /* Sources */, 7FC654FD1D49EA19004C390C /* Frameworks */, @@ -157,9 +158,9 @@ dependencies = ( 7FC655071D49EA19004C390C /* PBXTargetDependency */, ); - name = Tests; + name = JSONRPCKitTests; productName = Tests; - productReference = 7FC655001D49EA19004C390C /* Tests.xctest */; + productReference = 7FC655001D49EA19004C390C /* JSONRPCKitTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; CBB0C34D1BF0B1D6006A7D41 /* JSONRPCKit */ = { @@ -214,7 +215,7 @@ projectRoot = ""; targets = ( CBB0C34D1BF0B1D6006A7D41 /* JSONRPCKit */, - 7FC654FF1D49EA19004C390C /* Tests */, + 7FC654FF1D49EA19004C390C /* JSONRPCKitTests */, ); }; /* End PBXProject section */ @@ -277,7 +278,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ANALYZER_NONNULL = YES; - INFOPLIST_FILE = Tests/Info.plist; + INFOPLIST_FILE = Tests/JSONRPCKitTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "-.Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -289,7 +290,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ANALYZER_NONNULL = YES; - INFOPLIST_FILE = Tests/Info.plist; + INFOPLIST_FILE = Tests/JSONRPCKitTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "-.Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -455,7 +456,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 7FC655081D49EA19004C390C /* Build configuration list for PBXNativeTarget "Tests" */ = { + 7FC655081D49EA19004C390C /* Build configuration list for PBXNativeTarget "JSONRPCKitTests" */ = { isa = XCConfigurationList; buildConfigurations = ( 7FC655091D49EA19004C390C /* Debug */, diff --git a/JSONRPCKit.xcodeproj/xcshareddata/xcschemes/JSONRPCKit.xcscheme b/JSONRPCKit.xcodeproj/xcshareddata/xcschemes/JSONRPCKit.xcscheme index 7336462..a1b8790 100644 --- a/JSONRPCKit.xcodeproj/xcshareddata/xcschemes/JSONRPCKit.xcscheme +++ b/JSONRPCKit.xcodeproj/xcshareddata/xcschemes/JSONRPCKit.xcscheme @@ -34,8 +34,8 @@ diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..3236c9e --- /dev/null +++ b/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "Result", + "repositoryURL": "https://github.com/antitypical/Result.git", + "state": { + "branch": null, + "revision": "7477584259bfce2560a19e06ad9f71db441fff11", + "version": "3.2.4" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..4a3436d --- /dev/null +++ b/Package.swift @@ -0,0 +1,19 @@ +// swift-tools-version:4.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "JSONRPCKit", + products: [ + .library(name: "JSONRPCKit", targets: ["JSONRPCKit"]), + ], + dependencies: [ + .package(url: "https://github.com/antitypical/Result.git", from: "3.2.0"), + ], + targets: [ + .target(name: "JSONRPCKit", dependencies: ["Result"], path: "JSONRPCKit"), + .testTarget(name: "JSONRPCKitTests", dependencies: ["JSONRPCKit"]), + ], + swiftLanguageVersions: [4] +) diff --git a/Tests/BatchElementTests.swift b/Tests/JSONRPCKitTests/BatchElementTests.swift similarity index 100% rename from Tests/BatchElementTests.swift rename to Tests/JSONRPCKitTests/BatchElementTests.swift diff --git a/Tests/BatchFactoryTests.swift b/Tests/JSONRPCKitTests/BatchFactoryTests.swift similarity index 100% rename from Tests/BatchFactoryTests.swift rename to Tests/JSONRPCKitTests/BatchFactoryTests.swift diff --git a/Tests/Info.plist b/Tests/JSONRPCKitTests/Info.plist similarity index 100% rename from Tests/Info.plist rename to Tests/JSONRPCKitTests/Info.plist diff --git a/Tests/TestRequest.swift b/Tests/JSONRPCKitTests/TestRequest.swift similarity index 100% rename from Tests/TestRequest.swift rename to Tests/JSONRPCKitTests/TestRequest.swift From 6dede7b65eb6069d7caab57618101093f6b8339e Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 02:08:58 +0000 Subject: [PATCH 02/11] Enable tests on Linux --- Tests/JSONRPCKitTests/BatchElementTests.swift | 18 ++++++++++++++++++ Tests/JSONRPCKitTests/BatchFactoryTests.swift | 9 +++++++++ Tests/LinuxMain.swift | 7 +++++++ 3 files changed, 34 insertions(+) create mode 100644 Tests/LinuxMain.swift diff --git a/Tests/JSONRPCKitTests/BatchElementTests.swift b/Tests/JSONRPCKitTests/BatchElementTests.swift index 5cc0efb..0660c00 100644 --- a/Tests/JSONRPCKitTests/BatchElementTests.swift +++ b/Tests/JSONRPCKitTests/BatchElementTests.swift @@ -430,4 +430,22 @@ class BatchElementTests: XCTestCase { } } + static var allTests = [ + ("testRequestObject", testRequestObject), + ("testNotificationRequestObject", testNotificationRequestObject), + ("testResponseFromObject", testResponseFromObject), + ("testResponseFromArray", testResponseFromArray), + ("testResponseFromObjectResponseError", testResponseFromObjectResponseError), + ("testResponseFromArrayResponseError", testResponseFromArrayResponseError), + ("testResponseFromObjectresultObjectParseError", testResponseFromObjectresultObjectParseError), + ("testResponseFromArrayresultObjectParseError", testResponseFromArrayresultObjectParseError), + ("testResponseFromObjectErrorObjectParseError", testResponseFromObjectErrorObjectParseError), + ("testResponseFromArrayErrorObjectParseError", testResponseFromArrayErrorObjectParseError), + ("testResponseFromObjectunsupportedVersion", testResponseFromObjectunsupportedVersion), + ("testResponseFromArrayunsupportedVersion", testResponseFromArrayunsupportedVersion), + ("testResponseFromObjectresponseNotFound", testResponseFromObjectresponseNotFound), + ("testResponseFromArrayresponseNotFound", testResponseFromArrayresponseNotFound), + ("testResponseFromObjectmissingBothResultAndError", testResponseFromObjectmissingBothResultAndError), + ("testResponseFromArraymissingBothResultAndError", testResponseFromArraymissingBothResultAndError), + ] } diff --git a/Tests/JSONRPCKitTests/BatchFactoryTests.swift b/Tests/JSONRPCKitTests/BatchFactoryTests.swift index d5328b3..492e092 100644 --- a/Tests/JSONRPCKitTests/BatchFactoryTests.swift +++ b/Tests/JSONRPCKitTests/BatchFactoryTests.swift @@ -89,4 +89,13 @@ class BatchFactoryTests: XCTestCase { let nextId = batchFactory.idGenerator.next().value as? Int XCTAssertEqual(nextId, 10000) } + + static var allTests = [ + ("test1", test1), + ("test2", test2), + ("test3", test3), + ("test4", test4), + ("test5", test5), + ("testThreadSafety", testThreadSafety), + ] } diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..a87691d --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest +@testable import JSONRPCKitTests + +XCTMain([ + testCase(BatchElementTests.allTests), + testCase(BatchFactoryTests.allTests), +]) From 1c22aafd8da4f08c98760d6c8bba971dfba579fd Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 11:30:36 +0000 Subject: [PATCH 03/11] Change the structure --- JSONRPCKit.podspec | 2 +- JSONRPCKit.xcodeproj/project.pbxproj | 25 +++++++++++++++---- Package.swift | 2 +- .../JSONRPCKit}/Batch.swift | 0 .../JSONRPCKit}/BatchElement.swift | 0 .../JSONRPCKit}/BatchFactory.swift | 0 {JSONRPCKit => Sources/JSONRPCKit}/Id.swift | 0 .../JSONRPCKit}/IdGenerator.swift | 0 {JSONRPCKit => Sources/JSONRPCKit}/Info.plist | 0 .../JSONRPCKit}/JSONRPCError.swift | 0 .../JSONRPCKit}/JSONRPCKit.h | 0 .../JSONRPCKit}/NumberIdGenerator.swift | 0 .../JSONRPCKit}/Request.swift | 0 13 files changed, 22 insertions(+), 7 deletions(-) rename {JSONRPCKit => Sources/JSONRPCKit}/Batch.swift (100%) rename {JSONRPCKit => Sources/JSONRPCKit}/BatchElement.swift (100%) rename {JSONRPCKit => Sources/JSONRPCKit}/BatchFactory.swift (100%) rename {JSONRPCKit => Sources/JSONRPCKit}/Id.swift (100%) rename {JSONRPCKit => Sources/JSONRPCKit}/IdGenerator.swift (100%) rename {JSONRPCKit => Sources/JSONRPCKit}/Info.plist (100%) rename {JSONRPCKit => Sources/JSONRPCKit}/JSONRPCError.swift (100%) rename {JSONRPCKit => Sources/JSONRPCKit}/JSONRPCKit.h (100%) rename {JSONRPCKit => Sources/JSONRPCKit}/NumberIdGenerator.swift (100%) rename {JSONRPCKit => Sources/JSONRPCKit}/Request.swift (100%) diff --git a/JSONRPCKit.podspec b/JSONRPCKit.podspec index 387afe1..c67267c 100644 --- a/JSONRPCKit.podspec +++ b/JSONRPCKit.podspec @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.watchos.deployment_target = "2.0" s.tvos.deployment_target = "9.0" - s.source_files = "JSONRPCKit/*.{swift,h,m}" + s.source_files = "Sources/JSONRPCKit/*.{swift,h,m}" s.source = { :git => "https://github.com/bricklife/JSONRPCKit.git", :tag => "#{s.version}", diff --git a/JSONRPCKit.xcodeproj/project.pbxproj b/JSONRPCKit.xcodeproj/project.pbxproj index f03aa3d..8205b48 100644 --- a/JSONRPCKit.xcodeproj/project.pbxproj +++ b/JSONRPCKit.xcodeproj/project.pbxproj @@ -83,8 +83,7 @@ 7F359B771D4B1B0500032E8D /* BatchFactoryTests.swift */, 7FC655041D49EA19004C390C /* Info.plist */, ); - name = JSONRPCKitTests; - path = Tests/JSONRPCKitTests; + path = JSONRPCKitTests; sourceTree = ""; }; CB63E2391CE22F7E00E22B5C /* Frameworks */ = { @@ -95,11 +94,27 @@ name = Frameworks; sourceTree = ""; }; - CBB0C3441BF0B1D5006A7D41 = { + CB7B4D4F2010BB1800AEB6FF /* Sources */ = { isa = PBXGroup; children = ( CBB0C3501BF0B1D6006A7D41 /* JSONRPCKit */, + ); + path = Sources; + sourceTree = ""; + }; + CB7B4D502010BB4400AEB6FF /* Tests */ = { + isa = PBXGroup; + children = ( 7FC655011D49EA19004C390C /* JSONRPCKitTests */, + ); + path = Tests; + sourceTree = ""; + }; + CBB0C3441BF0B1D5006A7D41 = { + isa = PBXGroup; + children = ( + CB7B4D4F2010BB1800AEB6FF /* Sources */, + CB7B4D502010BB4400AEB6FF /* Tests */, CBB0C34F1BF0B1D6006A7D41 /* Products */, CB63E2391CE22F7E00E22B5C /* Frameworks */, ); @@ -416,7 +431,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = JSONRPCKit/Info.plist; + INFOPLIST_FILE = Sources/JSONRPCKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=appletv*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -439,7 +454,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = JSONRPCKit/Info.plist; + INFOPLIST_FILE = Sources/JSONRPCKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=appletv*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; diff --git a/Package.swift b/Package.swift index 4a3436d..a1bec29 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,7 @@ let package = Package( .package(url: "https://github.com/antitypical/Result.git", from: "3.2.0"), ], targets: [ - .target(name: "JSONRPCKit", dependencies: ["Result"], path: "JSONRPCKit"), + .target(name: "JSONRPCKit", dependencies: ["Result"]), .testTarget(name: "JSONRPCKitTests", dependencies: ["JSONRPCKit"]), ], swiftLanguageVersions: [4] diff --git a/JSONRPCKit/Batch.swift b/Sources/JSONRPCKit/Batch.swift similarity index 100% rename from JSONRPCKit/Batch.swift rename to Sources/JSONRPCKit/Batch.swift diff --git a/JSONRPCKit/BatchElement.swift b/Sources/JSONRPCKit/BatchElement.swift similarity index 100% rename from JSONRPCKit/BatchElement.swift rename to Sources/JSONRPCKit/BatchElement.swift diff --git a/JSONRPCKit/BatchFactory.swift b/Sources/JSONRPCKit/BatchFactory.swift similarity index 100% rename from JSONRPCKit/BatchFactory.swift rename to Sources/JSONRPCKit/BatchFactory.swift diff --git a/JSONRPCKit/Id.swift b/Sources/JSONRPCKit/Id.swift similarity index 100% rename from JSONRPCKit/Id.swift rename to Sources/JSONRPCKit/Id.swift diff --git a/JSONRPCKit/IdGenerator.swift b/Sources/JSONRPCKit/IdGenerator.swift similarity index 100% rename from JSONRPCKit/IdGenerator.swift rename to Sources/JSONRPCKit/IdGenerator.swift diff --git a/JSONRPCKit/Info.plist b/Sources/JSONRPCKit/Info.plist similarity index 100% rename from JSONRPCKit/Info.plist rename to Sources/JSONRPCKit/Info.plist diff --git a/JSONRPCKit/JSONRPCError.swift b/Sources/JSONRPCKit/JSONRPCError.swift similarity index 100% rename from JSONRPCKit/JSONRPCError.swift rename to Sources/JSONRPCKit/JSONRPCError.swift diff --git a/JSONRPCKit/JSONRPCKit.h b/Sources/JSONRPCKit/JSONRPCKit.h similarity index 100% rename from JSONRPCKit/JSONRPCKit.h rename to Sources/JSONRPCKit/JSONRPCKit.h diff --git a/JSONRPCKit/NumberIdGenerator.swift b/Sources/JSONRPCKit/NumberIdGenerator.swift similarity index 100% rename from JSONRPCKit/NumberIdGenerator.swift rename to Sources/JSONRPCKit/NumberIdGenerator.swift diff --git a/JSONRPCKit/Request.swift b/Sources/JSONRPCKit/Request.swift similarity index 100% rename from JSONRPCKit/Request.swift rename to Sources/JSONRPCKit/Request.swift From 1fed31ed52d4d796b17b74c3508394fb5a47d91e Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 11:33:44 +0000 Subject: [PATCH 04/11] Update the version number to `3.0.0` --- Cartfile | 2 +- Cartfile.private | 2 +- JSONRPCKit.podspec | 4 ++-- Sources/JSONRPCKit/Info.plist | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cartfile b/Cartfile index 343e772..fa9f48b 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "antitypical/Result" ~> 3.2 +github "antitypical/Result" ~> 3.2.0 diff --git a/Cartfile.private b/Cartfile.private index 31fe833..8b3aa2a 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1 +1 @@ -github "ishkawa/APIKit" ~> 3.2 +github "ishkawa/APIKit" ~> 3.2.0 diff --git a/JSONRPCKit.podspec b/JSONRPCKit.podspec index c67267c..91337fe 100644 --- a/JSONRPCKit.podspec +++ b/JSONRPCKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "JSONRPCKit" - s.version = "2.0.1" + s.version = "3.0.0" s.summary = "JSONRPCKit is a JSON-RPC 2.0 library purely written in Swift." s.homepage = "https://github.com/bricklife/JSONRPCKit" @@ -28,6 +28,6 @@ Pod::Spec.new do |s| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. LICENSE } - s.dependency "Result", "~> 3.2" + s.dependency "Result", "~> 3.2.0" end diff --git a/Sources/JSONRPCKit/Info.plist b/Sources/JSONRPCKit/Info.plist index 783e22e..e0f4bf7 100644 --- a/Sources/JSONRPCKit/Info.plist +++ b/Sources/JSONRPCKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.0.1 + 3.0.0 CFBundleSignature ???? CFBundleVersion From fb879da9034e65952cae70edfaa021535ae6f5de Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 11:53:42 +0000 Subject: [PATCH 05/11] Refactoring --- .../Example/SingleRequestViewController.swift | 4 ++-- Sources/JSONRPCKit/BatchElement.swift | 22 ++++++++----------- Sources/JSONRPCKit/BatchFactory.swift | 2 +- Sources/JSONRPCKit/NumberIdGenerator.swift | 2 +- Tests/JSONRPCKitTests/BatchElementTests.swift | 9 +++----- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Example/Example/SingleRequestViewController.swift b/Example/Example/SingleRequestViewController.swift index bc839e6..d049987 100644 --- a/Example/Example/SingleRequestViewController.swift +++ b/Example/Example/SingleRequestViewController.swift @@ -12,7 +12,7 @@ import JSONRPCKit public struct StringIdGenerator: IdGenerator { - fileprivate var currentId = 1 + private var currentId = 1 public mutating func next() -> Id { defer { @@ -29,7 +29,7 @@ class SingleRequestViewController: UIViewController { @IBOutlet weak var secondTextField: UITextField! @IBOutlet weak var subtractAnswerLabel: UILabel! - let batchFactory = BatchFactory() + let batchFactory = BatchFactory(idGenerator: StringIdGenerator()) func subtract(_ first: Int, _ second: Int) { let divideRequest = Divide( diff --git a/Sources/JSONRPCKit/BatchElement.swift b/Sources/JSONRPCKit/BatchElement.swift index fbfebc6..c8e3649 100644 --- a/Sources/JSONRPCKit/BatchElement.swift +++ b/Sources/JSONRPCKit/BatchElement.swift @@ -120,27 +120,23 @@ public struct BatchElement: BatchElementProcotol { public init(request: Request, version: String, id: Id) { let id: Id? = request.isNotification ? nil : id + var body: [String: Any] = [ - "jsonrpc": version as Any, - "method": request.method as Any, + "jsonrpc": version, + "method": request.method, ] - - if let id = id { - body["id"] = id.value - } - - if let parameters = request.parameters { - body["params"] = parameters - } - - request.extendedFields?.forEach { key, value in + + body["id"] = id?.value + body["params"] = request.parameters + + request.extendedFields?.forEach { (key, value) in body[key] = value } self.request = request self.version = version self.id = id - self.body = body as Any + self.body = body } } diff --git a/Sources/JSONRPCKit/BatchFactory.swift b/Sources/JSONRPCKit/BatchFactory.swift index 740b285..dd7d608 100644 --- a/Sources/JSONRPCKit/BatchFactory.swift +++ b/Sources/JSONRPCKit/BatchFactory.swift @@ -13,7 +13,7 @@ public final class BatchFactory { public let version: String public var idGenerator: IdGenerator - fileprivate let semaphore = DispatchSemaphore(value: 1) + private let semaphore = DispatchSemaphore(value: 1) public init(version: String = "2.0", idGenerator: IdGenerator = NumberIdGenerator()) { self.version = version diff --git a/Sources/JSONRPCKit/NumberIdGenerator.swift b/Sources/JSONRPCKit/NumberIdGenerator.swift index 2f2d402..2d980c2 100644 --- a/Sources/JSONRPCKit/NumberIdGenerator.swift +++ b/Sources/JSONRPCKit/NumberIdGenerator.swift @@ -10,7 +10,7 @@ import Foundation public struct NumberIdGenerator: IdGenerator { - fileprivate var currentId = 1 + private var currentId = 1 public init() {} diff --git a/Tests/JSONRPCKitTests/BatchElementTests.swift b/Tests/JSONRPCKitTests/BatchElementTests.swift index 0660c00..2290131 100644 --- a/Tests/JSONRPCKitTests/BatchElementTests.swift +++ b/Tests/JSONRPCKitTests/BatchElementTests.swift @@ -30,21 +30,18 @@ class BatchElementTests: XCTestCase { } func testNotificationRequestObject() { - let request = TestNotificationRequest(method: "method", parameters: ["key": "value"]) + let request = TestNotificationRequest(method: "method", parameters: nil) let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) XCTAssertNil(batchElement.id) XCTAssertEqual(batchElement.version, "2.0") let requestObject = batchElement.body as? [String: Any] - XCTAssertEqual(requestObject?.keys.count, 3) + XCTAssertEqual(requestObject?.keys.count, 2) XCTAssertEqual(requestObject?["jsonrpc"] as? String, "2.0") XCTAssertEqual(requestObject?["method"] as? String, "method") XCTAssertNil(requestObject?["id"]) - - let parameters = requestObject?["params"] as? [String: Any] - XCTAssertEqual(parameters?.keys.count, 1) - XCTAssertEqual(parameters?["key"] as? String, "value") + XCTAssertNil(requestObject?["params"]) } func testResponseFromObject() { From ed38be8db96d5feeba72a2f7889fd1535eb7fda0 Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 11:54:00 +0000 Subject: [PATCH 06/11] Add badges into README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7b8a9c6..13c472b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # JSONRPCKit +[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) +[![CocoaPods](https://img.shields.io/cocoapods/v/JSONRPCKit.svg)](https://cocoapods.org/) + JSONRPCKit is a [JSON-RPC 2.0](http://www.jsonrpc.org/specification) library purely written in Swift. ```swift From c687ea91d4df0564bf49f6e0c9c80157b784583a Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 12:24:30 +0000 Subject: [PATCH 07/11] Fix test --- JSONRPCKit.xcodeproj/project.pbxproj | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/JSONRPCKit.xcodeproj/project.pbxproj b/JSONRPCKit.xcodeproj/project.pbxproj index 8205b48..f31ac6e 100644 --- a/JSONRPCKit.xcodeproj/project.pbxproj +++ b/JSONRPCKit.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ 7FC654F81D48B6CB004C390C /* Batch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC654F61D48B6CB004C390C /* Batch.swift */; }; 7FC654F91D48B6CB004C390C /* BatchElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC654F71D48B6CB004C390C /* BatchElement.swift */; }; 7FC654FB1D49DF27004C390C /* BatchFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC654FA1D49DF27004C390C /* BatchFactory.swift */; }; - 7FC655051D49EA19004C390C /* JSONRPCKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CBB0C34E1BF0B1D6006A7D41 /* JSONRPCKit.framework */; }; 7FC6550C1D49FA20004C390C /* TestRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC6550B1D49FA20004C390C /* TestRequest.swift */; }; 7FD0A33D1D4B4024007C9EAB /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB31EFB91CF6E8FE00DD13DD /* Result.framework */; }; CB31EFBA1CF6E8FE00DD13DD /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB31EFB91CF6E8FE00DD13DD /* Result.framework */; }; @@ -60,7 +59,6 @@ buildActionMask = 2147483647; files = ( 7FD0A33D1D4B4024007C9EAB /* Result.framework in Frameworks */, - 7FC655051D49EA19004C390C /* JSONRPCKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -294,7 +292,10 @@ buildSettings = { CLANG_ANALYZER_NONNULL = YES; INFOPLIST_FILE = Tests/JSONRPCKitTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ""; + "LD_RUNPATH_SEARCH_PATHS[sdk=appletv*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=iphone*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "-.Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.0; @@ -306,7 +307,9 @@ buildSettings = { CLANG_ANALYZER_NONNULL = YES; INFOPLIST_FILE = Tests/JSONRPCKitTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=appletv*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=iphone*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "-.Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.0; From b67332d76991cfc0974d66d9344dcba41c2c6aca Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 12:27:03 +0000 Subject: [PATCH 08/11] Update travis settings --- .travis.yml | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6046b09..6219b30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,47 @@ -language: objective-c -osx_image: xcode7.3 - env: global: - LC_CTYPE=en_US.UTF-8 + +branches: + only: + - master -script: - - xcodebuild test -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit-iOS -sdk iphonesimulator | xcpretty -c - - xcodebuild build -workspace JSONRPCKit.xcworkspace -scheme Example -sdk iphonesimulator | xcpretty -c +matrix: + include: + - os: osx + osx_image: xcode9 + language: objective-c + env: + - JOB=Xcode + script: + - set -o pipefail + - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit | xcpretty -c + - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk iphonesimulator -destination "name=iPhone SE" | xcpretty -c + - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk appletvsimulator -destination "name=Apple TV 1080p" | xcpretty -c + - xcodebuild build -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk watchsimulator | xcpretty -c + - pod lib lint + - os: osx + osx_image: xcode9 + language: generic + env: + - JOB=SPM + script: + - swift --version + - swift build + - swift test + - os: linux + language: generic + env: + - JOB=Linux + - SWIFT_VERSION=4.0.3 + script: + - swift --version + - swift build + - swift test + sudo: required + dist: trusty + install: + - eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)" notifications: email: false From f4c5df23b96b1332fd94446c1272ec6a2cce90a5 Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 12:30:04 +0000 Subject: [PATCH 09/11] Add Travis CI badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 13c472b..9ca2ccd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # JSONRPCKit +[![Build Status](https://travis-ci.org/bricklife/JSONRPCKit.svg?branch=master)](https://travis-ci.org/bricklife/JSONRPCKit) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CocoaPods](https://img.shields.io/cocoapods/v/JSONRPCKit.svg)](https://cocoapods.org/) From 9947365cbe9ffd12c991d1e6c693b71245137890 Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 12:32:17 +0000 Subject: [PATCH 10/11] Remove tabs --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6219b30..d4800cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,10 +15,10 @@ matrix: - JOB=Xcode script: - set -o pipefail - - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit | xcpretty -c - - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk iphonesimulator -destination "name=iPhone SE" | xcpretty -c - - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk appletvsimulator -destination "name=Apple TV 1080p" | xcpretty -c - - xcodebuild build -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk watchsimulator | xcpretty -c + - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit | xcpretty -c + - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk iphonesimulator -destination "name=iPhone SE" | xcpretty -c + - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk appletvsimulator -destination "name=Apple TV 1080p" | xcpretty -c + - xcodebuild build -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk watchsimulator | xcpretty -c - pod lib lint - os: osx osx_image: xcode9 From 3bdb47797455f33319e34e68745526596d06a66f Mon Sep 17 00:00:00 2001 From: Shinichiro Oba Date: Thu, 18 Jan 2018 12:41:28 +0000 Subject: [PATCH 11/11] Fix tests for Linux --- Tests/JSONRPCKitTests/BatchElementTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/JSONRPCKitTests/BatchElementTests.swift b/Tests/JSONRPCKitTests/BatchElementTests.swift index 2290131..d498073 100644 --- a/Tests/JSONRPCKitTests/BatchElementTests.swift +++ b/Tests/JSONRPCKitTests/BatchElementTests.swift @@ -108,7 +108,7 @@ class BatchElementTests: XCTestCase { XCTFail() } catch { let error = error as? JSONRPCError - if case .responseError(let code, let message, let data as [String: AnyObject])? = error { + if case .responseError(let code, let message, let data as [String: Any])? = error { XCTAssertEqual(code, 123) XCTAssertEqual(message, "abc") XCTAssertEqual(data["key"] as? String, "value") @@ -146,7 +146,7 @@ class BatchElementTests: XCTestCase { XCTFail() } catch { let error = error as? JSONRPCError - if case .responseError(let code, let message, let data as [String: AnyObject])? = error { + if case .responseError(let code, let message, let data as [String: Any])? = error { XCTAssertEqual(code, 123) XCTAssertEqual(message, "abc") XCTAssertEqual(data["key"] as? String, "value")