[MNG-8237] Option deprecation notices cleanup (#1713)

This commit is contained in:
Guillaume Nodet 2024-09-12 06:39:22 +02:00 committed by GitHub
parent 237eeba760
commit 36de1c6e51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 76 additions and 32 deletions

View File

@ -20,10 +20,12 @@ package org.apache.maven.cli;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.DeprecatedAttributes;
import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option; import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
@ -130,11 +132,12 @@ public class CLIManager {
public static final String IGNORE_TRANSITIVE_REPOSITORIES = "itr"; public static final String IGNORE_TRANSITIVE_REPOSITORIES = "itr";
/** This option is deprecated and may be repurposed as Java debug in a future version. /** This option is deprecated and may be repurposed as Java debug in a future version.
* Use {@code -X/--verbose} instead. */ * Use {@code -X,--verbose} instead. */
@Deprecated @Deprecated
public static final String DEBUG = "debug"; public static final String DEBUG = "debug";
protected Options options; protected Options options;
protected final Set<Option> usedDeprecatedOptions = new LinkedHashSet<>();
@SuppressWarnings("checkstyle:MethodLength") @SuppressWarnings("checkstyle:MethodLength")
public CLIManager() { public CLIManager() {
@ -223,12 +226,6 @@ public class CLIManager {
.desc("Alternate path for the project settings file") .desc("Alternate path for the project settings file")
.hasArg() .hasArg()
.build()); .build());
options.addOption(Option.builder(ALTERNATE_GLOBAL_SETTINGS)
.longOpt("global-settings")
.desc("Alternate path for the global settings file")
.hasArg()
.deprecated()
.build());
options.addOption(Option.builder(ALTERNATE_INSTALLATION_SETTINGS) options.addOption(Option.builder(ALTERNATE_INSTALLATION_SETTINGS)
.longOpt("install-settings") .longOpt("install-settings")
.desc("Alternate path for the installation settings file") .desc("Alternate path for the installation settings file")
@ -239,12 +236,6 @@ public class CLIManager {
.desc("Alternate path for the user toolchains file") .desc("Alternate path for the user toolchains file")
.hasArg() .hasArg()
.build()); .build());
options.addOption(Option.builder(ALTERNATE_GLOBAL_TOOLCHAINS)
.longOpt("global-toolchains")
.desc("Alternate path for the global toolchains file")
.hasArg()
.deprecated()
.build());
options.addOption(Option.builder(ALTERNATE_INSTALLATION_TOOLCHAINS) options.addOption(Option.builder(ALTERNATE_INSTALLATION_TOOLCHAINS)
.longOpt("install-toolchains") .longOpt("install-toolchains")
.desc("Alternate path for the installation toolchains file") .desc("Alternate path for the installation toolchains file")
@ -351,13 +342,42 @@ public class CLIManager {
// Adding this back to make Maven fail if used // Adding this back to make Maven fail if used
options.addOption(Option.builder("llr") options.addOption(Option.builder("llr")
.longOpt("legacy-local-repository") .longOpt("legacy-local-repository")
.desc("UNSUPPORTED: Use of this option will make Maven invocation fail.") .desc("<deprecated> Use Maven 2 Legacy Local Repository behaviour.")
.deprecated(DeprecatedAttributes.builder()
.setSince("3.9.1")
.setDescription("UNSUPPORTED: Use of this option will make Maven invocation fail.")
.get())
.build()); .build());
// Deprecated // Deprecated
options.addOption(Option.builder() options.addOption(Option.builder()
.longOpt(DEBUG) .longOpt(DEBUG)
.desc("Produce execution verbose output (deprecated; only kept for backward compatibility)") .desc("<deprecated> Produce execution verbose output.")
.deprecated(DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("4.0.0")
.setDescription("Use -X,--verbose instead.")
.get())
.build());
options.addOption(Option.builder(ALTERNATE_GLOBAL_SETTINGS)
.longOpt("global-settings")
.desc("<deprecated> Alternate path for the global settings file.")
.hasArg()
.deprecated(DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("4.0.0")
.setDescription("Use -is,--install-settings instead.")
.get())
.build());
options.addOption(Option.builder(ALTERNATE_GLOBAL_TOOLCHAINS)
.longOpt("global-toolchains")
.desc("<deprecated> Alternate path for the global toolchains file.")
.hasArg()
.deprecated(DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("4.0.0")
.setDescription("Use -it,--install-toolchains instead.")
.get())
.build()); .build());
} }
@ -365,11 +385,17 @@ public class CLIManager {
// We need to eat any quotes surrounding arguments... // We need to eat any quotes surrounding arguments...
String[] cleanArgs = CleanArgument.cleanArgs(args); String[] cleanArgs = CleanArgument.cleanArgs(args);
CommandLineParser parser = new DefaultParser(); DefaultParser parser = DefaultParser.builder()
.setDeprecatedHandler(usedDeprecatedOptions::add)
.build();
return parser.parse(options, cleanArgs); return parser.parse(options, cleanArgs);
} }
public Set<Option> getUsedDeprecatedOptions() {
return usedDeprecatedOptions;
}
public void displayHelp(PrintStream stdout) { public void displayHelp(PrintStream stdout) {
stdout.println(); stdout.println();

View File

@ -423,17 +423,6 @@ public class MavenCli {
cliManager.displayHelp(System.out); cliManager.displayHelp(System.out);
throw e; throw e;
} }
// check for presence of unsupported command line options
try {
if (cliRequest.commandLine.hasOption("llr")) {
throw new UnrecognizedOptionException("Option '-llr' is not supported starting with Maven 3.9.1");
}
} catch (ParseException e) {
System.err.println("Unsupported options: " + e.getMessage());
cliManager.displayHelp(System.out);
throw e;
}
} }
private void informativeCommands(CliRequest cliRequest) throws ExitException { private void informativeCommands(CliRequest cliRequest) throws ExitException {
@ -495,7 +484,7 @@ public class MavenCli {
/** /**
* configure logging * configure logging
*/ */
void logging(CliRequest cliRequest) { void logging(CliRequest cliRequest) throws ExitException {
// LOG LEVEL // LOG LEVEL
CommandLine commandLine = cliRequest.commandLine; CommandLine commandLine = cliRequest.commandLine;
cliRequest.verbose = commandLine.hasOption(CLIManager.VERBOSE) || commandLine.hasOption(CLIManager.DEBUG); cliRequest.verbose = commandLine.hasOption(CLIManager.VERBOSE) || commandLine.hasOption(CLIManager.DEBUG);
@ -572,9 +561,37 @@ public class MavenCli {
} }
} }
if (commandLine.hasOption(CLIManager.DEBUG)) { // check for presence of deprecated options and print warning
slf4jLogger.warn("The option '--debug' is deprecated and may be repurposed as Java debug" boolean fail = false;
+ " in a future version. Use -X/--verbose instead."); for (Option option : cliRequest.commandLine.getOptions()) {
if (option.isDeprecated()) {
StringBuilder sb = new StringBuilder();
sb.append("The option -").append(option.getOpt());
if (option.getLongOpt() != null) {
sb.append(",--").append(option.getLongOpt());
}
sb.append(" is deprecated ");
if (option.getDeprecated().isForRemoval()) {
sb.append("and will be removed in a future version");
}
if (option.getDeprecated().getSince() != null) {
sb.append("since Maven ").append(option.getDeprecated().getSince());
}
boolean error = false;
if (option.getDeprecated().getDescription() != null) {
sb.append(": ").append(option.getDeprecated().getDescription());
error = option.getDeprecated().getDescription().startsWith("UNSUPPORTED:");
}
if (error) {
slf4jLogger.error(sb.toString());
fail = true;
} else {
slf4jLogger.warn(sb.toString());
}
}
}
if (fail) {
throw new ExitException(1);
} }
} }
@ -632,6 +649,7 @@ public class MavenCli {
BasicInterpolator interpolator = BasicInterpolator interpolator =
createInterpolator(paths, cliRequest.systemProperties, cliRequest.userProperties); createInterpolator(paths, cliRequest.systemProperties, cliRequest.userProperties);
CommandLine.Builder commandLineBuilder = new CommandLine.Builder(); CommandLine.Builder commandLineBuilder = new CommandLine.Builder();
commandLineBuilder.setDeprecatedHandler(o -> {});
for (Option option : cliRequest.commandLine.getOptions()) { for (Option option : cliRequest.commandLine.getOptions()) {
if (!String.valueOf(CLIManager.SET_USER_PROPERTY).equals(option.getOpt())) { if (!String.valueOf(CLIManager.SET_USER_PROPERTY).equals(option.getOpt())) {
List<String> values = option.getValuesList(); List<String> values = option.getValuesList();