File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/bin/env python
2+
3+ import os , subprocess
4+
5+ def extract_classes (f ):
6+ lines = subprocess .check_output (['jar' , 'tf' , f ]).split ()
7+ result = set ()
8+ for line in lines :
9+ v = line .decode ('utf-8' ).strip ()
10+ if v .endswith ('.class' ):
11+ result .add (v )
12+ return result
13+
14+ print ('Reading JAR files... ' , end = '' , flush = True )
15+ paths = []
16+ for root , dirs , files in os .walk ("." ):
17+ for name in files :
18+ if not name .lower ().endswith ('.jar' ): continue
19+ paths .append (os .path .join (root , name ))
20+
21+ classes = {}
22+ count = 0
23+ perc = ''
24+ for path in paths :
25+ count += 1
26+ classes [path ] = extract_classes (path )
27+ print ('\b ' * len (perc ), end = '' )
28+ perc = str (round (100 * count / len (paths ))) + '% '
29+ print (perc , end = '' , flush = True )
30+
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 )
39+ if len (dups ) > 0 :
40+ print (f'==> { jar1 } and { jar2 } have duplicates! E.g. { next (iter (dups ))} ' )
41+
42+ print ('Done!' )
You can’t perform that action at this time.
0 commit comments