Skip to content

Commit

Permalink
Rename environment variables to DEVELOCITY_ (#188)
Browse files Browse the repository at this point in the history
Part of #184
  • Loading branch information
gabrielfeo authored Apr 5, 2024
1 parent 9175810 commit feb9db9
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tasks.named<Jar>("javadocJar") {
}

tasks.named<Test>("integrationTest") {
environment("GRADLE_ENTERPRISE_API_LOG_LEVEL", "DEBUG")
environment("DEVELOCITY_API_LOG_LEVEL", "DEBUG")
}

java {
Expand Down
50 changes: 25 additions & 25 deletions library/src/main/kotlin/com/gabrielfeo/develocity/api/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -53,24 +53,24 @@ 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
* internal client, overwriting what's inherited from the base client of [clientBuilder],
* 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,

/**
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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,
)
}
Expand All @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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")
Expand All @@ -68,15 +68,15 @@ 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
}
}

@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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class DevelocityApiTest {
val error = assertThrows<Exception> {
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 {
Expand All @@ -30,7 +30,7 @@ class DevelocityApiTest {
val error = assertThrows<Exception> {
api.buildsApi.toString()
}
error.assertRootMessageContains("GRADLE_ENTERPRISE_API_TOKEN")
error.assertRootMessageContains("DEVELOCITY_API_TOKEN")
}

private fun Throwable.assertRootMessageContains(text: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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/",
)
}
}
Expand All @@ -29,8 +29,8 @@ class RetrofitTest {
vararg envVars: Pair<String, String?>,
): 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()
Expand Down

0 comments on commit feb9db9

Please sign in to comment.