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

Document --status, --stop and --purge in -h/--help #250

Merged
merged 1 commit into from
Dec 8, 2020
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
19 changes: 16 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 @@ -26,7 +26,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Consumer;
Expand All @@ -43,6 +42,15 @@
*/
public enum Environment {

/**
* Delete log files under the <code>mvnd.registry</code> directory that are older than <code>mvnd.logPurgePeriod</code>
*/
PURGE(null, null, null, OptionType.VOID, Flags.OPTIONAL, "--purge"),
/** Prints the status of daemon instances registered in the registry specified by <code>mvnd.registry</code> */
STATUS(null, null, null, OptionType.VOID, Flags.OPTIONAL, "--status"),
/** Stop all daemon instances registered in the registry specified by <code>mvnd.registry</code> */
STOP(null, null, null, OptionType.VOID, Flags.OPTIONAL, "--stop"),

//
// Log properties
//
Expand Down Expand Up @@ -216,7 +224,11 @@ public static String getProperty(String property) {

Environment(String property, String environmentVariable, Object default_, OptionType type, int flags,
String... options) {
this.property = Objects.requireNonNull(property);
if (property == null && options.length == 0) {
throw new IllegalArgumentException(
"An " + Environment.class.getSimpleName() + " entry must have property or options set");
}
this.property = property;
this.environmentVariable = environmentVariable;
this.default_ = default_ != null ? default_.toString() : null;
this.flags = flags;
Expand Down Expand Up @@ -346,7 +358,8 @@ public static Stream<DocumentedEnumEntry<Environment>> documentedEntries() {
}
return Stream.of(values)
.filter(env -> !env.isInternal())
.sorted(Comparator.comparing(Environment::getProperty))
.sorted(Comparator.<Environment, String> comparing(env -> env.property != null ? env.property : "")
.thenComparing(env -> !env.options.isEmpty() ? env.options.get(0) : ""))
.map(env -> new DocumentedEnumEntry<>(env, props.getProperty(env.name())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public String normalize(String value) {
/** A local file system path */
PATH,
/** A string */
STRING;
STRING,
/** No value */
VOID;

public String normalize(String value) {
return value;
Expand All @@ -65,6 +67,7 @@ public static Stream<DocumentedEnumEntry<OptionType>> documentedEntries() {
throw new RuntimeException("Could not read " + cliOptionsPath, e);
}
return Stream.of(values)
.filter(opt -> opt != VOID)
.sorted(Comparator.comparing(OptionType::name))
.map(env -> new DocumentedEnumEntry<>(env, props.getProperty(env.name())));
}
Expand Down
40 changes: 28 additions & 12 deletions daemon/src/main/java/org/apache/maven/cli/MvndHelpFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,40 @@ public static String displayHelp(CLIManager cliManager) {
int indentPos = help.length() + indent.length();
int lineEnd = help.length() + HelpFormatter.DEFAULT_WIDTH;
spaces(help, HelpFormatter.DEFAULT_LEFT_PAD);
help
.append("-D")
.append(env.getProperty())
.append("=<")
.append(env.getType().name().toLowerCase(Locale.ROOT))
.append('>');
final String property = env.getProperty();
if (property != null) {
help
.append("-D")
.append(property);
if (env.getType() != OptionType.VOID) {
help
.append("=<")
.append(env.getType().name().toLowerCase(Locale.ROOT))
.append('>');

}
}

final List<String> opts = env.getOptions();
if (!opts.isEmpty()) {
if (property != null) {
help.append(';');
}
boolean first = true;
for (String opt : opts) {
if (first) {
first = false;
} else {
help.append(',');
}
help.append(opt);
}
if (env.getType() != OptionType.VOID) {
help
.append(',')
.append(opt);
.append(" <")
.append(env.getType().name().toLowerCase(Locale.ROOT))
.append('>');
}
help
.append(" <")
.append(env.getType().name().toLowerCase(Locale.ROOT))
.append('>');
}
help.append(' ');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.assertj.core.api.Assertions;
import org.mvndaemon.mvnd.common.DaemonInfo;
import org.mvndaemon.mvnd.common.DaemonRegistry;
Expand Down