use of com.puppycrawl.tools.checkstyle.PackageObjectFactory in project eclipse-cs by checkstyle.
the class CheckerFactory method createCheckerInternal.
/**
* Creates a new checker and configures it with the given configuration file.
*
* @param input
* the input source for the configuration file
* @param configFileUri
* the URI of the configuration file, or <code>null</code> if it could not be determined
* @param propResolver
* a property resolver null
* @param project
* the project
* @return the newly created Checker
* @throws CheckstyleException
* an exception during the creation of the checker occured
*/
private static Checker createCheckerInternal(InputSource input, PropertyResolver propResolver, IProject project) throws CheckstyleException, CheckstylePluginException {
// load configuration
final Configuration configuration = ConfigurationLoader.loadConfiguration(input, propResolver, IgnoredModulesOptions.OMIT);
ClassLoader moduleClassLoader = CheckstylePlugin.getDefault().getAddonExtensionClassLoader();
Set<String> packageNames = PackageNamesLoader.getPackageNames(moduleClassLoader);
// create and configure checker
Checker checker = new Checker();
checker.setModuleFactory(new PackageObjectFactory(packageNames, moduleClassLoader, ModuleLoadOption.TRY_IN_ALL_REGISTERED_PACKAGES));
try {
checker.setCharset(project.getDefaultCharset());
} catch (UnsupportedEncodingException e) {
CheckstylePluginException.rethrow(e);
} catch (CoreException e) {
CheckstylePluginException.rethrow(e);
}
// set the eclipse platform locale
Locale platformLocale = CheckstylePlugin.getPlatformLocale();
checker.setLocaleLanguage(platformLocale.getLanguage());
checker.setLocaleCountry(platformLocale.getCountry());
checker.setClassLoader(sSharedClassLoader);
checker.configure(configuration);
// reset the basedir if it is set so it won't get into the plugins way
// of determining workspace resources from checkstyle reported file
// names, see
// https://sourceforge.net/tracker/?func=detail&aid=2880044&group_id=80344&atid=559497
checker.setBasedir(null);
return checker;
}
use of com.puppycrawl.tools.checkstyle.PackageObjectFactory 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;
}
Aggregations