Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Set SdkVersion in default SentryOptions created in sentry-core module #506

Merged
merged 6 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ object Config {
object BuildPlugins {
val androidGradle = "com.android.tools.build:gradle:4.0.1"
val kotlinGradlePlugin = "gradle-plugin"
val buildConfig = "com.github.gmazzo.buildconfig"
val buildConfigVersion = "2.0.2"
}

object Android {
Expand Down Expand Up @@ -58,7 +60,8 @@ object Config {
}

object Sentry {
val SENTRY_CLIENT_NAME = "sentry.java.android"
val SENTRY_CLIENT_NAME = "sentry.java"
maciejwalkowiak marked this conversation as resolved.
Show resolved Hide resolved
val SENTRY_ANDROID_CLIENT_NAME = "$SENTRY_CLIENT_NAME.android"
val group = "io.sentry"
val description = "SDK for sentry.io"
val website = "https://sentry.io"
Expand Down
2 changes: 1 addition & 1 deletion sentry-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
versionName = project.version.toString()
versionCode = project.properties[Config.Sentry.buildVersionCodeProp].toString().toInt()

buildConfigField("String", "SENTRY_CLIENT_NAME", "\"${Config.Sentry.SENTRY_CLIENT_NAME}\"")
buildConfigField("String", "SENTRY_CLIENT_NAME", "\"${Config.Sentry.SENTRY_ANDROID_CLIENT_NAME}\"")
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public SentryAndroidOptions() {
}

private @NotNull SdkVersion createSdkVersion() {
final SdkVersion sdkVersion = new SdkVersion();
SdkVersion sdkVersion = getSdkVersion();

if (sdkVersion == null) {
sdkVersion = new SdkVersion();
}

sdkVersion.setName(BuildConfig.SENTRY_CLIENT_NAME);
String version = BuildConfig.VERSION_NAME;
sdkVersion.setVersion(version);

// add 2 default packages
sdkVersion.addPackage("maven:sentry-android-core", version);
// TODO: sentry-core should add itself as the version may mismatch
sdkVersion.addPackage("maven:sentry-core", version);

return sdkVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class SentryAndroidOptionsTest {
assertEquals(BuildConfig.VERSION_NAME, sdkVersion.version)

assertTrue(sdkVersion.packages!!.any {
it.name == "maven:sentry-android-core"
it.name == "maven:sentry-android-core" &&
maciejwalkowiak marked this conversation as resolved.
Show resolved Hide resolved
it.version == BuildConfig.VERSION_NAME
})

assertTrue(sdkVersion.packages!!.any {
bruno-garcia marked this conversation as resolved.
Show resolved Hide resolved
it.name == "maven:sentry-core"
it.name == "maven:sentry-core" &&
it.version == BuildConfig.VERSION_NAME
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.sentry.android.ndk

import io.sentry.core.SentryOptions
import io.sentry.core.protocol.SdkVersion
import kotlin.test.Test
import kotlin.test.assertNull
import kotlin.test.assertTrue
Expand All @@ -10,9 +9,7 @@ class SentryNdkUtilTest {

@Test
fun `SentryNdk adds the Ndk package into the package list`() {
val options = SentryOptions().apply {
sdkVersion = SdkVersion()
}
val options = SentryOptions()
SentryNdkUtil.addPackage(options.sdkVersion)
assertTrue(options.sdkVersion!!.packages!!.any {
it.name == "maven:sentry-android-ndk"
Expand All @@ -22,7 +19,9 @@ class SentryNdkUtilTest {

@Test
fun `SentryNdk do not add the Ndk package into the package list`() {
val options = SentryOptions()
val options = SentryOptions().apply {
sdkVersion = null
}
SentryNdkUtil.addPackage(options.sdkVersion)

assertNull(options.sdkVersion?.packages)
Expand Down
13 changes: 13 additions & 0 deletions sentry-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id(Config.QualityPlugins.errorProne)
id(Config.Deploy.novodaBintray)
id(Config.QualityPlugins.gradleVersions)
id(Config.BuildPlugins.buildConfig) version Config.BuildPlugins.buildConfigVersion
}

configure<JavaPluginConvention> {
Expand Down Expand Up @@ -65,6 +66,18 @@ tasks {
}
}

buildConfig {
useJavaOutput()
packageName("io.sentry.core")
maciejwalkowiak marked this conversation as resolved.
Show resolved Hide resolved
buildConfigField("String", "SDK_NAME", "\"${Config.Sentry.SENTRY_CLIENT_NAME}\"")
buildConfigField("String", "SDK_VERSION", "\"${project.version}\"")
}

val generateBuildConfig by tasks
tasks.withType<JavaCompile>().configureEach {
dependsOn(generateBuildConfig)
}

//TODO: move thse blocks to parent gradle file, DRY
configure<PublishExtension> {
userOrg = Config.Sentry.userOrg
Expand Down
13 changes: 13 additions & 0 deletions sentry-core/src/main/java/io/sentry/core/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1036,5 +1036,18 @@ public SentryOptions() {
integrations.add(new ShutdownHookIntegration());

eventProcessors.add(new MainEventProcessor(this));

setSdkVersion(createSdkVersion());
}

private @NotNull SdkVersion createSdkVersion() {
final SdkVersion sdkVersion = new SdkVersion();

sdkVersion.setName(BuildConfig.SDK_NAME);
String version = BuildConfig.SDK_VERSION;
sdkVersion.setVersion(version);
sdkVersion.addPackage("maven:sentry-core", version);

return sdkVersion;
}
}
15 changes: 15 additions & 0 deletions sentry-core/src/test/java/io/sentry/core/SentryOptionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,19 @@ class SentryOptionsTest {
val options = SentryOptions()
assertNotNull(options.executorService)
}

@Test
fun `init should set SdkVersion`() {
val sentryOptions = SentryOptions()
assertNotNull(sentryOptions.sdkVersion)
val sdkVersion = sentryOptions.sdkVersion!!

assertEquals(BuildConfig.SDK_NAME, sdkVersion.name)
assertEquals(BuildConfig.SDK_VERSION, sdkVersion.version)

assertTrue(sdkVersion.packages!!.any {
bruno-garcia marked this conversation as resolved.
Show resolved Hide resolved
it.name == "maven:sentry-core" &&
it.version == BuildConfig.SDK_VERSION
})
}
}