@@ -63,15 +63,7 @@ public PmdValidator(final Environment env) {
63
63
@ SuppressWarnings ("PMD.AvoidInstantiatingObjectsInLoops" )
64
64
public Collection <Violation > validate (final Collection <File > files ) {
65
65
final SourceValidator validator = new SourceValidator (this .env );
66
- final Collection <DataSource > sources = new LinkedList <>();
67
- for (final File file : files ) {
68
- final String name = file .getPath ().substring (
69
- this .env .basedir ().toString ().length ()
70
- );
71
- if (!this .env .exclude ("pmd" , name )) {
72
- sources .add (new FileDataSource (file ));
73
- }
74
- }
66
+ final Collection <DataSource > sources = this .getNonExcludedFiles (files );
75
67
final Collection <RuleViolation > breaches = validator .validate (
76
68
sources , this .env .basedir ().getPath ()
77
69
);
@@ -98,4 +90,21 @@ public String name() {
98
90
return "PMD" ;
99
91
}
100
92
93
+ /**
94
+ * Filters out excluded files from further validation.
95
+ * @param files Files to validate
96
+ * @return Relevant source files
97
+ */
98
+ public Collection <DataSource > getNonExcludedFiles (final Collection <File > files ) {
99
+ final Collection <DataSource > sources = new LinkedList <>();
100
+ for (final File file : files ) {
101
+ final String name = file .getPath ().substring (
102
+ this .env .basedir ().toString ().length ()
103
+ );
104
+ if (!this .env .exclude ("pmd" , name )) {
105
+ sources .add (new FileDataSource (file ));
106
+ }
107
+ }
108
+ return sources ;
109
+ }
101
110
}
0 commit comments