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.internal.testmodules;
21  
22  import java.io.File;
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import com.puppycrawl.tools.checkstyle.api.AuditListener;
28  import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
29  import com.puppycrawl.tools.checkstyle.api.Configuration;
30  import com.puppycrawl.tools.checkstyle.api.RootModule;
31  
32  public class TestRootModuleChecker implements RootModule {
33  
34      private static boolean processed;
35      private static List<File> filesToCheck;
36      private static Configuration config;
37      private static boolean destroyed;
38      private static String property;
39  
40      @Override
41      public void configure(Configuration configuration) throws CheckstyleException {
42          config = configuration;
43          property = configuration.getAttribute("property");
44      }
45  
46      @Override
47      public void destroy() {
48          destroyed = true;
49      }
50  
51      @Override
52      public int process(List<File> files) {
53          processed = true;
54          filesToCheck = new ArrayList<>(files);
55          return 0;
56      }
57  
58      @Override
59      public void addListener(AuditListener listener) {
60          // not used
61      }
62  
63      @Override
64      public void setModuleClassLoader(ClassLoader moduleClassLoader) {
65          // not used
66      }
67  
68      public static boolean isProcessed() {
69          return processed;
70      }
71  
72      public static boolean isDestroyed() {
73          return destroyed;
74      }
75  
76      public static String getProperty() {
77          return property;
78      }
79  
80      public static void reset() {
81          processed = false;
82          destroyed = false;
83          filesToCheck = null;
84          config = null;
85          property = null;
86      }
87  
88      public static List<File> getFilesToCheck() {
89          return Collections.unmodifiableList(filesToCheck);
90      }
91  
92      public static Configuration getConfig() {
93          return config;
94      }
95  
96  }