Skip to content

Commit 28a7616

Browse files
committed
Make okHttpClient and retrofit internal
1 parent 23a9554 commit 28a7616

File tree

3 files changed

+50
-44
lines changed

3 files changed

+50
-44
lines changed
Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,23 @@
1-
@file:Suppress("RemoveExplicitTypeArguments")
2-
31
package com.gabrielfeo.gradle.enterprise.api
42

5-
import com.gabrielfeo.gradle.enterprise.api.auth.HttpBearerAuth
6-
import com.gabrielfeo.gradle.enterprise.api.infrastructure.Serializer
73
import com.gabrielfeo.gradle.enterprise.api.internal.*
8-
import com.gabrielfeo.gradle.enterprise.api.internal.caching.CacheEnforcingInterceptor
9-
import com.gabrielfeo.gradle.enterprise.api.internal.caching.CacheHitLoggingInterceptor
10-
import com.gabrielfeo.gradle.enterprise.api.internal.caching.cache
11-
import okhttp3.OkHttpClient
12-
import retrofit2.Retrofit
13-
import retrofit2.converter.moshi.MoshiConverterFactory
14-
import retrofit2.converter.scalars.ScalarsConverterFactory
154
import retrofit2.create
165

17-
var baseUrl: () -> String = { requireBaseUrl() }
18-
var accessToken: () -> String = { requireToken() }
6+
val api: GradleEnterpriseApi by lazy {
7+
retrofit.create(GradleEnterpriseApi::class.java)
8+
}
199

20-
var maxConcurrentRequests = 30
21-
var maxCacheSize = 500_000_000L
22-
var debugLoggingEnabled = System.getenv("GRADLE_ENTERPRISE_API_DEBUG_LOGGING").toBoolean()
10+
fun shutdown() {
11+
okHttpClient.dispatcher.executorService.shutdownNow()
12+
}
2313

14+
var maxCacheSize = 500_000_000L
2415
val cacheablePaths: MutableList<Regex> = mutableListOf(
2516
""".*/api/builds/[\d\w]+/(?:gradle|maven)-attributes""".toRegex(),
2617
)
2718

28-
val okHttpClient: OkHttpClient by lazy {
29-
OkHttpClient.Builder()
30-
.cache(cache)
31-
.addInterceptor(HttpBearerAuth("bearer", accessToken()))
32-
.addInterceptor(CacheHitLoggingInterceptor())
33-
.addNetworkInterceptor(CacheEnforcingInterceptor(cacheablePaths))
34-
.build()
35-
.apply {
36-
dispatcher.maxRequests = maxConcurrentRequests
37-
dispatcher.maxRequestsPerHost = maxConcurrentRequests
38-
}
39-
}
40-
41-
val retrofit: Retrofit by lazy {
42-
Retrofit.Builder()
43-
.baseUrl(baseUrl())
44-
.addConverterFactory(ScalarsConverterFactory.create())
45-
.addConverterFactory(MoshiConverterFactory.create(Serializer.moshi))
46-
.client(okHttpClient)
47-
.build()
48-
}
49-
50-
val api: GradleEnterpriseApi by lazy {
51-
retrofit.create<GradleEnterpriseApi>()
52-
}
19+
var baseUrl: () -> String = { requireBaseUrl() }
20+
var accessToken: () -> String = { requireToken() }
5321

54-
fun shutdown() {
55-
okHttpClient.dispatcher.executorService.shutdownNow()
56-
}
22+
var maxConcurrentRequests = 30
23+
var debugLoggingEnabled = System.getenv("GRADLE_ENTERPRISE_API_DEBUG_LOGGING").toBoolean()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.gabrielfeo.gradle.enterprise.api.internal
2+
3+
import com.gabrielfeo.gradle.enterprise.api.accessToken
4+
import com.gabrielfeo.gradle.enterprise.api.auth.HttpBearerAuth
5+
import com.gabrielfeo.gradle.enterprise.api.cacheablePaths
6+
import com.gabrielfeo.gradle.enterprise.api.internal.caching.CacheEnforcingInterceptor
7+
import com.gabrielfeo.gradle.enterprise.api.internal.caching.CacheHitLoggingInterceptor
8+
import com.gabrielfeo.gradle.enterprise.api.internal.caching.cache
9+
import com.gabrielfeo.gradle.enterprise.api.maxConcurrentRequests
10+
import okhttp3.OkHttpClient
11+
12+
val okHttpClient: OkHttpClient by lazy {
13+
OkHttpClient.Builder()
14+
.cache(cache)
15+
.addInterceptor(HttpBearerAuth("bearer", accessToken()))
16+
.addInterceptor(CacheHitLoggingInterceptor())
17+
.addNetworkInterceptor(CacheEnforcingInterceptor(cacheablePaths))
18+
.build()
19+
.apply {
20+
dispatcher.maxRequests = maxConcurrentRequests
21+
dispatcher.maxRequestsPerHost = maxConcurrentRequests
22+
}
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.gabrielfeo.gradle.enterprise.api.internal
2+
3+
import com.gabrielfeo.gradle.enterprise.api.baseUrl
4+
import com.gabrielfeo.gradle.enterprise.api.infrastructure.Serializer
5+
import retrofit2.Retrofit
6+
import retrofit2.converter.moshi.MoshiConverterFactory
7+
import retrofit2.converter.scalars.ScalarsConverterFactory
8+
9+
val retrofit: Retrofit by lazy {
10+
Retrofit.Builder()
11+
.baseUrl(baseUrl())
12+
.addConverterFactory(ScalarsConverterFactory.create())
13+
.addConverterFactory(MoshiConverterFactory.create(Serializer.moshi))
14+
.client(okHttpClient)
15+
.build()
16+
}

0 commit comments

Comments
 (0)