From cedebbf7dcdeb44f5a0771daf976b7bd5f216857 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 24 Mar 2021 08:48:27 +0100 Subject: [PATCH 1/3] Revert "Register all profile properties in the default config source." This reverts commit 8d85f2299f4b0565fee348bed5bba5a711032a1e. --- .../BuildTimeConfigurationReader.java | 15 +------------ ...luesTest.java => ConfigDefaultValues.java} | 22 +++---------------- 2 files changed, 4 insertions(+), 33 deletions(-) rename extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/{ConfigDefaultValuesTest.java => ConfigDefaultValues.java} (63%) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java b/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java index 48572a88c31c7..109885691ee38 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java @@ -296,7 +296,7 @@ ReadResult run() { nameBuilder.setLength(len); } // sweep-up - for (String propertyName : getAllProperties()) { + for (String propertyName : config.getPropertyNames()) { if (propertyName.equals(ConfigSource.CONFIG_ORDINAL)) { continue; } @@ -718,19 +718,6 @@ private Converter getConverter(SmallRyeConfig config, Field field, ConverterT convByType.put(valueType, converter); return converter; } - - /** - * We collect all properties from ConfigSources, because Config#getPropertyNames exclude the active profiled - * properties, meaning that the property is written in the default config source unprofiled. This may cause - * issues if we run with a different profile and fallback to defaults. - */ - private Set getAllProperties() { - Set properties = new HashSet<>(); - for (ConfigSource configSource : config.getConfigSources()) { - properties.addAll(configSource.getPropertyNames()); - } - return properties; - } } public static final class ReadResult { diff --git a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValuesTest.java b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValues.java similarity index 63% rename from extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValuesTest.java rename to extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValues.java index 5ff2078ff58d5..4380489a09b03 100644 --- a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValuesTest.java +++ b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValues.java @@ -15,17 +15,12 @@ import io.quarkus.test.QuarkusUnitTest; -public class ConfigDefaultValuesTest { +public class ConfigDefaultValues { @RegisterExtension static final QuarkusUnitTest TEST = new QuarkusUnitTest() .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) - .addAsResource(new StringAsset( - "config_ordinal=1000\n" + - "my.prop=1234\n" + - "%prod.my.prop=1234\n" + - "%dev.my.prop=5678\n" + - "%test.my.prop=1234"), - "application.properties")); + .addAsResource(new StringAsset("config_ordinal=1000\n" + + "my.prop=1234\n"), "application.properties")); @Inject Config config; @@ -44,17 +39,6 @@ void configDefaultValues() { assertEquals("1234", applicationProperties.getValue("my.prop")); } - @Test - void profileDefaultValues() { - ConfigSource defaultValues = getConfigSourceByName("PropertiesConfigSource[source=Specified default values]"); - assertNotNull(defaultValues); - assertEquals("1234", defaultValues.getValue("my.prop")); - assertEquals("1234", defaultValues.getValue("%prod.my.prop")); - assertEquals("5678", defaultValues.getValue("%dev.my.prop")); - assertEquals("1234", defaultValues.getValue("%test.my.prop")); - assertEquals("1234", config.getValue("my.prop", String.class)); - } - private ConfigSource getConfigSourceByName(String name) { for (ConfigSource configSource : config.getConfigSources()) { if (configSource.getName().contains(name)) { From b3378b45a6c904f2d602c467d23232f86c78b5ff Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Mon, 15 Mar 2021 13:15:59 +0000 Subject: [PATCH 2/3] Fix QuarkusSecurityIdentity.isAnonymous check (cherry picked from commit fdb63d34fbb3ee181473426d2f978ef571f5cc80) --- .../runtime/QuarkusSecurityIdentity.java | 29 +++- .../runtime/QuarkusSecurityIdentityTest.java | 133 ++++++++++++++++++ 2 files changed, 159 insertions(+), 3 deletions(-) diff --git a/extensions/security/runtime/src/main/java/io/quarkus/security/runtime/QuarkusSecurityIdentity.java b/extensions/security/runtime/src/main/java/io/quarkus/security/runtime/QuarkusSecurityIdentity.java index 54638f3d978f2..50bd92790f5b3 100644 --- a/extensions/security/runtime/src/main/java/io/quarkus/security/runtime/QuarkusSecurityIdentity.java +++ b/extensions/security/runtime/src/main/java/io/quarkus/security/runtime/QuarkusSecurityIdentity.java @@ -22,6 +22,7 @@ public class QuarkusSecurityIdentity implements SecurityIdentity { private final Set credentials; private final Map attributes; private final List>> permissionCheckers; + private final boolean anonymous; private QuarkusSecurityIdentity(Builder builder) { this.principal = builder.principal; @@ -29,6 +30,7 @@ private QuarkusSecurityIdentity(Builder builder) { this.credentials = Collections.unmodifiableSet(builder.credentials); this.attributes = Collections.unmodifiableMap(builder.attributes); this.permissionCheckers = Collections.unmodifiableList(builder.permissionCheckers); + this.anonymous = builder.anonymous; } @Override @@ -38,7 +40,7 @@ public Principal getPrincipal() { @Override public boolean isAnonymous() { - return false; + return anonymous; } @Override @@ -121,11 +123,13 @@ public static Builder builder() { } public static Builder builder(SecurityIdentity identity) { - return new Builder() + Builder builder = new Builder() .addAttributes(identity.getAttributes()) .addCredentials(identity.getCredentials()) .addRoles(identity.getRoles()) - .setPrincipal(identity.getPrincipal()); + .setPrincipal(identity.getPrincipal()) + .setAnonymous(identity.isAnonymous()); + return builder; } public static class Builder { @@ -135,6 +139,7 @@ public static class Builder { Set credentials = new HashSet<>(); Map attributes = new HashMap<>(); List>> permissionCheckers = new ArrayList<>(); + private boolean anonymous; boolean built = false; public Builder setPrincipal(Principal principal) { @@ -211,7 +216,25 @@ public Builder addPermissionChecker(Function> function) return this; } + /** + * Sets an anonymous identity status. + * + * @param anonymous the anonymous status + * @return This builder + */ + public Builder setAnonymous(boolean anonymous) { + if (built) { + throw new IllegalStateException(); + } + this.anonymous = anonymous; + return this; + } + public QuarkusSecurityIdentity build() { + if (principal == null && !anonymous) { + throw new IllegalStateException("Principal is null but anonymous status is false"); + } + built = true; return new QuarkusSecurityIdentity(this); } diff --git a/extensions/security/runtime/src/test/java/io/quarkus/security/runtime/QuarkusSecurityIdentityTest.java b/extensions/security/runtime/src/test/java/io/quarkus/security/runtime/QuarkusSecurityIdentityTest.java index c1704c16b5ef7..7d9dc11e67be3 100644 --- a/extensions/security/runtime/src/test/java/io/quarkus/security/runtime/QuarkusSecurityIdentityTest.java +++ b/extensions/security/runtime/src/test/java/io/quarkus/security/runtime/QuarkusSecurityIdentityTest.java @@ -1,11 +1,23 @@ package io.quarkus.security.runtime; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.security.Permission; +import java.security.Principal; +import java.util.Collections; +import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.Test; +import io.quarkus.security.credential.Credential; import io.quarkus.security.credential.PasswordCredential; import io.quarkus.security.identity.SecurityIdentity; +import io.smallrye.mutiny.Uni; public class QuarkusSecurityIdentityTest { @@ -18,11 +30,132 @@ public void testCopyIdentity() throws Exception { .addAttribute("key", "value") .build(); + assertFalse(identity1.isAnonymous()); + SecurityIdentity identity2 = QuarkusSecurityIdentity.builder(identity1).build(); + assertFalse(identity1.isAnonymous()); assertEquals(identity1.getAttributes(), identity2.getAttributes()); assertEquals(identity1.getPrincipal(), identity2.getPrincipal()); assertEquals(identity1.getCredentials(), identity2.getCredentials()); assertEquals(identity1.getRoles(), identity2.getRoles()); } + + @Test + public void testAnonymousPrincipalWithCustomIdentity() throws Exception { + SecurityIdentity identity1 = new TestSecurityIdentityAnonymousPrincipal(); + assertTrue(identity1.isAnonymous()); + assertEquals("anonymous-principal", identity1.getPrincipal().getName()); + + SecurityIdentity identity2 = QuarkusSecurityIdentity.builder(identity1).build(); + assertTrue(identity2.isAnonymous()); + assertEquals("anonymous-principal", identity2.getPrincipal().getName()); + } + + @Test + public void testPrincipalNullAnonymousFalseWithBuilder() throws Exception { + QuarkusSecurityIdentity.Builder builder = QuarkusSecurityIdentity.builder() + .addRole("admin") + .addCredential(new PasswordCredential("password".toCharArray())) + .addAttribute("key", "value"); + ; + + assertThrows(IllegalStateException.class, () -> builder.build()); + } + + @Test + public void testPrincipalNullAnonymousFalseWithCustomIdentity() throws Exception { + SecurityIdentity identity1 = new TestSecurityIdentityPrincipalNullAnonymousFalse(); + assertFalse(identity1.isAnonymous()); + assertNull(identity1.getPrincipal()); + + assertThrows(IllegalStateException.class, () -> QuarkusSecurityIdentity.builder(identity1).build()); + } + + @Test + public void testPrincipalNullAnonymousFalseWithCustomIdentityFixed() throws Exception { + SecurityIdentity identity1 = new TestSecurityIdentityPrincipalNullAnonymousFalse(); + assertFalse(identity1.isAnonymous()); + assertNull(identity1.getPrincipal()); + + SecurityIdentity identity2 = QuarkusSecurityIdentity.builder(identity1).setAnonymous(true).build(); + assertTrue(identity2.isAnonymous()); + assertNull(identity2.getPrincipal()); + } + + static class TestSecurityIdentityAnonymousPrincipal extends AbstractTestSecurityIdentity { + + @Override + public Principal getPrincipal() { + return new Principal() { + @Override + public String getName() { + return "anonymous-principal"; + } + }; + } + + @Override + public boolean isAnonymous() { + return true; + } + + } + + static class TestSecurityIdentityPrincipalNullAnonymousFalse extends AbstractTestSecurityIdentity { + + @Override + public Principal getPrincipal() { + return null; + } + + @Override + public boolean isAnonymous() { + return false; + } + + } + + static abstract class AbstractTestSecurityIdentity implements SecurityIdentity { + + @Override + public Set getRoles() { + return Collections.emptySet(); + } + + @Override + public boolean hasRole(String role) { + // TODO Auto-generated method stub + return false; + } + + @Override + public T getCredential(Class credentialType) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Set getCredentials() { + return Collections.emptySet(); + } + + @Override + public T getAttribute(String name) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map getAttributes() { + return Collections.emptyMap(); + } + + @Override + public Uni checkPermission(Permission permission) { + // TODO Auto-generated method stub + return null; + } + + } } From eea32102266f15bbb6055c0c8ce1cf0cc88bc568 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Tue, 23 Mar 2021 18:18:16 +0100 Subject: [PATCH 3/3] Support for providing a custom extension registry client impl in a maven artifact (cherry picked from commit 00cffa9ffc75b770b69d4c81923b9f0ae7efcf79) --- .../registry/ExtensionCatalogResolver.java | 81 ++++++++++++++++++- .../registry/client/RegistryClient.java | 48 +---------- .../client/RegistryClientDispatcher.java | 47 +++++++++++ .../MavenPlatformExtensionsResolver.java | 12 +-- .../maven/MavenRegistryClientFactory.java | 3 +- .../client/spi/RegistryClientEnvironment.java | 11 +++ .../spi/RegistryClientFactoryProvider.java | 12 +++ .../config/RegistriesConfigLocator.java | 3 + .../registry/config/RegistryConfig.java | 4 + .../config/json/JsonRegistryConfig.java | 24 ++++++ .../registry/util/PlatformArtifacts.java | 11 +++ .../registry/util/PlatformArtifactsTest.java | 15 ++++ 12 files changed, 212 insertions(+), 59 deletions(-) create mode 100644 independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/RegistryClientDispatcher.java create mode 100644 independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/spi/RegistryClientEnvironment.java create mode 100644 independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/spi/RegistryClientFactoryProvider.java diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/ExtensionCatalogResolver.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/ExtensionCatalogResolver.java index c50d4d8982439..719e3f3b8e5e9 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/ExtensionCatalogResolver.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/ExtensionCatalogResolver.java @@ -12,9 +12,14 @@ import io.quarkus.registry.catalog.json.JsonPlatformCatalog; import io.quarkus.registry.client.RegistryClientFactory; import io.quarkus.registry.client.maven.MavenRegistryClientFactory; +import io.quarkus.registry.client.spi.RegistryClientEnvironment; +import io.quarkus.registry.client.spi.RegistryClientFactoryProvider; import io.quarkus.registry.config.RegistriesConfig; import io.quarkus.registry.config.RegistriesConfigLocator; import io.quarkus.registry.config.RegistryConfig; +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -24,8 +29,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.ServiceLoader; import java.util.Set; import java.util.function.Function; +import org.eclipse.aether.artifact.DefaultArtifact; public class ExtensionCatalogResolver { @@ -45,6 +52,9 @@ public class Builder { private RegistriesConfig config; private boolean built; + private RegistryClientFactory defaultClientFactory; + private RegistryClientEnvironment clientEnv; + private Builder() { } @@ -95,14 +105,13 @@ private void completeConfig() { private void buildRegistryClients() { registries = new ArrayList<>(config.getRegistries().size()); - final RegistryClientFactory defaultClientFactory = new MavenRegistryClientFactory(artifactResolver, - log); for (RegistryConfig config : config.getRegistries()) { if (config.isDisabled()) { continue; } + final RegistryClientFactory clientFactory = getClientFactory(config); try { - registries.add(new RegistryExtensionResolver(defaultClientFactory.buildRegistryClient(config), log)); + registries.add(new RegistryExtensionResolver(clientFactory.buildRegistryClient(config), log)); } catch (RegistryResolutionException e) { // TODO this should be enabled once the registry comes to life log.debug(e.getMessage()); @@ -111,6 +120,72 @@ private void buildRegistryClients() { } } + private RegistryClientFactory getClientFactory(RegistryConfig config) { + final Object providerValue = config.getExtra().get("client-factory-artifact"); + if (providerValue == null) { + return getDefaultClientFactory(); + } + ArtifactCoords providerArtifact = null; + try { + final String providerStr = (String) providerValue; + providerArtifact = ArtifactCoords.fromString(providerStr); + } catch (Exception e) { + throw new IllegalStateException("Failed to process configuration of " + config.getId() + + " registry: failed to cast " + providerValue + " to String", e); + } + final File providerJar; + try { + providerJar = artifactResolver.resolve(new DefaultArtifact(providerArtifact.getGroupId(), + providerArtifact.getArtifactId(), providerArtifact.getClassifier(), + providerArtifact.getType(), providerArtifact.getVersion())).getArtifact().getFile(); + } catch (BootstrapMavenException e) { + throw new IllegalStateException( + "Failed to resolve the registry client factory provider artifact " + providerArtifact, e); + } + log.debug("Loading registry client factory for %s from %s", config.getId(), providerArtifact); + final ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); + try { + ClassLoader providerCl = new URLClassLoader(new URL[] { providerJar.toURI().toURL() }, originalCl); + final Iterator i = ServiceLoader + .load(RegistryClientFactoryProvider.class, providerCl).iterator(); + final RegistryClientFactoryProvider provider = i.next(); + if (i.hasNext()) { + final StringBuilder buf = new StringBuilder(); + buf.append("Found more than one registry client factory provider " + + provider.getClass().getName()); + while (i.hasNext()) { + buf.append(", ").append(i.next().getClass().getName()); + } + throw new Exception(buf.toString()); + } + return provider.newRegistryClientFactory(getClientEnv()); + } catch (Exception e) { + throw new IllegalStateException("Failed to load registry client factory from " + providerJar, e); + } finally { + Thread.currentThread().setContextClassLoader(originalCl); + } + } + + private RegistryClientFactory getDefaultClientFactory() { + return defaultClientFactory == null ? defaultClientFactory = new MavenRegistryClientFactory(artifactResolver, log) + : defaultClientFactory; + } + + private RegistryClientEnvironment getClientEnv() { + return clientEnv == null ? clientEnv = new RegistryClientEnvironment() { + + @Override + public MessageWriter log() { + return log; + } + + @Override + public MavenArtifactResolver resolver() { + return artifactResolver; + } + } : clientEnv; + } + private void assertNotBuilt() { if (built) { throw new IllegalStateException("The builder has already built an instance"); diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/RegistryClient.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/RegistryClient.java index f2b1e83075f0d..18a3242d83658 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/RegistryClient.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/RegistryClient.java @@ -1,55 +1,11 @@ package io.quarkus.registry.client; -import io.quarkus.maven.ArtifactCoords; -import io.quarkus.registry.RegistryResolutionException; -import io.quarkus.registry.catalog.ExtensionCatalog; -import io.quarkus.registry.catalog.PlatformCatalog; -import io.quarkus.registry.config.RegistryConfig; -import java.util.Objects; - /** * Implements the basic queries a registry client is supposed to handle. * Although there are only a few kinds of queries, a registry is not required to support * all of them. For example, a registry may be configured to only provide platform extensions or * the other way around - provide only non-platform extensions but not platforms. */ -public class RegistryClient - implements RegistryNonPlatformExtensionsResolver, RegistryPlatformExtensionsResolver, RegistryPlatformsResolver, - RegistryConfigResolver { - - private final RegistryPlatformsResolver platforms; - private final RegistryPlatformExtensionsResolver platformExtensions; - private final RegistryNonPlatformExtensionsResolver nonPlatformExtensions; - protected RegistryConfig config; - - public RegistryClient(RegistryConfig config, RegistryPlatformsResolver platforms, - RegistryPlatformExtensionsResolver platformExtensions, - RegistryNonPlatformExtensionsResolver nonPlatformExtensions) { - this.config = config; - this.platforms = platforms; - this.platformExtensions = Objects.requireNonNull(platformExtensions); - this.nonPlatformExtensions = nonPlatformExtensions; - } - - @Override - public PlatformCatalog resolvePlatforms(String quarkusVersion) throws RegistryResolutionException { - return platforms == null ? null : platforms.resolvePlatforms(quarkusVersion); - } - - @Override - public ExtensionCatalog resolvePlatformExtensions(ArtifactCoords platformCoords) - throws RegistryResolutionException { - return platformExtensions.resolvePlatformExtensions(platformCoords); - } - - @Override - public ExtensionCatalog resolveNonPlatformExtensions(String quarkusVersion) throws RegistryResolutionException { - return nonPlatformExtensions == null ? null - : nonPlatformExtensions.resolveNonPlatformExtensions(quarkusVersion); - } - - @Override - public RegistryConfig resolveRegistryConfig() throws RegistryResolutionException { - return config; - } +public interface RegistryClient extends RegistryNonPlatformExtensionsResolver, RegistryPlatformExtensionsResolver, + RegistryPlatformsResolver, RegistryConfigResolver { } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/RegistryClientDispatcher.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/RegistryClientDispatcher.java new file mode 100644 index 0000000000000..d60c7f56be97f --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/RegistryClientDispatcher.java @@ -0,0 +1,47 @@ +package io.quarkus.registry.client; + +import io.quarkus.maven.ArtifactCoords; +import io.quarkus.registry.RegistryResolutionException; +import io.quarkus.registry.catalog.ExtensionCatalog; +import io.quarkus.registry.catalog.PlatformCatalog; +import io.quarkus.registry.config.RegistryConfig; +import java.util.Objects; + +public class RegistryClientDispatcher implements RegistryClient { + + private final RegistryPlatformsResolver platforms; + private final RegistryPlatformExtensionsResolver platformExtensions; + private final RegistryNonPlatformExtensionsResolver nonPlatformExtensions; + protected RegistryConfig config; + + public RegistryClientDispatcher(RegistryConfig config, RegistryPlatformsResolver platforms, + RegistryPlatformExtensionsResolver platformExtensions, + RegistryNonPlatformExtensionsResolver nonPlatformExtensions) { + this.config = config; + this.platforms = platforms; + this.platformExtensions = Objects.requireNonNull(platformExtensions); + this.nonPlatformExtensions = nonPlatformExtensions; + } + + @Override + public PlatformCatalog resolvePlatforms(String quarkusVersion) throws RegistryResolutionException { + return platforms == null ? null : platforms.resolvePlatforms(quarkusVersion); + } + + @Override + public ExtensionCatalog resolvePlatformExtensions(ArtifactCoords platformCoords) + throws RegistryResolutionException { + return platformExtensions.resolvePlatformExtensions(platformCoords); + } + + @Override + public ExtensionCatalog resolveNonPlatformExtensions(String quarkusVersion) throws RegistryResolutionException { + return nonPlatformExtensions == null ? null + : nonPlatformExtensions.resolveNonPlatformExtensions(quarkusVersion); + } + + @Override + public RegistryConfig resolveRegistryConfig() throws RegistryResolutionException { + return config; + } +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenPlatformExtensionsResolver.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenPlatformExtensionsResolver.java index 84603090c98ab..d020c61b6847e 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenPlatformExtensionsResolver.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenPlatformExtensionsResolver.java @@ -3,12 +3,12 @@ import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; import io.quarkus.devtools.messagewriter.MessageWriter; import io.quarkus.maven.ArtifactCoords; -import io.quarkus.registry.Constants; import io.quarkus.registry.RegistryResolutionException; import io.quarkus.registry.catalog.ExtensionCatalog; import io.quarkus.registry.catalog.json.JsonCatalogMapperHelper; import io.quarkus.registry.catalog.json.JsonExtensionCatalog; import io.quarkus.registry.client.RegistryPlatformExtensionsResolver; +import io.quarkus.registry.util.PlatformArtifacts; import java.io.IOException; import java.nio.file.Path; import java.util.Objects; @@ -37,9 +37,7 @@ public ExtensionCatalog resolvePlatformExtensions(ArtifactCoords platformCoords) version = platformCoords.getVersion(); } final String groupId = platformCoords.getGroupId(); - final String artifactId = platformCoords.getArtifactId().endsWith(Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX) - ? platformCoords.getArtifactId() - : platformCoords.getArtifactId() + Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX; + final String artifactId = PlatformArtifacts.ensureCatalogArtifactId(platformCoords.getArtifactId()); final String classifier = version; final Artifact catalogArtifact = new DefaultArtifact(groupId, artifactId, classifier, "json", version); log.debug("Resolving platform extension catalog %s", catalogArtifact); @@ -60,11 +58,7 @@ public ExtensionCatalog resolvePlatformExtensions(ArtifactCoords platformCoords) private String resolveLatestBomVersion(ArtifactCoords bom, String versionRange) throws RegistryResolutionException { final Artifact bomArtifact = new DefaultArtifact(bom.getGroupId(), - bom.getArtifactId().endsWith(Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX) - ? bom.getArtifactId().substring(0, - bom.getArtifactId().length() - - Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX.length()) - : bom.getArtifactId(), + PlatformArtifacts.ensureBomArtifactId(bom.getArtifactId()), "", "pom", bom.getVersion()); log.debug("Resolving the latest version of %s:%s:%s:%s in the range %s", bom.getGroupId(), bom.getArtifactId(), bom.getClassifier(), bom.getType(), versionRange); diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenRegistryClientFactory.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenRegistryClientFactory.java index 78b94b1a10a86..0fd53684ac9c7 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenRegistryClientFactory.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenRegistryClientFactory.java @@ -8,6 +8,7 @@ import io.quarkus.registry.Constants; import io.quarkus.registry.RegistryResolutionException; import io.quarkus.registry.client.RegistryClient; +import io.quarkus.registry.client.RegistryClientDispatcher; import io.quarkus.registry.client.RegistryClientFactory; import io.quarkus.registry.client.RegistryNonPlatformExtensionsResolver; import io.quarkus.registry.client.RegistryPlatformsResolver; @@ -151,7 +152,7 @@ public RegistryClient buildRegistryClient(RegistryConfig config) throws Registry platformsResolver = new MavenPlatformsResolver(platformsConfig, resolver, log); } - return new RegistryClient(config, platformsResolver, + return new RegistryClientDispatcher(config, platformsResolver, Boolean.TRUE.equals(config.getPlatforms().getExtensionCatalogsIncluded()) ? new MavenPlatformExtensionsResolver(resolver, log) : new MavenPlatformExtensionsResolver(originalResolver, log), diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/spi/RegistryClientEnvironment.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/spi/RegistryClientEnvironment.java new file mode 100644 index 0000000000000..dec3d441923ae --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/spi/RegistryClientEnvironment.java @@ -0,0 +1,11 @@ +package io.quarkus.registry.client.spi; + +import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; +import io.quarkus.devtools.messagewriter.MessageWriter; + +public interface RegistryClientEnvironment { + + MessageWriter log(); + + MavenArtifactResolver resolver(); +} diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/spi/RegistryClientFactoryProvider.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/spi/RegistryClientFactoryProvider.java new file mode 100644 index 0000000000000..82fb7e3f4796f --- /dev/null +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/spi/RegistryClientFactoryProvider.java @@ -0,0 +1,12 @@ +package io.quarkus.registry.client.spi; + +import io.quarkus.registry.client.RegistryClientFactory; + +/** + * Registry client factory service provider interface that will be looked up on the class path using the ServiceLoader + * mechanism. + */ +public interface RegistryClientFactoryProvider { + + RegistryClientFactory newRegistryClientFactory(RegistryClientEnvironment env); +} 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 9b83b2062f470..2e12acae5bd34 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 @@ -101,6 +101,9 @@ private static RegistryConfig completeRequiredConfig(RegistryConfig original) { if (original.getPlatforms() != null) { config.setPlatforms(original.getPlatforms()); } + if (!original.getExtra().isEmpty()) { + config.setExtra(original.getExtra()); + } } return config; } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistryConfig.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistryConfig.java index ef758108e7c27..b33e7a0af7c25 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistryConfig.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistryConfig.java @@ -1,5 +1,7 @@ package io.quarkus.registry.config; +import java.util.Map; + public interface RegistryConfig { String getId(); @@ -17,4 +19,6 @@ public interface RegistryConfig { RegistryMavenConfig getMaven(); RegistryQuarkusVersionsConfig getQuarkusVersions(); + + Map getExtra(); } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/json/JsonRegistryConfig.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/json/JsonRegistryConfig.java index f0edf0d9e7fca..f9f29584d257d 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/json/JsonRegistryConfig.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/json/JsonRegistryConfig.java @@ -1,5 +1,7 @@ package io.quarkus.registry.config.json; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @@ -9,6 +11,9 @@ import io.quarkus.registry.config.RegistryNonPlatformExtensionsConfig; import io.quarkus.registry.config.RegistryPlatformsConfig; import io.quarkus.registry.config.RegistryQuarkusVersionsConfig; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; @JsonInclude(JsonInclude.Include.NON_NULL) @@ -22,6 +27,7 @@ public class JsonRegistryConfig implements RegistryConfig { private RegistryNonPlatformExtensionsConfig nonPlatformExtensions; private RegistryMavenConfig mavenConfig; private RegistryQuarkusVersionsConfig versionsConfig; + private Map extra; public JsonRegistryConfig() { } @@ -112,6 +118,24 @@ public void setQuarkusVersions(RegistryQuarkusVersionsConfig quarkusVersions) { this.versionsConfig = quarkusVersions; } + @JsonAnyGetter + @Override + public Map getExtra() { + return extra == null ? Collections.emptyMap() : extra; + } + + public void setExtra(Map extra) { + this.extra = extra; + } + + @JsonAnySetter + public void setAny(String name, Object value) { + if (extra == null) { + extra = new HashMap<>(); + } + extra.put(name, value); + } + public String toString() { return "[" + id + " maven=" + mavenConfig + "]"; } diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/util/PlatformArtifacts.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/util/PlatformArtifacts.java index 8a74dc99a288e..d2a4f9c2950fc 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/util/PlatformArtifacts.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/util/PlatformArtifacts.java @@ -19,6 +19,10 @@ public static ArtifactCoords ensureCatalogArtifact(ArtifactCoords coords) { : getCatalogArtifactForBom(coords.getGroupId(), coords.getArtifactId(), coords.getVersion()); } + public static String ensureCatalogArtifactId(String artifactId) { + return isCatalogArtifactId(artifactId) ? artifactId : artifactId + Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX; + } + public static boolean isCatalogArtifactId(String artifactId) { return artifactId != null && artifactId.endsWith(Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX); } @@ -26,4 +30,11 @@ public static boolean isCatalogArtifactId(String artifactId) { public static boolean isCatalogArtifact(ArtifactCoords coords) { return isCatalogArtifactId(coords.getArtifactId()); } + + public static String ensureBomArtifactId(String artifactId) { + return isCatalogArtifactId(artifactId) + ? artifactId.substring(0, artifactId.length() - Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX.length()) + : artifactId; + } + } diff --git a/independent-projects/tools/registry-client/src/test/java/io/quarkus/devtools/registry/util/PlatformArtifactsTest.java b/independent-projects/tools/registry-client/src/test/java/io/quarkus/devtools/registry/util/PlatformArtifactsTest.java index 1dab2be6aec76..8d114e6e4b22b 100644 --- a/independent-projects/tools/registry-client/src/test/java/io/quarkus/devtools/registry/util/PlatformArtifactsTest.java +++ b/independent-projects/tools/registry-client/src/test/java/io/quarkus/devtools/registry/util/PlatformArtifactsTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import io.quarkus.maven.ArtifactCoords; +import io.quarkus.registry.Constants; import io.quarkus.registry.util.PlatformArtifacts; import org.junit.jupiter.api.Test; @@ -28,6 +29,13 @@ public void ensureCatalogArtifact() { PlatformArtifacts.ensureCatalogArtifact(new ArtifactCoords("org.acme", "acme-bom", null, "pom", "1.0"))); } + @Test + public void ensureCatalogArtifactId() { + final String catalog = "acme-bom-quarkus-platform-descriptor"; + assertEquals(catalog, PlatformArtifacts.ensureCatalogArtifactId(catalog)); + assertEquals(catalog, PlatformArtifacts.ensureCatalogArtifactId("acme-bom")); + } + @Test public void isCatalogArtifactId() { assertTrue(PlatformArtifacts.isCatalogArtifactId("acme-bom-quarkus-platform-descriptor")); @@ -40,4 +48,11 @@ public void isCatalogArtifact() { new ArtifactCoords("org.acme", "acme-bom-quarkus-platform-descriptor", "1.0", "json", "1.0"))); assertFalse(PlatformArtifacts.isCatalogArtifact(new ArtifactCoords("org.acme", "acme-bom", null, "pom", "1.0"))); } + + @Test + public void ensureBomArtifactId() { + final String bom = "acme-bom"; + assertEquals(bom, PlatformArtifacts.ensureBomArtifactId(bom)); + assertEquals(bom, PlatformArtifacts.ensureBomArtifactId("acme-bom" + Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX)); + } }