Skip to content
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

Disable source context tasks if not enabled #536

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Add release information args to proguard mapping upload task ([#476](https://github.com/getsentry/sentry-android-gradle-plugin/pull/476))
- Auto install Sentry integrations for Java Backend, Desktop, etc. ([#521](https://github.com/getsentry/sentry-android-gradle-plugin/pull/521))

### Fixes

- Disable source context tasks if not enabled ([#536](https://github.com/getsentry/sentry-android-gradle-plugin/pull/536))

### Dependencies

- Bump CLI from v2.19.1 to v2.20.0 ([#520](https://github.com/getsentry/sentry-android-gradle-plugin/pull/520), [#531](https://github.com/getsentry/sentry-android-gradle-plugin/pull/531))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ class SourceContext {
taskSuffix
)

project.afterEvaluate {
generateBundleIdTask.configure {
it.enabled = extension.includeSourceContext.get()
}
collectSourcesTask.configure {
it.enabled = extension.includeSourceContext.get()
}
bundleSourcesTask.configure {
it.enabled = extension.includeSourceContext.get()
}
uploadSourceBundleTask.configure {
it.enabled = extension.includeSourceContext.get()
}
}

return SourceContextTasks(
generateBundleIdTask,
collectSourcesTask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class SentryGenerateDebugMetaPropertiesTask : DirectoryOutputTask() {
val props = Properties()
props.setProperty("io.sentry.build-tool", "gradle")
inputFiles.forEach { inputFile ->
props.putAll(PropertiesUtil.load(inputFile))
PropertiesUtil.loadMaybe(inputFile)?.let { props.putAll(it) }
}
debugMetaPropertiesFile.writer().use {
props.store(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@ class PropertiesUtil {
}
}
}

fun loadMaybe(file: File): Properties? {
if (!file.exists()) {
return null
}

return load(file)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,42 @@ class SentrySourceContextNonAndroidTest(
assertTrue { "BUILD SUCCESSFUL" in result.output }
}

@Test
fun `skips bundle and upload tasks if disabled`() {
appBuildFile.writeText(
// language=Groovy
"""
plugins {
id "org.jetbrains.kotlin.jvm"
id "io.sentry.jvm.gradle"
}

sentry {
includeSourceContext = false
}
""".trimIndent()
)

sentryPropertiesFile.writeText("")

testProjectDir.withDummyKtFile()
testProjectDir.withDummyJavaFile()

val result = runner
.appendArguments("app:assemble")
.build()

assertEquals(
result.task(":app:sentryUploadSourceBundleJava")?.outcome,
SKIPPED
)
assertEquals(
result.task(":app:sentryBundleSourcesJava")?.outcome,
SKIPPED
)
assertTrue { "BUILD SUCCESSFUL" in result.output }
}

@Test
fun `bundles source context`() {
appBuildFile.writeText(
Expand Down