Created
September 22, 2019 10:05
-
-
Save ctrueden/379b4ea5e7845be1b822f664a1a40e9e to your computer and use it in GitHub Desktop.
How to diff the API of two 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
#!/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