From 22c10352418eeab8f6516d648f0dea52b1b74b93 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Wed, 12 Aug 2020 16:27:29 +0100 Subject: [PATCH] fix: respect bugsnag.enabled flag --- features/disabled_bugsnag.feature | 5 +++++ features/fixtures/app/module/build.gradle | 4 +--- .../config/bugsnag/all_disabled.gradle | 12 ++++++----- .../auto_report_builds_disabled.gradle | 10 ++++++---- .../config/bugsnag/custom_build_info.gradle | 20 ++++++++++--------- .../config/bugsnag/disabled_bugsnag.gradle | 7 +++++++ .../config/bugsnag/disabled_build_type.gradle | 10 ++++++---- .../bugsnag/disabled_product_flavor.gradle | 10 ++++++---- .../config/bugsnag/empty_api_key.gradle | 8 +++++--- .../config/bugsnag/overwrite_enabled.gradle | 12 ++++++----- .../fixtures/config/bugsnag/standard.gradle | 8 +++++--- .../bugsnag/upload_debug_enabled.gradle | 10 ++++++---- .../config/bugsnag/wrong_endpoint.gradle | 8 +++++--- .../bugsnag/android/gradle/BugsnagPlugin.kt | 6 ++++++ 14 files changed, 83 insertions(+), 47 deletions(-) create mode 100644 features/disabled_bugsnag.feature create mode 100644 features/fixtures/config/bugsnag/disabled_bugsnag.gradle diff --git a/features/disabled_bugsnag.feature b/features/disabled_bugsnag.feature new file mode 100644 index 0000000000..a698d05b83 --- /dev/null +++ b/features/disabled_bugsnag.feature @@ -0,0 +1,5 @@ +Feature: Bugsnag disabled + +Scenario: No requests are received when bugsnag is disabled + When I build "default_app" using the "disabled_bugsnag" bugsnag config + Then I should receive 0 requests diff --git a/features/fixtures/app/module/build.gradle b/features/fixtures/app/module/build.gradle index c3630c14b5..aa5e3244cf 100644 --- a/features/fixtures/app/module/build.gradle +++ b/features/fixtures/app/module/build.gradle @@ -5,9 +5,7 @@ def bugsnagConfig = System.env.BUGSNAG_CONFIG ?: "standard" apply from: "../../config/android/${moduleConfig}.gradle" if (!System.env.UPDATING_GRADLEW) { - // apply config first (not overwritten by applying bugsnag plugin) - apply from: "../../config/bugsnag/${bugsnagConfig}.gradle" // apply bugsnag plugin configuration (e.g. custom sourceControl info) - apply plugin: 'com.bugsnag.android.gradle' + apply from: "../../config/bugsnag/${bugsnagConfig}.gradle" } diff --git a/features/fixtures/config/bugsnag/all_disabled.gradle b/features/fixtures/config/bugsnag/all_disabled.gradle index 11c0963355..ac3ee690a6 100644 --- a/features/fixtures/config/bugsnag/all_disabled.gradle +++ b/features/fixtures/config/bugsnag/all_disabled.gradle @@ -1,6 +1,8 @@ -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.uploadJvmMappings = false - project.bugsnag.reportBuilds = false +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" + uploadJvmMappings = false + reportBuilds = false } diff --git a/features/fixtures/config/bugsnag/auto_report_builds_disabled.gradle b/features/fixtures/config/bugsnag/auto_report_builds_disabled.gradle index c1b47ca047..082c5af5cd 100644 --- a/features/fixtures/config/bugsnag/auto_report_builds_disabled.gradle +++ b/features/fixtures/config/bugsnag/auto_report_builds_disabled.gradle @@ -1,5 +1,7 @@ -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.reportBuilds = false +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" + reportBuilds = false } diff --git a/features/fixtures/config/bugsnag/custom_build_info.gradle b/features/fixtures/config/bugsnag/custom_build_info.gradle index f648f7ed0b..129c64e7f7 100644 --- a/features/fixtures/config/bugsnag/custom_build_info.gradle +++ b/features/fixtures/config/bugsnag/custom_build_info.gradle @@ -1,16 +1,18 @@ -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.uploadJvmMappings = false +apply plugin: 'com.bugsnag.android.gradle' - project.bugsnag.builderName = "Mark Twain" - project.bugsnag.sourceControl.provider = "bitbucket" - project.bugsnag.sourceControl.repository = "https://example.com/bar/foo.git" - project.bugsnag.sourceControl.revision = "fab8721" +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" + uploadJvmMappings = false + + builderName = "Mark Twain" + sourceControl.provider = "bitbucket" + sourceControl.repository = "https://example.com/bar/foo.git" + sourceControl.revision = "fab8721" def map = new HashMap() map.put("MyKey", "MyValue") map.put("os_version", "BeOS") - project.bugsnag.metadata = map + metadata = map } diff --git a/features/fixtures/config/bugsnag/disabled_bugsnag.gradle b/features/fixtures/config/bugsnag/disabled_bugsnag.gradle new file mode 100644 index 0000000000..54a869e251 --- /dev/null +++ b/features/fixtures/config/bugsnag/disabled_bugsnag.gradle @@ -0,0 +1,7 @@ +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" + enabled = false +} diff --git a/features/fixtures/config/bugsnag/disabled_build_type.gradle b/features/fixtures/config/bugsnag/disabled_build_type.gradle index 9a36793855..33476bcfbc 100644 --- a/features/fixtures/config/bugsnag/disabled_build_type.gradle +++ b/features/fixtures/config/bugsnag/disabled_build_type.gradle @@ -1,9 +1,11 @@ -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" // disable bugsnag plugin for 'release' buildType - project.bugsnag.variantFilter { variant -> + variantFilter { variant -> if (variant.name.toLowerCase().contains("release")) { enabled = false } diff --git a/features/fixtures/config/bugsnag/disabled_product_flavor.gradle b/features/fixtures/config/bugsnag/disabled_product_flavor.gradle index 2577b14d26..7b7ebda7eb 100644 --- a/features/fixtures/config/bugsnag/disabled_product_flavor.gradle +++ b/features/fixtures/config/bugsnag/disabled_product_flavor.gradle @@ -1,9 +1,11 @@ -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" // disable bugsnag plugin for 'foo' productFlavor - project.bugsnag.variantFilter { variant -> + variantFilter { variant -> if (variant.name.toLowerCase().contains("foo")) { enabled = false } diff --git a/features/fixtures/config/bugsnag/empty_api_key.gradle b/features/fixtures/config/bugsnag/empty_api_key.gradle index 34e4c134be..a4ea8cd269 100644 --- a/features/fixtures/config/bugsnag/empty_api_key.gradle +++ b/features/fixtures/config/bugsnag/empty_api_key.gradle @@ -6,7 +6,9 @@ android { } } -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" } diff --git a/features/fixtures/config/bugsnag/overwrite_enabled.gradle b/features/fixtures/config/bugsnag/overwrite_enabled.gradle index fb2888a40c..21c239c50f 100644 --- a/features/fixtures/config/bugsnag/overwrite_enabled.gradle +++ b/features/fixtures/config/bugsnag/overwrite_enabled.gradle @@ -1,6 +1,8 @@ -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.reportBuilds = false - project.bugsnag.overwrite = true +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" + reportBuilds = false + overwrite = true } diff --git a/features/fixtures/config/bugsnag/standard.gradle b/features/fixtures/config/bugsnag/standard.gradle index fb740a3273..79c693270d 100644 --- a/features/fixtures/config/bugsnag/standard.gradle +++ b/features/fixtures/config/bugsnag/standard.gradle @@ -1,4 +1,6 @@ -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" } diff --git a/features/fixtures/config/bugsnag/upload_debug_enabled.gradle b/features/fixtures/config/bugsnag/upload_debug_enabled.gradle index 5b562cec85..3b4575d849 100644 --- a/features/fixtures/config/bugsnag/upload_debug_enabled.gradle +++ b/features/fixtures/config/bugsnag/upload_debug_enabled.gradle @@ -1,5 +1,7 @@ -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" - project.bugsnag.uploadDebugBuildMappings = true +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:${System.env.MOCK_API_PORT}" + releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}" + uploadDebugBuildMappings = true } diff --git a/features/fixtures/config/bugsnag/wrong_endpoint.gradle b/features/fixtures/config/bugsnag/wrong_endpoint.gradle index 542cfb9eeb..ff7ba0e5fc 100644 --- a/features/fixtures/config/bugsnag/wrong_endpoint.gradle +++ b/features/fixtures/config/bugsnag/wrong_endpoint.gradle @@ -1,4 +1,6 @@ -project.afterEvaluate { - project.bugsnag.endpoint = "http://localhost:12345" - project.bugsnag.releasesEndpoint = "http://localhost:12345" +apply plugin: 'com.bugsnag.android.gradle' + +bugsnag { + endpoint = "http://localhost:12345" + releasesEndpoint = "http://localhost:12345" } diff --git a/src/main/kotlin/com/bugsnag/android/gradle/BugsnagPlugin.kt b/src/main/kotlin/com/bugsnag/android/gradle/BugsnagPlugin.kt index 35ec284d91..7711c6aa2b 100644 --- a/src/main/kotlin/com/bugsnag/android/gradle/BugsnagPlugin.kt +++ b/src/main/kotlin/com/bugsnag/android/gradle/BugsnagPlugin.kt @@ -83,6 +83,9 @@ class BugsnagPlugin : Plugin { if (BugsnagManifestUuidTaskV2.isApplicable()) { check(android is CommonExtension<*, *, *, *, *, *, *, *>) android.onVariants { + if (!bugsnag.enabled.get()) { + return@onVariants + } val variant = VariantFilterImpl(name) if (!isVariantEnabled(bugsnag, variant)) { return@onVariants @@ -108,6 +111,9 @@ class BugsnagPlugin : Plugin { } project.afterEvaluate { + if (!bugsnag.enabled.get()) { + return@afterEvaluate + } android.applicationVariants.configureEach { variant -> val filterImpl = VariantFilterImpl(variant.name) if (!isVariantEnabled(bugsnag, filterImpl)) {