Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to overwrite a mapping when uploading #25

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ If you aren't using Gradle or need more manual control, [see the API docs](https
- [Automatic Proguard Config](#automatic-proguard-config)
- [Custom Endpoints](#custom-endpoints)
- [Disabling Bugsnag](#disabling-bugsnag)
- [Overwrite mapping file](#overwrite-mapping-file)
- [Build UUIDs](#build-uuids)
- [Support](#support)
- [Contributing](#contributing)
Expand Down Expand Up @@ -138,6 +139,15 @@ android {
}
```

## Overwrite mapping file
To overwrite a mapping file, you can set the `overwrite` property as follows:

```groovy
bugsnag {
overwrite false
}
```

You can also declare this inside a product flavor. Conflicting values (between multiple flavors or a flavor and a build-type) are ignored and the plugin will be disabled if `false` was set anywhere.

You may want to do this to speed up build types or flavors where you don't require Bugsnag's functionality. Bugsnag's generation of a UUID for each build into your manifest (see [Build UUIDs](#build-uuids)) causes the resources task to be run for each build, introducing a small delay if your build's changes don't involve resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package com.bugsnag.android.gradle
class BugsnagPluginExtension {
def String endpoint = 'https://upload.bugsnag.com'
def String apiKey = null
def boolean autoUpload = true;
def boolean autoProguardConfig = true;
def boolean autoUpload = true
def boolean autoProguardConfig = true
def boolean overwrite = false
}
27 changes: 13 additions & 14 deletions src/main/groovy/com/bugsnag/android/gradle/BugsnagUploadTask.groovy
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.bugsnag.android.gradle

import groovy.util.XmlParser
import groovy.xml.Namespace

import org.apache.http.HttpEntity
import org.apache.http.HttpResponse
import org.apache.http.client.HttpClient
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.mime.MultipartEntity
import org.apache.http.entity.mime.MultipartEntityBuilder
import org.apache.http.entity.mime.content.FileBody
import org.apache.http.entity.mime.content.StringBody
import org.apache.http.impl.client.DefaultHttpClient
import org.apache.http.util.EntityUtils

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

Expand Down Expand Up @@ -66,31 +64,32 @@ class BugsnagUploadTask extends DefaultTask {
}

// Upload the mapping file to Bugsnag
MultipartEntity mpEntity = new MultipartEntity();
mpEntity.addPart("proguard", new FileBody(mappingFile));
mpEntity.addPart("apiKey", new StringBody(apiKey));
mpEntity.addPart("appId", new StringBody(applicationId));
mpEntity.addPart("versionCode", new StringBody(versionCode));
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addPart("proguard", new FileBody(mappingFile));
builder.addPart("apiKey", new StringBody(apiKey));
builder.addPart("appId", new StringBody(applicationId));
builder.addPart("versionCode", new StringBody(versionCode));

// Uniquely identify the build so that we can identify the proguard file.
def buildUUID = getBuildUUID(metaDataTags, ns)
if(buildUUID != null) {
mpEntity.addPart("buildUUID", new StringBody(buildUUID));
builder.addPart("buildUUID", new StringBody(buildUUID));
}

// Get the build version
def versionName = xml.attributes()[ns.versionName]
if (versionName != null) {
mpEntity.addPart("versionName", new StringBody(versionName));
builder.addPart("versionName", new StringBody(versionName));
}

if (System.properties['bugsnag.overwrite']) {
mpEntity.addPart("overwrite", new StringBody("true"));
if (project.bugsnag.overwrite || System.properties['bugsnag.overwrite']) {
builder.addPart("overwrite", new StringBody("true"));
}
HttpEntity entity = builder.build()

// Make the request
HttpPost httpPost = new HttpPost(project.bugsnag.endpoint)
httpPost.setEntity(mpEntity);
httpPost.setEntity(entity)

HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(httpPost);
Expand Down