Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8237] Option deprecation notices cleanup #1713

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.DeprecatedAttributes;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
Expand Down Expand Up @@ -130,11 +132,12 @@ public class CLIManager {
public static final String IGNORE_TRANSITIVE_REPOSITORIES = "itr";

/** 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
public static final String DEBUG = "debug";

protected Options options;
protected final Set<Option> usedDeprecatedOptions = new LinkedHashSet<>();

@SuppressWarnings("checkstyle:MethodLength")
public CLIManager() {
Expand Down Expand Up @@ -223,12 +226,6 @@ public CLIManager() {
.desc("Alternate path for the project settings file")
.hasArg()
.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)
.longOpt("install-settings")
.desc("Alternate path for the installation settings file")
Expand All @@ -239,12 +236,6 @@ public CLIManager() {
.desc("Alternate path for the user toolchains file")
.hasArg()
.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)
.longOpt("install-toolchains")
.desc("Alternate path for the installation toolchains file")
Expand Down Expand Up @@ -351,25 +342,60 @@ public CLIManager() {
// Adding this back to make Maven fail if used
options.addOption(Option.builder("llr")
.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());

// Deprecated
options.addOption(Option.builder()
.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());
}

public CommandLine parse(String[] args) throws ParseException {
// We need to eat any quotes surrounding arguments...
String[] cleanArgs = CleanArgument.cleanArgs(args);

CommandLineParser parser = new DefaultParser();
DefaultParser parser = DefaultParser.builder()
.setDeprecatedHandler(usedDeprecatedOptions::add)
.build();

return parser.parse(options, cleanArgs);
}

public Set<Option> getUsedDeprecatedOptions() {
return usedDeprecatedOptions;
}

public void displayHelp(PrintStream stdout) {
stdout.println();

Expand Down
48 changes: 33 additions & 15 deletions maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,17 +423,6 @@ void cli(CliRequest cliRequest) throws Exception {
cliManager.displayHelp(System.out);
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 {
Expand Down Expand Up @@ -495,7 +484,7 @@ private CommandLine cliMerge(CommandLine mavenConfig, CommandLine mavenCli) {
/**
* configure logging
*/
void logging(CliRequest cliRequest) {
void logging(CliRequest cliRequest) throws ExitException {
// LOG LEVEL
CommandLine commandLine = cliRequest.commandLine;
cliRequest.verbose = commandLine.hasOption(CLIManager.VERBOSE) || commandLine.hasOption(CLIManager.DEBUG);
Expand Down Expand Up @@ -572,9 +561,37 @@ void logging(CliRequest cliRequest) {
}
}

if (commandLine.hasOption(CLIManager.DEBUG)) {
slf4jLogger.warn("The option '--debug' is deprecated and may be repurposed as Java debug"
+ " in a future version. Use -X/--verbose instead.");
// check for presence of deprecated options and print warning
boolean fail = false;
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);
}
}

Expand Down Expand Up @@ -632,6 +649,7 @@ void properties(CliRequest cliRequest) throws Exception {
BasicInterpolator interpolator =
createInterpolator(paths, cliRequest.systemProperties, cliRequest.userProperties);
CommandLine.Builder commandLineBuilder = new CommandLine.Builder();
commandLineBuilder.setDeprecatedHandler(o -> {});
for (Option option : cliRequest.commandLine.getOptions()) {
if (!String.valueOf(CLIManager.SET_USER_PROPERTY).equals(option.getOpt())) {
List<String> values = option.getValuesList();
Expand Down