Skip to content

Instantly share code, notes, and snippets.

@ctrueden
Created September 22, 2019 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctrueden/379b4ea5e7845be1b822f664a1a40e9e to your computer and use it in GitHub Desktop.
Save ctrueden/379b4ea5e7845be1b822f664a1a40e9e to your computer and use it in GitHub Desktop.
How to diff the API of two JAR files
#!/bin/sh
# TODO: Why doesn't this work
trap "exit" INT
die() {
echo "$1" 2>&1
exit 1
}
dumpAPI() {
jar="$1"
jar tf "$jar" |
grep '\.class$' | # only process classes
grep -v '\$' | # filter out inner classes
sed 's/\.class$//' | # remove .class suffix
sed 's_/_._g' | # change path -> package separators
sort | # process in consistent order
while read p
do
javap -cp "$jar" "$p"
done
}
jar1="$1"
jar2="$2"
test -f "$jar1" -a -f "$jar2" || die "Please specify two JAR files."
out1=$(mktemp)
out2=$(mktemp)
dumpAPI "$jar1" > "$out1"
dumpAPI "$jar2" > "$out2"
# NB: Or replace with your favorite diff tool.
diff "$out1" "$out2"
# Clean up.
rm -f "$out1" "$out2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment