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

Show which options are discriminating in the output of mvnd --help #851

Merged
merged 2 commits into from
May 23, 2023
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
21 changes: 18 additions & 3 deletions common/src/main/java/org/mvndaemon/mvnd/common/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public enum Environment {
//
// System properties
//
/** Java home for starting the daemon */
JAVA_HOME("java.home", "JAVA_HOME", null, OptionType.PATH, Flags.NONE),
/** Java home for starting the daemon. */
JAVA_HOME("java.home", "JAVA_HOME", null, OptionType.PATH, Flags.DOCUMENTED_AS_DISCRIMINATING),
/**
* The daemon installation directory. The client normally sets this according to where its <code>mvnd</code>
* executable is located
Expand Down Expand Up @@ -346,7 +346,11 @@ public static String getProperty(String property) {
this.property = property;
this.environmentVariable = environmentVariable;
this.default_ = default_ != null ? default_.toString() : null;
this.flags = flags;
if ((flags & Flags.DISCRIMINATING) != 0) {
this.flags = (flags | Flags.DOCUMENTED_AS_DISCRIMINATING);
} else {
this.flags = flags;
}
this.type = type;
if (options.length == 0) {
this.options = Collections.emptyMap();
Expand Down Expand Up @@ -400,6 +404,10 @@ public boolean isDiscriminating() {
return (flags & Flags.DISCRIMINATING) != 0;
}

public boolean isDocumentedAsDiscriminating() {
return (flags & Flags.DOCUMENTED_AS_DISCRIMINATING) != 0;
}

public boolean isInternal() {
return (flags & Flags.INTERNAL) != 0;
}
Expand Down Expand Up @@ -602,8 +610,15 @@ public String getJavaDoc() {

static class Flags {
private static final int NONE = 0b0;
/**
* Implies {@link #DOCUMENTED_AS_DISCRIMINATING} - this is implemented in
* {@link Environment#Environment(String, String, Object, OptionType, int, String...)}
*/
private static final int DISCRIMINATING = 0b1;

private static final int INTERNAL = 0b10;
private static final int OPTIONAL = 0b100;
/** Set automatically for entries having {@link #DISCRIMINATING} */
private static final int DOCUMENTED_AS_DISCRIMINATING = 0b1000;
}
}
23 changes: 13 additions & 10 deletions daemon/src/main/java/org/apache/maven/cli/MvndHelpFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,15 @@ public static String displayHelp(CLIManager cliManager) {
spaces(help, indentPos - help.length());
wrap(help, toPlainText(entry.getJavaDoc()), terminalWidth, lineEnd, indent);

indentedLine(help, terminalWidth, "Default", env.getDefault(), indent);
indentedLine(help, terminalWidth, "Env. variable", env.getEnvironmentVariable(), indent);
if (env.isDocumentedAsDiscriminating()) {
indentedLine(help, terminalWidth, "This is a discriminating start parameter.", indent);
}
if (env.getDefault() != null) {
indentedLine(help, terminalWidth, "Default: " + env.getDefault(), indent);
}
if (env.getEnvironmentVariable() != null) {
indentedLine(help, terminalWidth, "Env. variable: " + env.getEnvironmentVariable(), indent);
}
});

help.append(lineSeparator).append(lineSeparator).append("mvnd value types:");
Expand Down Expand Up @@ -151,14 +158,10 @@ private static int getTerminalWidth() {
return terminalWidth;
}

private static void indentedLine(
StringBuilder stringBuilder, int terminalWidth, String key, String value, String indent) {
int lineEnd;
if (value != null) {
lineEnd = stringBuilder.length() + terminalWidth;
stringBuilder.append(System.lineSeparator()).append(indent);
wrap(stringBuilder, key + ": " + value, terminalWidth, lineEnd, indent);
}
private static void indentedLine(StringBuilder stringBuilder, int terminalWidth, String text, String indent) {
final int lineEnd = stringBuilder.length() + terminalWidth;
stringBuilder.append(System.lineSeparator()).append(indent);
wrap(stringBuilder, text, terminalWidth, lineEnd, indent);
}

/**
Expand Down