001////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code for adherence to a set of rules.
003// Copyright (C) 2001-2014  Oliver Burn
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////////////////////////////////////////////////////////////////////////////////
019package com.puppycrawl.tools.checkstyle.api;
020
021import java.io.File;
022import java.util.List;
023import java.util.TreeSet;
024
025/**
026 * Interface for Checking a set of files for some criteria.
027 *
028 * @author lkuehne
029 * @author oliver
030 */
031public interface FileSetCheck
032    extends Configurable, Contextualizable
033{
034    /**
035     * Sets the MessageDispatcher that is used to dispatch error
036     * messages to AuditListeners during processing.
037     * @param dispatcher the dispatcher
038     */
039    void setMessageDispatcher(MessageDispatcher dispatcher);
040
041    /**
042     * Initialise the instance. This is the time to verify that everything
043     * required to perform it job.
044     */
045    void init();
046
047    /** Cleans up the object. **/
048    void destroy();
049
050    /**
051     * Called when about to be called to process a set of files.
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     * <p>
061     * The file set to process might contain files that are not
062     * interesting to the FileSetCheck. Such files should be ignored,
063     * no error message should be fired for them. For example a FileSetCheck
064     * that checks java files should ignore HTML or properties files.
065     * </p>
066     * <p>
067     * The method should return the set of messages to be logged.
068     * </p>
069     *
070     * @param file the file to be processed
071     * @param lines an immutable list of the contents of the file.
072     * @return the list of messages to be logged.
073     */
074    TreeSet<LocalizedMessage> process(File file, List<String> lines);
075
076    /**
077     * Called when all the files have been processed. This is the time to
078     * perform any checks that need to be done across a set of files. In this
079     * method, the implementation is responsible for the logging of messages.
080     */
081    void finishProcessing();
082}