8000 Issue #16857: api: add new int process(List<Path> files) method to Ro… · checkstyle/checkstyle@f5895a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit f5895a3

Browse files
author
Vincent Potucek
committed
Issue #16857: api: add new int process(List<Path> files) method to RootModule - add api
1 parent 27671da commit f5895a3

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

config/jsoref-spellchecker/whitelist.words

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ stylesheet
12791279
subdir
12801280
subelements
12811281
subext
1282+
subpath
12821283
subscope
12831284
sudo
12841285
suitebuilder

src/main/java/com/puppycrawl/tools/checkstyle/Checker.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import java.io.UnsupportedEncodingException;
2727
import java.nio.charset.Charset;
2828
import java.nio.charset.StandardCharsets;
29+
import java.nio.file.Path;
2930
import java.util.ArrayList;
31+
import java.util.Collection;
3032
import java.util.List;
3133
import java.util.Locale;
3234
import java.util.Set;
@@ -208,6 +210,13 @@ public void setBasedir(String basedir) {
208210
this.basedir = basedir;
209211
}
210212

213+
@Override
214+
public int process(Collection<Path> files) throws CheckstyleException {
215+
return process(files.stream()
216+
.map(Path::toFile)
217+
.collect(Collectors.toUnmodifiableList()));
218+
}
219+
211220
@Override
212221
public int process(List<File> files) throws CheckstyleException {
213222
if (cacheFile != null) {

src/main/java/com/puppycrawl/tools/checkstyle/api/RootModule.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package com.puppycrawl.tools.checkstyle.api;
2121

2222
import java.io.File;
23+
import java.nio.file.Path;
24+
import java.util.Collection;
2325
import java.util.List;
2426

2527
/**
@@ -43,6 +45,18 @@ public interface RootModule extends Configurable {
4345
*/
4446
int process(List<File> files) throws CheckstyleException;
4547

48+
/**
49+
* Processes a set of files.
50+
* Once this is done, it is highly recommended to call for
51+
* the destroy method to close and remove the listeners.
52+
*
53+
* @param files the list of files to be audited.
54+
* @return the total number of audit events with error severity found
55+
* @throws CheckstyleException if error condition within Checkstyle occurs
56+
* @see #destroy()
57+
*/
58+
int process(Collection<Path> files) throws CheckstyleException;
59+
4660
/**
4761
* Add the listener that will be used to receive events from the audit.
4862
*

src/test/java/com/puppycrawl/tools/checkstyle/CheckerTest.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,34 @@ public void testDestroy() throws Exception {
143143
checker.addFilter(filter);
144144
final TestBeforeExecutionFileFilter fileFilter = new TestBeforeExecutionFileFilter();
145145
checker.addBeforeExecutionFileFilter(fileFilter);
146+
// should remove all listeners, file sets, and filters
147+
checker.destroy();
148+
checker.process(Collections.singletonList(createTempFile("junit")));
149+
assertDestroy(checker, auditAdapter, fileSet, filter, fileFilter);
150+
}
146151

152+
@Test
153+
public void testDestroyPath() throws Exception {
154+
final Checker checker = new Checker();
155+
final DebugAuditAdapter auditAdapter = new DebugAuditAdapter();
156+
checker.addListener(auditAdapter);
157+
final TestFileSetCheck fileSet = new TestFileSetCheck();
158+
checker.addFileSetCheck(fileSet);
159+
final DebugFilter filter = new DebugFilter();
160+
checker.addFilter(filter);
161+
final TestBeforeExecutionFileFilter fileFilter = new TestBeforeExecutionFileFilter();
162+
checker.addBeforeExecutionFileFilter(fileFilter);
147163
// should remove all listeners, file sets, and filters
148164
checker.destroy();
165+
checker.process(Collections.singletonList(createTempFile("junit").toPath()));
166+
assertDestroy(checker, auditAdapter, fileSet, filter, fileFilter);
167+
}
149168

150-
final File tempFile = createTempFile("junit");
151-
checker.process(Collections.singletonList(tempFile));
169+
private void assertDestroy(Checker checker,
170+
DebugAuditAdapter auditAdapter,
171+
TestFileSetCheck fileSet,
172+
DebugFilter filter,
173+
TestBeforeExecutionFileFilter fileFilter) {
152174
final SortedSet<Violation> violations = new TreeSet<>();
153175
violations.add(new Violation(1, 0, "a Bundle", "message.key",
154176
new Object[] {"arg"}, null, getClass(), null));

src/test/java/com/puppycrawl/tools/checkstyle/internal/testmodules/TestRootModuleChecker.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
package com.puppycrawl.tools.checkstyle.internal.testmodules;
2121

2222
import java.io.File;
23+
import java.nio.file.Path;
2324
import java.util.ArrayList;
25+
import java.util.Collection;
2426
import java.util.Collections;
2527
import java.util.List;
28+
import java.util.stream.Collectors;
2629

2730
import com.puppycrawl.tools.checkstyle.api.AuditListener;
2831
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
@@ -55,6 +58,13 @@ public int process(List<File> files) {
5558
return 0;
5659
}
5760

61+
@Override
62+
public int process(Collection<Path> files) {
63+
return process(files.stream()
64+
.map(Path::toFile)
65+
.collect(Collectors.toUnmodifiableList()));
66+
}
67+
5868
@Override
5969
public void addListener(AuditListener listener) {
6070
// not used

src/test/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtilTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import java.io.File;
2727
import java.io.IOException;
28+
import java.nio.file.Path;
29+
import java.util.Collection;
2830
import java.util.Collections;
2931
import java.util.List;
3032
import java.util.Set;
@@ -301,6 +303,11 @@ public int process(List<File> files) {
301303
return 0;
302304
}
303305

306+
@Override
307+
public int process(Collection<Path> files) {
308+
return 0;
309+
}
310+
304311
@Override
305312
public void destroy() {
306313
// dummy method

0 commit comments

Comments
 (0)
0