Skip to content
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

Add Swift Package Manager support #1177

Merged
merged 10 commits into from
Dec 31, 2020
69 changes: 40 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
osx_image: xcode9.3
language: objective-c

cache:
directories:
- Carthage
- Xcode/Testing-iOS/Pods
- Xcode/Testing-macOS/Pods
jobs:
include:
- stage: Swift PM
osx_image: xcode11.5
script:
# Build the project using Swift PM
- swift build
# Test the project using Swift PM
- swift test

before_install:
# - brew update
# - brew outdated carthage || brew upgrade carthage
- export IOS_SIMULATOR_DESTINATION="platform=iOS Simulator,name=iPhone 8,OS=11.3"
- stage: Xcode Tests
osx_image: xcode9.3
cache:
directories:
- Carthage
- Xcode/Testing-iOS/Pods
- Xcode/Testing-macOS/Pods

install:
- carthage bootstrap --no-build
- cd Xcode
- bundle install
- bundle exec pod repo update --silent
- bundle exec pod install --project-directory=Testing-iOS/
- bundle exec pod install --project-directory=Testing-macOS/
- cd ../
before_install:
# - brew update
# - brew outdated carthage || brew upgrade carthage
- export IOS_SIMULATOR_DESTINATION="platform=iOS Simulator,name=iPhone 8,OS=11.3"

before_script:
- set -o pipefail
install:
- carthage bootstrap --no-build
- cd Xcode
- bundle install
- bundle exec pod repo update --silent
- bundle exec pod install --project-directory=Testing-iOS/
- bundle exec pod install --project-directory=Testing-macOS/
- cd ../

script:
- xcodebuild -workspace Xcode/Testing-macOS/XMPPFrameworkTests.xcworkspace -scheme XMPPFrameworkTests -sdk macosx -destination 'platform=OS X,arch=x86_64' test | xcpretty -c
- travis_retry xcodebuild -workspace Xcode/Testing-iOS/XMPPFrameworkTests.xcworkspace -scheme XMPPFrameworkTests -sdk iphonesimulator -destination "$IOS_SIMULATOR_DESTINATION" test | xcpretty -c
- xcodebuild -workspace Xcode/Testing-macOS/XMPPFrameworkTests.xcworkspace -scheme XMPPFrameworkSwiftTests -sdk macosx -destination 'platform=OS X,arch=x86_64' test | xcpretty -c
- travis_retry xcodebuild -workspace Xcode/Testing-iOS/XMPPFrameworkTests.xcworkspace -scheme XMPPFrameworkSwiftTests -sdk iphonesimulator -destination "$IOS_SIMULATOR_DESTINATION" test | xcpretty -c
before_script:
- set -o pipefail

- xcodebuild -project XMPPFramework.xcodeproj -scheme "XMPPFramework (tvOS)" -sdk appletvsimulator -arch x86_64 build | xcpretty -c
- xcodebuild -project Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj -scheme "XMPPFrameworkTests (macOS)" -sdk macosx -arch x86_64 test | xcpretty -c
- xcodebuild -project Xcode/Testing-Carthage/XMPPFrameworkSwiftTests.xcodeproj -scheme "XMPPFrameworkTests (macOS)" -sdk macosx -arch x86_64 test | xcpretty -c
- travis_retry xcodebuild -project Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj -scheme "XMPPFrameworkTests (iOS)" -sdk iphonesimulator -destination "$IOS_SIMULATOR_DESTINATION" test | xcpretty -c
script:
- xcodebuild -workspace Xcode/Testing-macOS/XMPPFrameworkTests.xcworkspace -scheme XMPPFrameworkTests -sdk macosx -destination 'platform=OS X,arch=x86_64' test | xcpretty -c
- travis_retry xcodebuild -workspace Xcode/Testing-iOS/XMPPFrameworkTests.xcworkspace -scheme XMPPFrameworkTests -sdk iphonesimulator -destination "$IOS_SIMULATOR_DESTINATION" test | xcpretty -c
- xcodebuild -workspace Xcode/Testing-macOS/XMPPFrameworkTests.xcworkspace -scheme XMPPFrameworkSwiftTests -sdk macosx -destination 'platform=OS X,arch=x86_64' test | xcpretty -c
- travis_retry xcodebuild -workspace Xcode/Testing-iOS/XMPPFrameworkTests.xcworkspace -scheme XMPPFrameworkSwiftTests -sdk iphonesimulator -destination "$IOS_SIMULATOR_DESTINATION" test | xcpretty -c

- xcodebuild -project XMPPFramework.xcodeproj -scheme "XMPPFramework (tvOS)" -sdk appletvsimulator -arch x86_64 build | xcpretty -c
- xcodebuild -project Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj -scheme "XMPPFrameworkTests (macOS)" -sdk macosx -arch x86_64 test | xcpretty -c
- xcodebuild -project Xcode/Testing-Carthage/XMPPFrameworkSwiftTests.xcodeproj -scheme "XMPPFrameworkTests (macOS)" -sdk macosx -arch x86_64 test | xcpretty -c
- travis_retry xcodebuild -project Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj -scheme "XMPPFrameworkTests (iOS)" -sdk iphonesimulator -destination "$IOS_SIMULATOR_DESTINATION" test | xcpretty -c
105 changes: 105 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// swift-tools-version:5.1
import PackageDescription

let package = Package(
name: "XMPPFramework",
platforms: [
.macOS(.v10_10),
.iOS(.v8),
.tvOS(.v9)
],
products: [
.library(
name: "XMPPFramework",
targets: ["XMPPFramework"]
),
.library(
name: "XMPPFrameworkSwift",
targets: ["XMPPFrameworkSwift"]
)
],
dependencies: [
.package(url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", .upToNextMajor(from: "3.6.1")),
.package(url: "https://github.com/robbiehanson/CocoaAsyncSocket.git", .upToNextMajor(from: "7.6.4")),
.package(url: "https://github.com/karimhm/KissXML.git", .branch("swift-pm")),
.package(url: "https://github.com/karimhm/libidn-framework.git", .branch("swift_pm"))
karimhm marked this conversation as resolved.
Show resolved Hide resolved
],
targets: [
.target(
name: "XMPPFramework",
dependencies: [
"CocoaLumberjack",
"CocoaAsyncSocket",
"KissXML",
"libidn"
],
path: ".",
exclude: [
"Swift",
"Xcode",
],
publicHeadersPath: "include/XMPPFramework",
linkerSettings: [
.linkedLibrary("xml2"),
.linkedLibrary("resolv")
]
),
.target(
name: "XMPPFrameworkSwift",
dependencies: [
"XMPPFramework",
"CocoaLumberjackSwift"
],
path: "Swift"
),
.target(
name: "XMPPFrameworkTestsShared",
dependencies: [
"XMPPFramework"
],
path: "Xcode/Testing-Shared",
sources: [
"XMPPMockStream.m"
],
publicHeadersPath: "."
),
.testTarget(
name: "XMPPFrameworkTests",
dependencies: [
"XMPPFramework",
"XMPPFrameworkTestsShared"
],
path: "Xcode/Testing-Shared",
exclude: [
"XMPPMockStream.m",
"XMPPvCardTests.m",
"XMPPRoomLightCoreDataStorageTests.m",
karimhm marked this conversation as resolved.
Show resolved Hide resolved
"XMPPBookmarksTests.swift",
"XMPPPushTests.swift",
"XMPPStanzaIdTests.swift",
"XMPPSwift.swift"
]
),
.testTarget(
name: "XMPPFrameworkSwiftTests",
dependencies: [
"XMPPFramework",
"XMPPFrameworkSwift",
"XMPPFrameworkTestsShared"
],
path: "Xcode",
exclude: [
"XMPPFrameworkTests-Bridging-Header.h"
],
sources: [
"Testing-Shared/XMPPBookmarksTests.swift",
"Testing-Shared/XMPPPushTests.swift",
"Testing-Shared/XMPPStanzaIdTests.swift",
"Testing-Shared/XMPPSwift.swift",
"Testing-Swift/XMPPBookmarksModuleTests.swift",
"Testing-Swift/XMPPPresenceTests.swift",
"Testing-Swift/XMPPvCardTempTests.swift"
]
)
]
)
4 changes: 2 additions & 2 deletions Swift/Core/XMLElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public extension XMLElement {

// MARK: Extracting a single element.

public func element(forName name: String) -> XMLElement? {
func element(forName name: String) -> XMLElement? {
let elements = self.elements(forName: name)
return elements.first
}

public func element(forName name: String, xmlns: String) -> XMLElement? {
func element(forName name: String, xmlns: String) -> XMLElement? {
let elements = self.elements(forLocalName: name, uri: xmlns)
return elements.first
}
Expand Down
9 changes: 6 additions & 3 deletions Swift/Core/XMPPIQ.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
//

import Foundation
#if canImport(XMPPFramework)
import XMPPFramework
#endif

public extension XMPPIQ {
public enum IQType: String {
enum IQType: String {
case get
case set
case result
case error
}

public var iqType: IQType? {
var iqType: IQType? {
guard let type = self.type else { return nil }
let iqType = IQType(rawValue: type)
return iqType
}

public convenience init(iqType: IQType,
convenience init(iqType: IQType,
to JID: XMPPJID? = nil,
elementID eid: String? = nil,
child childElement: XMLElement? = nil) {
Expand Down
9 changes: 6 additions & 3 deletions Swift/Core/XMPPMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@
//

import Foundation
#if canImport(XMPPFramework)
import XMPPFramework
#endif

public extension XMPPMessage {
public enum MessageType: String {
enum MessageType: String {
case chat
case error
case groupchat
case headline
case normal
}

public var messageType: MessageType? {
var messageType: MessageType? {
guard let type = self.type else {
return nil
}
return MessageType(rawValue: type)
}

public convenience init(messageType: MessageType? = nil,
convenience init(messageType: MessageType? = nil,
to: XMPPJID? = nil,
elementID: String? = nil,
child: XMLElement? = nil) {
Expand Down
9 changes: 6 additions & 3 deletions Swift/Core/XMPPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(XMPPFramework)
import XMPPFramework
#endif

// MARK: - Multicast Delegate
public extension XMPPModule {
Expand All @@ -30,7 +33,7 @@ public extension XMPPModule {
* multicast.xmppBookmarks!(self, didNotRetrieveBookmarks: obj as? XMPPIQ)
* })
*/
public var multicast: GCDMulticastDelegate {
var multicast: GCDMulticastDelegate {
return __multicastDelegate as! GCDMulticastDelegate
}

Expand All @@ -47,7 +50,7 @@ public extension XMPPModule {
* multicastDelegate.xmppBookmarks!(self, didRetrieve: bookmarks, responseIq: responseIq)
*
*/
public var multicastDelegate: AnyObject {
var multicastDelegate: AnyObject {
return __multicastDelegate as AnyObject
}
}
Expand All @@ -66,7 +69,7 @@ public extension XMPPModule {
* else
* dispatch_sync(moduleQueue, block); (or dispatch_async)
*/
public func performBlock(async: Bool = false, _ block: @escaping ()->()) {
func performBlock(async: Bool = false, _ block: @escaping ()->()) {
if async {
__performBlockAsync(block)
} else {
Expand Down
13 changes: 8 additions & 5 deletions Swift/Core/XMPPPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
//

import Foundation
#if canImport(XMPPFramework)
import XMPPFramework
#endif

public extension XMPPPresence {
/// The 'type' attribute of a presence stanza is OPTIONAL. A presence stanza that does not possess a 'type' attribute is used to signal to the server that the sender is online and available for communication. If included, the 'type' attribute specifies a lack of availability, a request to manage a subscription to another entity's presence, a request for another entity's current presence, or an error related to a previously-sent presence stanza. If included, the 'type' attribute MUST have one of the following values
public enum PresenceType: String {
enum PresenceType: String {
/// Signals that the entity is no longer available for communication.
case unavailable
/// The sender wishes to subscribe to the recipient's presence.
Expand All @@ -28,7 +31,7 @@ public extension XMPPPresence {
}

/// The OPTIONAL <show/> element contains non-human-readable XML character data that specifies the particular availability status of an entity or specific resource. A presence stanza MUST NOT contain more than one <show/> element. The <show/> element MUST NOT possess any attributes. If provided, the XML character data value MUST be one of the following (additional availability types could be defined through a properly-namespaced child element of the presence stanza):
public enum ShowType: String {
enum ShowType: String {
/// The entity or resource is busy (dnd = "Do Not Disturb").
case dnd
/// The entity or resource is away for an extended period (xa = "eXtended Away").
Expand All @@ -53,21 +56,21 @@ public extension XMPPPresence {
}
}

public var showType: ShowType? {
var showType: ShowType? {
guard let show = self.show else {
return nil
}
return ShowType(rawValue: show)
}

public var presenceType: PresenceType? {
var presenceType: PresenceType? {
guard let type = self.type else {
return nil
}
return PresenceType(rawValue: type)
}

public convenience init(type: PresenceType? = nil,
convenience init(type: PresenceType? = nil,
show: ShowType? = nil,
status: String? = nil,
to jid: XMPPJID? = nil) {
Expand Down
7 changes: 5 additions & 2 deletions Swift/Utilities/GCDMulticastDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
#if canImport(XMPPFramework)
import XMPPFramework
#endif

/**
* This helper makes it slightly easier to call the MulticastDelegate
Expand All @@ -21,15 +24,15 @@ import Foundation
*
* This will prevent your code from crashing during the forced cast.
*/
extension GCDMulticastDelegate {
public extension GCDMulticastDelegate {
/**
* This is a helper mainly to provide better code completion.
*
* multicast.invoke(ofType: XMPPBookmarksDelegate.self, { (multicast) in
* multicast.xmppBookmarks!(self, didNotRetrieveBookmarks: obj as? XMPPIQ)
* })
*/
public func invoke<T>(ofType: T.Type, _ invocation: (_ multicast: T) -> ()) {
func invoke<T>(ofType: T.Type, _ invocation: (_ multicast: T) -> ()) {
// Crashing here? See the documentation above.
// You must implement a stub extension on GCDMulticastDelegate conforming to the
// delegate type you are attempting to downcast.
Expand Down
4 changes: 4 additions & 0 deletions Swift/XEP-0048/XMPPBookmarksModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import Foundation
#else
import CocoaLumberjackSwift
#endif

#if canImport(XMPPFramework)
import XMPPFramework
#endif

@objc public enum XMPPBookmarksMode: Int {
/// Private XML Storage (XEP-0049)
Expand Down
Loading