001///////////////////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
003// Copyright (C) 2001-2025 the original author or authors.
004//
005// This library is free software; you can redistribute it and/or
006// modify it under the terms of the GNU Lesser General Public
007// License as published by the Free Software Foundation; either
008// version 2.1 of the License, or (at your option) any later version.
009//
010// This library is distributed in the hope that it will be useful,
011// but WITHOUT ANY WARRANTY; without even the implied warranty of
012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013// Lesser General Public License for more details.
014//
015// You should have received a copy of the GNU Lesser General Public
016// License along with this library; if not, write to the Free Software
017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018///////////////////////////////////////////////////////////////////////////////////////////////
019
020package com.puppycrawl.tools.checkstyle.api;
021
022import java.io.File;
023import java.util.SortedSet;
024
025/**
026 * Interface for Checking a set of files for some criteria.
027 *
028 */
029public interface FileSetCheck
030 extends Configurable, Contextualizable {
031
032 /**
033 * Sets the MessageDispatcher that is used to dispatch audit events
034 * to AuditListeners during processing.
035 *
036 * @param dispatcher the dispatcher
037 */
038 void setMessageDispatcher(MessageDispatcher dispatcher);
039
040 /**
041 * Initialise the instance. This is the time to verify that everything
042 * required to perform its job.
043 */
044 void init();
045
046 /** Cleans up the object. **/
047 void destroy();
048
049 /**
050 * Called when about to be called to process a set of files.
051 *
052 * @param charset the character set used to read the files.
053 */
054 void beginProcessing(String charset);
055
056 /**
057 * Request to process a file. The implementation should use the supplied
058 * contents and not read the contents again. This reduces the amount of
059 * file I/O.
060 *
061 * <p>
062 * The file set to process might contain files that are not
063 * interesting to the FileSetCheck. Such files should be ignored,
064 * no audit event should be fired for them. For example a FileSetCheck
065 * that checks java files should ignore HTML or properties files.
066 * </p>
067 *
068 * <p>
069 * The method should return the set of violations to be logged.
070 * </p>
071 *
072 * @param file the file to be processed
073 * @param fileText the contents of the file.
074 * @return the sorted set of violations to be logged.
075 * @throws CheckstyleException if error condition within Checkstyle occurs
076 */
077 SortedSet<Violation> process(File file, FileText fileText) throws CheckstyleException;
078
079 /**
080 * Called when all the files have been processed. This is the time to
081 * perform any checks that need to be done across a set of files. In this
082 * method, the implementation is responsible for the logging of violations.
083 */
084 void finishProcessing();
085
086}