Skip to content

Commit

Permalink
v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench authored Jan 23, 2019
2 parents b0efaf2 + 28c7417 commit 2306223
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 66 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 4.0.0 (TBD)

* Remove support for Jack compiler
[#142](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/142)

* Address provider api warnings
[#146](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/146)

## 3.6.0 (2018-12-12)

* Support automatic upload when building App Bundles
Expand Down
13 changes: 13 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Upgrading Guide
===============

Upgrade from 3.X to 4.X
-----------------------

This release removes support for the [Jack compiler](https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html), but is otherwise backwards compatible. Update the version number to 4.+ to upgrade:

```groovy
dependencies {
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:4.+'
}
```
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 = 3.6.0
version = 4.0.0

ANDROID_MIN_SDK_VERSION=14
ANDROID_TARGET_SDK_VERSION=27
Expand Down
92 changes: 35 additions & 57 deletions src/main/groovy/com/bugsnag/android/gradle/BugsnagPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.api.BaseVariantOutput
import com.android.build.gradle.api.LibraryVariant
import com.android.build.gradle.internal.dsl.BuildType
import org.gradle.api.DomainObjectSet
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down Expand Up @@ -134,7 +133,7 @@ class BugsnagPlugin implements Plugin<Project> {
*/
private static void setupMappingFileUpload(Project project, BugsnagTaskDeps deps) {
def uploadTask = project.tasks.create("uploadBugsnag${taskNameForOutput(deps.output)}Mapping", BugsnagUploadProguardTask)
uploadTask.partName = isJackEnabled(project, deps.variant) ? "jack" : "proguard"
uploadTask.partName = "proguard"
prepareUploadTask(uploadTask, deps, project)
}

Expand Down Expand Up @@ -167,7 +166,7 @@ class BugsnagPlugin implements Plugin<Project> {
setupBugsnagTask(releasesTask, deps)

if (shouldUploadDebugMappings(project, deps.output)) {
findAssembleBundleTasks(deps.output, project).forEach {
findAssembleBundleTasks(deps.variant, deps.output, project).forEach {
releasesTask.mustRunAfter it

if (project.bugsnag.autoReportBuilds) {
Expand All @@ -188,7 +187,7 @@ class BugsnagPlugin implements Plugin<Project> {
uploadTask.applicationId = deps.variant.applicationId

if (shouldUploadDebugMappings(project, deps.output)) {
findAssembleBundleTasks(deps.output, project).forEach {
findAssembleBundleTasks(deps.variant, deps.output, project).forEach {
uploadTask.mustRunAfter it

if (project.bugsnag.autoUpload) {
Expand All @@ -208,10 +207,10 @@ class BugsnagPlugin implements Plugin<Project> {
* @param project the current project
* @return the assemble + bundle tasks
*/
private static Set<Task> findAssembleBundleTasks(BaseVariantOutput output, Project project) {
private static Set<Task> findAssembleBundleTasks(BaseVariant variant, BaseVariantOutput output, Project project) {
Set<String> taskNames = new HashSet<>()
taskNames.addAll(findTaskNamesForPrefix(output, "assemble"))
taskNames.addAll(findTaskNamesForPrefix(output, "bundle"))
taskNames.addAll(findTaskNamesForPrefix(variant, output, "assemble"))
taskNames.addAll(findTaskNamesForPrefix(variant, output, "bundle"))

project.tasks.findAll {
taskNames.contains(it.name)
Expand All @@ -224,9 +223,10 @@ class BugsnagPlugin implements Plugin<Project> {
*
* E.g. [bundle, bundleRelease, bundleFooRelease]
*/
private static Set<String> findTaskNamesForPrefix(BaseVariantOutput output, String prefix) {
private static Set<String> findTaskNamesForPrefix(BaseVariant variant, BaseVariantOutput output, String prefix) {
String variantName = output.name.split("-")[0].capitalize()
String assembleTaskName = output.assemble.name
def assembleTask = resolveAssembleTask(variant)
String assembleTaskName = assembleTask.name
String buildTypeTaskName = assembleTaskName.replaceAll(variantName, "")
String buildType = buildTypeTaskName.replaceAll("assemble", "")
String variantTaskName = assembleTaskName.replaceAll(buildType, "")
Expand All @@ -239,13 +239,29 @@ class BugsnagPlugin implements Plugin<Project> {
return taskNames
}

private static def resolveAssembleTask(BaseVariant variant) {
try {
return variant.assembleProvider.get()
} catch (Throwable ignored) {
return variant.assemble
}
}

private static void setupManifestUuidTask(Project project, BugsnagTaskDeps deps) {
BugsnagManifestTask manifestTask = project.tasks.create("processBugsnag${taskNameForOutput(deps.output)}Manifest", BugsnagManifestTask)
setupBugsnagTask(manifestTask, deps)
def processManifest = deps.output.processManifest
def processManifest = resolveProcessManifest(deps.output)
processManifest.finalizedBy(manifestTask)
}

static def resolveProcessManifest(BaseVariantOutput output) {
try {
return output.processManifestProvider.get()
} catch (Throwable ignored) {
return output.processManifest
}
}

/**
* Automatically add the "edit proguard settings" task to the
* build process.
Expand Down Expand Up @@ -289,7 +305,15 @@ class BugsnagPlugin implements Plugin<Project> {
if (variant instanceof LibraryVariant) {
variant.getPackageLibrary().dependsOn task
} else {
variant.getPackageApplication().dependsOn task
resolvePackageApplication(variant).dependsOn task
}
}

static def resolvePackageApplication(BaseVariant variant) {
try {
return variant.getPackageApplicationProvider().get()
} catch (Throwable ignored) {
return variant.getPackageApplication()
}
}

Expand All @@ -302,52 +326,6 @@ class BugsnagPlugin implements Plugin<Project> {
return (variant.productFlavors + variant.buildType).any(hasDisabledBugsnag)
}

/**
* Checks to see if the Jack compiler is being used for the given variant
*
* @param project The project to check in
* @param variant The variant to check
* @return true if Jack is enabled, else false
*/
private static boolean isJackEnabled(Project project, BaseVariant variant) {

// First check the selected build type to see if there are jack settings
def buildTypes = project.android.buildTypes.store
BuildType b = findNode(buildTypes, variant.baseName)

if (b?.hasProperty('jackOptions')
&& b.jackOptions.enabled instanceof Boolean) {

return b.jackOptions.enabled

// Now check the default config to see if any Jack settings are defined
} else if (project.android.defaultConfig?.hasProperty('jackOptions')
&& project.android.defaultConfig.jackOptions.enabled instanceof Boolean) {

return project.android.defaultConfig.jackOptions.enabled
} else {
return false
}
}

/**
* Finds the given build type in a TreeSet of buildtypes
* @param set The TreeSet of build types
* @param name The name of the buildtype to search for
* @return The buildtype, or null if not found
*/
private static BuildType findNode(def set, String name) {
Iterator<BuildType> iterator = set.iterator()

while (iterator.hasNext()) {
BuildType node = iterator.next()
if (node.getName() == name) {
return node
}
}
return null
}

/**
* Returns true if the DexGuard plugin has been applied to the project
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.bugsnag.android.gradle

import com.android.build.gradle.api.BaseVariantOutput
import com.android.build.gradle.tasks.ExternalNativeBuildTask
import com.android.build.gradle.tasks.ProcessAndroidResources
import org.apache.http.entity.mime.MultipartEntity
import org.apache.http.entity.mime.content.FileBody
import org.apache.http.entity.mime.content.StringBody
Expand Down Expand Up @@ -57,8 +56,7 @@ class BugsnagUploadNdkTask extends BugsnagMultiPartUploadTask {
}
}

Collection<ExternalNativeBuildTask> tasks = variant.externalNativeBuildTasks
for (ExternalNativeBuildTask task : tasks) {
for (ExternalNativeBuildTask task : resolveExternalNativeBuildTasks()) {
File objFolder = task.objFolder
File soFolder = task.soFolder
findSharedObjectFiles(objFolder, processor)
Expand All @@ -74,16 +72,34 @@ class BugsnagUploadNdkTask extends BugsnagMultiPartUploadTask {
}
}

private static File findSymbolPath(BaseVariantOutput variantOutput) {
ProcessAndroidResources resources = variantOutput.processResources
private Collection<ExternalNativeBuildTask> resolveExternalNativeBuildTasks() {
try {
return variant.externalNativeBuildProviders
.stream()
.map({ it.get() })
.collect()
} catch (Throwable ignored) {
return variant.externalNativeBuildTasks
}
}

private static File findSymbolPath(BaseVariantOutput variantOutput) {
def resources = resolveProcessAndroidResources(variantOutput)
def symbolPath = resources.textSymbolOutputFile

if (symbolPath == null) {
throw new IllegalStateException("Could not find symbol path")
}
symbolPath
}

private static def resolveProcessAndroidResources(BaseVariantOutput variantOutput) {
try {
return variantOutput.processResourcesProvider.get()
} catch (Throwable ignored) {
return variantOutput.processResources
}
}
/**
* Searches the subdirectories of a given path and executes a block on
* any shared object files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.api.BaseVariantOutput
import groovy.xml.Namespace
import org.gradle.api.DefaultTask
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider

import java.nio.file.Paths

Expand Down Expand Up @@ -34,7 +32,8 @@ class BugsnagVariantOutputTask extends DefaultTask {
*/
File getManifestPath() {
File directory
def outputDir = variantOutput.processManifest.manifestOutputDirectory
def processManifest = BugsnagPlugin.resolveProcessManifest(variantOutput)
def outputDir = processManifest.manifestOutputDirectory

if (outputDir instanceof File) {
directory = outputDir
Expand Down

0 comments on commit 2306223

Please sign in to comment.