Package org.nuxeo.launcher.config
Class ConfigurationGenerator
- java.lang.Object
-
- org.nuxeo.launcher.config.ConfigurationGenerator
-
public class ConfigurationGenerator extends Object
Builder for server configuration and datasource files from templates and properties.- Author:
- jcarsique
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConfigurationGenerator.Builder
-
Field Summary
Fields Modifier and Type Field Description static StringBOOTSTRAP_JAR_REGEXprotected static PathDEFAULT_NUXEO_CONF_PATHprotected static PatternJAVA_OPTS_PATTERNJava options split by spaces followed by an even number of quotes (or zero).static StringJAVA_OPTS_PROPJava options configured inbin/nuxeo.confandbin/nuxeoctl.static StringJULI_JAR_REGEXstatic StringNUXEO_ENVIRONMENT_CONF_FORMATprotected static StringPARAM_INCLUDED_TEMPLATESAbsolute or relative PATH to the included templates (comma separated list).protected PropertiessystemPropertiesSystem properties used to load the configuration, generallySystem.getProperties().static StringTEMPLATE_SEPARATORstatic StringVERSIONED_REGEX
-
Constructor Summary
Constructors Modifier Constructor Description ConfigurationGenerator()Deprecated.since 11.5, usebuild()instead.ConfigurationGenerator(boolean quiet, boolean debug)Deprecated.since 11.5, usebuilder()instead.protectedConfigurationGenerator(ConfigurationGenerator.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTemplate(String templatesToAdd)Add template(s) to theConfigurationConstants.PARAM_TEMPLATES_NAMElist if not already presentstatic ConfigurationGeneratorbuild()static ConfigurationGenerator.Builderbuilder()protected voidcreateDirectoriesIfNotExist(Path path)protected Map<String,String>evalDynamicProperties()Generate properties which values are based on othersprotected voidgenerateFiles()Map<String,String>getChangedParameters(Map<String,String> changedParameters)Filters given parameters including them only if (there was no previous value and new value is not empty/null) or (there was a previous value and it differs from the new value)ConfigurationHoldergetConfigurationHolder()Returns theConfigurationHolderheld by the generator.CryptogetCrypto()EnvironmentgetEnv()List<String>getJavaOpts(Function<String,String> mapper)Gets the Java options defined in Nuxeo configuration files, e.g.CryptoPropertiesgetUserConfig()protected voidincludeTemplates()booleaninit()Initialize configurator, check requirements and load current configurationbooleaninit(boolean forceReload)Initialize configurator, check requirements and load current configurationprotected static voidinitLogsIfNeeded(ConfigurationHolder configHolder)Initializes log configuration if it doesn't exist.voidrmTemplate(String templatesToRm)Remove template(s) from theConfigurationConstants.PARAM_TEMPLATES_NAMElistvoidrun()Runs the configuration files generation.voidsaveConfiguration(Map<String,String> changedParameters)Save changed parameters innuxeo.conf.voidsaveConfiguration(Map<String,String> changedParameters, boolean setGenerationOnceToFalse, boolean setGenerationFalseToOnce)Save changed parameters innuxeo.conf.voidsaveFilteredConfiguration(Map<String,String> changedParameters)Save changed parameters innuxeo.conf, filtering parameters withgetChangedParameters(Map)Map<String,String>setProperties(String template, Map<String,String> newParametersToSave)Set properties in the given template, if it existsMap<String,String>setProperties(Map<String,String> newParametersToSave)Set properties in nuxeo configurationStringsetProperty(String key, String value)Set a property in nuxeo configurationvoidverifyInstallation()Create needed directories.
-
-
-
Field Detail
-
TEMPLATE_SEPARATOR
public static final String TEMPLATE_SEPARATOR
- Since:
- 6.0
- See Also:
- Constant Field Values
- Implementation Note:
- also used for profiles
-
NUXEO_ENVIRONMENT_CONF_FORMAT
public static final String NUXEO_ENVIRONMENT_CONF_FORMAT
- Since:
- 11.1
- See Also:
- Constant Field Values
-
PARAM_INCLUDED_TEMPLATES
protected static final String PARAM_INCLUDED_TEMPLATES
Absolute or relative PATH to the included templates (comma separated list).- See Also:
- Constant Field Values
-
JAVA_OPTS_PATTERN
protected static final Pattern JAVA_OPTS_PATTERN
Java options split by spaces followed by an even number of quotes (or zero).- Since:
- 9.3
-
JAVA_OPTS_PROP
public static final String JAVA_OPTS_PROP
Java options configured inbin/nuxeo.confandbin/nuxeoctl.- Since:
- 9.3
- See Also:
- Constant Field Values
-
VERSIONED_REGEX
public static final String VERSIONED_REGEX
- See Also:
- Constant Field Values
-
BOOTSTRAP_JAR_REGEX
public static final String BOOTSTRAP_JAR_REGEX
- See Also:
- Constant Field Values
-
JULI_JAR_REGEX
public static final String JULI_JAR_REGEX
- See Also:
- Constant Field Values
-
DEFAULT_NUXEO_CONF_PATH
protected static final Path DEFAULT_NUXEO_CONF_PATH
- Since:
- 11.5
-
systemProperties
protected final Properties systemProperties
System properties used to load the configuration, generallySystem.getProperties().- Since:
- 11.5
-
-
Constructor Detail
-
ConfigurationGenerator
@Deprecated(since="11.5") public ConfigurationGenerator()
Deprecated.since 11.5, usebuild()instead.
-
ConfigurationGenerator
@Deprecated(since="11.5") public ConfigurationGenerator(boolean quiet, boolean debug)
Deprecated.since 11.5, usebuilder()instead.- Parameters:
quiet- Suppress info level messages from the console outputdebug- Activate debug level logging- Since:
- 5.6
-
ConfigurationGenerator
protected ConfigurationGenerator(ConfigurationGenerator.Builder builder)
- Since:
- 11.5
-
-
Method Detail
-
build
public static ConfigurationGenerator build()
- Since:
- 11.5
-
builder
public static ConfigurationGenerator.Builder builder()
- Since:
- 11.5
-
initLogsIfNeeded
protected static void initLogsIfNeeded(ConfigurationHolder configHolder)
Initializes log configuration if it doesn't exist.This is called in
ConfigurationGenerator(Builder), so the givenconfigHolderis not yetloaded.- Since:
- 11.5
-
getUserConfig
public CryptoProperties getUserConfig()
-
run
public void run() throws ConfigurationExceptionRuns the configuration files generation.- Throws:
ConfigurationException
-
init
public boolean init()
Initialize configurator, check requirements and load current configuration- Returns:
- returns true if current install is configurable, else returns false
-
init
public boolean init(boolean forceReload)
Initialize configurator, check requirements and load current configuration- Parameters:
forceReload- If true, forces configuration reload.- Returns:
- returns true if current install is configurable, else returns false
- Since:
- 5.6
-
includeTemplates
protected void includeTemplates() throws ConfigurationException- Throws:
ConfigurationException- Since:
- 5.7
-
evalDynamicProperties
protected Map<String,String> evalDynamicProperties() throws ConfigurationException
Generate properties which values are based on others- Returns:
- Map with new parameters to save in
nuxeoConf - Throws:
ConfigurationException- Since:
- 5.5
-
generateFiles
protected void generateFiles() throws ConfigurationException- Throws:
ConfigurationException
-
saveConfiguration
public void saveConfiguration(Map<String,String> changedParameters) throws ConfigurationException
Save changed parameters innuxeo.conf. This method does not check values in map. UsesaveFilteredConfiguration(Map)for parameters filtering.- Parameters:
changedParameters- Map of modified parameters- Throws:
ConfigurationException- See Also:
saveFilteredConfiguration(Map)
-
saveConfiguration
public void saveConfiguration(Map<String,String> changedParameters, boolean setGenerationOnceToFalse, boolean setGenerationFalseToOnce) throws ConfigurationException
Save changed parameters innuxeo.conf. If a parameter value is empty ("" or null), then the property is unset.ConfigurationConstants.PARAM_TEMPLATES_NAMEandConfigurationConstants.PARAM_FORCE_GENERATIONcannot be unset, but their value can be changed.This method does not check values in map: use
saveFilteredConfiguration(Map)for parameters filtering.- Parameters:
changedParameters- Map of modified parameterssetGenerationOnceToFalse- If generation was on (true or once), then set it to false or not?setGenerationFalseToOnce- If generation was off (false), then set it to once?- Throws:
ConfigurationException- Since:
- 5.5
- See Also:
saveFilteredConfiguration(Map)
-
saveFilteredConfiguration
public void saveFilteredConfiguration(Map<String,String> changedParameters) throws ConfigurationException
Save changed parameters innuxeo.conf, filtering parameters withgetChangedParameters(Map)- Parameters:
changedParameters- Maps of modified parameters- Throws:
ConfigurationException- Since:
- 5.4.2
- See Also:
saveConfiguration(Map),getChangedParameters(Map)
-
getChangedParameters
public Map<String,String> getChangedParameters(Map<String,String> changedParameters)
Filters given parameters including them only if (there was no previous value and new value is not empty/null) or (there was a previous value and it differs from the new value)- Parameters:
changedParameters- parameters to be filtered- Returns:
- filtered map
- Since:
- 5.4.2
-
verifyInstallation
public void verifyInstallation() throws ConfigurationExceptionCreate needed directories. Check existence of old paths. If old paths have been found and they cannot be upgraded automatically, then upgrading message is logged and error thrown.- Throws:
ConfigurationException- If a deprecated directory has been detected.- Since:
- 5.4.2
-
createDirectoriesIfNotExist
protected void createDirectoriesIfNotExist(Path path) throws IOException
- Throws:
IOException- Since:
- 11.5
-
addTemplate
public void addTemplate(String templatesToAdd) throws ConfigurationException
Add template(s) to theConfigurationConstants.PARAM_TEMPLATES_NAMElist if not already present- Parameters:
templatesToAdd- Comma separated templates to add- Throws:
ConfigurationException- Since:
- 5.5
-
rmTemplate
public void rmTemplate(String templatesToRm) throws ConfigurationException
Remove template(s) from theConfigurationConstants.PARAM_TEMPLATES_NAMElist- Parameters:
templatesToRm- Comma separated templates to remove- Throws:
ConfigurationException- Since:
- 5.5
-
setProperty
public String setProperty(String key, String value) throws ConfigurationException
Set a property in nuxeo configuration- Returns:
- The old value
- Throws:
ConfigurationException- Since:
- 5.5
-
setProperties
public Map<String,String> setProperties(Map<String,String> newParametersToSave) throws ConfigurationException
Set properties in nuxeo configuration- Returns:
- The old values
- Throws:
ConfigurationException- Since:
- 7.4
-
setProperties
public Map<String,String> setProperties(String template, Map<String,String> newParametersToSave) throws ConfigurationException
Set properties in the given template, if it exists- Returns:
- The old values
- Throws:
ConfigurationException- Since:
- 7.4
-
getEnv
public Environment getEnv()
- Returns:
- an
Environmentinitialized with a few basics - Since:
- 5.6
-
getCrypto
public Crypto getCrypto()
-
getJavaOpts
public List<String> getJavaOpts(Function<String,String> mapper)
Gets the Java options defined in Nuxeo configuration files, e.g.bin/nuxeo.confandbin/nuxeoctl.- Returns:
- the Java options.
- Since:
- 9.3
-
getConfigurationHolder
public ConfigurationHolder getConfigurationHolder()
Returns theConfigurationHolderheld by the generator.This configuration could be empty if the
init()method hasn't been called.- Returns:
- the
ConfigurationHolderheld by the generator. - Since:
- 11.5
- See Also:
init()
-
-