Created
June 14, 2016 15:45
-
-
Save giacobenin/3b94396b17862f818246ed1d2b1c796b to your computer and use it in GitHub Desktop.
It outputs the major java version of the input class file, or the major java version of each class file contained in the input directory.
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 | |
root=$1 | |
VERSION="" | |
function major_to_version { | |
local major="$1" | |
case $major in | |
46) VERSION="1.2";; | |
47) VERSION="1.3";; | |
48) VERSION="1.4";; | |
49) VERSION="1.5";; | |
50) VERSION="1.6";; | |
51) VERSION="1.7";; | |
52) VERSION="1.8";; | |
*) VERSION="major $major" | |
esac | |
} | |
function get_version { | |
local class_file="$1" | |
local major=`javap -verbose $class_file | grep "major" | cut -d ':' -f 2 | tr -d ' '` | |
major_to_version $major | |
} | |
if [ -d $root ]; then | |
for f in `find $root -name *.class`; do | |
get_version $f | |
echo "$VERSION" | |
done | |
else | |
get_version $root | |
echo "$VERSION" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment