forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf6180f
commit a448c4f
Showing
6 changed files
with
180 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/MutableXxJvmOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.quarkus.bootstrap.model; | ||
|
||
import java.util.List; | ||
|
||
import io.quarkus.bootstrap.BootstrapConstants; | ||
|
||
public class MutableXxJvmOption extends MutableBaseJvmOption<MutableXxJvmOption> { | ||
|
||
public static final String PROPERTY_GROUP_PREFIX = "xx."; | ||
|
||
private static final String COMPLETE_PROPERTY_PREFIX = BootstrapConstants.EXT_DEV_MODE_JVM_OPTION_PREFIX | ||
+ PROPERTY_GROUP_PREFIX; | ||
|
||
private static final String DASH_XX_COLLON = "-XX:"; | ||
|
||
public static MutableXxJvmOption fromQuarkusExtensionProperty(String propertyName, String value) { | ||
final String optionName = propertyName.substring(COMPLETE_PROPERTY_PREFIX.length()); | ||
return value.isBlank() ? newInstance(optionName) : newInstance(optionName, value); | ||
} | ||
|
||
public static MutableXxJvmOption newInstance(String name) { | ||
return newInstance(name, null); | ||
} | ||
|
||
public static MutableXxJvmOption newInstance(String name, String value) { | ||
var result = new MutableXxJvmOption(); | ||
result.setName(name); | ||
if (value != null) { | ||
result.addValue(value); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
protected String getQuarkusExtensionPropertyPrefix() { | ||
return COMPLETE_PROPERTY_PREFIX; | ||
} | ||
|
||
@Override | ||
public List<String> toCliOptions() { | ||
if (!hasValue()) { | ||
return toBooleanOption(true); | ||
} | ||
if (getValues().size() == 1) { | ||
var value = getValues().iterator().next(); | ||
if ("true".equalsIgnoreCase(value) || "+".equals(value)) { | ||
return toBooleanOption(true); | ||
} | ||
if ("false".equalsIgnoreCase(value) || "-".equals(value)) { | ||
return toBooleanOption(false); | ||
} | ||
return List.of(DASH_XX_COLLON + getName() + "=" + value); | ||
} | ||
throw new IllegalArgumentException( | ||
"Failed to format option " + DASH_XX_COLLON + getName() + " with values " + getValues()); | ||
} | ||
|
||
private List<String> toBooleanOption(boolean enabled) { | ||
return List.of(DASH_XX_COLLON + (enabled ? "+" : "-") + getName()); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../bootstrap/app-model/src/test/java/io/quarkus/bootstrap/model/MutableXxJvmOptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.quarkus.bootstrap.model; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class MutableXxJvmOptionTest { | ||
|
||
@Test | ||
public void testHasNoValue() { | ||
assertThat(MutableXxJvmOption.newInstance("AllowUserSignalHandlers").hasValue()).isFalse(); | ||
} | ||
|
||
@Test | ||
public void testHasValue() { | ||
assertThat(MutableXxJvmOption.newInstance("AllowUserSignalHandlers", "true").hasValue()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testCliBooleanOptionWithNoValue() { | ||
assertThat(MutableXxJvmOption.newInstance("AllowUserSignalHandlers").toCliOptions()) | ||
.containsExactly("-XX:+AllowUserSignalHandlers"); | ||
} | ||
|
||
@Test | ||
public void testCliBooleanOptionWithTrueValue() { | ||
assertThat(MutableXxJvmOption.newInstance("AllowUserSignalHandlers", "true").toCliOptions()) | ||
.containsExactly("-XX:+AllowUserSignalHandlers"); | ||
} | ||
|
||
@Test | ||
public void testCliBooleanOptionWithFalseValue() { | ||
assertThat(MutableXxJvmOption.newInstance("AllowUserSignalHandlers", "false").toCliOptions()) | ||
.containsExactly("-XX:-AllowUserSignalHandlers"); | ||
} | ||
|
||
@Test | ||
public void testCliOptionWithSingleStringValue() { | ||
assertThat(MutableXxJvmOption.newInstance("ErrorFile", "./hs_err_pid<pid>.log").toCliOptions()) | ||
.containsExactly("-XX:ErrorFile=./hs_err_pid<pid>.log"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters