-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathBundleSourcesTask.kt
More file actions
109 lines (96 loc) · 4 KB
/
BundleSourcesTask.kt
File metadata and controls
109 lines (96 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package io.sentry.android.gradle.sourcecontext
import io.sentry.android.gradle.SentryPropertiesFileProvider
import io.sentry.android.gradle.autoinstall.SENTRY_GROUP
import io.sentry.android.gradle.extensions.SentryPluginExtension
import io.sentry.android.gradle.sourcecontext.GenerateBundleIdTask.Companion.SENTRY_BUNDLE_ID_PROPERTY
import io.sentry.android.gradle.tasks.SentryCliExecTask
import io.sentry.android.gradle.telemetry.SentryTelemetryService
import io.sentry.android.gradle.telemetry.withSentryTelemetry
import io.sentry.android.gradle.util.PropertiesUtil
import io.sentry.android.gradle.util.asSentryCliExec
import io.sentry.gradle.common.SentryVariant
import java.io.File
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskProvider
@CacheableTask
abstract class BundleSourcesTask : SentryCliExecTask() {
init {
group = SENTRY_GROUP
description = "Creates a Sentry source bundle file."
@Suppress("LeakingThis")
onlyIf { includeSourceContext.getOrElse(false) && !sourceDir.asFileTree.isEmpty }
}
@get:Input abstract val includeSourceContext: Property<Boolean>
@get:PathSensitive(PathSensitivity.RELATIVE)
@get:InputDirectory
abstract val sourceDir: DirectoryProperty
@get:InputFile
@get:PathSensitive(PathSensitivity.NONE)
abstract val bundleIdFile: RegularFileProperty
@get:OutputDirectory abstract val output: DirectoryProperty
override fun getArguments(args: MutableList<String>) {
val bundleId = readBundleIdFromFile(bundleIdFile.get().asFile)
args.add("debug-files")
args.add("bundle-jvm")
args.add("--output=${output.asFile.get().absolutePath}")
args.add("--debug-id=$bundleId")
args.add(sourceDir.get().asFile.absolutePath)
}
companion object {
internal fun readBundleIdFromFile(file: File): String {
val props = PropertiesUtil.load(file)
val bundleId: String? = props.getProperty(SENTRY_BUNDLE_ID_PROPERTY)
check(bundleId != null) { "$SENTRY_BUNDLE_ID_PROPERTY property is missing" }
return bundleId
}
fun register(
project: Project,
extension: SentryPluginExtension,
sentryTelemetryProvider: Provider<SentryTelemetryService>?,
variant: SentryVariant,
generateDebugIdTask: TaskProvider<GenerateBundleIdTask>,
collectSourcesTask: TaskProvider<CollectSourcesTask>,
output: Provider<Directory>,
debug: Property<Boolean>,
sentryOrg: Provider<String>,
sentryProject: Provider<String>,
sentryAuthToken: Property<String>,
sentryUrl: Property<String>,
includeSourceContext: Property<Boolean>,
taskSuffix: String = "",
): TaskProvider<BundleSourcesTask> {
return project.tasks.register(
"sentryBundleSources$taskSuffix",
BundleSourcesTask::class.java,
) { task ->
task.debug.set(debug)
task.sentryOrganization.set(sentryOrg)
task.sentryProject.set(sentryProject)
task.sentryAuthToken.set(sentryAuthToken)
task.sentryUrl.set(sentryUrl)
task.sourceDir.set(collectSourcesTask.flatMap { it.output })
SentryPropertiesFileProvider.getPropertiesFilePath(project, variant)?.let {
task.sentryProperties.set(File(it))
}
task.bundleIdFile.set(generateDebugIdTask.flatMap { it.outputFile })
task.output.set(output)
task.includeSourceContext.set(includeSourceContext)
sentryTelemetryProvider?.let { task.sentryTelemetryService.set(it) }
task.asSentryCliExec()
task.withSentryTelemetry(extension, sentryTelemetryProvider)
}
}
}
}