Created
October 8, 2021 13:37
-
-
Save shannah/87e9f63e00b307c3bc28ea598e013db7 to your computer and use it in GitHub Desktop.
A bash script for printing out classes in a jar file with version greater than some value
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/bash | |
JARPATH="$1" | |
MIN="$2" | |
if [[ "$JARPATH" == "" ]] || [[ "$MIN" == "" ]]; then | |
echo 'This script will scan the classes in a jar file, and print the ones whose ' | |
echo 'bytecode versions are greater than a given value.' | |
echo '' | |
echo 'Usage bash bcversions.sh JARPATH MAXVERSION' | |
echo ' JARPATH The path to the jar file to check' | |
echo ' MAXVERSION The max classfile version to ignore.' | |
echo '' | |
echo 'Example: ' | |
echo 'bash bcversions /path/to/myapp.jar 52' | |
echo ' The above will output all classes in myapp.jar with a bytecode version greater than 52' | |
echo '' | |
echo 'Created by Steve Hannah, Codename One https://www.codenameone.com' | |
exit 1 | |
fi | |
for line in `jar tf $JARPATH`; do | |
if [[ ! "$line" == *.class ]]; then | |
continue | |
fi | |
line=$(echo "$line" | sed s/\\//\./ | sed s/\.class//); | |
_version=$(javap -cp $JARPATH -verbose "$line" | grep -i "major version" | sed s/[^0-9]*//); | |
if [[ "$_version" -gt "$MIN" ]]; then | |
echo "$line: version $_version" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment