Created
June 23, 2021 06:05
-
-
Save ilyaevseev/2c8884e8e0e6968aa79bc7b7fb6e98ef to your computer and use it in GitHub Desktop.
Quick-n-dirty finder for duplicated classes in JAR-files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Usage sample: | |
# python find-jdups.py dir1 dir2 ... | grep -v = | sort | uniq | awk -F/ '{ print $NF }' | |
import os | |
import sys | |
import zipfile | |
pathlist = dict() | |
def store_path(key, val): | |
if not key in pathlist: | |
pathlist[key] = [val] | |
return | |
pl = pathlist[key] | |
if pl[0] != val: | |
pl.append(val); | |
def read_jar(jarpath): | |
jar = zipfile.ZipFile(jarpath) | |
dir = jar.namelist() | |
for n in dir: | |
if '.class' in n: | |
store_path(n, jarpath) | |
def read_dir(dir): | |
for root, dirs, files in os.walk(dir): | |
for name in files: | |
if '.jar' in name: | |
read_jar(os.path.join(root, name)) | |
def print_dups(): | |
for cls in pathlist: | |
jars = pathlist[cls] | |
if len(jars) > 1: | |
print("%s = %d" % (cls, len(jars))) | |
for j in jars: | |
print("\t%s" % (j)) | |
for n in range(1, len(sys.argv)): | |
read_dir(sys.argv[n]) | |
print_dups() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment