public abstract class LaunchConfigs extends Object
LaunchConfig
objects using various strategies. Designed to be used to construct a launch config via a Properties
instance.
Most methods
eventually delegate to createWithBaseDir(ClassLoader, java.nio.file.Path, java.util.Properties)
.
When things go wrong, a LaunchException
will be thrown.
Modifier and Type | Class and Description |
---|---|
class |
LaunchConfigs.Property
Constants for meaningful configuration properties.
|
Modifier and Type | Field and Description |
---|---|
static String |
CONFIG_RESOURCE_DEFAULT |
static String |
CONFIG_RESOURCE_PROPERTY |
static String |
SYSPROP_PREFIX_DEFAULT
Value: "ratpack.".
|
static String |
SYSPROP_PREFIX_PROPERTY
Value: "ratpack.syspropPrefix".
|
Modifier and Type | Method and Description |
---|---|
static LaunchConfig |
createFromFile(ClassLoader classLoader,
Path baseDir,
Path configFile,
Properties overrideProperties,
Properties defaultProperties)
Delegates to
createWithBaseDir(ClassLoader, java.nio.file.Path, java.util.Properties) , after merging the properties from configFile and overrideProperties . |
static LaunchConfig |
createFromGlobalProperties(ClassLoader classLoader,
Properties globalProperties,
Properties defaultProperties)
Delegates to
createFromGlobalProperties(ClassLoader, String, java.util.Properties, java.util.Properties) , extracting the “propertyPrefix” from the “globalProperties”. |
static LaunchConfig |
createFromGlobalProperties(ClassLoader classLoader,
String propertyPrefix,
Properties globalProperties,
Properties defaultProperties)
Delegates to
createFromProperties(ClassLoader, java.util.Properties, java.util.Properties) after extracting the “prefixed” properties from the global properties. |
static LaunchConfig |
createFromProperties(ClassLoader classLoader,
Properties overrideProperties,
Properties defaultProperties)
Delegates to
createFromFile(ClassLoader, java.nio.file.Path, java.nio.file.Path, java.util.Properties, java.util.Properties) , after trying to find the config properties file. |
static LaunchConfig |
createWithBaseDir(ClassLoader classLoader,
Path baseDir,
Properties properties)
Delegates to
createWithBaseDir(ClassLoader, java.nio.file.Path, java.util.Properties, java.util.Map) , using System.getenv() as the environment variables. |
static LaunchConfig |
createWithBaseDir(ClassLoader classLoader,
Path baseDir,
Properties properties,
Map<String,String> envVars)
Constructs a launch config, based on the given properties and environment variables.
|
static Properties |
getDefaultPrefixedProperties()
Extracts the properties prefixed with "ratpack." from the system properties, without the prefix.
|
public static final String SYSPROP_PREFIX_PROPERTY
public static final String SYSPROP_PREFIX_DEFAULT
public static final String CONFIG_RESOURCE_PROPERTY
public static final String CONFIG_RESOURCE_DEFAULT
public static LaunchConfig createFromGlobalProperties(ClassLoader classLoader, Properties globalProperties, Properties defaultProperties)
createFromGlobalProperties(ClassLoader, String, java.util.Properties, java.util.Properties)
, extracting the “propertyPrefix” from the “globalProperties”. Determines the
“propertyPrefix” value and delegates to createFromGlobalProperties(ClassLoader, String, java.util.Properties, java.util.Properties)
. The value is determined by: globalProperties.getProperty(SYSPROP_PREFIX_PROPERTY, SYSPROP_PREFIX_DEFAULT)
classLoader
- The classloader to use to find the properties file.globalProperties
- The environmental (override) propertiesdefaultProperties
- The default properties to use when a property is omittedpublic static LaunchConfig createFromGlobalProperties(ClassLoader classLoader, String propertyPrefix, Properties globalProperties, Properties defaultProperties)
createFromProperties(ClassLoader, java.util.Properties, java.util.Properties)
after extracting the “prefixed” properties from the global properties. The properties of
globalProperties
that begin with propertyPrefix
are extracted into a new property set, with the property names having the prefix removed. This becomes the overrideProperties
for the delegation to createFromProperties(ClassLoader, java.util.Properties, java.util.Properties)
.
classLoader
- The classloader to use to find the properties filepropertyPrefix
- The prefix of properties in globalProperties
that should be extracted to form the override propertiesglobalProperties
- The environmental (override) propertiesdefaultProperties
- The default properties to use when a property is omittedpublic static Properties getDefaultPrefixedProperties()
public static LaunchConfig createFromProperties(ClassLoader classLoader, Properties overrideProperties, Properties defaultProperties)
createFromFile(ClassLoader, java.nio.file.Path, java.nio.file.Path, java.util.Properties, java.util.Properties)
, after trying to find the config properties file. The overrideProperties
are queried for the CONFIG_RESOURCE_PROPERTY
(defaulting to CONFIG_RESOURCE_DEFAULT
). The classLoader
is asked for the classpath resource with this
name.
If the resource DOES NOT exist, createFromFile(ClassLoader, java.nio.file.Path, java.nio.file.Path, java.util.Properties, java.util.Properties)
is called with the current JVM user dir as
the baseDir
and null
as the configFile
.
If the resource DOES exist, createFromFile(ClassLoader, java.nio.file.Path, java.nio.file.Path, java.util.Properties, java.util.Properties)
is called with that file resource as the configFile
, and its parent directory as the baseDir
.
classLoader
- The classloader to use to find the properties fileoverrideProperties
- The properties that provide the path to the config file resource, and any overridesdefaultProperties
- The default properties to use when a property is omittedpublic static LaunchConfig createFromFile(ClassLoader classLoader, Path baseDir, @Nullable Path configFile, Properties overrideProperties, Properties defaultProperties)
createWithBaseDir(ClassLoader, java.nio.file.Path, java.util.Properties)
, after merging the properties from configFile
and overrideProperties
. If configFile
exists and is not null, it is read as a properties file. It is then merged with defaultProperties
& overrideProperties
. The default properties are overridden by values
in the properties file, while the override properties will override these properties.
classLoader
- The classloader to use to find the properties filebaseDir
- The LaunchConfig.getBaseDir()
of the eventual launch configconfigFile
- The configuration properties fileoverrideProperties
- The properties that override default and file propertiesdefaultProperties
- The default properties to use when a property is omittedpublic static LaunchConfig createWithBaseDir(ClassLoader classLoader, Path baseDir, Properties properties)
createWithBaseDir(ClassLoader, java.nio.file.Path, java.util.Properties, java.util.Map)
, using System.getenv()
as the environment variables.classLoader
- The classloader used to load the LaunchConfigs.Property.HANDLER_FACTORY
classbaseDir
- The LaunchConfig.getBaseDir()
valueproperties
- The values to use to construct the launch configpublic static LaunchConfig createWithBaseDir(ClassLoader classLoader, Path baseDir, Properties properties, Map<String,String> envVars)
See LaunchConfigs.Property
for details on the valid properties.
classLoader
- The classloader used to load the LaunchConfigs.Property.HANDLER_FACTORY
classbaseDir
- The LaunchConfig.getBaseDir()
valueproperties
- The values to use to construct the launch configenvVars
- The environment variables to use to construct the launch config