Package com.puppycrawl.tools.checkstyle
Class ConfigurationLoader
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.ConfigurationLoader
-
public final class ConfigurationLoader extends Object
Loads a configuration from a standard configuration XML file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConfigurationLoader.IgnoredModulesOptions
Enum to specify behaviour regarding ignored modules.private class
ConfigurationLoader.InternalLoader
Implements 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 static char
DOLLAR_SIGN
Dollar sign literal.private static String
DOLLAR_SIGN_STRING
Dollar sign string.private static String
DTD_CONFIGURATION_NAME_1_0
The resource for version 1_0 of the configuration dtd.private static String
DTD_CONFIGURATION_NAME_1_1
The resource for version 1_1 of the configuration dtd.private static String
DTD_CONFIGURATION_NAME_1_2
The resource for version 1_2 of the configuration dtd.static String
DTD_CONFIGURATION_NAME_1_3
The resource for version 1_3 of the configuration dtd.private static String
DTD_PUBLIC_CS_ID_1_0
The new public ID for version 1_0 of the configuration dtd.private static String
DTD_PUBLIC_CS_ID_1_1
The new public ID for version 1_1 of the configuration dtd.private static String
DTD_PUBLIC_CS_ID_1_2
The new public ID for version 1_2 of the configuration dtd.static String
DTD_PUBLIC_CS_ID_1_3
The new public ID for version 1_3 of the configuration dtd.private static String
DTD_PUBLIC_ID_1_0
The public ID for version 1_0 of the configuration dtd.private static String
DTD_PUBLIC_ID_1_1
The public ID for version 1_1 of the configuration dtd.private static String
DTD_PUBLIC_ID_1_2
The public ID for version 1_2 of the configuration dtd.private static String
DTD_PUBLIC_ID_1_3
The public ID for version 1_3 of the configuration dtd.private boolean
omitIgnoredModules
Flags if modules with the severity 'ignore' should be omitted.private PropertyResolver
overridePropsResolver
Property resolver.private static String
SAX_PARSE_EXCEPTION_FORMAT
Format of message for sax parse exception.private ConfigurationLoader.InternalLoader
saxHandler
The SAX document handler.private ThreadModeSettings
threadModeSettings
The thread mode configuration.private static String
UNABLE_TO_PARSE_EXCEPTION_PREFIX
Prefix for the exception when unable to parse resource.
-
Constructor Summary
Constructors Modifier Constructor Description private
ConfigurationLoader(PropertyResolver overrideProps, boolean omitIgnoredModules, ThreadModeSettings threadModeSettings)
Creates a newConfigurationLoader
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static Map<String,String>
createIdToResourceNameMap()
Creates mapping between local resources and dtd ids.static Configuration
loadConfiguration(String config, PropertyResolver overridePropsResolver)
Returns the module configurations in a specified file.static Configuration
loadConfiguration(String config, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions)
Returns the module configurations in a specified file.static Configuration
loadConfiguration(String config, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions, ThreadModeSettings threadModeSettings)
Returns the module configurations in a specified file.static Configuration
loadConfiguration(String config, PropertyResolver overridePropsResolver, ThreadModeSettings threadModeSettings)
Returns the module configurations in a specified file.static Configuration
loadConfiguration(InputSource configSource, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions)
Returns the module configurations from a specified input source.static Configuration
loadConfiguration(InputSource configSource, PropertyResolver overridePropsResolver, ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions, ThreadModeSettings threadModeSettings)
Returns the module configurations from a specified input source.private Configuration
parseInputSource(InputSource source)
Parses the specified input source loading the configuration information.private static void
parsePropertyString(String value, Collection<String> fragments, Collection<String> propertyRefs)
Parses a string containing${xxx}
style property references into two collections.private static String
replaceProperties(String value, PropertyResolver props, String defaultValue)
Replaces${xxx}
style constructions in the given value with the string value of the corresponding data types.
-
-
-
Field Detail
-
DTD_PUBLIC_CS_ID_1_3
public static final 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
public static final String DTD_CONFIGURATION_NAME_1_3
The resource for version 1_3 of the configuration dtd.- See Also:
- Constant Field Values
-
SAX_PARSE_EXCEPTION_FORMAT
private static final 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 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 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 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 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 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 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 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 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 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 String DTD_PUBLIC_ID_1_3
The public ID for version 1_3 of the configuration dtd.- See Also:
- Constant Field Values
-
UNABLE_TO_PARSE_EXCEPTION_PREFIX
private static final 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
-
DOLLAR_SIGN_STRING
private static final String DOLLAR_SIGN_STRING
Dollar sign string.
-
saxHandler
private final ConfigurationLoader.InternalLoader saxHandler
The SAX document handler.
-
overridePropsResolver
private final PropertyResolver overridePropsResolver
Property resolver.
-
omitIgnoredModules
private final boolean omitIgnoredModules
Flags if modules with the severity 'ignore' should be omitted.
-
threadModeSettings
private final ThreadModeSettings threadModeSettings
The thread mode configuration.
-
-
Constructor Detail
-
ConfigurationLoader
private ConfigurationLoader(PropertyResolver overrideProps, boolean omitIgnoredModules, ThreadModeSettings threadModeSettings) throws ParserConfigurationException, SAXException
Creates a newConfigurationLoader
instance.- Parameters:
overrideProps
- resolver for overriding propertiesomitIgnoredModules
-true
if ignored modules should be omittedthreadModeSettings
- the thread mode configuration- Throws:
ParserConfigurationException
- if an error occursSAXException
- if an error occurs
-
-
Method Detail
-
createIdToResourceNameMap
private static Map<String,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 Configuration parseInputSource(InputSource source) throws IOException, 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- Returns:
- the check configurations
- Throws:
IOException
- if an error occursSAXException
- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(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(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(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
-OMIT
if modules with severity 'ignore' should be omitted,EXECUTE
otherwise- Returns:
- the check configurations
- Throws:
CheckstyleException
- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(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
-OMIT
if modules with severity 'ignore' should be omitted,EXECUTE
otherwisethreadModeSettings
- the thread mode configuration- Returns:
- the check configurations
- Throws:
CheckstyleException
- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(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
-OMIT
if modules with severity 'ignore' should be omitted,EXECUTE
otherwise- Returns:
- the check configurations
- Throws:
CheckstyleException
- if an error occurs
-
loadConfiguration
public static Configuration loadConfiguration(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
-OMIT
if modules with severity 'ignore' should be omitted,EXECUTE
otherwisethreadModeSettings
- the thread mode configuration- Returns:
- the check configurations
- Throws:
CheckstyleException
- if an error occurs
-
replaceProperties
private static String replaceProperties(String value, PropertyResolver props, 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
- Parameters:
value
- The string to be scanned for property references. Must not benull
.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.
- Throws:
CheckstyleException
- if the string contains an opening${} without a closing {@code }
-
parsePropertyString
private static void parsePropertyString(String value, Collection<String> fragments, Collection<String> propertyRefs) throws CheckstyleException
Parses a string containing${xxx}
style property references into two collections. The first one is a collection of text fragments, while the other is a set of string property names.null
entries in the first collection indicate a property reference from the second collection.Code copied from ant
- Parameters:
value
- Text to parse. Must not benull
.fragments
- Collection to add text fragments to. Must not benull
.propertyRefs
- Collection to add property names to. Must not benull
.- Throws:
CheckstyleException
- if the string contains an opening${} without a closing {@code }
-
-