Skip to content

Commit

Permalink
Use the container-provided settings decrypter
Browse files Browse the repository at this point in the history
Fixes #33220

Co-authored-by: Alexey Loubyansky <[email protected]>
  • Loading branch information
dmlloyd and aloubyansky committed Jun 5, 2023
1 parent 4eb4c63 commit 747c492
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 337 deletions.
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

0 comments on commit 747c492

Please sign in to comment.