Skip to content

Commit

Permalink
Configure SISU bean filtering for the bootstrap Maven resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Feb 16, 2024
1 parent 234e0e9 commit 1f231f0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -132,6 +130,8 @@ public class BootstrapMavenContext {
private Boolean effectiveModelBuilder;
private Boolean wsModuleParentHierarchy;
private SettingsDecrypter settingsDecrypter;
private final List<String> excludeSisuBeanPackages;
private final List<String> includeSisuBeanPackages;

public static BootstrapMavenContextConfig<?> config() {
return new BootstrapMavenContextConfig<>();
Expand All @@ -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) {
Expand Down Expand Up @@ -871,12 +873,15 @@ private void initRepoSystemAndManager() {

protected MavenFactory configureMavenFactory() {
return MavenFactory.create(RepositorySystem.class.getClassLoader(), builder -> {
builder.addBean(ModelBuilder.class).setSupplier(new BeanSupplier<ModelBuilder>() {
@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();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -36,6 +37,45 @@ public class BootstrapMavenContextConfig<T extends BootstrapMavenContextConfig<?
protected Boolean effectiveModelBuilder;
protected Boolean wsModuleParentHierarchy;
protected Function<Path, Model> modelProvider;
protected List<String> excludeSisuBeanPackages;
protected List<String> includeSisuBeanPackages;

public T excludeSisuBeanPackage(String packageName) {
if (excludeSisuBeanPackages == null) {
excludeSisuBeanPackages = new ArrayList<>();
}
excludeSisuBeanPackages.add(packageName);
return (T) this;
}

protected List<String> 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<String> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -130,7 +169,7 @@ public T setRemoteRepositories(List<RemoteRepository> remoteRepos) {
/**
* Remote plugin repositories that should be used by the resolver
*
* @param repoPluginRepos remote plugin repositories
* @param remotePluginRepos remote plugin repositories
* @return
*/
@SuppressWarnings("unchecked")
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<plexus-sec-dispatcher.version>2.0</plexus-sec-dispatcher.version>
<plexus-utils.version>3.5.1</plexus-utils.version>
<smallrye-common.version>2.3.0</smallrye-common.version>
<smallrye-beanbag.version>1.3.2</smallrye-beanbag.version>
<smallrye-beanbag.version>1.4.0</smallrye-beanbag.version>
<gradle-tooling.version>8.6</gradle-tooling.version>
<quarkus-fs-util.version>0.0.10</quarkus-fs-util.version>
<org-crac.version>0.1.3</org-crac.version>
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/extension-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<version.surefire.plugin>3.2.5</version.surefire.plugin>
<maven-plugin-plugin.version>3.10.2</maven-plugin-plugin.version>
<jackson-bom.version>2.16.1</jackson-bom.version>
<smallrye-beanbag.version>1.3.2</smallrye-beanbag.version>
<smallrye-beanbag.version>1.4.0</smallrye-beanbag.version>
<junit.jupiter.version>5.10.2</junit.jupiter.version>
</properties>
<build>
Expand Down

0 comments on commit 1f231f0

Please sign in to comment.