Skip to content

Commit

Permalink
Use the container-provided settings decrypter
Browse files Browse the repository at this point in the history
Fixes #33220
  • Loading branch information
dmlloyd committed May 16, 2023
1 parent efc0f9b commit deb78ee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 335 deletions.
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.

This file was deleted.

This file was deleted.

Loading

0 comments on commit deb78ee

Please sign in to comment.