-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Okhttp-integration version check (#327)
- Loading branch information
Showing
10 changed files
with
146 additions
and
132 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
49 changes: 23 additions & 26 deletions
49
plugin-build/src/main/kotlin/io/sentry/android/gradle/util/SentryAndroidSdkChecker.kt
This file contains 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 |
---|---|---|
@@ -1,55 +1,52 @@ | ||
package io.sentry.android.gradle.util | ||
|
||
import io.sentry.android.gradle.services.SentrySdkStateHolder | ||
import io.sentry.android.gradle.services.SentryModulesService | ||
import org.gradle.api.Project | ||
import org.gradle.api.UnknownDomainObjectException | ||
import org.gradle.api.artifacts.result.ResolvedComponentResult | ||
import org.gradle.api.logging.Logger | ||
import org.gradle.api.provider.Provider | ||
|
||
fun Project.detectSentryAndroidSdk( | ||
configurationName: String, | ||
variantName: String, | ||
sdkStateHolder: Provider<SentrySdkStateHolder> | ||
sentryModulesService: Provider<SentryModulesService> | ||
) { | ||
val configProvider = try { | ||
configurations.named(configurationName) | ||
} catch (e: UnknownDomainObjectException) { | ||
logger.warn { | ||
"Unable to find configuration $configurationName for variant $variantName." | ||
} | ||
sdkStateHolder.get().sdkState = SentryAndroidSdkState.MISSING | ||
sentryModulesService.get().modules = emptyMap() | ||
return | ||
} | ||
|
||
configProvider.configure { configuration -> | ||
configuration.incoming.afterResolve { | ||
val version = it.resolutionResult.allComponents.findSentryAndroidSdk() | ||
if (version == null) { | ||
logger.warn { "sentry-android dependency was not found." } | ||
sdkStateHolder.get().sdkState = SentryAndroidSdkState.MISSING | ||
return@afterResolve | ||
val sentryModules = it.resolutionResult.allComponents.filterSentryModules(logger) | ||
logger.info { | ||
"Detected Sentry modules $sentryModules " + | ||
"for variant: $variantName, config: $configurationName" | ||
} | ||
|
||
val state = try { | ||
val sdkState = SentryAndroidSdkState.from(version) | ||
logger.info { | ||
"Detected sentry-android $sdkState for version: $version, " + | ||
"variant: $variantName, config: $configurationName" | ||
} | ||
sdkState | ||
} catch (e: IllegalStateException) { | ||
logger.warn { e.localizedMessage } | ||
SentryAndroidSdkState.MISSING | ||
} | ||
sdkStateHolder.get().sdkState = state | ||
sentryModulesService.get().modules = sentryModules | ||
} | ||
} | ||
} | ||
|
||
private fun Set<ResolvedComponentResult>.findSentryAndroidSdk(): String? { | ||
val sentryDep = find { resolvedComponent: ResolvedComponentResult -> | ||
val moduleVersion = resolvedComponent.moduleVersion ?: return@find false | ||
moduleVersion.group == "io.sentry" && moduleVersion.name == "sentry-android-core" | ||
private fun Set<ResolvedComponentResult>.filterSentryModules(logger: Logger): Map<String, SemVer> { | ||
return filter { resolvedComponent: ResolvedComponentResult -> | ||
val moduleVersion = resolvedComponent.moduleVersion ?: return@filter false | ||
moduleVersion.group == "io.sentry" | ||
}.associate { | ||
val name = it.moduleVersion?.name ?: "" | ||
val version = it.moduleVersion?.version ?: "" | ||
val semver = try { | ||
SemVer.parse(version) | ||
} catch (e: Throwable) { | ||
logger.info { "Unable to parse version $version of $name" } | ||
SemVer() | ||
} | ||
name to semver | ||
} | ||
return sentryDep?.moduleVersion?.version | ||
} |
32 changes: 0 additions & 32 deletions
32
plugin-build/src/main/kotlin/io/sentry/android/gradle/util/SentryAndroidSdkState.kt
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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.