|
1 | 1 | package com.gabrielfeo.gradle.enterprise.api |
2 | 2 |
|
3 | 3 | import com.gabrielfeo.gradle.enterprise.api.internal.* |
4 | | -import retrofit2.create |
| 4 | +import java.io.File |
5 | 5 |
|
| 6 | +/** |
| 7 | + * The global instance of [GradleEnterpriseApi]. |
| 8 | + */ |
6 | 9 | val api: GradleEnterpriseApi by lazy { |
7 | 10 | retrofit.create(GradleEnterpriseApi::class.java) |
8 | 11 | } |
9 | 12 |
|
| 13 | +/** |
| 14 | + * Provides the URL of a Gradle Enterprise API instance. By default, uses environment variable |
| 15 | + * `GRADLE_ENTERPRISE_URL`. |
| 16 | + */ |
| 17 | +var baseUrl: () -> String = { |
| 18 | + requireBaseUrl(envName = "GRADLE_ENTERPRISE_URL") |
| 19 | +} |
| 20 | + |
| 21 | +/** |
| 22 | + * Provides the access token for a Gradle Enterprise API instance. By default, uses keychain entry |
| 23 | + * `gradle-enterprise-api-token` or environment variable `GRADLE_ENTERPRISE_URL`. |
| 24 | + */ |
| 25 | +var accessToken: () -> String = { |
| 26 | + requireToken( |
| 27 | + keychainName = "gradle-enterprise-api-token", |
| 28 | + envName = "GRADLE_ENTERPRISE_API_TOKEN", |
| 29 | + ) |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Shutdown the internal OkHttp client, releasing resources and allowing the program to finish |
| 34 | + * before the client's idle timeout. |
| 35 | + * |
| 36 | + * https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/#shutdown-isnt-necessary |
| 37 | + */ |
10 | 38 | fun shutdown() { |
11 | 39 | okHttpClient.dispatcher.executorService.shutdownNow() |
12 | 40 | } |
13 | 41 |
|
14 | | -var maxCacheSize = 500_000_000L |
| 42 | +/** |
| 43 | + * List of patterns matching API URLs that are OK to store in the HTTP cache. Matches by default: |
| 44 | + * - {host}/api/builds/{id}/gradle-attributes |
| 45 | + * - {host}/api/builds/{id}/maven-attributes |
| 46 | + * |
| 47 | + * By default, the Gradle Enterprise disallows HTTP caching via response headers. This library |
| 48 | + * removes such headers to forcefully allow caching, if the path is matched by any of these |
| 49 | + * patterns. |
| 50 | + */ |
15 | 51 | val cacheablePaths: MutableList<Regex> = mutableListOf( |
16 | 52 | """.*/api/builds/[\d\w]+/(?:gradle|maven)-attributes""".toRegex(), |
17 | 53 | ) |
18 | 54 |
|
19 | | -var baseUrl: () -> String = { requireBaseUrl() } |
20 | | -var accessToken: () -> String = { requireToken() } |
| 55 | +/** |
| 56 | + * Maximum amount of concurrent requests allowed. Further requests will be queued. By default, |
| 57 | + * uses environment variable `GRADLE_ENTERPRISE_API_MAX_CONCURRENT_REQUESTS` or 15. |
| 58 | + * |
| 59 | + * https://square.github.io/okhttp/4.x/okhttp/okhttp3/-dispatcher |
| 60 | + */ |
| 61 | +var maxConcurrentRequests = System.getenv("GRADLE_ENTERPRISE_API_MAX_CONCURRENT_REQUESTS")?.toInt() |
| 62 | + ?: 15 |
| 63 | + |
| 64 | +/** |
| 65 | + * Max size of the HTTP cache. By default, uses environment variable |
| 66 | + * `GRADLE_ENTERPRISE_API_MAX_CACHE_SIZE` or ~1 GB. |
| 67 | + */ |
| 68 | +var maxCacheSize = System.getenv("GRADLE_ENTERPRISE_API_MAX_CACHE_SIZE")?.toLong() |
| 69 | + ?: 1_000_000_000L |
| 70 | + |
| 71 | +/** |
| 72 | + * HTTP cache location. By default, uses environment variable `GRADLE_ENTERPRISE_API_CACHE_DIR` |
| 73 | + * or the system temporary folder (`java.io.tmpdir` / gradle-enterprise-api-kotlin-cache). |
| 74 | + */ |
| 75 | +var cacheDir = System.getenv("GRADLE_ENTERPRISE_API_CACHE_DIR")?.let(::File) |
| 76 | + ?: File(System.getProperty("java.io.tmpdir"), "gradle-enterprise-api-kotlin-cache") |
21 | 77 |
|
22 | | -var maxConcurrentRequests = 15 |
| 78 | +/** |
| 79 | + * Enables debug logging from the library. All logging is output to the program's standard streams. |
| 80 | + * By default, uses environment variable `GRADLE_ENTERPRISE_API_DEBUG_LOGGING` or `false`. |
| 81 | + */ |
23 | 82 | var debugLoggingEnabled = System.getenv("GRADLE_ENTERPRISE_API_DEBUG_LOGGING").toBoolean() |
0 commit comments