Skip to content

Commit

Permalink
Support short variants of boolean properties apache#279
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Dec 21, 2020
1 parent 87e6712 commit 0d03956
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ public Path asPath() {
}

public boolean asBoolean() {
return Boolean.parseBoolean(get());
final String val = get();
return "".equals(val) || Boolean.parseBoolean(val);
}

public int asInt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Properties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mvndaemon.mvnd.client.DaemonParameters.EnvValue;
import org.mvndaemon.mvnd.client.DaemonParameters.ValueSource;
import org.mvndaemon.mvnd.common.Environment;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -119,6 +121,14 @@ void cygwin() {
assertEquals("C:\\jdk-11.0.2\\", Environment.cygpath("/cygdrive/c/jdk-11.0.2/"));
}

@Test
void emptyBooleanEnvValueIsTrue() {
final String EMPTY_STRING = "";
final EnvValue envVal = new EnvValue(Environment.MVND_NO_BUFERING,
new ValueSource(sb -> sb.append("envValueAsBoolean"), () -> EMPTY_STRING));
assertEquals(true, envVal.asBoolean());
}

static class EnvironmentResource implements AutoCloseable {

private final Properties props = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import org.mvndaemon.mvnd.common.Environment.DocumentedEnumEntry;

public enum OptionType {
/** <code>true</code> or <code>false</code> */
/**
* <code>true</code> or <code>false</code>; empty string is also interpreted as <code>true</code> - so
* <code>-Dmvnd.noBuffering</code> is equivalent to <code>-Dmvnd.noBuffering=true</code>
*/
BOOLEAN,
/**
* An unlabeled whole number of milliseconds or a whole number followed by an optional space and a unit
Expand Down

0 comments on commit 0d03956

Please sign in to comment.