Skip to content

Instantly share code, notes, and snippets.

@brunoro
Created August 2, 2016 15:28
Show Gist options
  • Save brunoro/74ca7aeedff7c7a3843b98299a76407c to your computer and use it in GitHub Desktop.
Save brunoro/74ca7aeedff7c7a3843b98299a76407c to your computer and use it in GitHub Desktop.
Looks for .jar file in a path that conflict with a reference .jar
#!/bin/bash
# Looks for jars in a path that conflicting with a reference jar.
# usage: ./conflicting_jars.sh <reference.jar> <path/to/other/jars>
function abspath() {
# from http://stackoverflow.com/questions/3915040/bash-fish-command-to-print-absolute-path-to-a-file
# generate absolute path from relative path
# $1 : relative filename
# return : absolute path
if [ -d "$1" ]; then
# dir
(cd "$1"; pwd)
elif [ -f "$1" ]; then
# file
if [[ $1 == */* ]]; then
echo "$(cd "${1%/*}"; pwd)/${1##*/}"
else
echo "$(pwd)/$1"
fi
fi
}
function normpath() {
tr "/" "_"
}
DIR=`mktemp -d`
echo "writing output to '$DIR'"
echo
BASEJAR=$1
NORMPATH_BASEJAR=`abspath $BASEJAR | tr "/" "_"`
BASEJAR_CLASSLIST="$DIR/$NORMPATH_BASEJAR.classlist"
jar tf "$BASEJAR" | grep ".class" > "$BASEJAR_CLASSLIST"
JARS=`find $2 -name "*.jar" -print`
for JAR in $JARS
do
NORMPATH_JAR=`abspath $JAR | tr "/" "_"`
if [ $NORMPATH_JAR != $NORMPATH_BASEJAR ]
then
CLASSLIST="$DIR/$NORMPATH_JAR.classlist"
jar tf $JAR | grep ".class" > $CLASSLIST
JOINCOUNT=`join $CLASSLIST $BASEJAR_CLASSLIST | wc -l`
if [ $JOINCOUNT -gt 0 ]
then
echo $JAR
echo "class overlap: $JOINCOUNT"
echo
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment