From 1f231f0ebbaef987f292afc839b37a72dddfdf9e Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Fri, 16 Feb 2024 16:24:04 +0100 Subject: [PATCH] Configure SISU bean filtering for the bootstrap Maven resolver --- .../resolver/maven/BootstrapMavenContext.java | 21 +++++---- .../maven/BootstrapMavenContextConfig.java | 43 ++++++++++++++++++- independent-projects/bootstrap/pom.xml | 2 +- .../extension-maven-plugin/pom.xml | 2 +- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java index e9f25f657a335..5150d282ca810 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java @@ -79,8 +79,6 @@ import io.quarkus.bootstrap.resolver.maven.workspace.ModelUtils; import io.quarkus.bootstrap.util.PropertyUtils; import io.quarkus.maven.dependency.ArtifactCoords; -import io.smallrye.beanbag.BeanSupplier; -import io.smallrye.beanbag.Scope; import io.smallrye.beanbag.maven.MavenFactory; public class BootstrapMavenContext { @@ -132,6 +130,8 @@ public class BootstrapMavenContext { private Boolean effectiveModelBuilder; private Boolean wsModuleParentHierarchy; private SettingsDecrypter settingsDecrypter; + private final List excludeSisuBeanPackages; + private final List includeSisuBeanPackages; public static BootstrapMavenContextConfig config() { return new BootstrapMavenContextConfig<>(); @@ -158,6 +158,8 @@ public BootstrapMavenContext(BootstrapMavenContextConfig config) this.remotePluginRepos = config.remotePluginRepos; this.remoteRepoManager = config.remoteRepoManager; this.cliOptions = config.cliOptions; + this.excludeSisuBeanPackages = config.getExcludeSisuBeanPackages(); + this.includeSisuBeanPackages = config.getIncludeSisuBeanPackages(); if (config.rootProjectDir == null) { final String topLevelBaseDirStr = PropertyUtils.getProperty(MAVEN_TOP_LEVEL_PROJECT_BASEDIR); if (topLevelBaseDirStr != null) { @@ -871,12 +873,15 @@ private void initRepoSystemAndManager() { protected MavenFactory configureMavenFactory() { return MavenFactory.create(RepositorySystem.class.getClassLoader(), builder -> { - builder.addBean(ModelBuilder.class).setSupplier(new BeanSupplier() { - @Override - public ModelBuilder get(Scope scope) { - return new MavenModelBuilder(BootstrapMavenContext.this); - } - }).setPriority(100).build(); + for (var pkg : includeSisuBeanPackages) { + builder.includePackage(pkg); + } + for (var pkg : excludeSisuBeanPackages) { + builder.excludePackage(pkg); + } + builder.addBean(ModelBuilder.class) + .setSupplier(scope -> new MavenModelBuilder(BootstrapMavenContext.this)) + .setPriority(100).build(); }); } diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java index 8b645d5b0c2bc..0f44dcc37a8ec 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java @@ -4,6 +4,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; import java.util.function.Function; @@ -36,6 +37,45 @@ public class BootstrapMavenContextConfig modelProvider; + protected List excludeSisuBeanPackages; + protected List includeSisuBeanPackages; + + public T excludeSisuBeanPackage(String packageName) { + if (excludeSisuBeanPackages == null) { + excludeSisuBeanPackages = new ArrayList<>(); + } + excludeSisuBeanPackages.add(packageName); + return (T) this; + } + + protected List getExcludeSisuBeanPackages() { + if (excludeSisuBeanPackages == null) { + return List.of("org.apache.maven.shared.release", + "org.apache.maven.toolchain", + "org.apache.maven.lifecycle", + "org.apache.maven.execution", + "org.apache.maven.plugin"); + } + return excludeSisuBeanPackages; + } + + public T includeSisuBeanPackage(String packageName) { + if (includeSisuBeanPackages == null) { + includeSisuBeanPackages = new ArrayList<>(); + } + includeSisuBeanPackages.add(packageName); + return (T) this; + } + + protected List getIncludeSisuBeanPackages() { + if (includeSisuBeanPackages == null) { + return List.of("io.smallrye.beanbag", + "org.eclipse.aether", + "org.sonatype.plexus.components", + "org.apache.maven"); + } + return includeSisuBeanPackages; + } /** * Local repository location @@ -80,7 +120,6 @@ public T setCurrentProject(LocalProject currentProject) { * POM configuration will be picked up by the resolver and all the local projects * belonging to the workspace will be resolved at their original locations instead of * the actually artifacts installed in the repository. - * Note, that if {@link #workspace} is provided, this setting will be ignored. * * @param workspaceDiscovery enables or disables workspace discovery * @return this instance of the builder @@ -130,7 +169,7 @@ public T setRemoteRepositories(List remoteRepos) { /** * Remote plugin repositories that should be used by the resolver * - * @param repoPluginRepos remote plugin repositories + * @param remotePluginRepos remote plugin repositories * @return */ @SuppressWarnings("unchecked") diff --git a/independent-projects/bootstrap/pom.xml b/independent-projects/bootstrap/pom.xml index 234df90e16837..12c80992c08de 100644 --- a/independent-projects/bootstrap/pom.xml +++ b/independent-projects/bootstrap/pom.xml @@ -74,7 +74,7 @@ 2.0 3.5.1 2.3.0 - 1.3.2 + 1.4.0 8.6 0.0.10 0.1.3 diff --git a/independent-projects/extension-maven-plugin/pom.xml b/independent-projects/extension-maven-plugin/pom.xml index bf88d879a4012..cd28821da4835 100644 --- a/independent-projects/extension-maven-plugin/pom.xml +++ b/independent-projects/extension-maven-plugin/pom.xml @@ -43,7 +43,7 @@ 3.2.5 3.10.2 2.16.1 - 1.3.2 + 1.4.0 5.10.2