Skip to content

Commit f8ed84c

Browse files
authored
Maven Upgrade Tool: remove unused --force and --yes options (Fixes #11001) (#11066) (#11079)
* Remove unused --force and --yes options from mvnup tool Fixes #11001 The mvnup tool displayed --force and --yes options in its help output, but these options were never actually used by the tool. The 'apply' goal always saves modifications without prompting, making these options misleading to users. Changes: - Removed force() and yes() methods from UpgradeOptions API interface - Removed CLI option parsing for --force/-f and --yes/-y in CommonsCliUpgradeOptions - Removed help text for these options from both CommonsCliUpgradeOptions.displayHelp() and Help goal - Removed test that verified these options were included in help output The mvnenc (encryption) tool continues to use its own force() and yes() methods as those are actually functional in that context. (cherry picked from commit 4b686c5)
1 parent fcb8f35 commit f8ed84c

4 files changed

Lines changed: 0 additions & 57 deletions

File tree

api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvnup/UpgradeOptions.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,6 @@
3333
*/
3434
@Experimental
3535
public interface UpgradeOptions extends Options {
36-
/**
37-
* Should the operation be forced (ie overwrite existing files, if any).
38-
*
39-
* @return an {@link Optional} containing the boolean value {@code true} if specified, or empty
40-
*/
41-
Optional<Boolean> force();
42-
43-
/**
44-
* Should imply "yes" to all questions.
45-
*
46-
* @return an {@link Optional} containing the boolean value {@code true} if specified, or empty
47-
*/
48-
Optional<Boolean> yes();
49-
5036
/**
5137
* Returns the list of upgrade goals to be executed.
5238
* These goals can include operations like "check", "dependencies", "plugins", etc.

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,6 @@ protected CommonsCliUpgradeOptions(String source, CLIManager cliManager, Command
4444
super(source, cliManager, commandLine);
4545
}
4646

47-
@Override
48-
@Nonnull
49-
public Optional<Boolean> force() {
50-
if (commandLine.hasOption(CLIManager.FORCE)) {
51-
return Optional.of(Boolean.TRUE);
52-
}
53-
return Optional.empty();
54-
}
55-
56-
@Override
57-
@Nonnull
58-
public Optional<Boolean> yes() {
59-
if (commandLine.hasOption(CLIManager.YES)) {
60-
return Optional.of(Boolean.TRUE);
61-
}
62-
return Optional.empty();
63-
}
64-
6547
@Override
6648
@Nonnull
6749
public Optional<List<String>> goals() {
@@ -143,8 +125,6 @@ public void displayHelp(ParserRequest request, Consumer<String> printStream) {
143125
printStream.accept(" --plugins Upgrade plugins known to fail with Maven 4");
144126
printStream.accept(
145127
" -a, --all Apply all upgrades (equivalent to --model-version 4.1.0 --infer --model --plugins)");
146-
printStream.accept(" -f, --force Overwrite files without asking for confirmation");
147-
printStream.accept(" -y, --yes Answer \"yes\" to all prompts automatically");
148128
printStream.accept("");
149129
printStream.accept("Default behavior: --model and --plugins are applied if no other options are specified");
150130
printStream.accept("");
@@ -157,8 +137,6 @@ protected CommonsCliUpgradeOptions copy(
157137
}
158138

159139
protected static class CLIManager extends CommonsCliOptions.CLIManager {
160-
public static final String FORCE = "f";
161-
public static final String YES = "y";
162140
public static final String MODEL_VERSION = "m";
163141
public static final String DIRECTORY = "d";
164142
public static final String INFER = "i";
@@ -169,14 +147,6 @@ protected static class CLIManager extends CommonsCliOptions.CLIManager {
169147
@Override
170148
protected void prepareOptions(org.apache.commons.cli.Options options) {
171149
super.prepareOptions(options);
172-
options.addOption(Option.builder(FORCE)
173-
.longOpt("force")
174-
.desc("Should overwrite without asking any configuration?")
175-
.build());
176-
options.addOption(Option.builder(YES)
177-
.longOpt("yes")
178-
.desc("Should imply user answered \"yes\" to all incoming questions?")
179-
.build());
180150
options.addOption(Option.builder(MODEL_VERSION)
181151
.longOpt("model-version")
182152
.hasArg()

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/Help.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public int execute(UpgradeContext context) throws Exception {
5454
context.info(" --plugins Upgrade plugins known to fail with Maven 4");
5555
context.info(
5656
"-a, --all Apply all upgrades (equivalent to --model-version 4.1.0 --infer --model --plugins)");
57-
context.info("-f, --force Overwrite files without asking for confirmation");
58-
context.info("-y, --yes Answer \"yes\" to all prompts automatically");
5957
context.unindent();
6058
context.println();
6159
context.info("Default behavior: --model and --plugins are applied if no other options are specified");

impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/HelpTest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,4 @@ void testHelpIncludesDefaultBehavior() throws Exception {
103103
Mockito.verify(context.logger)
104104
.info("Default behavior: --model and --plugins are applied if no other options are specified");
105105
}
106-
107-
@Test
108-
void testHelpIncludesForceAndYesOptions() throws Exception {
109-
UpgradeContext context = createMockContext();
110-
111-
help.execute(context);
112-
113-
// Verify that --force and --yes options are included
114-
Mockito.verify(context.logger).info(" -f, --force Overwrite files without asking for confirmation");
115-
Mockito.verify(context.logger).info(" -y, --yes Answer \"yes\" to all prompts automatically");
116-
}
117106
}

0 commit comments

Comments
 (0)