Class ConfigurationLoader


  • public final class ConfigurationLoader
    extends java.lang.Object
    Loads a configuration from a standard configuration XML file.
    • Constructor Detail

      • ConfigurationLoader

        private ConfigurationLoader​(PropertyResolver overrideProps,
                                    boolean omitIgnoredModules,
                                    ThreadModeSettings threadModeSettings)
                             throws javax.xml.parsers.ParserConfigurationException,
                                    org.xml.sax.SAXException
        Creates a new ConfigurationLoader instance.
        Parameters:
        overrideProps - resolver for overriding properties
        omitIgnoredModules - true if ignored modules should be omitted
        threadModeSettings - the thread mode configuration
        Throws:
        javax.xml.parsers.ParserConfigurationException - if an error occurs
        org.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 Configuration 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
        Returns:
        the check configurations
        Throws:
        java.io.IOException - if an error occurs
        org.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 filename
        overridePropsResolver - 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 filename
        overridePropsResolver - overriding properties
        threadModeSettings - 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 configuration
        overridePropsResolver - overriding properties
        ignoredModulesOptions - 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​(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 configuration
        overridePropsResolver - overriding properties
        ignoredModulesOptions - OMIT if modules with severity 'ignore' should be omitted, EXECUTE otherwise
        threadModeSettings - 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

        Parameters:
        value - The string to be scanned for property references. Must not be null.
        props - Mapping (String to String) of property names to their values. Must not be null.
        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​(java.lang.String value,
                                                java.util.Collection<java.lang.String> fragments,
                                                java.util.Collection<java.lang.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 be null.
        fragments - Collection to add text fragments to. Must not be null.
        propertyRefs - Collection to add property names to. Must not be null.
        Throws:
        CheckstyleException - if the string contains an opening ${} without a closing {@code }