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

Close IO streams after the plugin has finished reading and writing #126

Merged
merged 5 commits into from
Sep 4, 2018
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.X.X (TBD)

### Bug fixes

* Close IO streams after the plugin has finished reading and writing
[Jamie Lynch](https://github.com/fractalwrench) [#126](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/126)

## 3.4.0 (2018-08-30)

* Compress Android NDK mapping files to decrease upload times
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ class BugsnagManifestTask extends BugsnagVariantOutputTask {
application.appendNode('meta-data', [(ns.name): BugsnagPlugin.BUILD_UUID_TAG, (ns.value): buildUUID])

// Write the manifest file
def writer = new FileWriter(manifestPath)
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.preserveWhitespace = true
printer.print(xml)
FileWriter writer = null

try {
writer = new FileWriter(manifestPath)

This comment was marked as resolved.

This comment was marked as resolved.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see 👍

def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.preserveWhitespace = true
printer.print(xml)
} catch (Exception e) {
project.logger.warn("Failed to update manifest with Bugsnag metadata", e)
} finally {
if (writer != null) {
writer.close()
}
}
} else {
project.logger.error("Bugsnag detected invalid manifest with no application element so did not write Build UUID")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ class BugsnagProguardConfigTask extends DefaultTask {
file.getParentFile().mkdirs()

// Write our recommended proguard settings to this file
FileWriter fr = new FileWriter(file.path)
fr.write(PROGUARD_CONFIG_SETTINGS)
fr.write("\n")
fr.close()
FileWriter fr = null

try {
fr = new FileWriter(file.path)
fr.write(PROGUARD_CONFIG_SETTINGS)
fr.write("\n")
} catch (Exception e) {
project.logger.warn("Failed to write Bugsnag ProGuard settings", e)
} finally {
if (fr != null) {
fr.close()
}
}

// Add this proguard settings file to the list
variant.getBuildType().buildType.proguardFiles(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class BugsnagReleasesTask extends BugsnagVariantOutputTask {
}

private boolean deliverPayload(JSONObject payload) {
OutputStream os = null

try {
URL url = new URL(project.bugsnag.releasesEndpoint)
HttpURLConnection conn = url.openConnection()
Expand All @@ -58,31 +60,40 @@ class BugsnagReleasesTask extends BugsnagVariantOutputTask {
conn.setConnectTimeout(Call.TIMEOUT_MILLIS)
conn.setDoOutput(true)

OutputStream os = conn.outputStream
os = conn.outputStream
os.write(payload.toString().getBytes("UTF-8"))
os.close()

int statusCode = conn.getResponseCode()

if (statusCode == 200) {
project.logger.info("Uploaded release info to Bugsnag")
return true
} else {
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.errorStream))
BufferedReader reader
String line

while ((line = reader.readLine()) != null) {
project.logger.error(line)
try {
reader = new BufferedReader(new InputStreamReader(conn.errorStream))
while ((line = reader.readLine()) != null) {
project.logger.error(line)
}
project.logger.warn("Release Request failed with statusCode " + statusCode)
} finally {
if (reader != null) {
reader.close()
}
}

project.logger.warn("Release Request failed with statusCode " + statusCode)
return false
}

} catch (IOException e) {
project.logger.error(project.bugsnag.releasesEndpoint)
project.logger.error("Failed to POST request", e)
return false
} finally {
if (os != null) {
os.close()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import org.apache.http.entity.mime.content.FileBody
import org.apache.http.entity.mime.content.StringBody
import org.gradle.api.tasks.TaskAction

import java.util.regex.Matcher
import java.util.regex.Pattern
import java.util.zip.GZIPOutputStream

import static groovy.io.FileType.FILES
Expand Down Expand Up @@ -116,6 +114,8 @@ class BugsnagUploadNdkTask extends BugsnagMultiPartUploadTask {
File objDumpPath = getObjDumpExecutable(arch)
if (objDumpPath != null) {

Reader outReader = null

try {
File outputDir = new File(project.buildDir, "bugsnag")

Expand Down Expand Up @@ -144,6 +144,10 @@ class BugsnagUploadNdkTask extends BugsnagMultiPartUploadTask {
}
} catch (Exception e) {
project.logger.error("failed to generate symbols for " + arch + ": " + e.getMessage(), e)
} finally {
if (outReader != null) {
outReader.close()
}
}
} else {
project.logger.error("Unable to upload NDK symbols: Could not find objdump location for " + arch)
Expand Down