15
15
* See the License for the specific language governing permissions and
16
16
* limitations under the License.
17
17
*/
18
-
19
18
package org .apache .hadoop .hbase ;
20
19
21
20
import java .io .File ;
@@ -53,24 +52,32 @@ public class ClassFinder {
53
52
54
53
public interface ResourcePathFilter {
55
54
boolean isCandidatePath (String resourcePath , boolean isJar );
56
- };
55
+ }
57
56
58
57
public interface FileNameFilter {
59
58
boolean isCandidateFile (String fileName , String absFilePath );
60
- };
59
+ }
61
60
62
61
public interface ClassFilter {
63
62
boolean isCandidateClass (Class <?> c );
64
- };
63
+ }
65
64
66
65
public static class Not implements ResourcePathFilter , FileNameFilter , ClassFilter {
67
66
private ResourcePathFilter resourcePathFilter ;
68
67
private FileNameFilter fileNameFilter ;
69
68
private ClassFilter classFilter ;
70
69
71
- public Not (ResourcePathFilter resourcePathFilter ){this .resourcePathFilter = resourcePathFilter ;}
72
- public Not (FileNameFilter fileNameFilter ){this .fileNameFilter = fileNameFilter ;}
73
- public Not (ClassFilter classFilter ){this .classFilter = classFilter ;}
70
+ public Not (ResourcePathFilter resourcePathFilter ) {
71
+ this .resourcePathFilter = resourcePathFilter ;
72
+ }
73
+
74
+ public Not (FileNameFilter fileNameFilter ) {
75
+ this .fileNameFilter = fileNameFilter ;
76
+ }
77
+
78
+ public Not (ClassFilter classFilter ) {
79
+ this .classFilter = classFilter ;
80
+ }
74
81
75
82
@ Override
76
83
public boolean isCandidatePath (String resourcePath , boolean isJar ) {
@@ -90,7 +97,10 @@ public static class And implements ClassFilter, ResourcePathFilter {
90
97
ClassFilter [] classFilters ;
91
98
ResourcePathFilter [] resourcePathFilters ;
92
99
93
- public And (ClassFilter ...classFilters ) { this .classFilters = classFilters ; }
100
+ public And (ClassFilter ...classFilters ) {
101
+ this .classFilters = classFilters ;
102
+ }
103
+
94
104
public And (ResourcePathFilter ... resourcePathFilters ) {
95
105
this .resourcePathFilters = resourcePathFilters ;
96
106
}
@@ -120,10 +130,6 @@ public ClassFinder(ClassLoader classLoader) {
120
130
this (null , null , null , classLoader );
121
131
}
122
132
123
- public ClassFinder () {
124
- this (ClassLoader .getSystemClassLoader ());
125
- }
126
-
127
133
public ClassFinder (ResourcePathFilter resourcePathFilter , FileNameFilter fileNameFilter ,
128
134
ClassFilter classFilter ) {
129
135
this (resourcePathFilter , fileNameFilter , classFilter , ClassLoader .getSystemClassLoader ());
@@ -180,7 +186,7 @@ public Set<Class<?>> findClasses(String packageName, boolean proceedOnExceptions
180
186
}
181
187
}
182
188
183
- Set <Class <?>> classes = new HashSet <Class <?> >();
189
+ Set <Class <?>> classes = new HashSet <>();
184
190
for (File directory : dirs ) {
185
191
classes .addAll (findClassesFromFiles (directory , packageName , proceedOnExceptions ));
186
192
}
@@ -193,16 +199,16 @@ public Set<Class<?>> findClasses(String packageName, boolean proceedOnExceptions
193
199
private Set <Class <?>> findClassesFromJar (String jarFileName ,
194
200
String packageName , boolean proceedOnExceptions )
195
201
throws IOException , ClassNotFoundException , LinkageError {
196
- JarInputStream jarFile = null ;
202
+ JarInputStream jarFile ;
197
203
try {
198
204
jarFile = new JarInputStream (new FileInputStream (jarFileName ));
199
205
} catch (IOException ioEx ) {
200
206
LOG .warn ("Failed to look for classes in " + jarFileName + ": " + ioEx );
201
207
throw ioEx ;
202
208
}
203
209
204
- Set <Class <?>> classes = new HashSet <Class <?> >();
205
- JarEntry entry = null ;
210
+ Set <Class <?>> classes = new HashSet <>();
211
+ JarEntry entry ;
206
212
try {
207
213
while (true ) {
208
214
try {
@@ -248,7 +254,7 @@ private Set<Class<?>> findClassesFromJar(String jarFileName,
248
254
249
255
private Set <Class <?>> findClassesFromFiles (File baseDirectory , String packageName ,
250
256
boolean proceedOnExceptions ) throws ClassNotFoundException , LinkageError {
251
- Set <Class <?>> classes = new HashSet <Class <?> >();
257
+ Set <Class <?>> classes = new HashSet <>();
252
258
if (!baseDirectory .exists ()) {
253
259
LOG .warn ("Failed to find " + baseDirectory .getAbsolutePath ());
254
260
return classes ;
@@ -285,16 +291,11 @@ private Class<?> makeClass(String className, boolean proceedOnExceptions)
285
291
Class <?> c = Class .forName (className , false , classLoader );
286
292
boolean isCandidateClass = null == classFilter || classFilter .isCandidateClass (c );
287
293
return isCandidateClass ? c : null ;
288
- } catch (ClassNotFoundException classNotFoundEx ) {
289
- if (!proceedOnExceptions ) {
290
- throw classNotFoundEx ;
291
- }
292
- LOG .debug ("Failed to instantiate or check " + className + ": " + classNotFoundEx );
293
- } catch (LinkageError linkageEx ) {
294
+ } catch (ClassNotFoundException | LinkageError exception ) {
294
295
if (!proceedOnExceptions ) {
295
- throw linkageEx ;
296
+ throw exception ;
296
297
}
297
- LOG .debug ("Failed to instantiate or check " + className + ": " + linkageEx );
298
+ LOG .debug ("Failed to instantiate or check " + className + ": " + exception );
298
299
}
299
300
return null ;
300
301
}
@@ -313,5 +314,5 @@ public boolean accept(File file) {
313
314
&& (null == nameFilter
314
315
|| nameFilter .isCandidateFile (file .getName (), file .getAbsolutePath ())));
315
316
}
316
- };
317
- };
317
+ }
318
+ }
0 commit comments