diff --git a/.github/workflows/masterCI.yml b/.github/workflows/masterCI.yml index d40ff95b..a7f9099e 100644 --- a/.github/workflows/masterCI.yml +++ b/.github/workflows/masterCI.yml @@ -58,6 +58,13 @@ jobs: # working-directory: RollbarPLCrashReporter # run: swift test -v --enable-test-discovery --enable-code-coverage --build-path ../DerivedData + - name: Build RollbarSwift + working-directory: RollbarSwift + run: swift build -v + #- name: Unit Test RollbarSwift + # working-directory: RollbarSwift + # run: swift test -v --enable-test-discovery --enable-code-coverage --build-path ../DerivedData + # - name: Unit Test RollbarCommon # working-directory: RollbarCommon # run: ../SonarCloud/build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir ../DerivedData/compilation-database @@ -77,7 +84,6 @@ jobs: CODE_SIGNING_REQUIRED=NO # clean build - - name: SonarCloud RollbarDeploys run: SonarCloud/build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir DerivedData/compilation-database xcodebuild @@ -130,6 +136,19 @@ jobs: CODE_SIGNING_REQUIRED=NO # clean build + - name: SonarCloud RollbarSwift + run: SonarCloud/build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir DerivedData/compilation-database + xcodebuild + -workspace RollbarSDK.xcworkspace + -scheme RollbarSwift + -derivedDataPath DerivedData + -enableCodeCoverage YES + build + test + CODE_SIGN_IDENTITY="-" + CODE_SIGNING_REQUIRED=NO + # clean build + - name: SonarCloud Test Coverage Conversion run: bash xccov-to-sonarqube-generic.sh DerivedData/Logs/Test/*.xcresult/ > sonarqube-generic-coverage.xml @@ -175,7 +194,7 @@ jobs: # run: swift test -v -# Fron SonarCCloud Docs: +# From SonarCCloud Docs: # Execute the Build Wrapper as a prefix to your build command: # build-wrapper-macosx-x86 --out-dir bw-output diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d8cdce4..a6bb8632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,11 +25,16 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ## Release Notes -**2.0.0** Preliminary Notes +**2.0.0-beta3** +- feat: added RollbarSwift + +**2.0.0-beta2** +- feat: added new developer option: suppressSdkInfoLogging + +**2.0.0-beta1** - comparing to Rollbar-iOS - feat: added RollbarPLCrashReporter module - feat: added RollbarKSCrash module - feat: added explicit reporting of NSErrors -- feat: added new developer option: suppressSdkInfoLogging - feat: defined default scrub fields - refactor: split out RollbarCommon, RollbarNotifier, RollbarDeploys - refactor: added use of lightweight generics diff --git a/Demos/macosAppSwift/macosAppSwift.xcodeproj/project.pbxproj b/Demos/macosAppSwift/macosAppSwift.xcodeproj/project.pbxproj new file mode 100644 index 00000000..c03f8180 --- /dev/null +++ b/Demos/macosAppSwift/macosAppSwift.xcodeproj/project.pbxproj @@ -0,0 +1,368 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 52; + objects = { + +/* Begin PBXBuildFile section */ + 55098C6525FA930D0045C180 /* macosAppSwiftApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55098C6425FA930D0045C180 /* macosAppSwiftApp.swift */; }; + 55098C6725FA930D0045C180 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55098C6625FA930D0045C180 /* ContentView.swift */; }; + 55098C6925FA93110045C180 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 55098C6825FA93110045C180 /* Assets.xcassets */; }; + 55098C6C25FA93110045C180 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 55098C6B25FA93110045C180 /* Preview Assets.xcassets */; }; + 5544A01F25FB074300C710A1 /* RollbarCommon in Frameworks */ = {isa = PBXBuildFile; productRef = 5544A01E25FB074300C710A1 /* RollbarCommon */; }; + 5544A02125FB074300C710A1 /* RollbarNotifier in Frameworks */ = {isa = PBXBuildFile; productRef = 5544A02025FB074300C710A1 /* RollbarNotifier */; }; + 5544A02325FB074300C710A1 /* RollbarSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 5544A02225FB074300C710A1 /* RollbarSwift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 55098C6125FA930D0045C180 /* macosAppSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = macosAppSwift.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 55098C6425FA930D0045C180 /* macosAppSwiftApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = macosAppSwiftApp.swift; sourceTree = ""; }; + 55098C6625FA930D0045C180 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 55098C6825FA93110045C180 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 55098C6B25FA93110045C180 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 55098C6D25FA93110045C180 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 55098C6E25FA93110045C180 /* macosAppSwift.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macosAppSwift.entitlements; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 55098C5E25FA930D0045C180 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5544A01F25FB074300C710A1 /* RollbarCommon in Frameworks */, + 5544A02125FB074300C710A1 /* RollbarNotifier in Frameworks */, + 5544A02325FB074300C710A1 /* RollbarSwift in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 55098C5825FA930D0045C180 = { + isa = PBXGroup; + children = ( + 55098C6325FA930D0045C180 /* macosAppSwift */, + 55098C6225FA930D0045C180 /* Products */, + 5544A01D25FB074300C710A1 /* Frameworks */, + ); + sourceTree = ""; + }; + 55098C6225FA930D0045C180 /* Products */ = { + isa = PBXGroup; + children = ( + 55098C6125FA930D0045C180 /* macosAppSwift.app */, + ); + name = Products; + sourceTree = ""; + }; + 55098C6325FA930D0045C180 /* macosAppSwift */ = { + isa = PBXGroup; + children = ( + 55098C6425FA930D0045C180 /* macosAppSwiftApp.swift */, + 55098C6625FA930D0045C180 /* ContentView.swift */, + 55098C6825FA93110045C180 /* Assets.xcassets */, + 55098C6D25FA93110045C180 /* Info.plist */, + 55098C6E25FA93110045C180 /* macosAppSwift.entitlements */, + 55098C6A25FA93110045C180 /* Preview Content */, + ); + path = macosAppSwift; + sourceTree = ""; + }; + 55098C6A25FA93110045C180 /* Preview Content */ = { + isa = PBXGroup; + children = ( + 55098C6B25FA93110045C180 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; + 5544A01D25FB074300C710A1 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 55098C6025FA930D0045C180 /* macosAppSwift */ = { + isa = PBXNativeTarget; + buildConfigurationList = 55098C7125FA93110045C180 /* Build configuration list for PBXNativeTarget "macosAppSwift" */; + buildPhases = ( + 55098C5D25FA930D0045C180 /* Sources */, + 55098C5E25FA930D0045C180 /* Frameworks */, + 55098C5F25FA930D0045C180 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = macosAppSwift; + packageProductDependencies = ( + 5544A01E25FB074300C710A1 /* RollbarCommon */, + 5544A02025FB074300C710A1 /* RollbarNotifier */, + 5544A02225FB074300C710A1 /* RollbarSwift */, + ); + productName = macosAppSwift; + productReference = 55098C6125FA930D0045C180 /* macosAppSwift.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 55098C5925FA930D0045C180 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1240; + LastUpgradeCheck = 1240; + TargetAttributes = { + 55098C6025FA930D0045C180 = { + CreatedOnToolsVersion = 12.4; + }; + }; + }; + buildConfigurationList = 55098C5C25FA930D0045C180 /* Build configuration list for PBXProject "macosAppSwift" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 55098C5825FA930D0045C180; + productRefGroup = 55098C6225FA930D0045C180 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 55098C6025FA930D0045C180 /* macosAppSwift */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 55098C5F25FA930D0045C180 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 55098C6C25FA93110045C180 /* Preview Assets.xcassets in Resources */, + 55098C6925FA93110045C180 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 55098C5D25FA930D0045C180 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 55098C6725FA930D0045C180 /* ContentView.swift in Sources */, + 55098C6525FA930D0045C180 /* macosAppSwiftApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 55098C6F25FA93110045C180 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 11.1; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 55098C7025FA93110045C180 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 11.1; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 55098C7225FA93110045C180 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = macosAppSwift/macosAppSwift.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_ASSET_PATHS = "\"macosAppSwift/Preview Content\""; + ENABLE_PREVIEWS = YES; + INFOPLIST_FILE = macosAppSwift/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 11.0; + PRODUCT_BUNDLE_IDENTIFIER = com.rollbar.macosAppSwift; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 55098C7325FA93110045C180 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = macosAppSwift/macosAppSwift.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_ASSET_PATHS = "\"macosAppSwift/Preview Content\""; + ENABLE_PREVIEWS = YES; + INFOPLIST_FILE = macosAppSwift/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 11.0; + PRODUCT_BUNDLE_IDENTIFIER = com.rollbar.macosAppSwift; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 55098C5C25FA930D0045C180 /* Build configuration list for PBXProject "macosAppSwift" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 55098C6F25FA93110045C180 /* Debug */, + 55098C7025FA93110045C180 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 55098C7125FA93110045C180 /* Build configuration list for PBXNativeTarget "macosAppSwift" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 55098C7225FA93110045C180 /* Debug */, + 55098C7325FA93110045C180 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 5544A01E25FB074300C710A1 /* RollbarCommon */ = { + isa = XCSwiftPackageProductDependency; + productName = RollbarCommon; + }; + 5544A02025FB074300C710A1 /* RollbarNotifier */ = { + isa = XCSwiftPackageProductDependency; + productName = RollbarNotifier; + }; + 5544A02225FB074300C710A1 /* RollbarSwift */ = { + isa = XCSwiftPackageProductDependency; + productName = RollbarSwift; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 55098C5925FA930D0045C180 /* Project object */; +} diff --git a/Demos/macosAppSwift/macosAppSwift/Assets.xcassets/AccentColor.colorset/Contents.json b/Demos/macosAppSwift/macosAppSwift/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 00000000..eb878970 --- /dev/null +++ b/Demos/macosAppSwift/macosAppSwift/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Demos/macosAppSwift/macosAppSwift/Assets.xcassets/AppIcon.appiconset/Contents.json b/Demos/macosAppSwift/macosAppSwift/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..3f00db43 --- /dev/null +++ b/Demos/macosAppSwift/macosAppSwift/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Demos/macosAppSwift/macosAppSwift/Assets.xcassets/Contents.json b/Demos/macosAppSwift/macosAppSwift/Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/Demos/macosAppSwift/macosAppSwift/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Demos/macosAppSwift/macosAppSwift/ContentView.swift b/Demos/macosAppSwift/macosAppSwift/ContentView.swift new file mode 100644 index 00000000..e5dddf33 --- /dev/null +++ b/Demos/macosAppSwift/macosAppSwift/ContentView.swift @@ -0,0 +1,117 @@ +// +// ContentView.swift +// macosAppSwift +// +// Created by Andrey Kornich on 2021-03-11. +// + +import SwiftUI +import RollbarSwift + +struct ContentView: View { + + var body: some View { + + VStack(content: { + + Text("Hello, world!") + .multilineTextAlignment(.center) + .padding() + + Button("Handle Swift Error") { + self.handleSwiftError() + } + + Button("Handle Obj-C Exception") { + self.handleObjCException() + } + + Button("Handle Obj-C Exception with Rollbar") { + self.handleObjCExceptionWithRollbar() + } + }) + } + +func handleSwiftError() { + + do { + + try self.generateSwiftError(); + } + catch AppError.problem1 { + + } + catch AppError.problem2 { + + } + catch { + + print("Unexpected error: \(error).") + } + } + + func generateSwiftError() throws { + + throw AppError.limitExceeded(limit: 5) + } + + func handleObjCException() { + + do { + + self.generateObjCException(); + } + catch { + + print("Unexpected error: \(error).") + } + } + + func generateObjCException() { + + RollbarTryCatch.throw("NSException from Obj-C...") + } + + func handleObjCExceptionWithRollbar() { + + let exceptionGuard = createGuard(); + + var success = true; + + success = exceptionGuard.tryExecute { + + self.generateObjCException(); + } + + print("Guarded execution succeeded: \(success).") + } + + func createGuard() -> RollbarExceptionGuard { + + let config = RollbarConfig(); + config.destination.accessToken = "2ffc7997ed864dda94f63e7b7daae0f3"; + config.destination.environment = "samples"; + config.developerOptions.transmit = true; + + let logger = RollbarLogger(configuration: config); + + let exceptionGuard = RollbarExceptionGuard(logger: logger); + + return exceptionGuard; + } +} + +struct ContentView_Previews: PreviewProvider { + + static var previews: some View { + + ContentView() + } +} + +// Declare our error type +enum AppError: Error { + case problem1 + case problem2 + case limitExceeded(limit: Int) +} diff --git a/Demos/macosAppSwift/macosAppSwift/Info.plist b/Demos/macosAppSwift/macosAppSwift/Info.plist new file mode 100644 index 00000000..69c84ae7 --- /dev/null +++ b/Demos/macosAppSwift/macosAppSwift/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + + diff --git a/Demos/macosAppSwift/macosAppSwift/Preview Content/Preview Assets.xcassets/Contents.json b/Demos/macosAppSwift/macosAppSwift/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/Demos/macosAppSwift/macosAppSwift/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Demos/macosAppSwift/macosAppSwift/macosAppSwift.entitlements b/Demos/macosAppSwift/macosAppSwift/macosAppSwift.entitlements new file mode 100644 index 00000000..40b639e4 --- /dev/null +++ b/Demos/macosAppSwift/macosAppSwift/macosAppSwift.entitlements @@ -0,0 +1,14 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + com.apple.security.network.client + + com.apple.security.network.server + + + diff --git a/Demos/macosAppSwift/macosAppSwift/macosAppSwiftApp.swift b/Demos/macosAppSwift/macosAppSwift/macosAppSwiftApp.swift new file mode 100644 index 00000000..e4fa59d3 --- /dev/null +++ b/Demos/macosAppSwift/macosAppSwift/macosAppSwiftApp.swift @@ -0,0 +1,17 @@ +// +// macosAppSwiftApp.swift +// macosAppSwift +// +// Created by Andrey Kornich on 2021-03-11. +// + +import SwiftUI + +@main +struct macosAppSwiftApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/Package.swift b/Package.swift index de35d7bf..3ea63de5 100644 --- a/Package.swift +++ b/Package.swift @@ -29,6 +29,9 @@ let package = Package( .library( name: "RollbarPLCrashReporter", targets: ["RollbarPLCrashReporter"]), + .library( + name: "RollbarSwift", + targets: ["RollbarSwift"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -95,6 +98,15 @@ let package = Package( ] ), + .target( + name: "RollbarSwift", + dependencies: ["RollbarCommon", "RollbarNotifier"], + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("RollbarSwift/Sources/RollbarSwift/**"), + ] + ), + ], swiftLanguageVersions: [ SwiftVersion.v4, diff --git a/RollbarCommon.podspec b/RollbarCommon.podspec index f4fbcf9a..9e9f1317 100644 --- a/RollbarCommon.podspec +++ b/RollbarCommon.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta2" + s.version = "2.0.0-beta3" s.name = "RollbarCommon" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarDeploys.podspec b/RollbarDeploys.podspec index 0e06671d..1b716f40 100644 --- a/RollbarDeploys.podspec +++ b/RollbarDeploys.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta2" + s.version = "2.0.0-beta3" s.name = "RollbarDeploys" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarKSCrash.podspec b/RollbarKSCrash.podspec index c040fc21..22e0242a 100644 --- a/RollbarKSCrash.podspec +++ b/RollbarKSCrash.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta2" + s.version = "2.0.0-beta3" s.name = "RollbarKSCrash" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarNotifier.podspec b/RollbarNotifier.podspec index d52b2644..add9883e 100644 --- a/RollbarNotifier.podspec +++ b/RollbarNotifier.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta2" + s.version = "2.0.0-beta3" s.name = "RollbarNotifier" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m index e5cb9d17..c6ffa5b6 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m +++ b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m @@ -22,7 +22,7 @@ #pragma mark - constants -static NSString * const NOTIFIER_VERSION = @"2.0.0-beta2"; +static NSString * const NOTIFIER_VERSION = @"2.0.0-beta3"; static NSString * const NOTIFIER_NAME = @"rollbar-apple"; diff --git a/RollbarPLCrashReporter.podspec b/RollbarPLCrashReporter.podspec index 2de70c78..ccf775d3 100644 --- a/RollbarPLCrashReporter.podspec +++ b/RollbarPLCrashReporter.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta2" + s.version = "2.0.0-beta3" s.name = "RollbarPLCrashReporter" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarSDK.experimental_podspec b/RollbarSDK.experimental_podspec index 57b51a3b..5781e1a5 100644 --- a/RollbarSDK.experimental_podspec +++ b/RollbarSDK.experimental_podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |sdk| # Rollbar SDK: # ============ - sdk.version = "2.0.0-beta2" + sdk.version = "2.0.0-beta3" sdk.name = "RollbarSDK" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." sdk.description = <<-DESC @@ -234,4 +234,44 @@ Pod::Spec.new do |sdk| plcrash.tvos.user_target_xcconfig = { "ONLY_ACTIVE_ARCH" => "YES", "EXCLUDED_ARCHS[sdk=appletvsimulator*]" => "arm64" } end + # RollbarSwift module: + # ===================== + sdk.subspec "RollbarSwift" do |swift| + swift.name = "RollbarSwift" + + # Any platform, if omitted: + # swift.platform = :ios + # swift.platform = :ios, "5.0" + + # When using multiple platforms: + # swift.ios.deployment_target = "9.0" + # swift.osx.deployment_target = "10.10" + # swift.tvos.deployment_target = "11.0" + # swift.watchos.deployment_target = "4.0" + + swift.source_files = "RollbarSwift/Sources/RollbarSwift/**/*.{h,m}" + # swift.exclude_files = "Classes/Exclude" + swift.public_header_files = "RollbarSwift/Sources/RollbarSwift/include/*.h" + # swift.module_map = "RollbarSwift/Sources/RollbarSwift/include/module.modulemap" + # swift.resource = "../rollbar-logo.png" + # swift.resources = "Resources/*.png" + # swift.preserve_paths = "FilesToSave", "MoreFilesToSave" + + swift.dependency "RollbarSDK/RollbarCommon" + swift.framework = "Foundation" + # swift.frameworks = "SomeFramework", "AnotherFramework" + # swift.library = "iconv" + # swift.libraries = "iconv", "xml2" + # swift.dependency "JSONKit", "~> 1.4" + swift.requires_arc = true + # swift.xcconfig = { + # "USE_HEADERMAP" => "NO", + # "HEADER_SEARCH_PATHS" => "$(PODS_ROOT)/Sources/RollbarSwift/**" + # } + swift.pod_target_xcconfig = { "ONLY_ACTIVE_ARCH" => "YES", "EXCLUDED_ARCHS[sdk=iphonesimulator*]" => "arm64" } + swift.user_target_xcconfig = { "ONLY_ACTIVE_ARCH" => "YES", "EXCLUDED_ARCHS[sdk=iphonesimulator*]" => "arm64" } + swift.tvos.pod_target_xcconfig = { "ONLY_ACTIVE_ARCH" => "YES", "EXCLUDED_ARCHS[sdk=appletvsimulator*]" => "arm64" } + swift.tvos.user_target_xcconfig = { "ONLY_ACTIVE_ARCH" => "YES", "EXCLUDED_ARCHS[sdk=appletvsimulator*]" => "arm64" } + end + end diff --git a/RollbarSDK.xcworkspace/contents.xcworkspacedata b/RollbarSDK.xcworkspace/contents.xcworkspacedata index da44fc63..7bbc2d69 100644 --- a/RollbarSDK.xcworkspace/contents.xcworkspacedata +++ b/RollbarSDK.xcworkspace/contents.xcworkspacedata @@ -4,6 +4,12 @@ + + + + @@ -37,6 +43,9 @@ + + @@ -56,6 +65,9 @@ + + @@ -72,6 +84,9 @@ + + diff --git a/RollbarSwift.podspec b/RollbarSwift.podspec new file mode 100644 index 00000000..0c040238 --- /dev/null +++ b/RollbarSwift.podspec @@ -0,0 +1,69 @@ +# +# Be sure to run `pod spec lint RollbarSDK.podspec' to ensure this is a valid spec. +# +# To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html +# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ +# + +Pod::Spec.new do |s| + + s.version = "2.0.0-beta3" + s.name = "RollbarSwift" + s.summary = "Application or client side SDK for interacting with the Rollbar API Server." + s.description = <<-DESC + Find, fix, and resolve errors with Rollbar. + Easily send error data using Rollbar API. + Analyze, de-dupe, send alerts, and prepare the data for further analysis. + Search, sort, and prioritize via the Rollbar dashboard. + DESC + s.homepage = "https://rollbar.com" + # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" + s.license = { :type => "MIT", :file => "LICENSE" } + # s.license = "MIT (example)" + s.documentation_url = "https://docs.rollbar.com/docs/ios" + s.authors = { "Andrey Kornich (Wide Spectrum Computing LLC)" => "akornich@gmail.com", + "Rollbar" => "support@rollbar.com" } + # s.author = { "Andrey Kornich" => "akornich@gmail.com" } + # Or just: s.author = "Andrey Kornich" + s.social_media_url = "http://twitter.com/rollbar" + s.source = { :git => "https://github.com/rollbar/rollbar-apple.git", + :tag => "v#{s.version}" + } + s.resource = "rollbar-logo.png" + # s.resources = "Resources/*.png" + + # When using multiple platforms: + s.ios.deployment_target = "9.0" + s.osx.deployment_target = "10.10" + s.tvos.deployment_target = "11.0" + # s.watchos.deployment_target = "4.0" + # Any platform, if omitted: + # s.platform = :ios + # s.platform = :ios, "5.0" + + s.source_files = "#{s.name}/Sources/#{s.name}/**/*.{h,m}" + s.public_header_files = "#{s.name}/Sources/#{s.name}/include/*.h" + s.module_map = "#{s.name}/Sources/#{s.name}/include/module.modulemap" + # s.exclude_files = "Classes/Exclude" + # s.preserve_paths = "FilesToSave", "MoreFilesToSave" + + s.framework = "Foundation" + s.dependency "RollbarCommon", "~> #{s.version}" + # s.frameworks = "SomeFramework", "AnotherFramework" + # s.library = "iconv" + # s.libraries = "iconv", "xml2" + # s.dependency "JSONKit", "~> 1.4" + + s.requires_arc = true + # s.xcconfig = { + # "USE_HEADERMAP" => "NO", + # "HEADER_SEARCH_PATHS" => "$(PODS_ROOT)/Sources/#{s.name}/**" + # } + + s.pod_target_xcconfig = { "ONLY_ACTIVE_ARCH" => "YES", "EXCLUDED_ARCHS[sdk=iphonesimulator*]" => "arm64" } + s.user_target_xcconfig = { "ONLY_ACTIVE_ARCH" => "YES", "EXCLUDED_ARCHS[sdk=iphonesimulator*]" => "arm64" } + + s.tvos.pod_target_xcconfig = { "ONLY_ACTIVE_ARCH" => "YES", "EXCLUDED_ARCHS[sdk=appletvsimulator*]" => "arm64" } + s.tvos.user_target_xcconfig = { "ONLY_ACTIVE_ARCH" => "YES", "EXCLUDED_ARCHS[sdk=appletvsimulator*]" => "arm64" } + +end diff --git a/RollbarSwift/.gitignore b/RollbarSwift/.gitignore new file mode 100644 index 00000000..95c43209 --- /dev/null +++ b/RollbarSwift/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ diff --git a/RollbarSwift/.swiftpm/xcode/xcshareddata/xcschemes/RollbarSwift.xcscheme b/RollbarSwift/.swiftpm/xcode/xcshareddata/xcschemes/RollbarSwift.xcscheme new file mode 100644 index 00000000..028e5fa8 --- /dev/null +++ b/RollbarSwift/.swiftpm/xcode/xcshareddata/xcschemes/RollbarSwift.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RollbarSwift/Package.swift b/RollbarSwift/Package.swift new file mode 100644 index 00000000..9024ce69 --- /dev/null +++ b/RollbarSwift/Package.swift @@ -0,0 +1,73 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "RollbarSwift", + platforms: [ + // Oldest targeted platform versions that are supported by this product. + .macOS(.v10_10), + .iOS(.v9), + .tvOS(.v11), + .watchOS(.v4), + ], + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "RollbarSwift", + targets: ["RollbarSwift"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + .package(path: "../RollbarCommon"), + .package(path: "../RollbarNotifier"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "RollbarSwift", + dependencies: ["RollbarCommon", "RollbarNotifier",], + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("Sources/RollbarSwift/**"), +// .headerSearchPath("Sources/RollbarSwift"), +// .headerSearchPath("Sources/RollbarSwift/include"), +// .headerSearchPath("Sources/RollbarSwift/DTOs"), + +// .define("DEFINES_MODULE"), + ] + ), + .testTarget( + name: "RollbarSwiftTests", + dependencies: ["RollbarSwift"], + cSettings: [ + .headerSearchPath("Tests/RollbarSwiftTests/**"), +// .headerSearchPath("Sources/RollbarNotifier"), +// .headerSearchPath("Sources/RollbarNotifier/include"), +// .headerSearchPath("Sources/RollbarNotifier/DTOs"), + +// .define("DEFINES_MODULE"), + ] + ), + .testTarget( + name: "RollbarSwiftTests-ObjC", + dependencies: ["RollbarSwift"], + cSettings: [ + .headerSearchPath("Tests/RollbarSwiftTests-ObjC/**"), +// .headerSearchPath("Sources/RollbarNotifier"), +// .headerSearchPath("Sources/RollbarNotifier/include"), +// .headerSearchPath("Sources/RollbarNotifier/DTOs"), + +// .define("DEFINES_MODULE"), + ] + ), + ], + swiftLanguageVersions: [ + SwiftVersion.v4, + SwiftVersion.v4_2, + SwiftVersion.v5, + ] +) diff --git a/RollbarSwift/README.md b/RollbarSwift/README.md new file mode 100644 index 00000000..cc67fbdc --- /dev/null +++ b/RollbarSwift/README.md @@ -0,0 +1,3 @@ +# RollbarSwift + +This is an SDK module implementing functionality and features specifically useful to Swift-based client code. diff --git a/RollbarSwift/Sources/RollbarSwift/RollbarExceptionGuard.m b/RollbarSwift/Sources/RollbarSwift/RollbarExceptionGuard.m new file mode 100644 index 00000000..7eb7f344 --- /dev/null +++ b/RollbarSwift/Sources/RollbarSwift/RollbarExceptionGuard.m @@ -0,0 +1,102 @@ +// +// RollbarExceptionGuard.m +// +// +// Created by Andrey Kornich on 2021-03-04. +// + +#import "RollbarExceptionGuard.h" +#import "RollbarTryCatch.h" + +@implementation RollbarExceptionGuard { +@private + RollbarLogger *logger; +} + +-(BOOL)tryExecute:(nonnull void(NS_NOESCAPE^)(void))block { + + NSError *error = nil; + return [self execute:block error:&error]; +} + +-(BOOL)execute:(nonnull void(NS_NOESCAPE^)(void))tryBlock + error:(__autoreleasing NSError * _Nullable * _Nullable)error { + + __block BOOL success = NO; + __block NSError* exceptionError = nil; + + [RollbarTryCatch try:^(void) { + + tryBlock(); + success = YES; + } + catch:^(NSException *exception) { + + exceptionError = [self convertException:exception]; + + if (nil != self->logger) { + + [self->logger log:RollbarLevel_Critical + exception:exception + data:nil + context:RollbarExceptionGuard.className + ]; + + [self->logger log:RollbarLevel_Critical + error:exceptionError + data:nil + context:RollbarExceptionGuard.className + ]; + } + + success = NO; + } + finally:^{ + + } + ]; + + *error = exceptionError; + + return success; +} + +-(instancetype)initWithLogger:(nonnull RollbarLogger *)logger { + + self = [super init]; + + if (nil != self) { + + self->logger = logger; + } + + return self; +} + +- (NSError *)convertException:(nonnull NSException *)exception { + + NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init]; + + if ((nil != exception.userInfo) && (0 < exception.userInfo.count)) { + + userInfo = + [[NSMutableDictionary alloc] initWithDictionary:exception.userInfo]; + } + + if (nil != exception.reason) { + + if (YES == [userInfo.allKeys containsObject:NSLocalizedFailureReasonErrorKey]) { + + [userInfo setObject:exception.reason + forKey:NSLocalizedFailureReasonErrorKey]; + } + } + + NSError *error = [[NSError alloc] initWithDomain:exception.name + code:0 + userInfo:userInfo]; + + return error; +} + +@end diff --git a/RollbarSwift/Sources/RollbarSwift/RollbarTryCatch.m b/RollbarSwift/Sources/RollbarSwift/RollbarTryCatch.m new file mode 100644 index 00000000..8df4a76c --- /dev/null +++ b/RollbarSwift/Sources/RollbarSwift/RollbarTryCatch.m @@ -0,0 +1,78 @@ +// +// RollbarTryCatch.m +// +// +// Created by Andrey Kornich on 2021-03-04. +// + +// +// SwiftTryCatch.h +// +// Created by William Falcon on 10/10/14. +// Copyright (c) 2014 William Falcon. All rights reserved. +// +/* + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + 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. + */ + +#import "RollbarTryCatch.h" + +@implementation RollbarTryCatch + ++ (void)try:(__attribute__((noescape)) void(^ _Nullable)(void))tryBlock + catch:(__attribute__((noescape)) void(^ _Nullable)(NSException* exception))catchBlock + finally:(__attribute__((noescape)) void(^ _Nullable)(void))finallyBlock { + + @try { + + if (NULL != tryBlock) { + + tryBlock(); + } + } + @catch (NSException *exception) { + + if (NULL != catchBlock) { + + catchBlock(exception); + } + } + @finally { + + if (NULL != finallyBlock) { + + finallyBlock(); + } + } +} + ++ (void)throwString:(NSString*)string { + + NSException *exception = [NSException exceptionWithName:string + reason:string + userInfo:nil]; + [RollbarTryCatch throwException:exception]; +} + ++ (void)throwException:(NSException*)exception { + + @throw exception; +} + +@end diff --git a/RollbarSwift/Sources/RollbarSwift/include/RollbarExceptionGuard.h b/RollbarSwift/Sources/RollbarSwift/include/RollbarExceptionGuard.h new file mode 100644 index 00000000..3de5d57c --- /dev/null +++ b/RollbarSwift/Sources/RollbarSwift/include/RollbarExceptionGuard.h @@ -0,0 +1,40 @@ +// +// RollbarExceptionGuard.h +// +// +// Created by Andrey Kornich on 2021-03-04. +// + +#import + +@import RollbarNotifier; + +@class RollbarLogger; + +NS_ASSUME_NONNULL_BEGIN + +/// Aids Swift code in handling NSExceptions thrown from within Objective-C calls +@interface RollbarExceptionGuard : NSObject + +/// Allows to safely execute code that could potentially throw NSExceptions. +/// @param block guarded code block +-(BOOL)tryExecute:(nonnull void(NS_NOESCAPE^)(void))block; + +/// Allows to safely execute code that could potentially throw NSExceptions. +/// @param block guarded code block +/// @param error NSError instance modeling corresponding NSException (if any thown from the guarded code block) +-(BOOL)execute:(nonnull void(NS_NOESCAPE^)(void))block + error:(__autoreleasing NSError * _Nullable * _Nullable)error; + +/// Designated initializer +/// @param logger RollbarLogger instance to use when reporting intercepted NSExceptions captured by this guard instance +-(instancetype)initWithLogger:(nonnull RollbarLogger *)logger +NS_DESIGNATED_INITIALIZER; + +/// Unavailable initializer +-(instancetype)init +NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/RollbarSwift/Sources/RollbarSwift/include/RollbarTryCatch.h b/RollbarSwift/Sources/RollbarSwift/include/RollbarTryCatch.h new file mode 100644 index 00000000..248b661a --- /dev/null +++ b/RollbarSwift/Sources/RollbarSwift/include/RollbarTryCatch.h @@ -0,0 +1,57 @@ +// +// RollbarTryCatch.h +// +// +// Created by Andrey Kornich on 2021-03-04. +// + +// +// SwiftTryCatch.h +// +// Created by William Falcon on 10/10/14. +// Copyright (c) 2014 William Falcon. All rights reserved. +// +/* + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + 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. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +/// Swift-friendly try-catch-finally equivalent for handling NSExceptions within the try-block +@interface RollbarTryCatch : NSObject + +/// Thows NSException using provided string as the exception message +/// @param tryBlock code block to try +/// @param catchBlock exception handling code block +/// @param finallyBlock finally-excuted code block ++ (void)try:(__attribute__((noescape)) void(^ _Nullable)(void))tryBlock + catch:(__attribute__((noescape)) void(^ _Nullable)(NSException* exception))catchBlock + finally:(__attribute__((noescape)) void(^ _Nullable)(void))finallyBlock; + +/// Thows NSException using provided string as the exception message +/// @param string exception message ++ (void)throwString:(NSString*)string; + +/// Throws NSException +/// @param exception specified NSException instance ++ (void)throwException:(NSException*)exception; + +@end + +NS_ASSUME_NONNULL_END diff --git a/RollbarSwift/Sources/RollbarSwift/include/module.modulemap b/RollbarSwift/Sources/RollbarSwift/include/module.modulemap new file mode 100644 index 00000000..8b671929 --- /dev/null +++ b/RollbarSwift/Sources/RollbarSwift/include/module.modulemap @@ -0,0 +1,8 @@ +module RollbarSwift { + umbrella "." + + export * + module * { export * } + + requires objc +} diff --git a/RollbarSwift/Tests/LinuxMain.swift b/RollbarSwift/Tests/LinuxMain.swift new file mode 100644 index 00000000..2138c249 --- /dev/null +++ b/RollbarSwift/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import RollbarSwiftTests + +var tests = [XCTestCaseEntry]() +tests += RollbarSwiftTests.allTests() +XCTMain(tests) diff --git a/RollbarSwift/Tests/RollbarSwiftTests-ObjC/RollbarSwiftTests.m b/RollbarSwift/Tests/RollbarSwiftTests-ObjC/RollbarSwiftTests.m new file mode 100644 index 00000000..1ebb2a19 --- /dev/null +++ b/RollbarSwift/Tests/RollbarSwiftTests-ObjC/RollbarSwiftTests.m @@ -0,0 +1,16 @@ +// Copyright (c) 2018 Rollbar, Inc. All rights reserved. + +#import + +@import RollbarSwift; + +@interface RollbarSwiftTests : XCTestCase +@end + +@implementation RollbarSwiftTests + +//- (void)testBasics { +//} + +@end + diff --git a/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift b/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift new file mode 100644 index 00000000..9027d1c1 --- /dev/null +++ b/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift @@ -0,0 +1,87 @@ +import XCTest +@testable import RollbarSwift + +final class RollbarSwiftTests: XCTestCase { + + func safeCode() { + + NSLog("Nothing dangerous here."); + } + + func produceObjCException() { + + RollbarTryCatch.throw("Fake NSException"); + } + + func createGuard() -> RollbarExceptionGuard { + + let config = RollbarConfig(); + config.destination.accessToken = "2ffc7997ed864dda94f63e7b7daae0f3"; + config.destination.environment = "unit-tests"; + config.developerOptions.transmit = true; + + let logger = RollbarLogger(configuration: config); + + let exceptionGuard = RollbarExceptionGuard(logger: logger); + + return exceptionGuard; + } + + func testExceptionGuard_tryExecute() { + + let exceptionGuard = createGuard(); + + var success = true; + + success = exceptionGuard.tryExecute { + + safeCode(); + } + + XCTAssertTrue(success); + + success = exceptionGuard.tryExecute { + + produceObjCException(); + } + + XCTAssertTrue(!success); + + Thread.sleep(forTimeInterval: 2); + } + + func testExceptionGuard_execute() { + + let exceptionGuard = createGuard(); + + do { + + try exceptionGuard.execute { + + safeCode(); + }; + } catch { + + XCTFail("Should never get here! Completely safe code was tried!"); + } + + do { + + try exceptionGuard.execute { + + produceObjCException(); + }; + } catch { + + NSLog(error.localizedDescription); + XCTAssertTrue(error.localizedDescription.contains("Fake NSException")); + } + + Thread.sleep(forTimeInterval: 2); + } + + static var allTests = [ + ("testExceptionGuard_tryExecute", testExceptionGuard_tryExecute), + ("testExceptionGuard_execute", testExceptionGuard_execute), + ] +} diff --git a/RollbarSwift/Tests/RollbarSwiftTests/XCTestManifests.swift b/RollbarSwift/Tests/RollbarSwiftTests/XCTestManifests.swift new file mode 100644 index 00000000..0bcce54c --- /dev/null +++ b/RollbarSwift/Tests/RollbarSwiftTests/XCTestManifests.swift @@ -0,0 +1,12 @@ +import XCTest + +#if !canImport(ObjectiveC) + +public func allTests() -> [XCTestCaseEntry] { + + return [ + testCase(RollbarSwiftTests.allTests), + ] +} + +#endif