Skip to content

Commit

Permalink
Merge pull request #263 from bugsnag/v5-enabled-flag
Browse files Browse the repository at this point in the history
Respect bugsnag.enabled flag when registering tasks
  • Loading branch information
fractalwrench committed Aug 13, 2020
2 parents d7511f0 + 22c1035 commit dda0ce4
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 47 deletions.
5 changes: 5 additions & 0 deletions features/disabled_bugsnag.feature
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions features/fixtures/app/module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
12 changes: 7 additions & 5 deletions features/fixtures/config/bugsnag/all_disabled.gradle
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 11 additions & 9 deletions features/fixtures/config/bugsnag/custom_build_info.gradle
Original file line number Diff line number Diff line change
@@ -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

}
7 changes: 7 additions & 0 deletions features/fixtures/config/bugsnag/disabled_bugsnag.gradle
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 6 additions & 4 deletions features/fixtures/config/bugsnag/disabled_build_type.gradle
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
10 changes: 6 additions & 4 deletions features/fixtures/config/bugsnag/disabled_product_flavor.gradle
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions features/fixtures/config/bugsnag/empty_api_key.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
12 changes: 7 additions & 5 deletions features/fixtures/config/bugsnag/overwrite_enabled.gradle
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 5 additions & 3 deletions features/fixtures/config/bugsnag/standard.gradle
Original file line number Diff line number Diff line change
@@ -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}"
}
10 changes: 6 additions & 4 deletions features/fixtures/config/bugsnag/upload_debug_enabled.gradle
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 5 additions & 3 deletions features/fixtures/config/bugsnag/wrong_endpoint.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 6 additions & 0 deletions src/main/kotlin/com/bugsnag/android/gradle/BugsnagPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class BugsnagPlugin : Plugin<Project> {
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
Expand All @@ -108,6 +111,9 @@ class BugsnagPlugin : Plugin<Project> {
}

project.afterEvaluate {
if (!bugsnag.enabled.get()) {
return@afterEvaluate
}
android.applicationVariants.configureEach { variant ->
val filterImpl = VariantFilterImpl(variant.name)
if (!isVariantEnabled(bugsnag, filterImpl)) {
Expand Down

0 comments on commit dda0ce4

Please sign in to comment.