Skip to content

Commit 675a016

Browse files
runningcodeclaude
andauthored
refactor(distribution): Separate upload and SDK installation controls (#1017)
* refactor(distribution): Separate upload and SDK installation controls Refactor the distribution API to provide clearer separation between: - Upload control via `enabled` property - Auto-update SDK installation via `updateSdkVariants` property This replaces the previous `enabledVariants` property which conflated both concerns. Key changes: - Add `enabled: Boolean` property to control distribution uploads (defaults to false during EA) - Rename `enabledVariants` to `updateSdkVariants` to clarify it controls auto-update SDK installation only - Add validation to ensure `updateSdkVariants` doesn't include variants in `ignoredVariants` - Add validation to ensure `updateSdkVariants` requires `enabled=true` - Update upload logic to check `enabled` instead of variant membership - Update tests to reflect new API 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor(distribution): Remove EA/GA references from comments Remove references to Early Access and General Availability from code comments to keep the implementation focused on current behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * style: Apply spotless formatting Apply spotless code formatting to distribution changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor(distribution): Match enabled convention with sizeAnalysis Set distribution.enabled convention to match sizeAnalysis.enabled, which uses CI detection (currently evaluates to false). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 76e2fb3 commit 675a016

File tree

5 files changed

+81
-16
lines changed

5 files changed

+81
-16
lines changed

plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@ fun ApplicationAndroidComponentsExtension.configure(
6161
tmpDir.mkdirs()
6262

6363
onVariants { variant ->
64+
// Validate distribution configuration for this variant
65+
val updateSdkVariants = extension.distribution.updateSdkVariants.get()
66+
val variantName = variant.name
67+
68+
if (updateSdkVariants.contains(variantName)) {
69+
val isVariantAllowed =
70+
isVariantAllowed(extension, variant.name, variant.flavorName, variant.buildType)
71+
72+
// Check if updateSdkVariants contains a variant that is ignored
73+
if (!isVariantAllowed) {
74+
throw IllegalArgumentException(
75+
"Invalid configuration: updateSdkVariants contains variant '$variantName' which is in ignoredVariants. " +
76+
"You cannot use the auto-update SDK in variants where the Sentry SDK is disabled."
77+
)
78+
}
79+
80+
// Check if updateSdkVariants is set but distribution uploads are disabled
81+
val distributionEnabled = extension.distribution.enabled.get()
82+
if (!distributionEnabled) {
83+
throw IllegalArgumentException(
84+
"Invalid configuration: updateSdkVariants contains variant '$variantName' but buildDistribution.enabled is false. " +
85+
"It doesn't make sense to embed the auto-update SDK without uploading the build."
86+
)
87+
}
88+
}
89+
6490
if (isVariantAllowed(extension, variant.name, variant.flavorName, variant.buildType)) {
6591
val paths = OutputPaths(project, variant.name)
6692
val sentryTelemetryProvider =
@@ -230,7 +256,7 @@ fun ApplicationAndroidComponentsExtension.configure(
230256
.toTransform(SingleArtifact.MERGED_MANIFEST)
231257
}
232258
val sizeAnalysisEnabled = extension.sizeAnalysis.enabled.get() == true
233-
val distributionEnabled = extension.distribution.enabledVariants.get().contains(variant.name)
259+
val distributionEnabled = extension.distribution.enabled.get() == true
234260
if (sizeAnalysisEnabled || distributionEnabled) {
235261
variant.configureUploadAppTasks(
236262
project,
@@ -396,11 +422,13 @@ private fun ApplicationVariant.configureDistributionPropertiesTask(
396422
sentryProject: String?,
397423
): TaskProvider<GenerateDistributionPropertiesTask>? {
398424
val variantName = name
399-
if (extension.distribution.enabledVariants.get().contains(variantName)) {
425+
val updateSdkVariants = extension.distribution.updateSdkVariants.get()
426+
427+
if (updateSdkVariants.contains(variantName)) {
400428
val variant = AndroidVariant74(this)
401429
// Distribution uses a custom auto-install implementation instead of the standard
402430
// InstallStrategy approach (see AutoInstall.kt) because it requires variant-specific
403-
// installation based on extension.distribution.enabledVariants, whereas other integrations
431+
// installation based on extension.distribution.updateSdkVariants, whereas other integrations
404432
// are installed globally when their dependencies are detected.
405433
if (extension.autoInstallation.enabled.get()) {
406434
val sentryVersion = extension.autoInstallation.sentryVersion.get()

plugin-build/src/main/kotlin/io/sentry/android/gradle/autoinstall/AutoInstall.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal const val SENTRY_GROUP = "io.sentry"
3131
// Note: sentry-android-distribution is not included here because it requires variant-specific
3232
// installation logic. Unlike other integrations that are installed globally when their
3333
// dependencies are detected, distribution must be installed per-variant based on
34-
// extension.distribution.enabledVariants. See
34+
// extension.distribution.updateSdkVariants. See
3535
// AndroidComponentsConfig.configureDistributionPropertiesTask.
3636
private val strategies =
3737
listOf(

plugin-build/src/main/kotlin/io/sentry/android/gradle/extensions/DistributionExtension.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
package io.sentry.android.gradle.extensions
22

3+
import io.sentry.android.gradle.util.CiUtils.isCi
34
import javax.inject.Inject
45
import org.gradle.api.model.ObjectFactory
56
import org.gradle.api.provider.Property
7+
import org.gradle.api.provider.ProviderFactory
68
import org.gradle.api.provider.SetProperty
79
import org.jetbrains.annotations.ApiStatus.Experimental
810

911
@Experimental
10-
open class DistributionExtension @Inject constructor(objects: ObjectFactory) {
12+
open class DistributionExtension
13+
@Inject
14+
constructor(objects: ObjectFactory, providerFactory: ProviderFactory) {
1115

1216
/**
13-
* Set of Android build variants that should have distribution enabled.
17+
* Controls whether build distribution uploads are enabled.
1418
*
15-
* Note: The global ignore settings (ignoredVariants, ignoredBuildTypes, ignoredFlavors) have no
16-
* relation to distribution and do not affect which variants are enabled here.
19+
* Defaults to false.
1720
*/
18-
val enabledVariants: SetProperty<String> =
21+
val enabled: Property<Boolean> =
22+
objects.property(Boolean::class.java).convention(providerFactory.isCi() && false)
23+
24+
/**
25+
* Set of Android build variants that should have the auto-update SDK added and auth token
26+
* embedded.
27+
*
28+
* This must be a subset of variants not in ignoredVariants. It is a build-time error to specify a
29+
* variant that is ignored by the Sentry plugin.
30+
*
31+
* Note: This controls auto-update SDK installation only. The [enabled] property controls whether
32+
* builds are uploaded for distribution.
33+
*/
34+
val updateSdkVariants: SetProperty<String> =
1935
objects.setProperty(String::class.java).convention(emptySet())
2036

2137
/** Auth token used for distribution operations. */

plugin-build/src/test/kotlin/io/sentry/android/gradle/extensions/DistributionExtensionTest.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11
package io.sentry.android.gradle.extensions
22

33
import kotlin.test.assertEquals
4+
import kotlin.test.assertFalse
45
import kotlin.test.assertTrue
56
import org.gradle.testfixtures.ProjectBuilder
67
import org.junit.Test
78

89
class DistributionExtensionTest {
910

1011
@Test
11-
fun `enabledVariants is empty by default`() {
12+
fun `enabled is false by default`() {
1213
val project = ProjectBuilder.builder().build()
1314
val extension = project.objects.newInstance(DistributionExtension::class.java)
1415

15-
assertTrue(extension.enabledVariants.get().isEmpty())
16+
assertFalse(extension.enabled.get())
1617
}
1718

1819
@Test
19-
fun `enabledVariants can be configured with variant names`() {
20+
fun `enabled can be configured`() {
2021
val project = ProjectBuilder.builder().build()
2122
val extension = project.objects.newInstance(DistributionExtension::class.java)
2223

23-
extension.enabledVariants.set(setOf("freeDebug", "paidRelease"))
24+
extension.enabled.set(true)
2425

25-
assertEquals(setOf("freeDebug", "paidRelease"), extension.enabledVariants.get())
26+
assertTrue(extension.enabled.get())
27+
}
28+
29+
@Test
30+
fun `updateSdkVariants is empty by default`() {
31+
val project = ProjectBuilder.builder().build()
32+
val extension = project.objects.newInstance(DistributionExtension::class.java)
33+
34+
assertTrue(extension.updateSdkVariants.get().isEmpty())
35+
}
36+
37+
@Test
38+
fun `updateSdkVariants can be configured with variant names`() {
39+
val project = ProjectBuilder.builder().build()
40+
val extension = project.objects.newInstance(DistributionExtension::class.java)
41+
42+
extension.updateSdkVariants.set(setOf("freeDebug", "paidRelease"))
43+
44+
assertEquals(setOf("freeDebug", "paidRelease"), extension.updateSdkVariants.get())
2645
}
2746

2847
@Test

plugin-build/src/test/kotlin/io/sentry/android/gradle/integration/SentryPluginAutoInstallTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ class SentryPluginAutoInstallTest :
426426
includeProguardMapping = false
427427
autoInstallation.enabled = true
428428
distribution {
429-
enabledVariants = ["debug"]
429+
enabled = true
430+
updateSdkVariants = ["debug"]
430431
}
431432
}
432433
"""
@@ -483,7 +484,8 @@ class SentryPluginAutoInstallTest :
483484
includeProguardMapping = false
484485
autoInstallation.enabled = false
485486
distribution {
486-
enabledVariants = ["debug"]
487+
enabled = true
488+
updateSdkVariants = ["debug"]
487489
}
488490
}
489491
"""

0 commit comments

Comments
 (0)