1 ///////////////////////////////////////////////////////////////////////////////////////////////
2 // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3 // Copyright (C) 2001-2026 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 extends Configurable, Contextualizable {
30
31 /**
32 * Sets the MessageDispatcher that is used to dispatch audit events
33 * to AuditListeners during processing.
34 *
35 * @param dispatcher the dispatcher
36 */
37 void setMessageDispatcher(MessageDispatcher dispatcher);
38
39 /**
40 * Initialise the instance. This is the time to verify that everything
41 * required to perform its job.
42 */
43 void init();
44
45 /** Cleans up the object. */
46 void destroy();
47
48 /**
49 * Called when about to be called to process a set of files.
50 *
51 * @param charset the character set used to read the files.
52 */
53 void beginProcessing(String charset);
54
55 /**
56 * Request to process a file. The implementation should use the supplied
57 * contents and not read the contents again. This reduces the amount of file I/O.
58 *
59 * <p>
60 * The file set to process might contain files that are not
61 * interesting to the FileSetCheck. Such files should be ignored,
62 * no audit event should be fired for them. For example a FileSetCheck
63 * that checks java files should ignore HTML or properties files.
64 * </p>
65 *
66 * <p>
67 * The method should return the set of violations to be logged.
68 * </p>
69 *
70 * @param file the file to be processed
71 * @param fileText the contents of the file.
72 * @return the sorted set of violations to be logged.
73 * @throws CheckstyleException if error condition within Checkstyle occurs
74 */
75 SortedSet<Violation> process(File file, FileText fileText) throws CheckstyleException;
76
77 /**
78 * Called when all the files have been processed. This is the time to
79 * perform any checks that need to be done across a set of files. In this
80 * method, the implementation is responsible for the logging of violations.
81 */
82 void finishProcessing();
83
84 }