-
-
Notifications
You must be signed in to change notification settings - Fork 41
fix(instrumentation): Resolve class availability at task time #1402
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b884f89
fix(instrumentation): Resolve class availability at task time
sentry-junior[bot] 3a70aa5
docs(changelog): Point runtime-opt fix at #1402
sentry-junior[bot] dc1ce67
test(instrumentation): Expect availability task
sentry-junior[bot] 4916101
test(instrumentation): Guard config-time classpath resolution
sentry-junior[bot] 04f8b93
fix(instrumentation): Use full resolution graph for availability
sentry-junior[bot] da8756f
docs(instrumentation): Explain missing classpath fallback
sentry-junior[bot] 2872513
docs(instrumentation): Clarify availability file and task wiring
sentry-junior[bot] b468884
test(instrumentation): Cover LoadClass availability injection E2E
sentry-junior[bot] 560ec62
test(instrumentation): Prefer instrumented LoadClass bytecode
sentry-junior[bot] 10c9a2c
test(instrumentation): Match expected LoadClass availability map
sentry-junior[bot] 4a568a8
fix(instrumentation): Pass availability as MapProperty to ASM
sentry-junior[bot] ebdf5d4
fix(instrumentation): Depend on availability task output via flatMap
sentry-junior[bot] c2b50db
fix(instrumentation): Run availability task before AsmClassesTransform
sentry-junior[bot] a511985
fix(instrumentation): Use @InputFile for availability, not MapProperty
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...ain/kotlin/io/sentry/android/gradle/tasks/dependencies/ResolveSdkClassAvailabilityTask.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package io.sentry.android.gradle.tasks.dependencies | ||
|
|
||
| import io.sentry.android.gradle.instrumentation.resolveClassAvailability | ||
| import org.gradle.api.DefaultTask | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.UnknownDomainObjectException | ||
| import org.gradle.api.file.RegularFileProperty | ||
| import org.gradle.api.internal.artifacts.DefaultModuleIdentifier | ||
| import org.gradle.api.provider.SetProperty | ||
| import org.gradle.api.tasks.CacheableTask | ||
| import org.gradle.api.tasks.Input | ||
| import org.gradle.api.tasks.OutputFile | ||
| import org.gradle.api.tasks.TaskAction | ||
| import org.gradle.api.tasks.TaskProvider | ||
|
|
||
| /** | ||
| * Resolves the variant runtime classpath at execution time and writes the optional SDK class | ||
| * availability map used by | ||
| * [io.sentry.android.gradle.instrumentation.SentrySdkOptimizationClassVisitorFactory]. | ||
| * | ||
| * Keeping resolution on a task input avoids resolving `*RuntimeClasspath` during configuration when | ||
| * AGP snapshots instrumentation parameters. | ||
| */ | ||
| @CacheableTask | ||
| abstract class ResolveSdkClassAvailabilityTask : DefaultTask() { | ||
|
|
||
| init { | ||
| description = "Resolves optional Sentry SDK class availability from the runtime classpath" | ||
| } | ||
|
|
||
| /** Module coordinates in `group:module` form from the resolved dependency graph. */ | ||
| @get:Input abstract val moduleIds: SetProperty<String> | ||
|
|
||
| @get:OutputFile abstract val outputFile: RegularFileProperty | ||
|
|
||
| @TaskAction | ||
| fun action() { | ||
| val modules = | ||
| moduleIds | ||
| .get() | ||
| .mapNotNull { coordinate -> | ||
| val parts = coordinate.split(':', limit = 2) | ||
| if (parts.size != 2) { | ||
| null | ||
| } else { | ||
| DefaultModuleIdentifier.newId(parts[0], parts[1]) | ||
| } | ||
| } | ||
| .toSet() | ||
|
|
||
| val availability = resolveClassAvailability(modules) | ||
| val output = outputFile.get().asFile | ||
| // Deterministic one-entry-per-line properties (no java.util.Properties timestamp header): | ||
| // androidx.core.view.ScrollingView=true | ||
| // timber.log.Timber=false | ||
| output.bufferedWriter().use { writer -> | ||
| availability.toSortedMap().forEach { (className, available) -> | ||
| writer.append(className).append('=').append(available.toString()).append('\n') | ||
| } | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| fun register( | ||
| project: Project, | ||
| configurationName: String, | ||
| taskSuffix: String, | ||
| ): TaskProvider<ResolveSdkClassAvailabilityTask>? { | ||
| val configuration = | ||
| try { | ||
| project.configurations.getByName(configurationName) | ||
| } catch (e: UnknownDomainObjectException) { | ||
| project.logger.warn( | ||
| "Unable to find configuration $configurationName for SDK class availability." | ||
| ) | ||
| return null | ||
| } | ||
|
|
||
| return project.tasks.register( | ||
| "resolveSentrySdkClassAvailability$taskSuffix", | ||
| ResolveSdkClassAvailabilityTask::class.java, | ||
| ) { task -> | ||
| // Lazy Provider: resolutionResult is only read when the task input is realized at | ||
| // execution time. Use allComponents (not artifactsFor) so presence matches the old | ||
| // graph-based path, including modules that do not publish android-classes artifacts. | ||
| task.moduleIds.set( | ||
| project.provider { | ||
| configuration.incoming.resolutionResult.allComponents | ||
| .mapNotNull { component -> component.moduleVersion?.module } | ||
| .map { module -> "${module.group}:${module.name}" } | ||
| .toSet() | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| ) | ||
| task.outputFile.set( | ||
| project.layout.buildDirectory.file( | ||
| "intermediates/sentry/classAvailability/${taskSuffix}.properties" | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment here or somewhere as to what we expect the file to look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added above the writer: