1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2019 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 error
34       * messages to AuditListeners during processing.
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 it 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       * @param charset the character set used to read the files.
51       */
52      void beginProcessing(String charset);
53  
54      /**
55       * Request to process a file. The implementation should use the supplied
56       * contents and not read the contents again. This reduces the amount of
57       * file I/O.
58       * <p>
59       * The file set to process might contain files that are not
60       * interesting to the FileSetCheck. Such files should be ignored,
61       * no error message should be fired for them. For example a FileSetCheck
62       * that checks java files should ignore HTML or properties files.
63       * </p>
64       * <p>
65       * The method should return the set of messages to be logged.
66       * </p>
67       *
68       * @param file the file to be processed
69       * @param fileText the contents of the file.
70       * @return the sorted set of messages to be logged.
71       * @throws CheckstyleException if error condition within Checkstyle occurs
72       */
73      SortedSet<LocalizedMessage> process(File file, FileText fileText) throws CheckstyleException;
74  
75      /**
76       * Called when all the files have been processed. This is the time to
77       * perform any checks that need to be done across a set of files. In this
78       * method, the implementation is responsible for the logging of messages.
79       */
80      void finishProcessing();
81  
82  }