All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bitrise.gradle.cache.BitriseBuildCacheServiceFactory.kt Maven / Gradle / Ivy

/**
 * Copyright (C)2022 Bitrise
 * All rights reserved.
 */
package io.bitrise.gradle.cache

import org.gradle.caching.BuildCacheService
import org.gradle.caching.BuildCacheServiceFactory
import java.util.*

class BitriseBuildCacheServiceFactory : BuildCacheServiceFactory {
    override fun createBuildCacheService(configuration: BitriseBuildCache, describer: BuildCacheServiceFactory.Describer): BuildCacheService {
        describer
            .type("GRPC")
            .config("endpoint", configuration.endpoint)
            .config("authToken", "")
            .config("chunkSize", configuration.chunkSize.toString())
            .config("timeout", configuration.timeout.toString())
            .config("messageTimeout", configuration.messageTimeout.toString())
            .config("debug", configuration.debug.toString())
            .config("retryCount", configuration.retryCount.toString())
            .config("messageRetryCount", configuration.messageRetryCount.toString())
            .config("numChannels", configuration.numChannels.toString())
            .config("maxConcurrencyPerChannel", configuration.maxConcurrencyPerChannel.toString())
            .config("blobValidationLevel", configuration.blobValidationLevel)
            .config("tlsCertPath", configuration.tlsCertPath ?: "")
            .config("overrideAuthority", configuration.overrideAuthority ?: "")

        var authToken = configuration.authToken
        var orgSlug = ""
        if (configuration.authToken.contains(":")) {
            val parts = configuration.authToken.split(":")
            val slugOrEmpty = parts[0]
            if(slugOrEmpty.trim().length > 1) {
                orgSlug = slugOrEmpty
                authToken = parts[1]
            }
        }
        return BitriseBuildCacheService(
            endpoint = configuration.endpoint,
            authToken = authToken,
            chunkSize = configuration.chunkSize,
            timeout = configuration.timeout,
            messageTimeout = configuration.messageTimeout,
            debug = configuration.debug,
            orgSlug = orgSlug,
            retryCount = configuration.retryCount,
            messageRetryCount = configuration.messageRetryCount,
            numChannels = configuration.numChannels,
            maxConcurrencyPerChannel = configuration.maxConcurrencyPerChannel,
            blobValidationLevel = ValidationLevel.valueOf(configuration.blobValidationLevel.uppercase(Locale.getDefault())),
            tlsCertPath = configuration.tlsCertPath,
            overrideAuthority = configuration.overrideAuthority,
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy