diff --git a/library/build.gradle.kts b/library/build.gradle.kts index e566ddbf..f7c8c26e 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -52,7 +52,7 @@ tasks.named("javadocJar") { } tasks.named("integrationTest") { - environment("GRADLE_ENTERPRISE_API_LOG_LEVEL", "DEBUG") + environment("DEVELOCITY_API_LOG_LEVEL", "DEBUG") } java { diff --git a/library/src/main/kotlin/com/gabrielfeo/develocity/api/Config.kt b/library/src/main/kotlin/com/gabrielfeo/develocity/api/Config.kt index 5c5f8dbf..ec9a1bb9 100644 --- a/library/src/main/kotlin/com/gabrielfeo/develocity/api/Config.kt +++ b/library/src/main/kotlin/com/gabrielfeo/develocity/api/Config.kt @@ -21,19 +21,19 @@ data class Config( * To use different SLF4J bindings, simply exclude the logback dependency. */ val logLevel: String? = - env["GRADLE_ENTERPRISE_API_LOG_LEVEL"], + env["DEVELOCITY_API_LOG_LEVEL"], /** * Provides the URL of a Develocity API instance REST API. By default, uses - * environment variable `GRADLE_ENTERPRISE_API_URL`. Must end with `/api/`. + * environment variable `DEVELOCITY_API_URL`. Must end with `/api/`. */ val apiUrl: String = - env["GRADLE_ENTERPRISE_API_URL"] - ?: error("GRADLE_ENTERPRISE_API_URL is required"), + env["DEVELOCITY_API_URL"] + ?: error("DEVELOCITY_API_URL is required"), /** * Provides the access token for a Develocity API instance. By default, uses keychain entry - * `gradle-enterprise-api-token` or environment variable `GRADLE_ENTERPRISE_API_TOKEN`. + * `gradle-enterprise-api-token` or environment variable `DEVELOCITY_API_TOKEN`. */ val apiToken: () -> String = { requireEnvOrKeychainToken() @@ -53,7 +53,7 @@ data class Config( /** * Maximum amount of concurrent requests allowed. Further requests will be queued. By default, - * uses environment variable `GRADLE_ENTERPRISE_API_MAX_CONCURRENT_REQUESTS` or 5 (OkHttp's + * uses environment variable `DEVELOCITY_API_MAX_CONCURRENT_REQUESTS` or 5 (OkHttp's * default value of [Dispatcher.maxRequestsPerHost]). * * If set, will set [Dispatcher.maxRequests] and [Dispatcher.maxRequestsPerHost] of the @@ -61,16 +61,16 @@ data class Config( * if any. */ val maxConcurrentRequests: Int? = - env["GRADLE_ENTERPRISE_API_MAX_CONCURRENT_REQUESTS"]?.toInt(), + env["DEVELOCITY_API_MAX_CONCURRENT_REQUESTS"]?.toInt(), /** * Timeout for reading an API response, used for [OkHttpClient.readTimeoutMillis]. - * By default, uses environment variable `GRADLE_ENTERPRISE_API_READ_TIMEOUT_MILLIS` + * By default, uses environment variable `DEVELOCITY_API_READ_TIMEOUT_MILLIS` * or 60_000. Keep in mind that Develocity API responses can be big and slow to send depending on * the endpoint. */ val readTimeoutMillis: Long = - env["GRADLE_ENTERPRISE_API_READ_TIMEOUT_MILLIS"]?.toLong() + env["DEVELOCITY_API_READ_TIMEOUT_MILLIS"]?.toLong() ?: 60_000L, /** @@ -126,30 +126,30 @@ data class Config( /** * Whether caching is enabled. By default, uses environment variable - * `GRADLE_ENTERPRISE_API_CACHE_ENABLED` or `false`. + * `DEVELOCITY_API_CACHE_ENABLED` or `false`. */ val cacheEnabled: Boolean = - env["GRADLE_ENTERPRISE_API_CACHE_ENABLED"].toBoolean(), + env["DEVELOCITY_API_CACHE_ENABLED"].toBoolean(), /** - * HTTP cache location. By default, uses environment variable `GRADLE_ENTERPRISE_API_CACHE_DIR` + * HTTP cache location. By default, uses environment variable `DEVELOCITY_API_CACHE_DIR` * or the system temporary folder (`java.io.tmpdir` / develocity-api-kotlin-cache). */ val cacheDir: File = - env["GRADLE_ENTERPRISE_API_CACHE_DIR"]?.let(::File) + env["DEVELOCITY_API_CACHE_DIR"]?.let(::File) ?: File(systemProperties["user.home"], ".develocity-api-kotlin-cache"), /** * Max size of the HTTP cache. By default, uses environment variable - * `GRADLE_ENTERPRISE_API_MAX_CACHE_SIZE` or ~1 GB. + * `DEVELOCITY_API_MAX_CACHE_SIZE` or ~1 GB. */ - val maxCacheSize: Long = env["GRADLE_ENTERPRISE_API_MAX_CACHE_SIZE"]?.toLong() + val maxCacheSize: Long = env["DEVELOCITY_API_MAX_CACHE_SIZE"]?.toLong() ?: 1_000_000_000L, /** * Regex pattern to match API URLs that are OK to store long-term in the HTTP cache, up to * [longTermCacheMaxAge] (1y by default, max value). By default, uses environment variable - * `GRADLE_ENTERPRISE_API_LONG_TERM_CACHE_URL_PATTERN` or a pattern matching: + * `DEVELOCITY_API_LONG_TERM_CACHE_URL_PATTERN` or a pattern matching: * - {host}/api/builds/{id}/gradle-attributes * - {host}/api/builds/{id}/maven-attributes * - {host}/api/builds/{id}/gradle-build-cache-performance @@ -158,7 +158,7 @@ data class Config( * Use `|` to define multiple patterns in one, e.g. `.*gradle-attributes|.*test-distribution`. */ val longTermCacheUrlPattern: Regex = - env["GRADLE_ENTERPRISE_API_LONG_TERM_CACHE_URL_PATTERN"]?.toRegex() + env["DEVELOCITY_API_LONG_TERM_CACHE_URL_PATTERN"]?.toRegex() ?: Regex( """ .*/api/builds/[\d\w]+/(?:gradle|maven)-(?:attributes|build-cache-performance) @@ -167,30 +167,30 @@ data class Config( /** * Max age in seconds for URLs to be cached long-term (matched by [longTermCacheUrlPattern]). - * By default, uses environment variable `GRADLE_ENTERPRISE_API_LONG_TERM_CACHE_MAX_AGE` or 1 year. + * By default, uses environment variable `DEVELOCITY_API_LONG_TERM_CACHE_MAX_AGE` or 1 year. */ val longTermCacheMaxAge: Long = - env["GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_MAX_AGE"]?.toLong() + env["DEVELOCITY_API_SHORT_TERM_CACHE_MAX_AGE"]?.toLong() ?: 365.days.inWholeSeconds, /** * Regex pattern to match API URLs that are OK to store short-term in the HTTP cache, up to * [shortTermCacheMaxAge] (1d by default). By default, uses environment variable - * `GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_URL_PATTERN` or a pattern matching: + * `DEVELOCITY_API_SHORT_TERM_CACHE_URL_PATTERN` or a pattern matching: * - {host}/api/builds * * Use `|` to define multiple patterns in one, e.g. `.*gradle-attributes|.*test-distribution`. */ val shortTermCacheUrlPattern: Regex = - env["GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_URL_PATTERN"]?.toRegex() + env["DEVELOCITY_API_SHORT_TERM_CACHE_URL_PATTERN"]?.toRegex() ?: """.*/builds(?:\?.*|\Z)""".toRegex(), /** * Max age in seconds for URLs to be cached short-term (matched by [shortTermCacheUrlPattern]). - * By default, uses environment variable `GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_MAX_AGE` or 1 day. + * By default, uses environment variable `DEVELOCITY_API_SHORT_TERM_CACHE_MAX_AGE` or 1 day. */ val shortTermCacheMaxAge: Long = - env["GRADLE_ENTERPRISE_API_SHORT_TERM_CACHE_MAX_AGE"]?.toLong() + env["DEVELOCITY_API_SHORT_TERM_CACHE_MAX_AGE"]?.toLong() ?: 1.days.inWholeSeconds, ) } @@ -202,6 +202,6 @@ internal fun requireEnvOrKeychainToken(): String { is KeychainResult.Error -> {} } } - return env["GRADLE_ENTERPRISE_API_TOKEN"] - ?: error("GRADLE_ENTERPRISE_API_TOKEN is required") + return env["DEVELOCITY_API_TOKEN"] + ?: error("DEVELOCITY_API_TOKEN is required") } diff --git a/library/src/main/kotlin/com/gabrielfeo/develocity/api/internal/Keychain.kt b/library/src/main/kotlin/com/gabrielfeo/develocity/api/internal/Keychain.kt index f16eec15..e96b57ab 100644 --- a/library/src/main/kotlin/com/gabrielfeo/develocity/api/internal/Keychain.kt +++ b/library/src/main/kotlin/com/gabrielfeo/develocity/api/internal/Keychain.kt @@ -47,5 +47,5 @@ internal class RealKeychain( private const val KEYCHAIN_DEPRECATION_WARNING = "WARNING: passing token via macOS keychain is deprecated. Please pass it as the " + - "GRADLE_ENTERPRISE_API_TOKEN environment variable instead. Keychain support will be " + + "DEVELOCITY_API_TOKEN environment variable instead. Keychain support will be " + "removed in the next release. See release notes for details and alternatives." diff --git a/library/src/test/kotlin/com/gabrielfeo/develocity/api/CacheConfigTest.kt b/library/src/test/kotlin/com/gabrielfeo/develocity/api/CacheConfigTest.kt index d311d538..801eff1e 100644 --- a/library/src/test/kotlin/com/gabrielfeo/develocity/api/CacheConfigTest.kt +++ b/library/src/test/kotlin/com/gabrielfeo/develocity/api/CacheConfigTest.kt @@ -7,7 +7,7 @@ class CacheConfigTest { @BeforeTest fun before() { - env = FakeEnv("GRADLE_ENTERPRISE_API_URL" to "https://example.com/api/") + env = FakeEnv("DEVELOCITY_API_URL" to "https://example.com/api/") systemProperties = FakeSystemProperties.macOs keychain = FakeKeychain() } diff --git a/library/src/test/kotlin/com/gabrielfeo/develocity/api/ConfigTest.kt b/library/src/test/kotlin/com/gabrielfeo/develocity/api/ConfigTest.kt index 5f6a5b4b..476a350b 100644 --- a/library/src/test/kotlin/com/gabrielfeo/develocity/api/ConfigTest.kt +++ b/library/src/test/kotlin/com/gabrielfeo/develocity/api/ConfigTest.kt @@ -8,7 +8,7 @@ class ConfigTest { @BeforeTest fun before() { - env = FakeEnv("GRADLE_ENTERPRISE_API_URL" to "https://example.com/api/") + env = FakeEnv("DEVELOCITY_API_URL" to "https://example.com/api/") systemProperties = FakeSystemProperties.macOs keychain = FakeKeychain() } @@ -23,26 +23,26 @@ class ConfigTest { @Test fun `Given URL set in env, apiUrl is env URL`() { - (env as FakeEnv)["GRADLE_ENTERPRISE_API_URL"] = "https://example.com/api/" + (env as FakeEnv)["DEVELOCITY_API_URL"] = "https://example.com/api/" assertEquals("https://example.com/api/", Config().apiUrl) } @Test fun `Given macOS and keychain token, keychain token used`() { - (env as FakeEnv)["GRADLE_ENTERPRISE_API_TOKEN"] = "bar" + (env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar" keychain = FakeKeychain("gradle-enterprise-api-token" to "foo") assertEquals("foo", Config().apiToken()) } @Test fun `Given macOS but no keychain token, env token used`() { - (env as FakeEnv)["GRADLE_ENTERPRISE_API_TOKEN"] = "bar" + (env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar" assertEquals("bar", Config().apiToken()) } @Test fun `Given Linux, keychain never tried and env token used`() { - (env as FakeEnv)["GRADLE_ENTERPRISE_API_TOKEN"] = "bar" + (env as FakeEnv)["DEVELOCITY_API_TOKEN"] = "bar" keychain = object : Keychain { override fun get(entry: String) = error("Error: Tried to access macOS keychain in Linux") @@ -68,7 +68,7 @@ class ConfigTest { @Test fun `maxConcurrentRequests accepts int`() { - (env as FakeEnv)["GRADLE_ENTERPRISE_API_MAX_CONCURRENT_REQUESTS"] = "1" + (env as FakeEnv)["DEVELOCITY_API_MAX_CONCURRENT_REQUESTS"] = "1" assertDoesNotThrow { Config().maxConcurrentRequests } @@ -76,7 +76,7 @@ class ConfigTest { @Test fun `Given timeout set in env, readTimeoutMillis returns env value`() { - (env as FakeEnv)["GRADLE_ENTERPRISE_API_READ_TIMEOUT_MILLIS"] = "100000" + (env as FakeEnv)["DEVELOCITY_API_READ_TIMEOUT_MILLIS"] = "100000" assertEquals(100_000L, Config().readTimeoutMillis) } } diff --git a/library/src/test/kotlin/com/gabrielfeo/develocity/api/DevelocityApiTest.kt b/library/src/test/kotlin/com/gabrielfeo/develocity/api/DevelocityApiTest.kt index 00abf392..daeb5b2f 100644 --- a/library/src/test/kotlin/com/gabrielfeo/develocity/api/DevelocityApiTest.kt +++ b/library/src/test/kotlin/com/gabrielfeo/develocity/api/DevelocityApiTest.kt @@ -16,12 +16,12 @@ class DevelocityApiTest { val error = assertThrows { DevelocityApi.newInstance(Config()) } - error.assertRootMessageContains("GRADLE_ENTERPRISE_API_URL") + error.assertRootMessageContains("DEVELOCITY_API_URL") } @Test fun `Fails lazily if no API token`() { - env = FakeEnv("GRADLE_ENTERPRISE_API_URL" to "example-url") + env = FakeEnv("DEVELOCITY_API_URL" to "example-url") keychain = FakeKeychain() systemProperties = FakeSystemProperties.linux val api = assertDoesNotThrow { @@ -30,7 +30,7 @@ class DevelocityApiTest { val error = assertThrows { api.buildsApi.toString() } - error.assertRootMessageContains("GRADLE_ENTERPRISE_API_TOKEN") + error.assertRootMessageContains("DEVELOCITY_API_TOKEN") } private fun Throwable.assertRootMessageContains(text: String) { diff --git a/library/src/test/kotlin/com/gabrielfeo/develocity/api/OkHttpClientTest.kt b/library/src/test/kotlin/com/gabrielfeo/develocity/api/OkHttpClientTest.kt index b7c4185f..4480444b 100644 --- a/library/src/test/kotlin/com/gabrielfeo/develocity/api/OkHttpClientTest.kt +++ b/library/src/test/kotlin/com/gabrielfeo/develocity/api/OkHttpClientTest.kt @@ -20,7 +20,7 @@ class OkHttpClientTest { @Test fun `Given maxConcurrentRequests, sets values in Dispatcher`() { val client = buildClient( - "GRADLE_ENTERPRISE_API_MAX_CONCURRENT_REQUESTS" to "123" + "DEVELOCITY_API_MAX_CONCURRENT_REQUESTS" to "123" ) assertEquals(123, client.dispatcher.maxRequests) assertEquals(123, client.dispatcher.maxRequestsPerHost) @@ -42,14 +42,14 @@ class OkHttpClientTest { @Test fun `Given cache enabled, configures caching`() { - val client = buildClient("GRADLE_ENTERPRISE_API_CACHE_ENABLED" to "true") + val client = buildClient("DEVELOCITY_API_CACHE_ENABLED" to "true") assertTrue(client.networkInterceptors.any { it is CacheEnforcingInterceptor }) assertNotNull(client.cache) } @Test fun `Given cache disabled, no caching or cache logging`() { - val client = buildClient("GRADLE_ENTERPRISE_API_CACHE_ENABLED" to "false") + val client = buildClient("DEVELOCITY_API_CACHE_ENABLED" to "false") assertTrue(client.networkInterceptors.none { it is CacheEnforcingInterceptor }) assertTrue(client.interceptors.none { it is CacheHitLoggingInterceptor }) assertNull(client.cache) @@ -67,10 +67,10 @@ class OkHttpClientTest { clientBuilder: OkHttpClient.Builder? = null, ): OkHttpClient { val fakeEnv = FakeEnv(*envVars) - if ("GRADLE_ENTERPRISE_API_TOKEN" !in fakeEnv) - fakeEnv["GRADLE_ENTERPRISE_API_TOKEN"] = "example-token" - if ("GRADLE_ENTERPRISE_API_URL" !in fakeEnv) - fakeEnv["GRADLE_ENTERPRISE_API_URL"] = "example-url" + if ("DEVELOCITY_API_TOKEN" !in fakeEnv) + fakeEnv["DEVELOCITY_API_TOKEN"] = "example-token" + if ("DEVELOCITY_API_URL" !in fakeEnv) + fakeEnv["DEVELOCITY_API_URL"] = "example-url" env = fakeEnv systemProperties = FakeSystemProperties.macOs keychain = FakeKeychain() diff --git a/library/src/test/kotlin/com/gabrielfeo/develocity/api/RetrofitTest.kt b/library/src/test/kotlin/com/gabrielfeo/develocity/api/RetrofitTest.kt index 780f0c60..189ef6ed 100644 --- a/library/src/test/kotlin/com/gabrielfeo/develocity/api/RetrofitTest.kt +++ b/library/src/test/kotlin/com/gabrielfeo/develocity/api/RetrofitTest.kt @@ -10,7 +10,7 @@ class RetrofitTest { @Test fun `Sets instance URL from options, stripping api segment`() { val retrofit = buildRetrofit( - "GRADLE_ENTERPRISE_API_URL" to "https://example.com/api/", + "DEVELOCITY_API_URL" to "https://example.com/api/", ) // That's what generated classes expect assertEquals("https://example.com/", retrofit.baseUrl().toString()) @@ -20,7 +20,7 @@ class RetrofitTest { fun `Rejects invalid URL`() { assertFails { buildRetrofit( - "GRADLE_ENTERPRISE_API_URL" to "https://example.com/", + "DEVELOCITY_API_URL" to "https://example.com/", ) } } @@ -29,8 +29,8 @@ class RetrofitTest { vararg envVars: Pair, ): Retrofit { val fakeEnv = FakeEnv(*envVars) - if ("GRADLE_ENTERPRISE_API_TOKEN" !in fakeEnv) - fakeEnv["GRADLE_ENTERPRISE_API_TOKEN"] = "example-token" + if ("DEVELOCITY_API_TOKEN" !in fakeEnv) + fakeEnv["DEVELOCITY_API_TOKEN"] = "example-token" env = fakeEnv systemProperties = FakeSystemProperties.macOs keychain = FakeKeychain()