com.puppycrawl.tools.checkstyle.api.RootModule Java Examples
The following examples show how to use
com.puppycrawl.tools.checkstyle.api.RootModule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NoHttpCheckITest.java From nohttp with Apache License 2.0 | 5 votes |
@Test public void processHasExpectedResults() throws Exception { Configuration configuration = loadConfiguration(); RootModule rootModule = createRootModule(configuration); try { processAndCheckResults(rootModule); } finally { rootModule.destroy(); } }
Example #2
Source File: NoHttpCheckITest.java From nohttp with Apache License 2.0 | 5 votes |
private RootModule createRootModule(Configuration configuration) throws CheckstyleException { ModuleFactory factory = new PackageObjectFactory( Checker.class.getPackage().getName(), getClass().getClassLoader()); RootModule rootModule = (RootModule) factory .createModule(configuration.getName()); rootModule.setModuleClassLoader(getClass().getClassLoader()); rootModule.configure(configuration); return rootModule; }
Example #3
Source File: SpringChecksTests.java From spring-javaformat with Apache License 2.0 | 5 votes |
@Test public void processHasExpectedResults() throws Exception { Locale previousLocale = Locale.getDefault(); Locale.setDefault(Locale.ENGLISH); Configuration configuration = loadConfiguration(); RootModule rootModule = createRootModule(configuration); try { processAndCheckResults(rootModule); } finally { rootModule.destroy(); Locale.setDefault(previousLocale); } }
Example #4
Source File: SpringChecksTests.java From spring-javaformat with Apache License 2.0 | 5 votes |
private RootModule createRootModule(Configuration configuration) throws CheckstyleException { ModuleFactory factory = new PackageObjectFactory(Checker.class.getPackage().getName(), getClass().getClassLoader()); RootModule rootModule = (RootModule) factory.createModule(configuration.getName()); rootModule.setModuleClassLoader(getClass().getClassLoader()); rootModule.configure(configuration); return rootModule; }
Example #5
Source File: SpringChecksTests.java From spring-javaformat with Apache License 2.0 | 5 votes |
private void processAndCheckResults(RootModule rootModule) throws CheckstyleException { rootModule.addListener(this.parameter.getAssertionsListener()); if (!RUNNING_ON_WINDOWS) { printDebugInfo(this.parameter.getSourceFile()); } rootModule.process(Arrays.asList(this.parameter.getSourceFile())); }
Example #6
Source File: CheckStyleExecutor.java From repositoryminer with Apache License 2.0 | 5 votes |
public Map<String, List<StyleProblem>> execute() throws CheckstyleException { Properties properties; if (propertiesFile == null) { properties = System.getProperties(); } else { properties = loadProperties(new File(propertiesFile)); } if (configFile == null) { configFile = "/google_checks.xml"; } // create configurations Configuration config = ConfigurationLoader.loadConfiguration(configFile, new PropertiesExpander(properties)); // create our custom audit listener RepositoryMinerAudit listener = new RepositoryMinerAudit(); listener.setRepositoryPathLength(repository.length()); ClassLoader moduleClassLoader = Checker.class.getClassLoader(); RootModule rootModule = getRootModule(config.getName(), moduleClassLoader); rootModule.setModuleClassLoader(moduleClassLoader); rootModule.configure(config); rootModule.addListener(listener); // executes checkstyle rootModule.process((List<File>) FileUtils.listFiles(new File(repository), EXTENSION_FILE_FILTER, true)); rootModule.destroy(); return listener.getFileErrors(); }
Example #7
Source File: Main.java From diff-check with GNU Lesser General Public License v2.1 | 4 votes |
/** * Executes required Checkstyle actions based on passed parameters. * @param cliOptions * pojo object that contains all options * @return number of violations of ERROR level * @throws IOException * when output file could not be found * @throws CheckstyleException * when properties file could not be loaded */ private static int runCheckstyle(CliOptions cliOptions) throws CheckstyleException, IOException { // setup the properties final Properties props; if (cliOptions.propertiesLocation == null) { props = System.getProperties(); } else { props = loadProperties(new File(cliOptions.propertiesLocation)); } // create a configuration final ThreadModeSettings multiThreadModeSettings = new ThreadModeSettings( cliOptions.checkerThreadsNumber, cliOptions.treeWalkerThreadsNumber); final ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions; if (cliOptions.executeIgnoredModules) { ignoredModulesOptions = ConfigurationLoader.IgnoredModulesOptions.EXECUTE; } else { ignoredModulesOptions = ConfigurationLoader.IgnoredModulesOptions.OMIT; } final Configuration config = ConfigurationLoader.loadConfiguration( cliOptions.configLocation, new PropertiesExpander(props), ignoredModulesOptions, multiThreadModeSettings); // create RootModule object and run it final int errorCounter; final ClassLoader moduleClassLoader = Checker.class.getClassLoader(); final RootModule rootModule = getRootModule(config.getName(), moduleClassLoader); try { final AuditListener listener; if (cliOptions.generateXpathSuppressionsFile) { // create filter to print generated xpath suppressions file final Configuration treeWalkerConfig = getTreeWalkerConfig(config); if (treeWalkerConfig != null) { final DefaultConfiguration moduleConfig = new DefaultConfiguration( XpathFileGeneratorAstFilter.class.getName()); moduleConfig.addAttribute(OPTION_TAB_WIDTH_NAME, Integer.toString(cliOptions.tabWidth)); ((DefaultConfiguration) treeWalkerConfig).addChild(moduleConfig); } listener = new XpathFileGeneratorAuditListener(System.out, AutomaticBean.OutputStreamOptions.NONE); } else { listener = createListener(cliOptions.format, cliOptions.outputLocation); } rootModule.setModuleClassLoader(moduleClassLoader); rootModule.configure(config); rootModule.addListener(listener); if (CollectionUtils.isNotEmpty(DIFF_ENTRY_LIST) && rootModule instanceof Checker) { Checker checker = (Checker) rootModule; checker.addFilter(new DiffLineFilter(DIFF_ENTRY_LIST)); } // run RootModule errorCounter = rootModule.process(cliOptions.files); } finally { rootModule.destroy(); } return errorCounter; }
Example #8
Source File: NoHttpCheckITest.java From nohttp with Apache License 2.0 | 4 votes |
private void processAndCheckResults(RootModule rootModule) throws CheckstyleException { rootModule.addListener(this.parameter.getAssersionsListener()); rootModule.process(Arrays.asList(this.parameter.getSourceFile())); }
Example #9
Source File: CheckStyleExecutor.java From repositoryminer with Apache License 2.0 | 4 votes |
private RootModule getRootModule(String name, ClassLoader moduleClassLoader) throws CheckstyleException { ModuleFactory factory = new PackageObjectFactory(Checker.class.getPackage().getName() + ".", moduleClassLoader); return (RootModule) factory.createModule(name); }
Example #10
Source File: Main.java From diff-check with GNU Lesser General Public License v2.1 | 3 votes |
/** * Creates a new instance of the root module that will control and run * Checkstyle. * @param name The name of the module. This will either be a short name that * will have to be found or the complete package name. * @param moduleClassLoader Class loader used to load the root module. * @return The new instance of the root module. * @throws CheckstyleException if no module can be instantiated from name */ private static RootModule getRootModule(String name, ClassLoader moduleClassLoader) throws CheckstyleException { final ModuleFactory factory = new PackageObjectFactory( Checker.class.getPackage().getName(), moduleClassLoader); return (RootModule) factory.createModule(name); }
Example #11
Source File: CheckUtil.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 2 votes |
/** * Checks whether a class may be considered as the checkstyle root module. * Checkstyle's root modules are classes which implement 'RootModule' interface. * @param loadedClass class to check. * @return true if a class may be considered as the checkstyle root module. */ public static boolean isRootModule(Class<?> loadedClass) { return RootModule.class.isAssignableFrom(loadedClass); }