Skip to content

Commit 144feb9

Browse files
committed
feat: print info message and exit when search no jar files or find no class files
1 parent 98282f7 commit 144feb9

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

bin/show-duplicate-java-classes

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# $ show-duplicate-java-classes path/to/lib_dir1 /path/to/lib_dir2
99
# $ show-duplicate-java-classes -c path/to/class_dir1 -c /path/to/class_dir2
1010
# $ show-duplicate-java-classes -c path/to/class_dir1 path/to/lib_dir1
11-
# $ show-duplicate-java-classes -L path/to/lib_dir1 # search jars in the sub-directories of lib dir
11+
# $ show-duplicate-java-classes -L path/to/lib_dir1 # search jars in the subdirectories of lib dir
1212
# $ show-duplicate-java-classes -J path/to/lib_dir1 # search jars in the jar file
1313
#
1414
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/java.md#-show-duplicate-java-classes
@@ -297,6 +297,9 @@ def print_duplicate_classes_info(class_paths_to_duplicate_classes, class_path_to
297297

298298

299299
def print_class_paths_info(class_path_to_classes):
300+
if not class_path_to_classes:
301+
return
302+
300303
max_idx_str_len = str_len(len(class_path_to_classes))
301304
max_classes_count_str_len = str_len(max(len(classes) for classes in class_path_to_classes.values()))
302305

@@ -329,14 +332,24 @@ def main():
329332
action='append', help='add class dir')
330333
option_parser.add_option('-R', '--no-find-progress', dest='show_responsive', default=True,
331334
action='store_false', help='do not display responsive find progress')
335+
332336
options, lib_dirs = option_parser.parse_args()
337+
class_dirs = options.class_dirs
338+
if not lib_dirs and not class_dirs:
339+
lib_dirs = ['.']
333340
global __show_responsive
334341
__show_responsive = options.show_responsive
335-
if not options.class_dirs and not lib_dirs:
336-
lib_dirs = ['.']
337342

338343
jar_files = list_jar_file_under_lib_dirs(lib_dirs, recursive=options.recursive_lib)
339-
class_path_to_classes = collect_class_path_to_classes(options.class_dirs, jar_files, options.recursive_jar)
344+
if not jar_files and not class_dirs:
345+
clear_responsive_message()
346+
print('search no jar files under lib dirs, and class dirs is absent.')
347+
return 0
348+
class_path_to_classes = collect_class_path_to_classes(class_dirs, jar_files, options.recursive_jar)
349+
if all(not classes for classes in class_path_to_classes.values()):
350+
clear_responsive_message()
351+
print('find no class files in jar files or class dirs.')
352+
return 0
340353

341354
print_responsive_message('find duplicate classes...')
342355
class_to_class_paths = invert_as_class_to_class_paths(class_path_to_classes)

0 commit comments

Comments
 (0)