Skip to content

Instantly share code, notes, and snippets.

@stainboy
Created September 26, 2017 10:34
Show Gist options
  • Save stainboy/187b51a856356efe9223abed3bc40c93 to your computer and use it in GitHub Desktop.
Save stainboy/187b51a856356efe9223abed3bc40c93 to your computer and use it in GitHub Desktop.
Find duplicated classes in WAR file
#!/usr/bin/env bash
# set -ex
function process {
local jar=$1
unzip -l $jar | grep .class | awk '{print $4" '$jar'"}' >> wtf.txt
}
export -f process
function findup {
local num=$1
local class=$2
echo "[$num] $class" >> final.log
cat wtf.txt | grep $class | awk '{print " "$2}' >> final.log
echo >> final.log
}
export -f findup
rm -f wtf.txt
ls *.jar | awk '{print "process "$1}' | bash
cat wtf.txt | awk '{print $1}' | sort | uniq -c | grep -v '1 ' | sort -r > dup.txt
echo "$(cat dup.txt | wc -l) duplicates found in the given war package!" > final.log
cat final.log
echo "Analyzing..."
cat dup.txt | awk '{print "findup "$1" "$2}' | bash
cat final.log
@stainboy
Copy link
Author

$ head final.log 
4823 duplicates found in the given war package!

[3] org/w3c/dom/UserDataHandler.class
 com.springsource.org.apache.xmlcommons-1.3.4.jar
 jaxen-1.1.6.jar
 xml-apis-1.3.04.jar

[3] org/apache/commons/logging/LogFactory.class
 commons-logging-1.1.1.jar
 jcl-over-slf4j-1.7.6.jar
 youzan-2.0.2.jar

[3] org/apache/commons/logging/LogConfigurationException.class
 commons-logging-1.1.1.jar
 jcl-over-slf4j-1.7.6.jar
 youzan-2.0.2.jar

[3] org/apache/commons/logging/Log.class
 commons-logging-1.1.1.jar
 jcl-over-slf4j-1.7.6.jar
 youzan-2.0.2.jar

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment