1 ///////////////////////////////////////////////////////////////////////////////////////////////
2 // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3 // Copyright (C) 2001-2025 the original author or authors.
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ///////////////////////////////////////////////////////////////////////////////////////////////
19
20 package com.puppycrawl.tools.checkstyle.api;
21
22 import java.io.File;
23 import java.util.SortedSet;
24
25 /**
26 * Interface for Checking a set of files for some criteria.
27 *
28 */
29 public interface FileSetCheck
30 extends Configurable, Contextualizable {
31
32 /**
33 * Sets the MessageDispatcher that is used to dispatch audit events
34 * to AuditListeners during processing.
35 *
36 * @param dispatcher the dispatcher
37 */
38 void setMessageDispatcher(MessageDispatcher dispatcher);
39
40 /**
41 * Initialise the instance. This is the time to verify that everything
42 * required to perform its job.
43 */
44 void init();
45
46 /** Cleans up the object. **/
47 void destroy();
48
49 /**
50 * Called when about to be called to process a set of files.
51 *
52 * @param charset the character set used to read the files.
53 */
54 void beginProcessing(String charset);
55
56 /**
57 * Request to process a file. The implementation should use the supplied
58 * contents and not read the contents again. This reduces the amount of
59 * file I/O.
60 *
61 * <p>
62 * The file set to process might contain files that are not
63 * interesting to the FileSetCheck. Such files should be ignored,
64 * no audit event should be fired for them. For example a FileSetCheck
65 * that checks java files should ignore HTML or properties files.
66 * </p>
67 *
68 * <p>
69 * The method should return the set of violations to be logged.
70 * </p>
71 *
72 * @param file the file to be processed
73 * @param fileText the contents of the file.
74 * @return the sorted set of violations to be logged.
75 * @throws CheckstyleException if error condition within Checkstyle occurs
76 */
77 SortedSet<Violation> process(File file, FileText fileText) throws CheckstyleException;
78
79 /**
80 * Called when all the files have been processed. This is the time to
81 * perform any checks that need to be done across a set of files. In this
82 * method, the implementation is responsible for the logging of violations.
83 */
84 void finishProcessing();
85
86 }