Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the container-provided settings decrypter #33333

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.eclipse.aether.repository.RemoteRepository;
import org.jboss.logging.Logger;

import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.devtools.commands.CreateExtension;
import io.quarkus.devtools.commands.data.QuarkusCommandException;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.maven.components.Prompter;
import io.quarkus.maven.utilities.MojoUtils;

/**
* Creates the base of a
Expand Down Expand Up @@ -213,6 +222,18 @@ public class CreateExtensionMojo extends AbstractMojo {
@Parameter(defaultValue = "${session}")
private MavenSession session;

@Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true)
List<RemoteRepository> repos;

@Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
RepositorySystemSession repoSession;

@Component
RepositorySystem repoSystem;

@Component
RemoteRepositoryManager remoteRepoManager;

@Override
public void execute() throws MojoExecutionException {

Expand All @@ -234,6 +255,20 @@ public void execute() throws MojoExecutionException {

autoComputeQuarkiverseExtensionId();

try {
final MavenArtifactResolver resolver = MavenArtifactResolver.builder()
.setRepositorySystem(repoSystem)
.setRepositorySystemSession(
getLog().isDebugEnabled() ? repoSession : MojoUtils.muteTransferListener(repoSession))
.setRemoteRepositories(repos)
.setRemoteRepositoryManager(remoteRepoManager)
.build();
// there should be a better way to pass the resolver
QuarkusProjectHelper.setArtifactResolver(resolver);
} catch (Exception e) {
throw new MojoExecutionException("Failed to initialize Maven artifact resolver", e);
}

final CreateExtension createExtension = new CreateExtension(basedir.toPath())
.extensionId(extensionId)
.extensionName(extensionName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.inject.Singleton;

import org.apache.maven.model.building.ModelBuilder;
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.impl.ArtifactResolver;
import org.eclipse.aether.impl.Deployer;
Expand Down Expand Up @@ -41,6 +42,8 @@ public class QuarkusWorkspaceProvider {

private final RemoteRepositoryManager remoteRepoManager;

private final SettingsDecrypter settingsDecrypter;

private volatile BootstrapMavenContext ctx;

@Inject
Expand All @@ -49,13 +52,15 @@ public QuarkusWorkspaceProvider(VersionResolver versionResolver,
ArtifactResolver artifactResolver,
MetadataResolver metadataResolver,
Deployer deployer,
RemoteRepositoryManager remoteRepoManager) {
RemoteRepositoryManager remoteRepoManager,
SettingsDecrypter settingsDecrypter) {
this.versionResolver = versionResolver;
this.versionRangeResolver = versionRangeResolver;
this.artifactResolver = artifactResolver;
this.metadataResolver = metadataResolver;
this.deployer = deployer;
this.remoteRepoManager = remoteRepoManager;
this.settingsDecrypter = settingsDecrypter;
}

public BootstrapMavenContext getMavenContext() {
Expand Down Expand Up @@ -89,6 +94,7 @@ protected MavenFactory configureMavenFactory() {
.addBeanInstance(metadataResolver)
.addBeanInstance(deployer)
.addBeanInstance(remoteRepoManager)
.addBeanInstance(settingsDecrypter)
.addBean(ModelBuilder.class)
.setSupplier(new BeanSupplier<ModelBuilder>() {
@Override
Expand Down
6 changes: 6 additions & 0 deletions independent-projects/bootstrap/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@
<groupId>io.smallrye.beanbag</groupId>
<artifactId>smallrye-beanbag-maven</artifactId>
<version>${smallrye-beanbag.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Smallrye Common dependencies, imported as a BOM -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.apache.maven.settings.building.SettingsBuildingResult;
import org.apache.maven.settings.building.SettingsProblem;
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.apache.maven.settings.crypto.SettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecryptionResult;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3Dom;
Expand Down Expand Up @@ -116,6 +118,7 @@ public class BootstrapMavenContext {
private boolean preferPomsFromWorkspace;
private Boolean effectiveModelBuilder;
private Boolean wsModuleParentHierarchy;
private SettingsDecrypter settingsDecrypter;

public static BootstrapMavenContextConfig<?> config() {
return new BootstrapMavenContextConfig<>();
Expand Down Expand Up @@ -275,6 +278,10 @@ public List<RemoteRepository> getRemotePluginRepositories() throws BootstrapMave
return remotePluginRepos == null ? remotePluginRepos = resolveRemotePluginRepos() : remotePluginRepos;
}

private SettingsDecrypter getSettingsDecrypter() {
return settingsDecrypter == null ? settingsDecrypter = newSettingsDecrypter() : settingsDecrypter;
}

public Settings getEffectiveSettings() throws BootstrapMavenException {
if (settings != null) {
return settings;
Expand Down Expand Up @@ -441,10 +448,10 @@ private DefaultRepositorySystemSession newRepositorySystemSession() throws Boots
}
}

final DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
final SettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
decrypt.setProxies(settings.getProxies());
decrypt.setServers(settings.getServers());
final SettingsDecryptionResult decrypted = new SettingsDecrypterImpl().decrypt(decrypt);
final SettingsDecryptionResult decrypted = getSettingsDecrypter().decrypt(decrypt);
if (!decrypted.getProblems().isEmpty() && log.isDebugEnabled()) {
// this is how maven handles these
for (SettingsProblem p : decrypted.getProblems()) {
Expand Down Expand Up @@ -748,6 +755,11 @@ public RemoteRepositoryManager newRemoteRepositoryManager() {
return remoteRepoManager;
}

private SettingsDecrypter newSettingsDecrypter() {
initRepoSystemAndManager();
return settingsDecrypter;
}

private void initRepoSystemAndManager() {
final MavenFactory factory = configureMavenFactory();
if (repoSystem == null) {
Expand All @@ -756,6 +768,9 @@ private void initRepoSystemAndManager() {
if (remoteRepoManager == null) {
remoteRepoManager = factory.getContainer().requireBean(RemoteRepositoryManager.class);
}
if (settingsDecrypter == null) {
settingsDecrypter = factory.getContainer().requireBean(SettingsDecrypter.class);
}
}

protected MavenFactory configureMavenFactory() {
Expand Down

This file was deleted.

Loading