[MNG-8461] Initial settings method must restore context state (#2004)

Effective settings are (should be) created twice, once for "early boot" of Plexus when extensions are loaded up, and then again when Maven "boots".

Bug was that early call "corrupted" (inited settings) in context causing that 2nd required call (due spy) was omitted. This resulted in lack of settings related spy events firing (as we do have IT for spy but it does not test settings events).

---

https://issues.apache.org/jira/browse/MNG-8461
Related: https://github.com/alextu/maven4-reproducer/issues/1
This commit is contained in:
Tamas Cservenak 2024-12-22 14:43:47 +01:00 committed by GitHub
parent 751d3f18c9
commit bebc3d4a2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -501,8 +501,12 @@ public abstract class LookupInvoker<C extends LookupContext> implements Invoker
* If there are Maven3 passwords presents in settings, this results in doubled warnings emitted. So Plexus DI * If there are Maven3 passwords presents in settings, this results in doubled warnings emitted. So Plexus DI
* creation call keeps "emitSettingsWarnings" false. If there are fatal issues, it will anyway "die" at that * creation call keeps "emitSettingsWarnings" false. If there are fatal issues, it will anyway "die" at that
* spot before warnings would be emitted. * spot before warnings would be emitted.
* <p>
* The method returns a "cleaner" runnable, as during extension loading the context needs to be "cleaned", restored
* to previous state (as it was before extension loading).
*/ */
protected void settings(C context, boolean emitSettingsWarnings, SettingsBuilder settingsBuilder) throws Exception { protected Runnable settings(C context, boolean emitSettingsWarnings, SettingsBuilder settingsBuilder)
throws Exception {
Options mavenOptions = context.invokerRequest.options(); Options mavenOptions = context.invokerRequest.options();
Path userSettingsFile = null; Path userSettingsFile = null;
@ -612,6 +616,14 @@ public abstract class LookupInvoker<C extends LookupContext> implements Invoker
} }
context.logger.info(""); context.logger.info("");
} }
return () -> {
context.installationSettingsPath = null;
context.projectSettingsPath = null;
context.userSettingsPath = null;
context.effectiveSettings = null;
context.interactive = true;
context.localRepositoryPath = null;
};
} }
protected void customizeSettingsRequest(C context, SettingsBuilderRequest settingsBuilderRequest) protected void customizeSettingsRequest(C context, SettingsBuilderRequest settingsBuilderRequest)

View File

@ -273,13 +273,14 @@ public class PlexusContainerCapsuleFactory<C extends LookupContext> implements C
}); });
ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
Runnable settingsCleaner = null;
try { try {
container.setLookupRealm(null); container.setLookupRealm(null);
container.setLoggerManager(createLoggerManager()); container.setLoggerManager(createLoggerManager());
container.getLoggerManager().setThresholds(toPlexusLoggingLevel(context.loggerLevel)); container.getLoggerManager().setThresholds(toPlexusLoggingLevel(context.loggerLevel));
Thread.currentThread().setContextClassLoader(container.getContainerRealm()); Thread.currentThread().setContextClassLoader(container.getContainerRealm());
invoker.settings(context, false, container.lookup(SettingsBuilder.class)); settingsCleaner = invoker.settings(context, false, container.lookup(SettingsBuilder.class));
MavenExecutionRequest mer = new DefaultMavenExecutionRequest(); MavenExecutionRequest mer = new DefaultMavenExecutionRequest();
invoker.populateRequest(context, new DefaultLookup(container), mer); invoker.populateRequest(context, new DefaultLookup(container), mer);
@ -288,6 +289,9 @@ public class PlexusContainerCapsuleFactory<C extends LookupContext> implements C
.lookup(BootstrapCoreExtensionManager.class) .lookup(BootstrapCoreExtensionManager.class)
.loadCoreExtensions(mer, providedArtifacts, extensions)); .loadCoreExtensions(mer, providedArtifacts, extensions));
} finally { } finally {
if (settingsCleaner != null) {
settingsCleaner.run();
}
try { try {
container.dispose(); container.dispose();
} finally { } finally {