From 440a6dcbcaf6708b777122294714482f6b159c99 Mon Sep 17 00:00:00 2001 From: Orkhan Alikhanov Date: Sun, 10 Nov 2019 21:35:13 +0400 Subject: [PATCH] Update for swift 5 --- .gitignore | 4 +++- .swift-version | 1 - .travis.yml | 21 +++------------- Cartfile | 2 +- Http.swift.podspec | 5 ++-- HttpSwift.xcodeproj/project.pbxproj | 19 ++++++++------- .../xcshareddata/xcschemes/HttpSwift.xcscheme | 24 ++++++++----------- Package.swift | 4 ++-- README.md | 6 ++--- Sources/Frameworks/RequestSwift | 2 +- Sources/Frameworks/SocketSwift | 2 +- Sources/Route.swift | 10 ++++---- Sources/Server.swift | 2 +- Sources/StaticServer.swift | 8 +++---- Tests/HttpSwiftTests/HttpSwiftTests.swift | 2 +- 15 files changed, 49 insertions(+), 63 deletions(-) delete mode 100644 .swift-version diff --git a/.gitignore b/.gitignore index 0b7259c..7e3e7e4 100644 --- a/.gitignore +++ b/.gitignore @@ -165,4 +165,6 @@ playground.xcworkspace # ignore cocoapod generated files Pods Podfile.lock -HttpSwift.xcworkspace \ No newline at end of file +HttpSwift.xcworkspace +Package.resolved +.swiftpm diff --git a/.swift-version b/.swift-version deleted file mode 100644 index 8a36cd1..0000000 --- a/.swift-version +++ /dev/null @@ -1 +0,0 @@ -4.1 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 15c850f..a8d7224 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,27 +10,12 @@ matrix: - sourceline: 'deb [trusted=yes] http://apt.orkhanalikhanov.com ./' packages: - libressl - install: eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)" + env: SWIFT_VERSION=5.0 + install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" script: env LD_LIBRARY_PATH='/usr/local/lib:/usr/local/opt/libressl/lib:$LD_LIBRARY_PATH' swift test - os: osx osx_image: xcode11.2 dist: trusty sudo: required - env: ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' - script: set -o pipefail && xcodebuild -project HttpSwift.xcodeproj -scheme HttpSwift -destination "$DESTINATION" $ACTION | xcpretty - - - os: osx - osx_image: xcode11.2 - dist: trusty - sudo: required - env: ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 11' - script: set -o pipefail && xcodebuild -project HttpSwift.xcodeproj -scheme HttpSwift -destination "$DESTINATION" $ACTION | xcpretty - - - os: osx - osx_image: xcode11.2 - dist: trusty - sudo: required - env: ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV' - script: set -o pipefail && xcodebuild -project HttpSwift.xcodeproj -scheme HttpSwift -destination "$DESTINATION" $ACTION | xcpretty - + script: set -o pipefail && xcodebuild -scheme RequestSwift -destination "platform=OS X" test | xcpretty && xcodebuild -scheme RequestSwift -destination "platform=iOS Simulator,name=iPhone 11" test | xcpretty && xcodebuild -scheme RequestSwift -destination "platform=tvOS Simulator,name=Apple TV" test | xcpretty diff --git a/Cartfile b/Cartfile index d2cc9db..f8ccf59 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "BiAtoms/Socket.swift" ~> 2.2 \ No newline at end of file +github "BiAtoms/Socket.swift" ~> 2.3.0 diff --git a/Http.swift.podspec b/Http.swift.podspec index 6f44f06..e1b8041 100644 --- a/Http.swift.podspec +++ b/Http.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Http.swift' - s.version = '2.1.2' + s.version = '2.2.0' s.summary = 'A tiny http server engine written in swift.' s.homepage = 'https://github.com/BiAtoms/Http.swift' s.license = { :type => 'MIT', :file => 'LICENSE' } @@ -8,9 +8,10 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/BiAtoms/Http.swift.git', :tag => s.version.to_s } s.module_name = 'HttpSwift' + s.swift_versions = ['5.0'] s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.9' s.tvos.deployment_target = '9.0' s.source_files = 'Sources/*.swift' - s.dependency 'Socket.swift', '~> 2.2' + s.dependency 'Socket.swift', '~> 2.3' end diff --git a/HttpSwift.xcodeproj/project.pbxproj b/HttpSwift.xcodeproj/project.pbxproj index 6b6ea02..7ff4374 100644 --- a/HttpSwift.xcodeproj/project.pbxproj +++ b/HttpSwift.xcodeproj/project.pbxproj @@ -287,27 +287,28 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1110; ORGANIZATIONNAME = BiAtoms; TargetAttributes = { 9DDDF8451F0C14CF00C3D4A6 = { CreatedOnToolsVersion = 8.3.2; - LastSwiftMigration = 0900; + LastSwiftMigration = 1110; ProvisioningStyle = Automatic; }; 9DDDF84E1F0C14CF00C3D4A6 = { CreatedOnToolsVersion = 8.3.2; - LastSwiftMigration = 0900; + LastSwiftMigration = 1110; ProvisioningStyle = Automatic; }; }; }; buildConfigurationList = 9DDDF8401F0C14CF00C3D4A6 /* Build configuration list for PBXProject "HttpSwift" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = 9DDDF83C1F0C14CF00C3D4A6; productRefGroup = 9DDDF8471F0C14CF00C3D4A6 /* Products */; @@ -425,6 +426,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -490,6 +492,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; @@ -562,7 +565,7 @@ SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -583,7 +586,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -600,7 +603,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -617,7 +620,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/HttpSwift.xcodeproj/xcshareddata/xcschemes/HttpSwift.xcscheme b/HttpSwift.xcodeproj/xcshareddata/xcschemes/HttpSwift.xcscheme index ce91a69..f546695 100644 --- a/HttpSwift.xcodeproj/xcshareddata/xcschemes/HttpSwift.xcscheme +++ b/HttpSwift.xcodeproj/xcshareddata/xcschemes/HttpSwift.xcscheme @@ -1,6 +1,6 @@ + + + + @@ -39,17 +48,6 @@ - - - - - - - - ' do - pod 'Http.swift', '~> 2.1' + pod 'Http.swift', '~> 2.2.0' end ``` @@ -72,7 +72,7 @@ $ brew install carthage To integrate Http.swift into your Xcode project using Carthage, specify it in your `Cartfile`: ```ogdl -github "BiAtoms/Http.swift" ~> 2.1 +github "BiAtoms/Http.swift" ~> 2.2.0 ``` Run `carthage update` to build the framework and drag the built `HttpSwift.framework` into your Xcode project. @@ -85,7 +85,7 @@ Once you have your Swift package set up, adding Http.swift as a dependency is as ```swift dependencies: [ - .package(url: "https://github.com/BiAtoms/Http.swift.git", from: "2.0.0") + .package(url: "https://github.com/BiAtoms/Http.swift.git", from: "2.2.0") ] ``` diff --git a/Sources/Frameworks/RequestSwift b/Sources/Frameworks/RequestSwift index 77a1c32..47cea3d 160000 --- a/Sources/Frameworks/RequestSwift +++ b/Sources/Frameworks/RequestSwift @@ -1 +1 @@ -Subproject commit 77a1c321ed092e39776317b4d25bb3337b9a2909 +Subproject commit 47cea3de9cb961f77c659a27894d32454b42e25f diff --git a/Sources/Frameworks/SocketSwift b/Sources/Frameworks/SocketSwift index e3b03cd..36911c1 160000 --- a/Sources/Frameworks/SocketSwift +++ b/Sources/Frameworks/SocketSwift @@ -1 +1 @@ -Subproject commit e3b03cdc7ec094fa4cc2d4c48255dd3b6e30f14d +Subproject commit 36911c13adfe12859ed43dcba878052b1897fcd3 diff --git a/Sources/Route.swift b/Sources/Route.swift index 82c6a7f..a47bd27 100644 --- a/Sources/Route.swift +++ b/Sources/Route.swift @@ -10,11 +10,11 @@ import Foundation public typealias RouteHandler = (Request) throws -> Response open class Route { - open let method: String - open let path: String - open let paramNames: [String] - open let regexPattern: String - open let handler: RouteHandler + public let method: String + public let path: String + public let paramNames: [String] + public let regexPattern: String + public let handler: RouteHandler open var middlewares: [MiddlewareHandler] = [] public init(method: String, path: String, handler: @escaping RouteHandler) { diff --git a/Sources/Server.swift b/Sources/Server.swift index 683247e..5710e6e 100644 --- a/Sources/Server.swift +++ b/Sources/Server.swift @@ -13,7 +13,7 @@ import SocketSwift public typealias MiddlewareHandler = (_ request: Request, _ closure: RouteHandler) throws -> Response open class Server { - open let queue = DispatchQueue(label: "com.biatoms.server-swift." + UUID().uuidString) + public let queue = DispatchQueue(label: "com.biatoms.server-swift." + UUID().uuidString) open var router = Router() open var socket: Socket! open var errorHandler: ErrorHandler.Type = ErrorHandler.self diff --git a/Sources/StaticServer.swift b/Sources/StaticServer.swift index 56a5ce7..1b668ee 100644 --- a/Sources/StaticServer.swift +++ b/Sources/StaticServer.swift @@ -9,7 +9,7 @@ import Foundation open class StaticServer { - open static func serveFile(at path: String) throws -> Response { + public static func serveFile(at path: String) throws -> Response { let file = File(path: path) if file.exists { return Response(.ok, body: file.bytes) @@ -17,12 +17,12 @@ open class StaticServer { throw ServerError.httpRouteNotFound } - open static func serveFile(in directory: String, path: String) throws -> Response { + public static func serveFile(in directory: String, path: String) throws -> Response { let path = directory.expandingTildeInPath.appendingPathComponent(path) return try serveFile(at: path) } - open static func fileBrowser(in directory: String, path subpath: String) throws -> Response { + public static func fileBrowser(in directory: String, path subpath: String) throws -> Response { let path = directory.expandingTildeInPath.appendingPathComponent(subpath) if let contents = try? FileManager.default.contentsOfDirectory(atPath: path) { return renderBrowser(for: subpath, content: contents) @@ -30,7 +30,7 @@ open class StaticServer { return try serveFile(at: path) } - open static func renderBrowser(for path: String, content: [String]) -> Response { + public static func renderBrowser(for path: String, content: [String]) -> Response { func wrap(_ tag: String, newLine: Bool = true, attrs: [String: String] = [:], _ content: () -> String) -> String { return "<\(tag)\(attrs.reduce("") { $0 + " \($1.key)=\"\($1.value)\"" })>\(newLine ? "\n" : "")\(content())\n" } diff --git a/Tests/HttpSwiftTests/HttpSwiftTests.swift b/Tests/HttpSwiftTests/HttpSwiftTests.swift index a808332..18f3256 100644 --- a/Tests/HttpSwiftTests/HttpSwiftTests.swift +++ b/Tests/HttpSwiftTests/HttpSwiftTests.swift @@ -32,7 +32,7 @@ class HttpSwiftTests: XCTestCase { let keyPath = rootPath.appendingPathExtension("key") let certPath = (path, keyPath, nil as String?) #else - let path = Bundle(for: HttpSwiftTests.self).url(forResource: "Http.swift", withExtension: "pfx")! + let path = Bundle(for: HttpSwiftTests.self).url(forResource: "Http.swift", withExtension: "pfx") ?? URL(string: NSString(string: URL(string: #file)!.appendingPathComponent("../../Http.swift.pfx").absoluteString).standardizingPath)! let certPath = (path, "orkhan1234") #endif try! server.run(port: 4443, certifiatePath: certPath)