Java Code Examples for com.puppycrawl.tools.checkstyle.Checker#setModuleClassLoader()

The following examples show how to use com.puppycrawl.tools.checkstyle.Checker#setModuleClassLoader() . 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: CheckerService.java    From vscode-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void initialize() {
    checker = new Checker();
    listener = new CheckerListener();
    // 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);
    checker.setModuleClassLoader(Checker.class.getClassLoader());
    checker.addListener(listener);
}
 
Example 2
Source File: CheckstyleExecutor.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void executeWithClassLoader() {
    final Checker checker = new Checker();
    OutputStream xmlOutput = null;
    try {
        checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
        checker.addListener(listener);

        final File xmlReport = configuration.getTargetXmlReport();
        if (xmlReport != null) {
            LOG.info("Checkstyle output report: {}", xmlReport.getAbsolutePath());
            xmlOutput = FileUtils.openOutputStream(xmlReport);
            checker.addListener(
                    new XMLLogger(xmlOutput, AutomaticBean.OutputStreamOptions.CLOSE));
        }

        checker.setCharset(configuration.getCharset().name());
        checker.configure(configuration.getCheckstyleConfiguration());
        checker.process(configuration
                .getSourceFiles()
                .stream()
                .map(InputFile::file)
                .collect(Collectors.toList()));
    }
    catch (Exception ex) {
        throw new IllegalStateException("Can not execute Checkstyle", ex);
    }
    finally {
        checker.destroy();
        if (Objects.nonNull(xmlOutput)) {
            close(xmlOutput);
        }
    }
}
 
Example 3
Source File: CheckstyleSourceCodeFileAnalyzerPlugin.java    From coderadar with MIT License 5 votes vote down vote up
private void init(Configuration configuration) {
  checker = new Checker();
  try {
    auditListener = new CoderadarAuditListener();
    final ClassLoader moduleClassLoader = Checker.class.getClassLoader();
    checker.setModuleClassLoader(moduleClassLoader);
    checker.configure(configuration);
    checker.addListener(auditListener);
  } catch (CheckstyleException e) {
    throw new AnalyzerConfigurationException(e);
  }
}
 
Example 4
Source File: CheckstyleProcessor.java    From sputnik with Apache License 2.0 5 votes vote down vote up
@NotNull
private Checker createChecker(@NotNull AuditListener auditListener) {
    try {
        Checker checker = new Checker();
        ClassLoader moduleClassLoader = Checker.class.getClassLoader();
        String configurationFile = getConfigurationFilename();
        Properties properties = System.getProperties();// loadProperties(new File(System.getProperty(CHECKSTYLE_PROPERTIES_FILE)));
        checker.setModuleClassLoader(moduleClassLoader);
        checker.configure(ConfigurationLoader.loadConfiguration(configurationFile, new PropertiesExpander(properties)));
        checker.addListener(auditListener);
        return checker;
    } catch (CheckstyleException e) {
        throw new ReviewException("Unable to create Checkstyle checker", e);
    }
}