Skip to content
Open
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ root = true

[*]
indent_style = space
indent_size = 4
indent_size = 2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a leftover from ktlint -> ktfmt migration

end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP apply false
alias(libs.plugins.androidLibrary) version BuildPluginsVersion.AGP apply false
alias(libs.plugins.spotless)
id("io.sentry.gradle")
}

allprojects {
Expand Down
5 changes: 1 addition & 4 deletions examples/android-gradle-kts/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
plugins {
alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP
id("io.sentry.android.gradle")
}
plugins { alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP }

android {
compileSdk = LibsVersion.SDK_VERSION
Expand Down
1 change: 0 additions & 1 deletion examples/android-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ buildscript {
}

apply plugin: 'com.android.application'
apply plugin: 'io.sentry.android.gradle'

android {
compileSdk = LibsVersion.SDK_VERSION
Expand Down
1 change: 0 additions & 1 deletion examples/android-guardsquare-proguard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ buildscript {
}

apply plugin: 'com.android.application'
apply plugin: 'io.sentry.android.gradle'
if (BuildPluginsVersion.INSTANCE.isProguardApplicable()) {
apply plugin: 'com.guardsquare.proguard'
}
Expand Down
1 change: 0 additions & 1 deletion examples/android-instrumentation-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kapt)
id("io.sentry.android.gradle")
}

// useful for local debugging of the androidx.sqlite lib
Expand Down
2 changes: 0 additions & 2 deletions examples/android-ndk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ buildscript {
}

apply plugin: 'com.android.application'
apply plugin: 'io.sentry.android.gradle'

android {
compileSdk = LibsVersion.SDK_VERSION
Expand All @@ -37,7 +36,6 @@ android {
}

if (System.getenv("AUTO_UPLOAD")) {
apply plugin: 'io.sentry.android.gradle'
sentry {
autoUploadProguardMapping = false
uploadNativeSymbols = true
Expand Down
4 changes: 4 additions & 0 deletions plugin-build/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ tasks.register<Test>("integrationTest").configure {

gradlePlugin {
plugins {
register("sentryRootPlugin") {
id = "io.sentry.gradle"
implementationClass = "io.sentry.gradle.SentryRootPlugin"
}
register("sentryPlugin") {
id = "io.sentry.android.gradle"
implementationClass = "io.sentry.android.gradle.SentryPlugin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.Variant
import com.android.build.gradle.AppExtension
import com.android.build.gradle.internal.utils.setDisallowChanges
import io.sentry.android.gradle.SentryPlugin.Companion.sep
import io.sentry.android.gradle.SentryPropertiesFileProvider.getPropertiesFilePath
import io.sentry.android.gradle.SentryTasksProvider.capitalized
import io.sentry.android.gradle.SentryTasksProvider.getMappingFileProvider
Expand Down Expand Up @@ -41,6 +40,7 @@ import io.sentry.android.gradle.util.collectModules
import io.sentry.android.gradle.util.hookWithAssembleTasks
import io.sentry.android.gradle.util.hookWithMinifyTasks
import io.sentry.android.gradle.util.info
import io.sentry.gradle.sep
import java.io.File
import org.gradle.api.Project
import org.gradle.api.file.Directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.sentry.android.gradle
import com.android.build.gradle.AppExtension
import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.api.BaseVariant
import io.sentry.android.gradle.SentryPlugin.Companion.sep
import io.sentry.android.gradle.SentryPropertiesFileProvider.getPropertiesFilePath
import io.sentry.android.gradle.SentryTasksProvider.capitalized
import io.sentry.android.gradle.SentryTasksProvider.getLintVitalAnalyzeProvider
Expand All @@ -30,6 +29,7 @@ import io.sentry.android.gradle.util.hookWithAssembleTasks
import io.sentry.android.gradle.util.hookWithMinifyTasks
import io.sentry.android.gradle.util.hookWithPackageTasks
import io.sentry.android.gradle.util.info
import io.sentry.gradle.sep
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.Directory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.sentry.android.gradle

import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.gradle.AppExtension
import io.sentry.BuildConfig
import io.sentry.android.gradle.autoinstall.installDependencies
import io.sentry.android.gradle.extensions.SentryPluginExtension
import io.sentry.android.gradle.util.AgpVersions
import java.io.File
import io.sentry.gradle.SENTRY_ORG_PARAMETER
import io.sentry.gradle.SENTRY_PROJECT_PARAMETER
import io.sentry.gradle.subplugin.AndroidAppSubplugin
import javax.inject.Inject
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -21,74 +19,55 @@ abstract class SentryPlugin
constructor(private val buildEvents: BuildEventListenerRegistryInternal) : Plugin<Project> {

override fun apply(project: Project) {
if (AgpVersions.CURRENT < AgpVersions.VERSION_7_0_0) {
throw StopExecutionException(
project.logger.warn(
"""
WARNING: Using 'io.sentry.android.gradle' is deprecated and this plugin will be removed in the future.
Consider migrating to 'io.sentry.gradle' (root project gradle plugin) instead.
"""
.trimIndent()
)
project.checkAgpApplied()
project.checkAgpVersion()

val extraProperties = project.extensions.getByName("ext") as ExtraPropertiesExtension
val sentryOrgParameter =
runCatching { extraProperties.get(SENTRY_ORG_PARAMETER).toString() }.getOrNull()
val sentryProjectParameter =
runCatching { extraProperties.get(SENTRY_PROJECT_PARAMETER).toString() }.getOrNull()

val extension = SentryPluginExtension.of(project)
AndroidAppSubplugin(project, extension)
.apply(buildEvents, sentryOrgParameter, sentryProjectParameter)
}

private fun Project.checkAgpApplied() {
if (!plugins.hasPlugin("com.android.application")) {
logger.warn(
"""
Using io.sentry.android.gradle:3+ with Android Gradle Plugin < 7 is not supported.
Either upgrade the AGP version to 7+, or use an earlier version of the Sentry
Android Gradle Plugin. For more information check our migration guide
https://docs.sentry.io/platforms/android/migration/#migrating-from-iosentrysentry-android-gradle-plugin-2x-to-iosentrysentry-android-gradle-plugin-300
"""
.trimIndent()
)
}
if (!project.plugins.hasPlugin("com.android.application")) {
project.logger.warn(
WARNING: Using 'io.sentry.android.gradle' is only supported for the app module.
Please make sure that you apply the Sentry gradle plugin alongside 'com.android.application' on the _module_ level, and not on the root project level.
https://docs.sentry.io/platforms/android/configuration/gradle/
"""
WARNING: Using 'io.sentry.android.gradle' is only supported for the app module.
Please make sure that you apply the Sentry gradle plugin alongside 'com.android.application' on the _module_ level, and not on the root project level.
https://docs.sentry.io/platforms/android/configuration/gradle/
"""
.trimIndent()
)
}
}

val extension = project.extensions.create("sentry", SentryPluginExtension::class.java, project)

project.pluginManager.withPlugin("com.android.application") {
val oldAGPExtension = project.extensions.getByType(AppExtension::class.java)
val androidComponentsExt =
project.extensions.getByType(AndroidComponentsExtension::class.java)
val cliExecutable = project.cliExecutableProvider()

val extraProperties = project.extensions.getByName("ext") as ExtraPropertiesExtension

val sentryOrgParameter =
runCatching { extraProperties.get(SENTRY_ORG_PARAMETER).toString() }.getOrNull()
val sentryProjectParameter =
runCatching { extraProperties.get(SENTRY_PROJECT_PARAMETER).toString() }.getOrNull()

// new API configuration
androidComponentsExt.configure(
project,
extension,
buildEvents,
cliExecutable,
sentryOrgParameter,
sentryProjectParameter,
)

// old API configuration
oldAGPExtension.configure(
project,
extension,
cliExecutable,
sentryOrgParameter,
sentryProjectParameter,
buildEvents,
private fun Project.checkAgpVersion() {
if (AgpVersions.CURRENT < AgpVersions.VERSION_7_0_0) {
throw StopExecutionException(
"""
Using io.sentry.android.gradle:3+ with Android Gradle Plugin < 7 is not supported.
Either upgrade the AGP version to 7+, or use an earlier version of the Sentry
Android Gradle Plugin. For more information check our migration guide
https://docs.sentry.io/platforms/android/migration/#migrating-from-iosentrysentry-android-gradle-plugin-2x-to-iosentrysentry-android-gradle-plugin-300
"""
.trimIndent()
)

project.installDependencies(extension, true)
}
}

companion object {
const val SENTRY_ORG_PARAMETER = "sentryOrg"
const val SENTRY_PROJECT_PARAMETER = "sentryProject"
internal const val SENTRY_SDK_VERSION = BuildConfig.SdkVersion

internal val sep = File.separator

// a single unified logger used by instrumentation
internal val logger by lazy { LoggerFactory.getLogger(SentryPlugin::class.java) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.sentry.android.gradle.autoinstall

import io.sentry.android.gradle.SentryPlugin.Companion.SENTRY_SDK_VERSION
import io.sentry.gradle.SENTRY_SDK_VERSION
import java.io.Serializable
import org.gradle.api.invocation.Gradle
import org.jetbrains.annotations.TestOnly
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.sentry.android.gradle.extensions

import io.sentry.android.gradle.SentryPlugin.Companion.SENTRY_SDK_VERSION
import io.sentry.gradle.SENTRY_SDK_VERSION
import javax.inject.Inject
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,9 @@ abstract class SentryPluginExtension @Inject constructor(project: Project) {
*/
val telemetryDsn: Property<String> =
objects.property(String::class.java).convention(SENTRY_SAAS_DSN)

internal companion object {
fun of(project: Project): SentryPluginExtension =
project.extensions.create("sentry", SentryPluginExtension::class.java, project)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class GenerateBundleIdTask : PropertiesFileOutputTask() {

init {
description =
"Generates a unique build ID to be used " + "when bundling sources for upload to Sentry"
"Generates a unique build ID to be used when bundling sources for upload to Sentry"

@Suppress("LeakingThis") onlyIf { includeSourceContext.getOrElse(false) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.sentry.gradle

import io.sentry.gradle.subplugin.RootPlugin
import javax.inject.Inject
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.StopExecutionException
import org.gradle.internal.build.event.BuildEventListenerRegistryInternal
import org.slf4j.LoggerFactory

internal abstract class SentryRootPlugin
@Inject
constructor(private val buildEvents: BuildEventListenerRegistryInternal) : Plugin<Project> {

override fun apply(project: Project) {
if (project == project.rootProject) {
RootPlugin(project).apply(buildEvents)
} else {
throw StopExecutionException("io.sentry.gradle must be applied only to the root project.")
}
}

companion object {
// a single unified logger used by instrumentation
internal val logger by lazy { LoggerFactory.getLogger(SentryRootPlugin::class.java) }
}
}
11 changes: 11 additions & 0 deletions plugin-build/src/main/kotlin/io/sentry/gradle/Shared.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.sentry.gradle

import io.sentry.BuildConfig
import java.io.File

internal const val SENTRY_ORG_PARAMETER = "sentryOrg"
internal const val SENTRY_PROJECT_PARAMETER = "sentryProject"

internal const val SENTRY_SDK_VERSION = BuildConfig.SdkVersion

internal val sep = File.separator
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.sentry.gradle.subplugin

import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.gradle.AppExtension
import io.sentry.android.gradle.autoinstall.installDependencies
import io.sentry.android.gradle.cliExecutableProvider
import io.sentry.android.gradle.configure
import io.sentry.android.gradle.extensions.SentryPluginExtension
import io.sentry.android.gradle.util.AgpVersions
import org.gradle.api.Project
import org.gradle.api.tasks.StopExecutionException
import org.gradle.internal.build.event.BuildEventListenerRegistryInternal

class AndroidAppSubplugin(
private val project: Project,
private val extension: SentryPluginExtension,
) {
fun apply(
buildEvents: BuildEventListenerRegistryInternal,
sentryOrgParameter: String?,
sentryProjectParameter: String?,
) =
project.run {
checkAgpVersion()

val oldAGPExtension = extensions.getByType(AppExtension::class.java)
val androidComponentsExt = extensions.getByType(AndroidComponentsExtension::class.java)
val cliExecutable = cliExecutableProvider()

// new API configuration
androidComponentsExt.configure(
this,
extension,
buildEvents,
cliExecutable,
sentryOrgParameter,
sentryProjectParameter,
)

// old API configuration
oldAGPExtension.configure(
this,
extension,
cliExecutable,
sentryOrgParameter,
sentryProjectParameter,
buildEvents,
)

installDependencies(extension, true)
}

private fun Project.checkAgpVersion() {
if (AgpVersions.CURRENT < AgpVersions.VERSION_7_0_0) {
throw StopExecutionException(
"""
Using io.sentry.android.gradle:3+ with Android Gradle Plugin < 7 is not supported.
Either upgrade the AGP version to 7+, or use an earlier version of the Sentry
Android Gradle Plugin. For more information check our migration guide
https://docs.sentry.io/platforms/android/migration/#migrating-from-iosentrysentry-android-gradle-plugin-2x-to-iosentrysentry-android-gradle-plugin-300
"""
.trimIndent()
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.sentry.gradle.subplugin

import org.gradle.api.Project

class AndroidLibSubplugin(private val project: Project) {
fun apply() {
// TODO: add logic to upload source contexts here
}
}
Loading
Loading