-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathUploadSourceBundleTask.kt
More file actions
100 lines (88 loc) · 3.69 KB
/
Copy pathUploadSourceBundleTask.kt
File metadata and controls
100 lines (88 loc) · 3.69 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
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.tasks.SentryCliExecTask
import io.sentry.android.gradle.telemetry.SentryTelemetryService
import io.sentry.android.gradle.telemetry.withSentryTelemetry
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.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskProvider
import org.gradle.work.DisableCachingByDefault
@DisableCachingByDefault(because = "Uploads should not be cached")
abstract class UploadSourceBundleTask : SentryCliExecTask() {
init {
group = SENTRY_GROUP
description = "Uploads a Sentry source bundle file."
@Suppress("LeakingThis")
onlyIf { includeSourceContext.getOrElse(false) && !sourceBundleDir.asFileTree.isEmpty }
// Allows gradle to consider this task up-to-date if the inputs haven't changed
// As this task does not have any outputs, it will always be considered to be out-of-date
// otherwise
// More info here
// https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:task_outcomes
// and
// https://docs.gradle.org/current/userguide/incremental_build.html#sec:custom_up_to_date_logic
outputs.upToDateWhen { true }
}
@get:Input abstract val includeSourceContext: Property<Boolean>
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val sourceBundleDir: DirectoryProperty
@get:Input abstract val autoUploadSourceContext: Property<Boolean>
override fun getArguments(args: MutableList<String>) {
args.add("debug-files")
args.add("upload")
args.add("--type=jvm")
if (!autoUploadSourceContext.get()) {
args.add("--no-upload")
}
args.add(sourceBundleDir.get().asFile.absolutePath)
}
companion object {
fun register(
project: Project,
extension: SentryPluginExtension,
sentryTelemetryProvider: Provider<SentryTelemetryService>?,
variant: SentryVariant,
bundleSourcesTask: TaskProvider<BundleSourcesTask>,
debug: Property<Boolean>,
autoUploadSourceContext: Property<Boolean>,
sentryOrg: Provider<String>,
sentryProject: Provider<String>,
sentryAuthToken: Property<String>,
sentryUrl: Property<String>,
includeSourceContext: Property<Boolean>,
taskSuffix: String = "",
): TaskProvider<UploadSourceBundleTask> {
return project.tasks.register(
"sentryUploadSourceBundle$taskSuffix",
UploadSourceBundleTask::class.java,
) { task ->
task.debug.set(debug)
task.sentryOrganization.set(sentryOrg)
task.sentryProject.set(sentryProject)
task.sentryAuthToken.set(sentryAuthToken)
task.sentryUrl.set(sentryUrl)
task.sourceBundleDir.set(bundleSourcesTask.flatMap { it.output })
task.autoUploadSourceContext.set(autoUploadSourceContext)
SentryPropertiesFileProvider.getPropertiesFilePath(project, variant)?.let {
task.sentryProperties.set(File(it))
}
task.includeSourceContext.set(includeSourceContext)
sentryTelemetryProvider?.let { task.sentryTelemetryService.set(it) }
task.asSentryCliExec()
task.withSentryTelemetry(extension, sentryTelemetryProvider)
}
}
}
}