Package com.puppycrawl.tools.checkstyle
Class ConfigurationLoader
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.ConfigurationLoader
-
public final class ConfigurationLoader extends java.lang.Object
Loads a configuration from a standard configuration XML file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConfigurationLoader.IgnoredModulesOptionsEnum to specify behaviour regarding ignored modules.private classConfigurationLoader.InternalLoaderImplements the SAX document handler interfaces, so they do not appear in the public API of the ConfigurationLoader.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Deque<DefaultConfiguration>configStackThe loaded configurations.private ConfigurationconfigurationThe Configuration that is being built.private static charDOLLAR_SIGNDollar sign literal.private static java.lang.StringDTD_CONFIGURATION_NAME_1_0The resource for version 1_0 of the configuration dtd.private static java.lang.StringDTD_CONFIGURATION_NAME_1_1The resource for version 1_1 of the configuration dtd.private static java.lang.StringDTD_CONFIGURATION_NAME_1_2The resource for version 1_2 of the configuration dtd.private static java.lang.StringDTD_CONFIGURATION_NAME_1_3The resource for version 1_3 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_CS_ID_1_0The new public ID for version 1_0 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_CS_ID_1_1The new public ID for version 1_1 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_CS_ID_1_2The new public ID for version 1_2 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_CS_ID_1_3The new public ID for version 1_3 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_ID_1_0The public ID for version 1_0 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_ID_1_1The public ID for version 1_1 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_ID_1_2The public ID for version 1_2 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_ID_1_3The public ID for version 1_3 of the configuration dtd.private booleanomitIgnoredModulesFlags if modules with the severity 'ignore' should be omitted.private PropertyResolveroverridePropsResolverProperty resolver.private static java.lang.StringSAX_PARSE_EXCEPTION_FORMATFormat of message for sax parse exception.private ConfigurationLoader.InternalLoadersaxHandlerThe SAX document handler.private ThreadModeSettingsthreadModeSettingsThe thread mode configuration.private static java.lang.StringUNABLE_TO_PARSE_EXCEPTION_PREFIXPrefix for the exception when unable to parse resource.
-
Constructor Summary
Constructors Modifier Constructor Description privateConfigurationLoader(PropertyResolver overrideProps, boolean omitIgnoredModules, ThreadModeSettings threadModeSettings)Creates a newConfigurationLoaderinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.Map<java.lang.String,java.lang.String>createIdToResourceNameMap()Creates mapping between local resources and dtd ids.static ConfigurationloadConfiguration(java.lang.String config, PropertyResolver overridePropsResolver)Returns the module configurations in a specified file.static ConfigurationloadConfiguration(java.lang.String config, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions)Returns the module configurations in a specified file.static ConfigurationloadConfiguration(java.lang.String config, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions, ThreadModeSettings threadModeSettings)Returns the module configurations in a specified file.static ConfigurationloadConfiguration(java.lang.String config, PropertyResolver overridePropsResolver, ThreadModeSettings threadModeSettings)Returns the module configurations in a specified file.static ConfigurationloadConfiguration(org.xml.sax.InputSource configSource, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions)Returns the module configurations from a specified input source.static ConfigurationloadConfiguration(org.xml.sax.InputSource configSource, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions, ThreadModeSettings threadModeSettings)Returns the module configurations from a specified input source.private voidparseInputSource(org.xml.sax.InputSource source)Parses the specified input source loading the configuration information.private static voidparsePropertyString(java.lang.String value, java.util.List<java.lang.String> fragments, java.util.List<java.lang.String> propertyRefs)Parses a string containing${xxx}style property references into two lists.private static java.lang.StringreplaceProperties(java.lang.String value, PropertyResolver props, java.lang.String defaultValue)Replaces${xxx}style constructions in the given value with the string value of the corresponding data types.
-
-
-
Field Detail
-
SAX_PARSE_EXCEPTION_FORMAT
private static final java.lang.String SAX_PARSE_EXCEPTION_FORMAT
Format of message for sax parse exception.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_0
private static final java.lang.String DTD_PUBLIC_ID_1_0
The public ID for version 1_0 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_0
private static final java.lang.String DTD_PUBLIC_CS_ID_1_0
The new public ID for version 1_0 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_CONFIGURATION_NAME_1_0
private static final java.lang.String DTD_CONFIGURATION_NAME_1_0
The resource for version 1_0 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_1
private static final java.lang.String DTD_PUBLIC_ID_1_1
The public ID for version 1_1 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_1
private static final java.lang.String DTD_PUBLIC_CS_ID_1_1
The new public ID for version 1_1 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_CONFIGURATION_NAME_1_1
private static final java.lang.String DTD_CONFIGURATION_NAME_1_1
The resource for version 1_1 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_2
private static final java.lang.String DTD_PUBLIC_ID_1_2
The public ID for version 1_2 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_2
private static final java.lang.String DTD_PUBLIC_CS_ID_1_2
The new public ID for version 1_2 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_CONFIGURATION_NAME_1_2
private static final java.lang.String DTD_CONFIGURATION_NAME_1_2
The resource for version 1_2 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_3
private static final java.lang.String DTD_PUBLIC_ID_1_3
The public ID for version 1_3 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_3
private static final java.lang.String DTD_PUBLIC_CS_ID_1_3
The new public ID for version 1_3 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_CONFIGURATION_NAME_1_3
private static final java.lang.String DTD_CONFIGURATION_NAME_1_3
The resource for version 1_3 of the configuration dtd.- See Also:
- Constant Field Values
-
UNABLE_TO_PARSE_EXCEPTION_PREFIX
private static final java.lang.String UNABLE_TO_PARSE_EXCEPTION_PREFIX
Prefix for the exception when unable to parse resource.- See Also:
- Constant Field Values
-
DOLLAR_SIGN
private static final char DOLLAR_SIGN
Dollar sign literal.- See Also:
- Constant Field Values
-
saxHandler
private final ConfigurationLoader.InternalLoader saxHandler
The SAX document handler.
-
overridePropsResolver
private final PropertyResolver overridePropsResolver
Property resolver.
-
configStack
private final java.util.Deque<DefaultConfiguration> configStack
The loaded configurations.
-
omitIgnoredModules
private final boolean omitIgnoredModules
Flags if modules with the severity 'ignore' should be omitted.
-
threadModeSettings
private final ThreadModeSettings threadModeSettings
The thread mode configuration.
-
configuration
private Configuration configuration
The Configuration that is being built.
-
-
Constructor Detail
-
ConfigurationLoader
private ConfigurationLoader(PropertyResolver overrideProps, boolean omitIgnoredModules, ThreadModeSettings threadModeSettings) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
Creates a newConfigurationLoaderinstance.- Parameters:
overrideProps- resolver for overriding propertiesomitIgnoredModules-trueif ignored modules should be omittedthreadModeSettings- the thread mode configuration- Throws:
javax.xml.parsers.ParserConfigurationException- if an error occursorg.xml.sax.SAXException- if an error occurs
-
-
Method Detail
-
createIdToResourceNameMap
private static java.util.Map<java.lang.String,java.lang.String> createIdToResourceNameMap()
Creates mapping between local resources and dtd ids. This method can't be moved to inner class because it must stay static because it is called from constructor and inner class isn't static.- Returns:
- map between local resources and dtd ids.
-
parseInputSource
private void parseInputSource(org.xml.sax.InputSource source) throws java.io.IOException, org.xml.sax.SAXException
Parses the specified input source loading the configuration information. The stream wrapped inside the source, if any, is NOT explicitly closed after parsing, it is the responsibility of the caller to close the stream.- Parameters:
source- the source that contains the configuration data- Throws:
java.io.IOException- if an error occursorg.xml.sax.SAXException- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(java.lang.String config, PropertyResolver overridePropsResolver) throws CheckstyleException
Returns the module configurations in a specified file.- Parameters:
config- location of config file, can be either a URL or a filenameoverridePropsResolver- overriding properties- Returns:
- the check configurations
- Throws:
CheckstyleException- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(java.lang.String config, PropertyResolver overridePropsResolver, ThreadModeSettings threadModeSettings) throws CheckstyleException
Returns the module configurations in a specified file.- Parameters:
config- location of config file, can be either a URL or a filenameoverridePropsResolver- overriding propertiesthreadModeSettings- the thread mode configuration- Returns:
- the check configurations
- Throws:
CheckstyleException- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(java.lang.String config, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions) throws CheckstyleException
Returns the module configurations in a specified file.- Parameters:
config- location of config file, can be either a URL or a filenameoverridePropsResolver- overriding propertiesignoredModulesOptions-OMITif modules with severity 'ignore' should be omitted,EXECUTEotherwise- Returns:
- the check configurations
- Throws:
CheckstyleException- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(java.lang.String config, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions, ThreadModeSettings threadModeSettings) throws CheckstyleException
Returns the module configurations in a specified file.- Parameters:
config- location of config file, can be either a URL or a filenameoverridePropsResolver- overriding propertiesignoredModulesOptions-OMITif modules with severity 'ignore' should be omitted,EXECUTEotherwisethreadModeSettings- the thread mode configuration- Returns:
- the check configurations
- Throws:
CheckstyleException- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(org.xml.sax.InputSource configSource, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions) throws CheckstyleException
Returns the module configurations from a specified input source. Note that if the source does wrap an open byte or character stream, clients are required to close that stream by themselves- Parameters:
configSource- the input stream to the Checkstyle configurationoverridePropsResolver- overriding propertiesignoredModulesOptions-OMITif modules with severity 'ignore' should be omitted,EXECUTEotherwise- Returns:
- the check configurations
- Throws:
CheckstyleException- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(org.xml.sax.InputSource configSource, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions, ThreadModeSettings threadModeSettings) throws CheckstyleException
Returns the module configurations from a specified input source. Note that if the source does wrap an open byte or character stream, clients are required to close that stream by themselves- Parameters:
configSource- the input stream to the Checkstyle configurationoverridePropsResolver- overriding propertiesignoredModulesOptions-OMITif modules with severity 'ignore' should be omitted,EXECUTEotherwisethreadModeSettings- the thread mode configuration- Returns:
- the check configurations
- Throws:
CheckstyleException- if an error occurs
-
replaceProperties
private static java.lang.String replaceProperties(java.lang.String value, PropertyResolver props, java.lang.String defaultValue) throws CheckstyleException
Replaces${xxx}style constructions in the given value with the string value of the corresponding data types. This method must remain outside inner class for easier testing since inner class requires an instance.Code copied from ant - http://cvs.apache.org/viewcvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
- Parameters:
value- The string to be scanned for property references. May benull, in which case this method returns immediately with no effect.props- Mapping (String to String) of property names to their values. Must not benull.defaultValue- default to use if one of the properties in value cannot be resolved from props.- Returns:
- the original string with the properties replaced, or
nullif the original string isnull. - Throws:
CheckstyleException- if the string contains an opening${} without a closing {@code }
-
parsePropertyString
private static void parsePropertyString(java.lang.String value, java.util.List<java.lang.String> fragments, java.util.List<java.lang.String> propertyRefs) throws CheckstyleException
Parses a string containing${xxx}style property references into two lists. The first list is a collection of text fragments, while the other is a set of string property names.nullentries in the first list indicate a property reference from the second list.Code copied from ant - http://cvs.apache.org/viewcvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
- Parameters:
value- Text to parse. Must not benull.fragments- List to add text fragments to. Must not benull.propertyRefs- List to add property names to. Must not benull.- Throws:
CheckstyleException- if the string contains an opening${} without a closing {@code }
-
-