Search in sources :

Example 1 with ThreadModeSettings

use of com.puppycrawl.tools.checkstyle.ThreadModeSettings in project checkstyle by checkstyle.

the class CheckstyleAntTask method createRootModule.

/**
 * Creates new instance of the root module.
 *
 * @return new instance of the root module
 * @throws BuildException if the root module could not be created.
 */
private RootModule createRootModule() {
    final RootModule rootModule;
    try {
        final Properties props = createOverridingProperties();
        final ThreadModeSettings threadModeSettings = ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE;
        final ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions;
        if (executeIgnoredModules) {
            ignoredModulesOptions = ConfigurationLoader.IgnoredModulesOptions.EXECUTE;
        } else {
            ignoredModulesOptions = ConfigurationLoader.IgnoredModulesOptions.OMIT;
        }
        final Configuration configuration = ConfigurationLoader.loadConfiguration(config, new PropertiesExpander(props), ignoredModulesOptions, threadModeSettings);
        final ClassLoader moduleClassLoader = Checker.class.getClassLoader();
        final ModuleFactory factory = new PackageObjectFactory(Checker.class.getPackage().getName() + ".", moduleClassLoader);
        rootModule = (RootModule) factory.createModule(configuration.getName());
        rootModule.setModuleClassLoader(moduleClassLoader);
        rootModule.configure(configuration);
    } catch (final CheckstyleException ex) {
        throw new BuildException(String.format(Locale.ROOT, "Unable to create Root Module: " + "config {%s}, classpath {%s}.", config, classpath), ex);
    }
    return rootModule;
}
Also used : Checker(com.puppycrawl.tools.checkstyle.Checker) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) PropertiesExpander(com.puppycrawl.tools.checkstyle.PropertiesExpander) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) Properties(java.util.Properties) ModuleFactory(com.puppycrawl.tools.checkstyle.ModuleFactory) ThreadModeSettings(com.puppycrawl.tools.checkstyle.ThreadModeSettings) RootModule(com.puppycrawl.tools.checkstyle.api.RootModule) BuildException(org.apache.tools.ant.BuildException) PackageObjectFactory(com.puppycrawl.tools.checkstyle.PackageObjectFactory) ConfigurationLoader(com.puppycrawl.tools.checkstyle.ConfigurationLoader)

Aggregations

Checker (com.puppycrawl.tools.checkstyle.Checker)1 ConfigurationLoader (com.puppycrawl.tools.checkstyle.ConfigurationLoader)1 ModuleFactory (com.puppycrawl.tools.checkstyle.ModuleFactory)1 PackageObjectFactory (com.puppycrawl.tools.checkstyle.PackageObjectFactory)1 PropertiesExpander (com.puppycrawl.tools.checkstyle.PropertiesExpander)1 ThreadModeSettings (com.puppycrawl.tools.checkstyle.ThreadModeSettings)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 RootModule (com.puppycrawl.tools.checkstyle.api.RootModule)1 Properties (java.util.Properties)1 BuildException (org.apache.tools.ant.BuildException)1