Skip to content

Commit 95c92ef

Browse files
committed
Fix CI-aware options to respect --force-interactive flag
- Modified MavenInvoker to skip CI optimizations when --force-interactive is specified - Updated CIOptimizationsIntegrationTest to reflect correct behavior where --force-interactive completely disables CI optimizations - This ensures users can override CI detection and get normal interactive behavior even in CI environments
1 parent f6e0c1e commit 95c92ef

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ protected MavenContext createContext(InvokerRequest invokerRequest) {
8989
MavenOptions options = (MavenOptions) invokerRequest.options().orElse(null);
9090

9191
// Apply CI-specific defaults if CI is detected and not overridden by user
92-
if (invokerRequest.ciInfo().isPresent() && options != null) {
92+
// Skip CI optimizations if --force-interactive is specified
93+
if (invokerRequest.ciInfo().isPresent()
94+
&& options != null
95+
&& !options.forceInteractive().orElse(false)) {
9396
options = new CIAwareMavenOptions(options, invokerRequest.ciInfo().get());
9497
}
9598

impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/CIOptimizationsIntegrationTest.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,22 @@ void testForceInteractiveOverridesCIDefaults() throws Exception {
196196
MavenInvoker invoker = new MavenInvoker(ProtoLookup.builder().build(), null);
197197
MavenContext context = invoker.createContext(mockRequest);
198198

199-
// Then: CI optimizations should still be applied (force-interactive affects interactive mode, not these
200-
// options)
201-
CIAwareMavenOptions ciOptions = (CIAwareMavenOptions) context.options();
202-
assertTrue(ciOptions.showVersion().orElse(false), "showVersion should still be enabled in CI");
203-
assertTrue(ciOptions.showErrors().orElse(false), "showErrors should still be enabled in CI");
204-
assertTrue(ciOptions.nonInteractive().orElse(false), "nonInteractive should still be enabled in CI");
205-
assertTrue(ciOptions.forceInteractive().orElse(false), "forceInteractive should be preserved");
199+
// Then: CI optimizations should NOT be applied when force-interactive is specified
200+
// The context should contain the original options, not the CI-aware wrapper
201+
assertFalse(
202+
context.options() instanceof CIAwareMavenOptions,
203+
"CI optimizations should not be applied when --force-interactive is specified");
204+
205+
// The original options should be preserved
206+
MavenOptions options = context.options();
207+
assertFalse(
208+
options.showVersion().orElse(false),
209+
"showVersion should not be enabled when force-interactive is used");
210+
assertFalse(
211+
options.showErrors().orElse(false), "showErrors should not be enabled when force-interactive is used");
212+
assertFalse(
213+
options.nonInteractive().orElse(false),
214+
"nonInteractive should not be enabled when force-interactive is used");
215+
assertTrue(options.forceInteractive().orElse(false), "forceInteractive should be preserved");
206216
}
207217
}

0 commit comments

Comments
 (0)