diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigLocator.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigLocator.java index 0f9f8ad0faab3..156166f6693a4 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigLocator.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigLocator.java @@ -270,7 +270,18 @@ static RegistriesConfig initFromEnvironmentOrNull(Map map) { if (isEnvVarOption(var.getKey(), envvarPrefix, "UPDATE_POLICY")) { registry.setUpdatePolicy(var.getValue()); - break; + } else if (isEnvVarOption(var.getKey(), envvarPrefix, "REPO_URL")) { + JsonRegistryMavenConfig maven = (JsonRegistryMavenConfig) registry.getMaven(); + if (maven == null) { + maven = new JsonRegistryMavenConfig(); + registry.setMaven(maven); + } + JsonRegistryMavenRepoConfig repository = (JsonRegistryMavenRepoConfig) maven.getRepository(); + if (repository == null) { + repository = new JsonRegistryMavenRepoConfig(); + maven.setRepository(repository); + } + repository.setUrl(var.getValue()); } } } diff --git a/independent-projects/tools/registry-client/src/test/java/io/quarkus/registry/config/RegistriesConfigLocatorTest.java b/independent-projects/tools/registry-client/src/test/java/io/quarkus/registry/config/RegistriesConfigLocatorTest.java index 7dd751539e147..d5e1bd2991280 100644 --- a/independent-projects/tools/registry-client/src/test/java/io/quarkus/registry/config/RegistriesConfigLocatorTest.java +++ b/independent-projects/tools/registry-client/src/test/java/io/quarkus/registry/config/RegistriesConfigLocatorTest.java @@ -6,6 +6,8 @@ import io.quarkus.registry.config.json.JsonRegistriesConfig; import io.quarkus.registry.config.json.JsonRegistryConfig; import io.quarkus.registry.config.json.JsonRegistryDescriptorConfig; +import io.quarkus.registry.config.json.JsonRegistryMavenConfig; +import io.quarkus.registry.config.json.JsonRegistryMavenRepoConfig; import io.quarkus.registry.config.json.RegistriesConfigMapperHelper; import java.io.StringReader; import java.io.StringWriter; @@ -85,6 +87,40 @@ void testRegistryUpdatePolicyFromEnvironment() { assertThat(actualConfig).isEqualTo(expectedConfig); } + @Test + void testRegistryRepositoryURLFromEnvironment() { + final Map env = new HashMap<>(); + env.put(RegistriesConfigLocator.QUARKUS_REGISTRIES, "registry.acme.org,registry.other.io"); + env.put(RegistriesConfigLocator.QUARKUS_REGISTRY_ENV_VAR_PREFIX + "REGISTRY_ACME_ORG_UPDATE_POLICY", "always"); + env.put(RegistriesConfigLocator.QUARKUS_REGISTRY_ENV_VAR_PREFIX + "REGISTRY_OTHER_IO_REPO_URL", + "https://custom.registry.net/mvn"); + final RegistriesConfig actualConfig = initFromEnvironment(env); + + final JsonRegistriesConfig expectedConfig = new JsonRegistriesConfig(); + + JsonRegistryConfig registry = new JsonRegistryConfig(); + registry.setId("registry.acme.org"); + JsonRegistryDescriptorConfig descriptor = new JsonRegistryDescriptorConfig(); + descriptor.setArtifact(ArtifactCoords.fromString("org.acme.registry:quarkus-registry-descriptor::json:1.0-SNAPSHOT")); + registry.setDescriptor(descriptor); + registry.setUpdatePolicy("always"); + expectedConfig.addRegistry(registry); + + registry = new JsonRegistryConfig(); + registry.setId("registry.other.io"); + descriptor = new JsonRegistryDescriptorConfig(); + descriptor.setArtifact(ArtifactCoords.fromString("io.other.registry:quarkus-registry-descriptor::json:1.0-SNAPSHOT")); + registry.setDescriptor(descriptor); + JsonRegistryMavenConfig maven = new JsonRegistryMavenConfig(); + registry.setMaven(maven); + JsonRegistryMavenRepoConfig repo = new JsonRegistryMavenRepoConfig(); + maven.setRepository(repo); + repo.setUrl("https://custom.registry.net/mvn"); + expectedConfig.addRegistry(registry); + + assertThat(actualConfig).isEqualTo(expectedConfig); + } + private static RegistriesConfig initFromEnvironment(Map env) { return RegistriesConfigLocator.initFromEnvironmentOrNull(env); }