com.bugsnag.android.gradle.internal.UploadRequestClient.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bugsnag-android-gradle-plugin Show documentation
Show all versions of bugsnag-android-gradle-plugin Show documentation
Gradle plugin to automatically upload ProGuard mapping files to Bugsnag.
package com.bugsnag.android.gradle.internal
import com.bugsnag.android.gradle.AndroidManifestInfo
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import java.util.Objects
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.FutureTask
abstract class UploadRequestClient : AutoCloseable, BuildService {
private val requestMap = ConcurrentHashMap>()
/**
* Executes request with automatic de-duplication of similar requests.
*
* If the version information and payload match another request that
* has already been enqueued, the response value of the existing request
* will be returned. If no existing requests match, a new request will
* be enqueued and executed.
*
* Equality is measured by the [AndroidManifestInfo]
* and the request payload.
*/
fun makeRequestIfNeeded(
manifestInfo: AndroidManifestInfo,
payloadHash: Int,
request: () -> String
): String {
val versionInfoHash = manifestInfo.hashCode()
val requestIdHash = Objects.hash(versionInfoHash, payloadHash)
val future = requestMap.getOrPut(requestIdHash.toString()) {
FutureTask { request() }
}
future.run()
return future.get()
}
override fun close() {
requestMap.forEach { (_, future) ->
future.cancel(true)
}
}
}
internal fun newUploadRequestClientProvider(project: Project, prefix: String): Provider {
return project.gradle.sharedServices.registerIfAbsent(
"bugsnag${prefix.capitalize()}UploadRequestClient",
UploadRequestClient::class.java
) {
// No parameters!
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy