net.pincette.jes.util.Configuration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pincette-jes-util Show documentation
Show all versions of pincette-jes-util Show documentation
Utilities to work with pincette-jes
package net.pincette.jes.util;
import static com.typesafe.config.ConfigFactory.parseFile;
import static java.lang.System.getProperty;
import static net.pincette.util.Util.tryToGetRethrow;
import static net.pincette.util.Util.tryToGetSilent;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import java.io.File;
import java.util.Optional;
/**
* Some configuration utilities.
*
* @since 1.0
* @author Werner Donn\u00e9
*/
public class Configuration {
private Configuration() {}
/**
* Tries to load the default configuration application.conf
from the conf
* directory. If the system property config.resource
is set its value is also
* resolved against the conf
directory.
*
* @return The resolved configuration.
* @see load
* @since 1.0
*/
public static Config loadDefault() {
return Optional.ofNullable(getProperty("config.resource"))
.flatMap(resource -> tryToGetRethrow(() -> parseFile(new File(new File("conf"), resource))))
.orElseGet(
() ->
tryToGetSilent(() -> parseFile(new File(new File("conf"), "application.conf")))
.orElseGet(ConfigFactory::load));
}
}