Skip to content

Commit a1d4010

Browse files
chore: add detekt & dokka (#86)
* add detekt * apply detekt changes * add dokka * add dokka action * update dokka action * depend generate-dokka on build * update scope naming: * update scope doc * update ScopeDecorator docs * add detekt make target * Format code * add detekt to .PHONY * update Scope * update API * fix format * update tests * add changelog * add separate workflow for generate dokka * Remove Suppress annotations * ignore forbidden comments and revert changelog * exclude Attachment from unused private member * Add baseline task * Update generate-dokka.yml * Update detekt.yml --------- Co-authored-by: Sentry Github Bot <[email protected]>
1 parent 82ab2b8 commit a1d4010

File tree

31 files changed

+241
-95
lines changed

31 files changed

+241
-95
lines changed

.github/workflows/generate-dokka.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Generate Dokka
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
jobs:
14+
generate-dokka:
15+
runs-on: ubuntu-latest
16+
environment:
17+
name: github-pages
18+
url: ${{ steps.deployment.outputs.page_url }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
23+
- name: set up JDK 11
24+
uses: actions/setup-java@v3
25+
with:
26+
distribution: "adopt"
27+
java-version: "11"
28+
29+
- name: Cache Gradle packages
30+
uses: actions/cache@v2
31+
with:
32+
path: |
33+
~/.gradle/caches
34+
~/.gradle/wrapper
35+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
36+
restore-keys: |
37+
${{ runner.os }}-gradle-
38+
39+
- name: Setup Pages
40+
uses: actions/configure-pages@v3
41+
42+
- name: Generate docs with dokka
43+
run: make generateDokka
44+
45+
- name: Upload artifact
46+
uses: actions/upload-pages-artifact@v1
47+
with:
48+
path: ${{ github.workspace }}/build/dokka/htmlMultiModule
49+
50+
- name: Deploy to GitHub Pages
51+
id: deployment
52+
uses: actions/deploy-pages@v1

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all clean compile dryRelease checkFormat checkApi buildAppleSamples format stop
1+
.PHONY: all clean compile dryRelease checkFormat checkApi buildAppleSamples generateDokka detekt format stop
22

33
all: stop clean compile
44

@@ -11,6 +11,14 @@ clean:
1111
dryRelease:
1212
./gradlew publishToMavenLocal --no-daemon --no-parallel
1313

14+
# Run detekt
15+
detekt:
16+
./gradlew detekt
17+
18+
# Generate Dokka
19+
generateDokka:
20+
./gradlew dokkaHtmlMultiModule
21+
1422
# Check API
1523
checkApi:
1624
./gradlew apiCheck
@@ -40,7 +48,7 @@ buildAppleSamples:
4048

4149

4250
# Build all targets, run tests and checks api
43-
compile: checkApi buildProject buildAppleSamples
51+
compile: checkApi detekt buildProject buildAppleSamples
4452

4553
# We stop gradle at the end to make sure the cache folders
4654
# don't contain any lock files and are free to be cached.

build.gradle.kts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import com.diffplug.spotless.LineEnding
22
import com.vanniktech.maven.publish.MavenPublishPlugin
33
import com.vanniktech.maven.publish.MavenPublishPluginExtension
4+
import io.gitlab.arturbosch.detekt.Detekt
45

56
plugins {
67
id(Config.gradleMavenPublishPlugin).version(Config.gradleMavenPublishPluginVersion)
78
id(Config.QualityPlugins.spotless).version(Config.QualityPlugins.spotlessVersion)
9+
id(Config.QualityPlugins.detekt).version(Config.QualityPlugins.detektVersion)
10+
id(Config.dokka).version(Config.dokkaVersion)
811
kotlin(Config.multiplatform).version(Config.kotlinVersion).apply(false)
912
kotlin(Config.cocoapods).version(Config.kotlinVersion).apply(false)
1013
id(Config.jetpackCompose).version(Config.composeVersion).apply(false)
@@ -52,6 +55,12 @@ subprojects {
5255
}
5356
}
5457

58+
subprojects {
59+
if (project.name.contains("sentry-kotlin-multiplatform")) {
60+
apply(plugin = Config.dokka)
61+
}
62+
}
63+
5564
spotless {
5665
lineEndings = LineEnding.UNIX
5766

@@ -64,3 +73,39 @@ spotless {
6473
ktlint()
6574
}
6675
}
76+
77+
val detektConfigFilePath = "$rootDir/config/detekt/detekt.yml"
78+
val detektBaselineFilePath = "$rootDir/config/detekt/baseline.xml"
79+
80+
detekt {
81+
buildUponDefaultConfig = true
82+
config = files(detektConfigFilePath)
83+
baseline = file(detektBaselineFilePath)
84+
}
85+
86+
fun SourceTask.detektExcludes() {
87+
exclude("**/build/**")
88+
exclude("**/*.kts")
89+
exclude("**/buildSrc/**")
90+
exclude("**/*Test*/**")
91+
exclude("**/resources/**")
92+
exclude("**/sentry-samples/**")
93+
}
94+
95+
tasks.withType<Detekt>().configureEach {
96+
reports {
97+
html.required.set(true)
98+
}
99+
setSource(files(project.projectDir))
100+
detektExcludes()
101+
}
102+
103+
/** Task for generating a Detekt baseline.xml */
104+
val detektProjectBaseline by tasks.registering(io.gitlab.arturbosch.detekt.DetektCreateBaselineTask::class) {
105+
buildUponDefaultConfig.set(true)
106+
setSource(files(rootDir))
107+
config.setFrom(files(detektConfigFilePath))
108+
baseline.set(file(detektBaselineFilePath))
109+
include("**/*.kt")
110+
detektExcludes()
111+
}

buildSrc/src/main/java/Config.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ object Config {
1010
val gradleMavenPublishPlugin = "com.vanniktech.maven.publish"
1111
val androidGradle = "com.android.library"
1212
val kotlinSerializationPlugin = "plugin.serialization"
13+
val dokka = "org.jetbrains.dokka"
14+
val dokkaVersion = "1.8.10"
1315

1416
object BuildPlugins {
1517
val buildConfig = "com.codingfeline.buildkonfig"
@@ -19,6 +21,8 @@ object Config {
1921
object QualityPlugins {
2022
val spotless = "com.diffplug.spotless"
2123
val spotlessVersion = "6.11.0"
24+
val detekt = "io.gitlab.arturbosch.detekt"
25+
val detektVersion = "1.22.0"
2226
val binaryCompatibility = "org.jetbrains.kotlinx.binary-compatibility-validator"
2327
val binaryCompatibilityVersion = "0.13.1"
2428
}

config/detekt/baseline.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<SmellBaseline>
3+
<ManuallySuppressedIssues/>
4+
<CurrentIssues>
5+
<ID>SwallowedException:CocoaScopeProvider.kt$CocoaScopeProvider$e: Throwable</ID>
6+
<ID>SwallowedException:SentryLevel.kt$SentryLevel.Companion$throwable: Throwable</ID>
7+
<ID>TooGenericExceptionCaught:CocoaScopeProvider.kt$CocoaScopeProvider$e: Throwable</ID>
8+
<ID>TooGenericExceptionCaught:SentryLevel.kt$SentryLevel.Companion$throwable: Throwable</ID>
9+
<ID>TooGenericExceptionThrown:SentryKMP.kt$Sentry$throw RuntimeException("Uncaught Exception from Kotlin Multiplatform.")</ID>
10+
</CurrentIssues>
11+
</SmellBaseline>

config/detekt/detekt.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
comments:
2+
UndocumentedPublicClass:
3+
active: true
4+
includes: "**/commonMain/**"
5+
UndocumentedPublicProperty:
6+
active: true
7+
includes: "**/commonMain/**"
8+
style:
9+
UnnecessaryAbstractClass:
10+
active: false
11+
ForbiddenComment:
12+
active: false
13+
UnusedPrivateMember:
14+
excludes:
15+
- "**/Attachment.kt"
16+
complexity:
17+
TooManyFunctions:
18+
excludes: [
19+
"**/SentryKMP.kt",
20+
"**/SentryBridge.kt",
21+
"**/CocoaScopeProvider.kt",
22+
"**/Scope.kt",
23+
"**/JvmScopeProvider.kt",
24+
"**/Breadcrumb.kt",
25+
]
26+

sentry-kotlin-multiplatform/api/android/sentry-kotlin-multiplatform.api

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,7 @@ public final class io/sentry/kotlin/multiplatform/HttpStatusCodeRange {
4545
public final class io/sentry/kotlin/multiplatform/HttpStatusCodeRange$Companion {
4646
}
4747

48-
public final class io/sentry/kotlin/multiplatform/Scope : io/sentry/kotlin/multiplatform/ScopeProvider {
49-
public fun <init> (Lio/sentry/kotlin/multiplatform/ScopeProvider;)V
50-
public fun addAttachment (Lio/sentry/kotlin/multiplatform/Attachment;)V
51-
public fun addBreadcrumb (Lio/sentry/kotlin/multiplatform/protocol/Breadcrumb;)V
52-
public fun clear ()V
53-
public fun clearAttachments ()V
54-
public fun clearBreadcrumbs ()V
55-
public fun getContexts ()Ljava/util/Map;
56-
public fun getLevel ()Lio/sentry/kotlin/multiplatform/SentryLevel;
57-
public fun getTags ()Ljava/util/Map;
58-
public fun getUser ()Lio/sentry/kotlin/multiplatform/protocol/User;
59-
public fun removeContext (Ljava/lang/String;)V
60-
public fun removeExtra (Ljava/lang/String;)V
61-
public fun removeTag (Ljava/lang/String;)V
62-
public fun setContext (Ljava/lang/String;C)V
63-
public fun setContext (Ljava/lang/String;Ljava/lang/Number;)V
64-
public fun setContext (Ljava/lang/String;Ljava/lang/Object;)V
65-
public fun setContext (Ljava/lang/String;Ljava/lang/String;)V
66-
public fun setContext (Ljava/lang/String;Ljava/util/Collection;)V
67-
public fun setContext (Ljava/lang/String;Z)V
68-
public fun setContext (Ljava/lang/String;[Ljava/lang/Object;)V
69-
public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
70-
public fun setLevel (Lio/sentry/kotlin/multiplatform/SentryLevel;)V
71-
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
72-
public fun setUser (Lio/sentry/kotlin/multiplatform/protocol/User;)V
73-
}
74-
75-
public abstract interface class io/sentry/kotlin/multiplatform/ScopeProvider {
48+
public abstract interface class io/sentry/kotlin/multiplatform/Scope {
7649
public abstract fun addAttachment (Lio/sentry/kotlin/multiplatform/Attachment;)V
7750
public abstract fun addBreadcrumb (Lio/sentry/kotlin/multiplatform/protocol/Breadcrumb;)V
7851
public abstract fun clear ()V

sentry-kotlin-multiplatform/api/jvm/sentry-kotlin-multiplatform.api

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,7 @@ public final class io/sentry/kotlin/multiplatform/HttpStatusCodeRange {
4242
public final class io/sentry/kotlin/multiplatform/HttpStatusCodeRange$Companion {
4343
}
4444

45-
public final class io/sentry/kotlin/multiplatform/Scope : io/sentry/kotlin/multiplatform/ScopeProvider {
46-
public fun <init> (Lio/sentry/kotlin/multiplatform/ScopeProvider;)V
47-
public fun addAttachment (Lio/sentry/kotlin/multiplatform/Attachment;)V
48-
public fun addBreadcrumb (Lio/sentry/kotlin/multiplatform/protocol/Breadcrumb;)V
49-
public fun clear ()V
50-
public fun clearAttachments ()V
51-
public fun clearBreadcrumbs ()V
52-
public fun getContexts ()Ljava/util/Map;
53-
public fun getLevel ()Lio/sentry/kotlin/multiplatform/SentryLevel;
54-
public fun getTags ()Ljava/util/Map;
55-
public fun getUser ()Lio/sentry/kotlin/multiplatform/protocol/User;
56-
public fun removeContext (Ljava/lang/String;)V
57-
public fun removeExtra (Ljava/lang/String;)V
58-
public fun removeTag (Ljava/lang/String;)V
59-
public fun setContext (Ljava/lang/String;C)V
60-
public fun setContext (Ljava/lang/String;Ljava/lang/Number;)V
61-
public fun setContext (Ljava/lang/String;Ljava/lang/Object;)V
62-
public fun setContext (Ljava/lang/String;Ljava/lang/String;)V
63-
public fun setContext (Ljava/lang/String;Ljava/util/Collection;)V
64-
public fun setContext (Ljava/lang/String;Z)V
65-
public fun setContext (Ljava/lang/String;[Ljava/lang/Object;)V
66-
public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
67-
public fun setLevel (Lio/sentry/kotlin/multiplatform/SentryLevel;)V
68-
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
69-
public fun setUser (Lio/sentry/kotlin/multiplatform/protocol/User;)V
70-
}
71-
72-
public abstract interface class io/sentry/kotlin/multiplatform/ScopeProvider {
45+
public abstract interface class io/sentry/kotlin/multiplatform/Scope {
7346
public abstract fun addAttachment (Lio/sentry/kotlin/multiplatform/Attachment;)V
7447
public abstract fun addBreadcrumb (Lio/sentry/kotlin/multiplatform/protocol/Breadcrumb;)V
7548
public abstract fun clear ()V

sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/CocoaScopeProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
1010
import io.sentry.kotlin.multiplatform.protocol.User
1111
import Scope.Sentry.SentryScope as PrivateCocoaScope
1212

13-
internal class CocoaScopeProvider(private val scope: CocoaScope) : ScopeProvider {
13+
internal class CocoaScopeProvider(private val scope: CocoaScope) : Scope {
1414

1515
/*
1616
This bridge exposes private Cocoa SDK API to fetch internal properties such as user, level, etc.

sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ internal actual object SentryBridge {
4242
}
4343

4444
actual fun captureException(throwable: Throwable, scopeCallback: ScopeCallback): SentryId {
45-
val cocoaSentryId = SentrySDK.captureException(throwable.asNSException(true), configureScopeCallback(scopeCallback))
45+
val cocoaSentryId = SentrySDK.captureException(
46+
throwable.asNSException(true),
47+
configureScopeCallback(scopeCallback)
48+
)
4649
return SentryId(cocoaSentryId.toString())
4750
}
4851

@@ -72,8 +75,7 @@ internal actual object SentryBridge {
7275
CocoaScopeProvider(it)
7376
}
7477
cocoaScopeProvider?.let {
75-
val scope = Scope(it)
76-
scopeCallback.invoke(scope)
78+
scopeCallback.invoke(it)
7779
}
7880
}
7981
}

0 commit comments

Comments
 (0)