Skip to content

Commit

Permalink
v4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench authored Mar 13, 2019
2 parents 2306223 + 6863a4b commit b584aef
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 5 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
## 4.0.0 (TBD)
## 4.1.0 (2019-03-13)

Note: this version of the plugin will fail the build if a mapping file is not uploaded successfully.
Previously if this occurred the failure would have been logged as an error and the build would have continued.

This behaviour can be disabled by setting `failOnUploadError` to `false`.

* Fail on upload error
[#151](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/151)

## 4.0.0 (2019-01-23)

* Remove support for Jack compiler
[#142](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/142)
Expand Down
28 changes: 28 additions & 0 deletions features/fail_on_upload_error.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: Build stops when mapping file upload fails

Scenario: Upload successfully with API key, mapping file, and correct endpoint
When I build "default_app" using the "standard" bugsnag config
Then I should receive 2 requests
And the exit code equals 0

Scenario: No uploads or build failures when obfuscation is disabled
When I build "disabled_obfuscation" using the "standard" bugsnag config
Then I should receive 0 requests
And the exit code equals 0

Scenario: Upload failure due to empty API key
When I build the failing "default_app" using the "empty_api_key" bugsnag config
Then I should receive 1 request
And the request 0 is valid for the Build API
And the exit code equals 1

Scenario: Upload failure due to connectivity failure
When I build the failing "default_app" using the "wrong_endpoint" bugsnag config
Then I should receive 0 requests
And the exit code equals 1

Scenario: Upload failure due to missing mapping file
When I build the failing "missing_mapping_file" using the "standard" bugsnag config
Then I should receive 1 request
And the request 0 is valid for the Build API
And the exit code equals 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

defaultConfig {
applicationId 'com.bugsnag.android.example'
minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)
versionCode Integer.parseInt(project.SAMPLE_VERSION_CODE)
versionName project.SAMPLE_VERSION_NAME
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apply plugin: 'com.android.application'
apply from: 'config/android/common.gradle'

task deleteMappingFile {
doLast {
File mappingFile = new File("module/build/outputs/mapping/release/mapping.txt")
mappingFile.delete()
project.logger.lifecycle("Delete mapping file!")
}
}

// delete the mapping file after generation, but before bugsnag can upload it
project.afterEvaluate {
project.android.applicationVariants.all { variant ->
variant.outputs.each { output ->
output.assemble.finalizedBy(deleteMappingFile)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project.afterEvaluate {
project.bugsnag.apiKey = ""
project.bugsnag.endpoint = "http://localhost:${System.env.MOCK_API_PORT}"
project.bugsnag.releasesEndpoint = "http://localhost:${System.env.MOCK_API_PORT}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project.afterEvaluate {
project.bugsnag.endpoint = "http://localhost:12345"
project.bugsnag.releasesEndpoint = "http://localhost:12345"
}
14 changes: 14 additions & 0 deletions features/steps/gradle_plugin_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@
assert_not_nil(parts["appId"], "'appId' should not be nil")
assert_not_nil(parts["arch"], "'arch' should not be nil")
end

When("I build the failing {string} using the {string} bugsnag config") do |module_config, bugsnag_config|
begin
steps %Q{
When I build "#{module_config}" using the "#{bugsnag_config}" bugsnag config
}
assert(false, "Expected script to fail with non-zero exit code")
rescue SystemExit
end
end

Then(/^the exit code equals (\d+)$/) do |exit_code|
assert_equal(exit_code, $?.exitstatus.to_i)
end
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = com.bugsnag
version = 4.0.0
version = 4.1.0

ANDROID_MIN_SDK_VERSION=14
ANDROID_TARGET_SDK_VERSION=27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import org.apache.http.impl.client.DefaultHttpClient
import org.apache.http.params.HttpConnectionParams
import org.apache.http.params.HttpParams
import org.apache.http.util.EntityUtils
import org.gradle.api.GradleException
import org.gradle.api.GradleScriptException

/**
Task to upload ProGuard mapping files to Bugsnag.
Expand All @@ -34,9 +37,13 @@ abstract class BugsnagMultiPartUploadTask extends BugsnagVariantOutputTask {
}

def uploadMultipartEntity(MultipartEntity mpEntity) {
if (apiKey == null) {
if (apiKey == null || apiKey == "") {
project.logger.warn("Skipping upload due to invalid parameters")
return
if (project.bugsnag.failOnUploadError) {
throw new GradleException("Skipping upload due to invalid parameters")
} else {
return
}
}

addPropertiesToMultipartEntity(mpEntity)
Expand All @@ -51,6 +58,10 @@ abstract class BugsnagMultiPartUploadTask extends BugsnagVariantOutputTask {
uploadSuccessful = uploadToServer(mpEntity)
retryCount--
}

if (!uploadSuccessful && project.bugsnag.failOnUploadError) {
throw new GradleException("Upload did not succeed")
}
}

def addPropertiesToMultipartEntity(MultipartEntity mpEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class BugsnagPlugin implements Plugin<Project> {
setupProguardAutoConfig(project, variant)

variant.outputs.each { output ->
if (!variant.buildType.minifyEnabled && !hasDexguardPlugin(project)) {
return
}

BugsnagTaskDeps deps = new BugsnagTaskDeps()
deps.variant = variant
deps.output = output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BugsnagPluginExtension {
boolean ndk = false
String sharedObjectPath = null
String projectRoot = null
boolean failOnUploadError = true

// release API values
String builderName = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.apache.http.entity.mime.HttpMultipartMode
import org.apache.http.entity.mime.MultipartEntity
import org.apache.http.entity.mime.content.FileBody
import org.apache.http.util.TextUtils
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.tasks.TaskAction

Expand Down Expand Up @@ -42,7 +43,11 @@ class BugsnagUploadProguardTask extends BugsnagMultiPartUploadTask {
// will not exist (but we also won't need it).
if (!mappingFile || !mappingFile.exists()) {
project.logger.warn("Mapping file not found: ${mappingFile}")
return
if (project.bugsnag.failOnUploadError) {
throw new GradleException("Mapping file not found: ${mappingFile}")
} else {
return
}
}

// Read the API key and Build ID etc..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PluginExtensionTest {
assertFalse(proj.bugsnag.ndk)
assertNull(proj.bugsnag.sharedObjectPath)
assertFalse(BugsnagPlugin.hasDexguardPlugin(proj))
assertTrue(proj.bugsnag.failOnUploadError)

assertFalse(BugsnagPlugin.hasMultipleOutputs(proj))

Expand Down

0 comments on commit b584aef

Please sign in to comment.