Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/generate-dokka.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Generate Dokka

on:
release:
types: [released]

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

jobs:
generate-dokka:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: set up JDK 11
uses: actions/setup-java@v3
with:
distribution: "adopt"
java-version: "11"

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Setup Pages
uses: actions/configure-pages@v3

- name: Generate docs with dokka
run: make generateDokka

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ${{ github.workspace }}/build/dokka/htmlMultiModule

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all clean compile dryRelease checkFormat checkApi buildAppleSamples format stop
.PHONY: all clean compile dryRelease checkFormat checkApi buildAppleSamples generateDokka detekt format stop

all: stop clean compile

Expand All @@ -11,6 +11,14 @@ clean:
dryRelease:
./gradlew publishToMavenLocal --no-daemon --no-parallel

# Run detekt
detekt:
./gradlew detekt

# Generate Dokka
generateDokka:
./gradlew dokkaHtmlMultiModule

# Check API
checkApi:
./gradlew apiCheck
Expand Down Expand Up @@ -40,7 +48,7 @@ buildAppleSamples:


# Build all targets, run tests and checks api
compile: checkApi buildProject buildAppleSamples
compile: checkApi detekt buildProject buildAppleSamples

# We stop gradle at the end to make sure the cache folders
# don't contain any lock files and are free to be cached.
Expand Down
45 changes: 45 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import com.diffplug.spotless.LineEnding
import com.vanniktech.maven.publish.MavenPublishPlugin
import com.vanniktech.maven.publish.MavenPublishPluginExtension
import io.gitlab.arturbosch.detekt.Detekt

plugins {
id(Config.gradleMavenPublishPlugin).version(Config.gradleMavenPublishPluginVersion)
id(Config.QualityPlugins.spotless).version(Config.QualityPlugins.spotlessVersion)
id(Config.QualityPlugins.detekt).version(Config.QualityPlugins.detektVersion)
id(Config.dokka).version(Config.dokkaVersion)
kotlin(Config.multiplatform).version(Config.kotlinVersion).apply(false)
kotlin(Config.cocoapods).version(Config.kotlinVersion).apply(false)
id(Config.jetpackCompose).version(Config.composeVersion).apply(false)
Expand Down Expand Up @@ -52,6 +55,12 @@ subprojects {
}
}

subprojects {
if (project.name.contains("sentry-kotlin-multiplatform")) {
apply(plugin = Config.dokka)
}
}

spotless {
lineEndings = LineEnding.UNIX

Expand All @@ -64,3 +73,39 @@ spotless {
ktlint()
}
}

val detektConfigFilePath = "$rootDir/config/detekt/detekt.yml"
val detektBaselineFilePath = "$rootDir/config/detekt/baseline.xml"

detekt {
buildUponDefaultConfig = true
config = files(detektConfigFilePath)
baseline = file(detektBaselineFilePath)
}

fun SourceTask.detektExcludes() {
exclude("**/build/**")
exclude("**/*.kts")
exclude("**/buildSrc/**")
exclude("**/*Test*/**")
exclude("**/resources/**")
exclude("**/sentry-samples/**")
}

tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true)
}
setSource(files(project.projectDir))
detektExcludes()
}

/** Task for generating a Detekt baseline.xml */
val detektProjectBaseline by tasks.registering(io.gitlab.arturbosch.detekt.DetektCreateBaselineTask::class) {
buildUponDefaultConfig.set(true)
setSource(files(rootDir))
config.setFrom(files(detektConfigFilePath))
baseline.set(file(detektBaselineFilePath))
include("**/*.kt")
detektExcludes()
}
4 changes: 4 additions & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ object Config {
val gradleMavenPublishPlugin = "com.vanniktech.maven.publish"
val androidGradle = "com.android.library"
val kotlinSerializationPlugin = "plugin.serialization"
val dokka = "org.jetbrains.dokka"
val dokkaVersion = "1.8.10"

object BuildPlugins {
val buildConfig = "com.codingfeline.buildkonfig"
Expand All @@ -19,6 +21,8 @@ object Config {
object QualityPlugins {
val spotless = "com.diffplug.spotless"
val spotlessVersion = "6.11.0"
val detekt = "io.gitlab.arturbosch.detekt"
val detektVersion = "1.22.0"
val binaryCompatibility = "org.jetbrains.kotlinx.binary-compatibility-validator"
val binaryCompatibilityVersion = "0.13.1"
}
Expand Down
11 changes: 11 additions & 0 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version='1.0' encoding='UTF-8'?>
<SmellBaseline>
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>SwallowedException:CocoaScopeProvider.kt$CocoaScopeProvider$e: Throwable</ID>
<ID>SwallowedException:SentryLevel.kt$SentryLevel.Companion$throwable: Throwable</ID>
<ID>TooGenericExceptionCaught:CocoaScopeProvider.kt$CocoaScopeProvider$e: Throwable</ID>
<ID>TooGenericExceptionCaught:SentryLevel.kt$SentryLevel.Companion$throwable: Throwable</ID>
<ID>TooGenericExceptionThrown:SentryKMP.kt$Sentry$throw RuntimeException("Uncaught Exception from Kotlin Multiplatform.")</ID>
</CurrentIssues>
</SmellBaseline>
26 changes: 26 additions & 0 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
comments:
UndocumentedPublicClass:
active: true
includes: "**/commonMain/**"
UndocumentedPublicProperty:
active: true
includes: "**/commonMain/**"
style:
UnnecessaryAbstractClass:
active: false
ForbiddenComment:
active: false
UnusedPrivateMember:
excludes:
- "**/Attachment.kt"
complexity:
TooManyFunctions:
excludes: [
"**/SentryKMP.kt",
"**/SentryBridge.kt",
"**/CocoaScopeProvider.kt",
"**/Scope.kt",
"**/JvmScopeProvider.kt",
"**/Breadcrumb.kt",
]

Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,7 @@ public final class io/sentry/kotlin/multiplatform/HttpStatusCodeRange {
public final class io/sentry/kotlin/multiplatform/HttpStatusCodeRange$Companion {
}

public final class io/sentry/kotlin/multiplatform/Scope : io/sentry/kotlin/multiplatform/ScopeProvider {
public fun <init> (Lio/sentry/kotlin/multiplatform/ScopeProvider;)V
public fun addAttachment (Lio/sentry/kotlin/multiplatform/Attachment;)V
public fun addBreadcrumb (Lio/sentry/kotlin/multiplatform/protocol/Breadcrumb;)V
public fun clear ()V
public fun clearAttachments ()V
public fun clearBreadcrumbs ()V
public fun getContexts ()Ljava/util/Map;
public fun getLevel ()Lio/sentry/kotlin/multiplatform/SentryLevel;
public fun getTags ()Ljava/util/Map;
public fun getUser ()Lio/sentry/kotlin/multiplatform/protocol/User;
public fun removeContext (Ljava/lang/String;)V
public fun removeExtra (Ljava/lang/String;)V
public fun removeTag (Ljava/lang/String;)V
public fun setContext (Ljava/lang/String;C)V
public fun setContext (Ljava/lang/String;Ljava/lang/Number;)V
public fun setContext (Ljava/lang/String;Ljava/lang/Object;)V
public fun setContext (Ljava/lang/String;Ljava/lang/String;)V
public fun setContext (Ljava/lang/String;Ljava/util/Collection;)V
public fun setContext (Ljava/lang/String;Z)V
public fun setContext (Ljava/lang/String;[Ljava/lang/Object;)V
public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
public fun setLevel (Lio/sentry/kotlin/multiplatform/SentryLevel;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setUser (Lio/sentry/kotlin/multiplatform/protocol/User;)V
}

public abstract interface class io/sentry/kotlin/multiplatform/ScopeProvider {
public abstract interface class io/sentry/kotlin/multiplatform/Scope {
public abstract fun addAttachment (Lio/sentry/kotlin/multiplatform/Attachment;)V
public abstract fun addBreadcrumb (Lio/sentry/kotlin/multiplatform/protocol/Breadcrumb;)V
public abstract fun clear ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,7 @@ public final class io/sentry/kotlin/multiplatform/HttpStatusCodeRange {
public final class io/sentry/kotlin/multiplatform/HttpStatusCodeRange$Companion {
}

public final class io/sentry/kotlin/multiplatform/Scope : io/sentry/kotlin/multiplatform/ScopeProvider {
public fun <init> (Lio/sentry/kotlin/multiplatform/ScopeProvider;)V
public fun addAttachment (Lio/sentry/kotlin/multiplatform/Attachment;)V
public fun addBreadcrumb (Lio/sentry/kotlin/multiplatform/protocol/Breadcrumb;)V
public fun clear ()V
public fun clearAttachments ()V
public fun clearBreadcrumbs ()V
public fun getContexts ()Ljava/util/Map;
public fun getLevel ()Lio/sentry/kotlin/multiplatform/SentryLevel;
public fun getTags ()Ljava/util/Map;
public fun getUser ()Lio/sentry/kotlin/multiplatform/protocol/User;
public fun removeContext (Ljava/lang/String;)V
public fun removeExtra (Ljava/lang/String;)V
public fun removeTag (Ljava/lang/String;)V
public fun setContext (Ljava/lang/String;C)V
public fun setContext (Ljava/lang/String;Ljava/lang/Number;)V
public fun setContext (Ljava/lang/String;Ljava/lang/Object;)V
public fun setContext (Ljava/lang/String;Ljava/lang/String;)V
public fun setContext (Ljava/lang/String;Ljava/util/Collection;)V
public fun setContext (Ljava/lang/String;Z)V
public fun setContext (Ljava/lang/String;[Ljava/lang/Object;)V
public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
public fun setLevel (Lio/sentry/kotlin/multiplatform/SentryLevel;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setUser (Lio/sentry/kotlin/multiplatform/protocol/User;)V
}

public abstract interface class io/sentry/kotlin/multiplatform/ScopeProvider {
public abstract interface class io/sentry/kotlin/multiplatform/Scope {
public abstract fun addAttachment (Lio/sentry/kotlin/multiplatform/Attachment;)V
public abstract fun addBreadcrumb (Lio/sentry/kotlin/multiplatform/protocol/Breadcrumb;)V
public abstract fun clear ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
import io.sentry.kotlin.multiplatform.protocol.User
import Scope.Sentry.SentryScope as PrivateCocoaScope

internal class CocoaScopeProvider(private val scope: CocoaScope) : ScopeProvider {
internal class CocoaScopeProvider(private val scope: CocoaScope) : Scope {

/*
This bridge exposes private Cocoa SDK API to fetch internal properties such as user, level, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ internal actual object SentryBridge {
}

actual fun captureException(throwable: Throwable, scopeCallback: ScopeCallback): SentryId {
val cocoaSentryId = SentrySDK.captureException(throwable.asNSException(true), configureScopeCallback(scopeCallback))
val cocoaSentryId = SentrySDK.captureException(
throwable.asNSException(true),
configureScopeCallback(scopeCallback)
)
return SentryId(cocoaSentryId.toString())
}

Expand Down Expand Up @@ -72,8 +75,7 @@ internal actual object SentryBridge {
CocoaScopeProvider(it)
}
cocoaScopeProvider?.let {
val scope = Scope(it)
scopeCallback.invoke(scope)
scopeCallback.invoke(it)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlin.reflect.KClass
* If [appendCausedBy] is `true` then the name, message and stack trace
* of the [causes][Throwable.cause] will be appended, else causes are ignored.
*/
public fun Throwable.asNSException(appendCausedBy: Boolean = false): NSException {
internal fun Throwable.asNSException(appendCausedBy: Boolean = false): NSException {
val returnAddresses = getFilteredStackTraceAddresses().let { addresses ->
if (!appendCausedBy) return@let addresses
addresses.toMutableList().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import platform.Foundation.NSNumber
* Drops the Kotlin crash that follows an unhandled Kotlin exception except our custom SentryEvent.
*/
internal fun dropKotlinCrashEvent(event: SentryEvent?): SentryEvent? {
return event?.takeUnless { it.isCrashEvent && (it.tags?.containsKey(kotlinCrashedTag) ?: false) }
return event?.takeUnless { it.isCrashEvent && (it.tags?.containsKey(KOTLIN_CRASH_TAG) ?: false) }
}

/**
Expand All @@ -57,14 +57,14 @@ internal fun setSentryUnhandledExceptionHook(): Unit = wrapUnhandledExceptionHoo
// https://github.com/getsentry/sentry-cocoa/blob/678172142ac1d10f5ed7978f69d16ab03e801057/Sources/Sentry/SentryClient.m#L409
SentrySDK.storeEnvelope(envelope)
SentrySDK.configureScope { scope ->
scope?.setTagValue(kotlinCrashedTag, kotlinCrashedTag)
scope?.setTagValue(KOTLIN_CRASH_TAG, KOTLIN_CRASH_TAG)
}
}

/**
* Tag used to mark the Kotlin termination crash.
*/
internal const val kotlinCrashedTag = "nsexceptionkt.kotlin_crashed"
internal const val KOTLIN_CRASH_TAG = "nsexceptionkt.kotlin_crashed"

/**
* Converts `this` [Throwable] to a [SentryEnvelope].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import cocoapods.Sentry.SentryScope as CocoaScope
actual abstract class BaseSentryScopeTest {
actual fun initializeScope(): Scope {
val cocoaScope = CocoaScope()
val cocoaScopeProvider = CocoaScopeProvider(cocoaScope)
return Scope(cocoaScopeProvider)
return CocoaScopeProvider(cocoaScope)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.sentry.kotlin.multiplatform.extensions.toKmpUser
import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
import io.sentry.kotlin.multiplatform.protocol.User

internal class JvmScopeProvider(private val scope: JvmScope) : ScopeProvider {
internal class JvmScopeProvider(private val scope: JvmScope) : Scope {

override var level: SentryLevel?
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ internal actual object SentryBridge {
private fun configureScopeCallback(scopeCallback: ScopeCallback): (JvmScope) -> Unit {
return {
val jvmScopeProvider = JvmScopeProvider(it)
val scope = Scope(jvmScopeProvider)
scopeCallback.invoke(scope)
scopeCallback.invoke(jvmScopeProvider)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.sentry.SentryOptions
actual abstract class BaseSentryScopeTest {
actual fun initializeScope(): Scope {
val jvmScope = JvmScope(SentryOptions())
val jvmScopeProvider = JvmScopeProvider(jvmScope)
return Scope(jvmScopeProvider)
return JvmScopeProvider(jvmScope)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.kotlin.multiplatform

/** An attachment to be sent along with the event. */
public expect class Attachment {

/** The bytes of the attachment. */
Expand Down
Loading