16
16
import java .util .ArrayList ;
17
17
import java .util .List ;
18
18
import java .util .Map ;
19
+ import java .util .regex .Pattern ;
19
20
import java .util .stream .Collectors ;
20
21
21
22
import org .eclipse .core .resources .IProject ;
22
23
import org .eclipse .core .resources .ProjectScope ;
23
24
import org .eclipse .core .runtime .CoreException ;
25
+ import org .eclipse .core .runtime .IPath ;
24
26
import org .eclipse .jdt .core .ICompilationUnit ;
25
27
import org .eclipse .jdt .core .IJavaElement ;
26
28
import org .eclipse .jdt .core .IJavaProject ;
@@ -43,11 +45,14 @@ public class CleanUp extends AbstractEclipseBuild<CleanupResult> {
43
45
44
46
private Map <String , String > customProfile ;
45
47
private boolean applyCleanupsIndividually ;
48
+ private List <Pattern > ignores ;
46
49
47
- CleanUp (Path projectDir , boolean debug , Map <String , String > customProfile , boolean applyCleanupsIndividually ) {
50
+ CleanUp (Path projectDir , boolean debug , Map <String , String > customProfile , boolean applyCleanupsIndividually ,
51
+ List <Pattern > ignores ) {
48
52
super (projectDir , debug );
49
53
this .customProfile = customProfile ;
50
54
this .applyCleanupsIndividually = applyCleanupsIndividually ;
55
+ this .ignores = ignores ;
51
56
}
52
57
53
58
@ Override
@@ -101,6 +106,9 @@ private List<ICompilationUnit> getCompilationUnits(IProject project) throws Java
101
106
IPackageFragment pf = (IPackageFragment ) javaElement ;
102
107
ICompilationUnit [] compilationUnits = pf .getCompilationUnits ();
103
108
for (ICompilationUnit compilationUnit : compilationUnits ) {
109
+ if (isIgnored (compilationUnit )) {
110
+ continue ;
111
+ }
104
112
units .add (compilationUnit );
105
113
}
106
114
}
@@ -110,6 +118,22 @@ private List<ICompilationUnit> getCompilationUnits(IProject project) throws Java
110
118
return units ;
111
119
}
112
120
121
+ private boolean isIgnored (ICompilationUnit compilationUnit ) {
122
+ if (ignores == null || ignores .isEmpty ()) {
123
+ return false ;
124
+ }
125
+ IProject project = compilationUnit .getJavaProject ().getProject ();
126
+ IPath location = project .getFullPath ();
127
+ IPath path = compilationUnit .getPath ().makeRelativeTo (location );
128
+ String pathString = path .toString ();
129
+ for (Pattern ignored : ignores ) {
130
+ if (ignored .matcher (pathString ).matches ()) {
131
+ return true ;
132
+ }
133
+ }
134
+ return false ;
135
+ }
136
+
113
137
private ICleanUp [] getCleanups (CleanupResult result , CleanUpOptions options ) {
114
138
ICleanUp [] cleanUps = JavaPlugin .getDefault ().getCleanUpRegistry ().createCleanUps ();
115
139
for (ICleanUp cleanUp : cleanUps ) {
0 commit comments