/** * Load system configuration, using the supplied configLocation as base. The config location is converted * into an URI first. */ public static Config getConfig(@Nonnull final String configLocation, @Nullable final String configName) { final ConfigFactory configFactory = new ConfigFactory(URI.create(configLocation), configName); return new Config(configFactory.load()); }
/** * Load Configuration, using the supplied URI as base. The loaded configuration can be overridden using * system properties. */ public static Config getConfig(@Nonnull final URI configLocation, @Nullable final String configName) { final ConfigFactory configFactory = new ConfigFactory(configLocation, configName); return new Config(configFactory.load()); }
/** * Loads the configuration. The no-args method uses system properties to determine which configurations * to load. * * -Dness.config=x/y/z defines a hierarchy of configurations from general * to detail. * * The ness.config.location variable must be set. * If the ness.config variable is unset, the default value "default" is used. * * @throws IllegalStateException If the ness.config.location variable is not set. */ public static Config getConfig() { final Configuration systemConfig = new SystemConfiguration(); final String configName = systemConfig.getString(CONFIG_PROPERTY_NAME); final String configLocation = systemConfig.getString(CONFIG_LOCATION_PROPERTY_NAME); Preconditions.checkState(configLocation != null, "Config location must be set!"); final ConfigFactory configFactory = new ConfigFactory(URI.create(configLocation), configName); return new Config(configFactory.load()); }
/** * Creates a fixed configuration for the supplied {@link AbstractConfiguration} objects. Only key/value * pairs from these objects will be present in the final configuration. * * There is no implicit override from system properties. */ public static Config getFixedConfig(@Nullable final AbstractConfiguration ... configs) { final CombinedConfiguration cc = new CombinedConfiguration(new OverrideCombiner()); if (configs != null) { for (final AbstractConfiguration config : configs) { cc.addConfiguration(config); } } return new Config(cc); }
/** * Return an empty configuration object without any properties set. This object is immutable so every * bean created from this config object will only have the defaults. This is mostly useful for testing. */ public static Config getEmptyConfig() { return new Config(new CombinedConfiguration(new OverrideCombiner())); }
return new Config(cc);