@@ -7,16 +7,17 @@ def extract_classes(f):
77 result = set ()
88 for line in lines :
99 v = line .decode ('utf-8' ).strip ()
10- if v .endswith ('.class' ):
10+ if v .endswith ('.class' ) and not v . endswith ( 'module-info.class' ) :
1111 result .add (v )
1212 return result
1313
1414print ('Reading JAR files... ' , end = '' , flush = True )
1515paths = []
16- for root , dirs , files in os .walk ("." ):
16+ for root , dirs , files in os .walk ('.' ):
1717 for name in files :
1818 if not name .lower ().endswith ('.jar' ): continue
1919 paths .append (os .path .join (root , name ))
20+ paths .sort ()
2021
2122classes = {}
2223count = 0
@@ -25,18 +26,22 @@ def extract_classes(f):
2526 count += 1
2627 classes [path ] = extract_classes (path )
2728 print ('\b ' * len (perc ), end = '' )
28- perc = str (round (100 * count / len (paths ))) + '% '
29+ perc = str (round (100 * count / len (paths ))) + '% '
2930 print (perc , end = '' , flush = True )
3031
31- exceptions = [ 'module-info.class' ]
32- print ('Scanning for duplicate classes..' )
33- for jar1 in classes :
34- for jar2 in classes :
35- if jar1 == jar2 : continue
36- dups = classes [ jar1 ]. intersection ( classes [ jar2 ])
37- for exc in exceptions :
38- if exc in dups : dups . remove ( exc )
32+ print ()
33+ print ('Scanning for duplicate classes... ' )
34+ for i1 in range ( len ( paths )) :
35+ p1 = paths [ i1 ]
36+ duplist = []
37+ for i2 in range ( i1 + 1 , len ( paths )):
38+ p2 = paths [ i2 ]
39+ dups = classes [ p1 ]. intersection ( classes [ p2 ] )
3940 if len (dups ) > 0 :
40- print (f'==> { jar1 } and { jar2 } have duplicates! E.g. { next (iter (dups ))} ' )
41+ duplist .append (f'==> { p2 } (e.g. { next (iter (dups ))} )' )
42+ if len (duplist ) > 0 :
43+ print (p1 )
44+ for line in duplist :
45+ print (line )
4146
4247print ('Done!' )
0 commit comments