Skip to content

Commit a9f6f3b

Browse files
committed
[MNG-8461] Initial settings method must restore context state
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. --- https://issues.apache.org/jira/browse/MNG-8461
1 parent 575ad37 commit a9f6f3b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,12 @@ protected void settings(C context) throws Exception {
501501
* If there are Maven3 passwords presents in settings, this results in doubled warnings emitted. So Plexus DI
502502
* creation call keeps "emitSettingsWarnings" false. If there are fatal issues, it will anyway "die" at that
503503
* spot before warnings would be emitted.
504+
* <p>
505+
* The method returns a "cleaner" runnable, as during extension loading the context needs to be "cleaned", restored
506+
* to previous state (as it was before extension loading).
504507
*/
505-
protected void settings(C context, boolean emitSettingsWarnings, SettingsBuilder settingsBuilder) throws Exception {
508+
protected Runnable settings(C context, boolean emitSettingsWarnings, SettingsBuilder settingsBuilder)
509+
throws Exception {
506510
Options mavenOptions = context.invokerRequest.options();
507511

508512
Path userSettingsFile = null;
@@ -612,6 +616,14 @@ protected void settings(C context, boolean emitSettingsWarnings, SettingsBuilder
612616
}
613617
context.logger.info("");
614618
}
619+
return () -> {
620+
context.installationSettingsPath = null;
621+
context.projectSettingsPath = null;
622+
context.userSettingsPath = null;
623+
context.effectiveSettings = null;
624+
context.interactive = true;
625+
context.localRepositoryPath = null;
626+
};
615627
}
616628

617629
protected void customizeSettingsRequest(C context, SettingsBuilderRequest settingsBuilderRequest)

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,14 @@ protected void configure() {
273273
});
274274

275275
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
276+
Runnable settingsCleaner = null;
276277
try {
277278
container.setLookupRealm(null);
278279
container.setLoggerManager(createLoggerManager());
279280
container.getLoggerManager().setThresholds(toPlexusLoggingLevel(context.loggerLevel));
280281
Thread.currentThread().setContextClassLoader(container.getContainerRealm());
281282

282-
invoker.settings(context, false, container.lookup(SettingsBuilder.class));
283+
settingsCleaner = invoker.settings(context, false, container.lookup(SettingsBuilder.class));
283284

284285
MavenExecutionRequest mer = new DefaultMavenExecutionRequest();
285286
invoker.populateRequest(context, new DefaultLookup(container), mer);
@@ -288,6 +289,9 @@ protected void configure() {
288289
.lookup(BootstrapCoreExtensionManager.class)
289290
.loadCoreExtensions(mer, providedArtifacts, extensions));
290291
} finally {
292+
if (settingsCleaner != null) {
293+
settingsCleaner.run();
294+
}
291295
try {
292296
container.dispose();
293297
} finally {

0 commit comments

Comments
 (0)