Skip to content

Simplify startup code #5701

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

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[refactor] simplify code
  • Loading branch information
dizzzz committed Apr 13, 2025
commit 063c9aff6d3a1f57c2bc59839578f009a998a953
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static void checkForCompatibleJavaVersion() throws StartException {
static void checkForCompatibleJavaVersion(final Optional<String> checkJavaVersion) throws StartException {
final Optional<int[]> maybeJavaVersionComponents = extractJavaVersionComponents(checkJavaVersion);

if (!maybeJavaVersionComponents.isPresent()) {
if (maybeJavaVersionComponents.isEmpty()) {
// Could not determine major java version, so best to let the user proceed...
return;
}
Expand Down
8 changes: 4 additions & 4 deletions exist-start/src/main/java/org/exist/start/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void runEx(String[] args) throws StartException {
final Optional<Path> jettyHomeDir = getFromSysPropOrEnv(PROP_JETTY_HOME, ENV_JETTY_HOME).map(Paths::get);

Optional<Path> existJettyConfigFile = getFromSysPropOrEnv(PROP_EXIST_JETTY_CONFIG, ENV_EXIST_JETTY_CONFIG).map(Paths::get);
if (!existJettyConfigFile.isPresent()) {
if (existJettyConfigFile.isEmpty()) {
final String config;
if ("jetty".equals(_mode)) {
config = STANDARD_ENABLED_JETTY_CONFIGS;
Expand All @@ -233,7 +233,7 @@ public void runEx(String[] args) throws StartException {
existJettyConfigFile = existHomeDir.map(f -> f.resolve(CONFIG_DIR_NAME).resolve(config));
}

if (!existJettyConfigFile.isPresent()) {
if (existJettyConfigFile.isEmpty()) {
System.err.println("ERROR: jetty config file could not be found! Make sure to set exist.jetty.config or EXIST_JETTY_CONFIG.");
System.err.flush();
throw new StartException(ERROR_CODE_NO_JETTY_CONFIG);
Expand All @@ -247,7 +247,7 @@ public void runEx(String[] args) throws StartException {

// find log4j2.xml
Optional<Path> log4jConfigurationFile = Optional.ofNullable(System.getProperty(PROP_LOG4J_CONFIGURATION_FILE)).map(Paths::get);
if (!log4jConfigurationFile.isPresent()) {
if (log4jConfigurationFile.isEmpty()) {
if (existHomeDir.isPresent() && Files.exists(existHomeDir.get().resolve(CONFIG_DIR_NAME))) {
log4jConfigurationFile = existHomeDir.map(f -> f.resolve(CONFIG_DIR_NAME).resolve("log4j2.xml"));
}
Expand Down Expand Up @@ -300,7 +300,7 @@ public void runEx(String[] args) throws StartException {

private Optional<String> getFromSysPropOrEnv(final String sysPropName, final String envVarName) {
Optional<String> value = Optional.ofNullable(System.getProperty(sysPropName));
if (!value.isPresent()) {
if (value.isEmpty()) {
value = Optional.ofNullable(System.getenv().get(envVarName));
// if we managed to detect from environment, store it in a system property
value.ifPresent(s -> System.setProperty(sysPropName, s));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,21 @@ private static <T> Optional<T> or(final Optional<T> left, final Supplier<Optiona
public boolean addComponent(final String component) {
if (component != null && !component.isEmpty()) {
try {
final Path p = Paths.get(component);
if (Files.exists(p)) {
final Path key = p.toAbsolutePath();
if (!_elements.contains(key)) {
_elements.add(key);
return true;
}
}
final Path path = Paths.get(component);
return addComponent(path);
} catch (final InvalidPathException e) {
e.printStackTrace();
}
}
return false;
}

public boolean addComponent(final Path component) {
if (component != null) {
try {
if (Files.exists(component)) {
final Path key = component.toAbsolutePath();
if (!_elements.contains(key)) {
_elements.add(key);
return true;
}
}
} catch (final InvalidPathException e) {
e.printStackTrace();
public boolean addComponent(final Path path) throws InvalidPathException {
if (path != null & Files.exists(path)) {
final Path key = path.toAbsolutePath();
if (!_elements.contains(key)) {
_elements.add(key);
return true;
}
}
return false;
Expand Down