Search in sources :

Example 1 with FileSetCheck

use of com.puppycrawl.tools.checkstyle.api.FileSetCheck in project checkstyle by checkstyle.

the class Checker method process.

@Override
public int process(List<File> files) throws CheckstyleException {
    if (cacheFile != null) {
        cacheFile.putExternalResources(getExternalResourceLocations());
    }
    // Prepare to start
    fireAuditStarted();
    for (final FileSetCheck fsc : fileSetChecks) {
        fsc.beginProcessing(charset);
    }
    final List<File> targetFiles = files.stream().filter(file -> CommonUtil.matchesFileExtension(file, fileExtensions)).collect(Collectors.toList());
    processFiles(targetFiles);
    // Finish up
    // It may also log!!!
    fileSetChecks.forEach(FileSetCheck::finishProcessing);
    // It may also log!!!
    fileSetChecks.forEach(FileSetCheck::destroy);
    final int errorCount = counter.getCount();
    fireAuditFinished();
    return errorCount;
}
Also used : Context(com.puppycrawl.tools.checkstyle.api.Context) SortedSet(java.util.SortedSet) FilterSet(com.puppycrawl.tools.checkstyle.api.FilterSet) AuditListener(com.puppycrawl.tools.checkstyle.api.AuditListener) BeforeExecutionFileFilter(com.puppycrawl.tools.checkstyle.api.BeforeExecutionFileFilter) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) FileSetCheck(com.puppycrawl.tools.checkstyle.api.FileSetCheck) Locale(java.util.Locale) MessageDispatcher(com.puppycrawl.tools.checkstyle.api.MessageDispatcher) Violation(com.puppycrawl.tools.checkstyle.api.Violation) PrintWriter(java.io.PrintWriter) Filter(com.puppycrawl.tools.checkstyle.api.Filter) BeforeExecutionFileFilterSet(com.puppycrawl.tools.checkstyle.api.BeforeExecutionFileFilterSet) CommonUtil(com.puppycrawl.tools.checkstyle.utils.CommonUtil) StringWriter(java.io.StringWriter) Set(java.util.Set) IOException(java.io.IOException) ExternalResourceHolder(com.puppycrawl.tools.checkstyle.api.ExternalResourceHolder) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) FileText(com.puppycrawl.tools.checkstyle.api.FileText) List(java.util.List) Stream(java.util.stream.Stream) AutomaticBean(com.puppycrawl.tools.checkstyle.api.AutomaticBean) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) SeverityLevelCounter(com.puppycrawl.tools.checkstyle.api.SeverityLevelCounter) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RootModule(com.puppycrawl.tools.checkstyle.api.RootModule) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) SeverityLevel(com.puppycrawl.tools.checkstyle.api.SeverityLevel) FileSetCheck(com.puppycrawl.tools.checkstyle.api.FileSetCheck) File(java.io.File)

Example 2 with FileSetCheck

use of com.puppycrawl.tools.checkstyle.api.FileSetCheck in project checkstyle by checkstyle.

the class Checker method setupChild.

/**
 * {@inheritDoc} Creates child module.
 *
 * @noinspection ChainOfInstanceofChecks
 */
@Override
protected void setupChild(Configuration childConf) throws CheckstyleException {
    final String name = childConf.getName();
    final Object child;
    try {
        child = moduleFactory.createModule(name);
        if (child instanceof AutomaticBean) {
            final AutomaticBean bean = (AutomaticBean) child;
            bean.contextualize(childContext);
            bean.configure(childConf);
        }
    } catch (final CheckstyleException ex) {
        throw new CheckstyleException("cannot initialize module " + name + " - " + ex.getMessage(), ex);
    }
    if (child instanceof FileSetCheck) {
        final FileSetCheck fsc = (FileSetCheck) child;
        fsc.init();
        addFileSetCheck(fsc);
    } else if (child instanceof BeforeExecutionFileFilter) {
        final BeforeExecutionFileFilter filter = (BeforeExecutionFileFilter) child;
        addBeforeExecutionFileFilter(filter);
    } else if (child instanceof Filter) {
        final Filter filter = (Filter) child;
        addFilter(filter);
    } else if (child instanceof AuditListener) {
        final AuditListener listener = (AuditListener) child;
        addListener(listener);
    } else {
        throw new CheckstyleException(name + " is not allowed as a child in Checker");
    }
}
Also used : FileSetCheck(com.puppycrawl.tools.checkstyle.api.FileSetCheck) BeforeExecutionFileFilter(com.puppycrawl.tools.checkstyle.api.BeforeExecutionFileFilter) Filter(com.puppycrawl.tools.checkstyle.api.Filter) BeforeExecutionFileFilter(com.puppycrawl.tools.checkstyle.api.BeforeExecutionFileFilter) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) AuditListener(com.puppycrawl.tools.checkstyle.api.AuditListener) AutomaticBean(com.puppycrawl.tools.checkstyle.api.AutomaticBean)

Aggregations

AuditListener (com.puppycrawl.tools.checkstyle.api.AuditListener)2 AutomaticBean (com.puppycrawl.tools.checkstyle.api.AutomaticBean)2 BeforeExecutionFileFilter (com.puppycrawl.tools.checkstyle.api.BeforeExecutionFileFilter)2 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)2 FileSetCheck (com.puppycrawl.tools.checkstyle.api.FileSetCheck)2 Filter (com.puppycrawl.tools.checkstyle.api.Filter)2 AuditEvent (com.puppycrawl.tools.checkstyle.api.AuditEvent)1 BeforeExecutionFileFilterSet (com.puppycrawl.tools.checkstyle.api.BeforeExecutionFileFilterSet)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 Context (com.puppycrawl.tools.checkstyle.api.Context)1 ExternalResourceHolder (com.puppycrawl.tools.checkstyle.api.ExternalResourceHolder)1 FileText (com.puppycrawl.tools.checkstyle.api.FileText)1 FilterSet (com.puppycrawl.tools.checkstyle.api.FilterSet)1 MessageDispatcher (com.puppycrawl.tools.checkstyle.api.MessageDispatcher)1 RootModule (com.puppycrawl.tools.checkstyle.api.RootModule)1 SeverityLevel (com.puppycrawl.tools.checkstyle.api.SeverityLevel)1 SeverityLevelCounter (com.puppycrawl.tools.checkstyle.api.SeverityLevelCounter)1 Violation (com.puppycrawl.tools.checkstyle.api.Violation)1 CommonUtil (com.puppycrawl.tools.checkstyle.utils.CommonUtil)1 File (java.io.File)1