Skip to content

Commit bc658b8

Browse files
committed
Improve OciRegistriesService state checks
1 parent f3e3d48 commit bc658b8

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/functionalTest/kotlin/io/github/sgtsilvio/gradle/oci/CentralRegistryDeclarationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ internal class CentralRegistryDeclarationTest {
7373
projectDir,
7474
"""
7575
dependencyResolutionManagement {
76-
repositoriesMode = RepositoriesMode.PREFER_PROJECT
76+
repositoriesMode = RepositoriesMode.PREFER_PROJECT
7777
oci {
7878
registries {
7979
gitHubContainerRegistry {}

src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciRegistriesImpl.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,15 @@ internal abstract class OciRegistriesService : BuildService<BuildServiceParamete
176176
imageMapping: OciImageMappingImpl,
177177
) = synchronized(this) {
178178
if (state != null) {
179-
throw IllegalStateException()
179+
throw IllegalStateException("OciRegistriesService.init must be called exactly once immediately after creation")
180180
}
181181
state = State.Initialized(registries, repositoryPort, imageMapping)
182182
}
183183

184184
fun start() = synchronized(this) {
185185
val currentState = state
186+
?: throw IllegalStateException("OciRegistriesService.start must be called after init")
186187
if (currentState !is State.Initialized) {
187-
if ((currentState == null) || (currentState == State.Closed)) {
188-
throw IllegalStateException()
189-
}
190188
return
191189
}
192190
if (currentState.registries.isEmpty()) {
@@ -262,6 +260,7 @@ internal abstract class OciRegistriesService : BuildService<BuildServiceParamete
262260

263261
final override fun close() = synchronized(this) {
264262
val currentState = state
263+
?: throw IllegalStateException("OciRegistriesService.close must be called after init")
265264
if (currentState is State.Started) {
266265
for (httpServer in currentState.httpServers) {
267266
httpServer.disposeNow()

0 commit comments

Comments
 (0)