Skip to content

Commit

Permalink
Merge pull request #171 from bugsnag/transitive-dependency-so-files
Browse files Browse the repository at this point in the history
Update plugin to extract SO files from transitive dependencies
  • Loading branch information
fractalwrench authored Jul 18, 2019
2 parents 5783928 + ed3e63d commit effdf42
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.5.2 (2019-07-18)

Update plugin to extract SO files from transitive dependencies
[#171](https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/171)

## 4.5.1 (2019-07-17)

Lookup shared object files correctly in new artefact IDs
Expand Down
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.5.1
version = 4.5.2

ANDROID_MIN_SDK_VERSION=14
ANDROID_TARGET_SDK_VERSION=27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package com.bugsnag.android.gradle

import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.ResolvedConfiguration
import org.gradle.api.artifacts.ResolvedDependency
import org.gradle.api.tasks.TaskAction

import java.util.stream.Collectors

class BugsnagNdkSetupTask extends DefaultTask {

BugsnagNdkSetupTask() {
Expand All @@ -13,29 +17,55 @@ class BugsnagNdkSetupTask extends DefaultTask {

@TaskAction
void setupNdkProject() {
project.configurations.findAll {
it.toString().contains('CompileClasspath')
}.each { config ->
ResolvedArtifact artifact = config.resolvedConfiguration.resolvedArtifacts.find {
String identifier = it.id.componentIdentifier.toString()
List<String> soArtefacts = ["bugsnag-android", "bugsnag-android-ndk",
"bugsnag-plugin-android-anr", "bugsnag-plugin-android-ndk",]

boolean isBugsnagArtefact = soArtefacts.stream().anyMatch {
identifier.contains(it)
}
isBugsnagArtefact && it.file != null
}
if (artifact) {
File artifactFile = artifact.file
File buildDir = project.buildDir
File dst = new File(buildDir, "/intermediates/bugsnag-libs")

project.copy {
from project.zipTree(artifactFile)
into(project.file(dst))
Set<ResolvedArtifact> artifacts = new HashSet<>()

findCompileConfigurations().each { config ->
config.firstLevelModuleDependencies.stream()
.filter { (it.moduleGroup == "com.bugsnag") }
.forEach {
artifacts.addAll(resolveArtifacts(it))
}
}
artifacts.forEach { copyArtifact(it) }
}

Set<ResolvedArtifact> resolveArtifacts(ResolvedDependency dependency) {
dependency.allModuleArtifacts.findAll {
String identifier = it.id.componentIdentifier.toString()
List<String> soArtefacts = ["bugsnag-android", "bugsnag-android-ndk",
"bugsnag-plugin-android-anr", "bugsnag-plugin-android-ndk",]

boolean isBugsnagArtefact = soArtefacts.stream().anyMatch {
identifier.contains(it)
}
isBugsnagArtefact && it.file != null
}
}

void copyArtifact(ResolvedArtifact artifact) {
File artifactFile = artifact.file
File buildDir = project.buildDir
File dst = new File(buildDir, "/intermediates/bugsnag-libs")

project.copy {
from project.zipTree(artifactFile)
into(project.file(dst))
}
}

/**
* @return the ResolvedConfiguration for any gradle configurations which add compile-time dependencies.
* e.g. if 'bugsnag-android' is added as a dependency, it will be part of the 'api' configuration.
*/
private Set<ResolvedConfiguration> findCompileConfigurations() {
project.configurations
.findAll { it.toString().contains('CompileClasspath') }
.stream()
.map { it.resolvedConfiguration }
.collect(Collectors.toSet())
}

/**
* Copies artifacts to a location in the build directory where their shared object files can be read.
*/
}

0 comments on commit effdf42

Please sign in to comment.