Skip to content

Instantly share code, notes, and snippets.

@mslinn
Created December 18, 2012 23:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mslinn/4333057 to your computer and use it in GitHub Desktop.
Save mslinn/4333057 to your computer and use it in GitHub Desktop.
Searches path for .class files compiled from specified Scala or Java class Usage: findClasses fileName [className] -c classpath; if not specified then all classes under target/scala-* are searched -e Exact match required for fileName, or className if specified -s Show javap decompilation output
#!/bin/bash
function help {
echo "Searches path for .class files compiled from specified Scala or Java class"
echo "Usage: $(basename $0) fileName [className]"
echo " -c classpath; if not specified then all classes under target/scala-* are searched"
echo " -e Exact match required for fileName, or className if specified"
echo " -s Show javap decompilation output"
exit -1
}
CLASSPATH='target/scala-*/classes/'
while getopts "des\?" opt; do
case $opt in
c ) CLASSPATH="$OPTARG" ;;
d ) set -xv ;;
e ) EXACT_MATCH=true ;;
s ) SHOW_CONTENTS=true ;;
h ) help ;;
\?) help ;;
esac
done
shift $(($OPTIND-1))
if [ $# -lt 1 ]; then help; fi
FILE_NAME=$1
if [ $# -eq 1 ]; then
CLASS_NAME=$1
else
CLASS_NAME=$2
fi
for CP in $CLASSPATH; do
if [ "$EXACT_MATCH" ]; then
FILES=`find $CP -name \*${CLASS_NAME}.class`
else
FILES=`find $CP -name \*${CLASS_NAME}\*`
fi
for F in $FILES; do
CONTENTS=`javap -classpath $CP $F`
FOUND=`echo "$CONTENTS" | grep -H "Compiled from \"*${FILE_NAME}"`
if [ -n "$FOUND" ]; then
echo "$F"
if [ "$SHOW_CONTENTS" ]; then echo "$CONTENTS"; fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment