Repository navigation
Expand file tree
/
Copy pathcheck-jar.sh
More file actions
executable file
·115 lines (110 loc) · 1.84 KB
/
Copy pathcheck-jar.sh
File metadata and controls
executable file
·115 lines (110 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#! /bin/bash
ONLY_FIRST_FILE=true
MAX_MAJOR=0
WORK_DIR=$(mktemp -d)
#WORK_DIR="/tmp/tmp.nbCuo3Tzv2"
# check if tmp dir was created
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "Could not create temp dir"
exit 1
fi
# deletes the temp directory
function cleanup {
rm -rf "$WORK_DIR"
#echo "Deleted temp working directory $WORK_DIR"
}
# check one class file
function check {
found=false
for file in *.class;
do
[ -f "$file" ] || continue
msg=$(javap -v $file | grep major)
ver=${msg:17:2}
if [ "$ver" -gt "$MAX_MAJOR" ]; then
echo "$file $ver"
MAX_MAJOR="$ver"
fi
found=true
break
done
if [ $ONLY_FIRST_FILE = true ] && [ $found = false ];
then
for d in *;
do
if [ -d "$d" ]; then
pushd $d > /dev/null
pwd=$(pwd)
classname=${pwd#"$WORK_DIR"/}
echo -en "\r\e[K$classname"
check
popd > /dev/null
fi
done
fi
}
# register the cleanup function to be called on the EXIT signal
trap cleanup EXIT
filename=$(basename "$1")
cp $1 $WORK_DIR
pushd $WORK_DIR > /dev/null
unzip -n -q $filename "*.class"
for file in *.class;
do
[ -f "$file" ] || continue
msg=$(javap -v $file | grep major)
ver=${msg:17:2}
if [ "$ver" -gt "$MAX_MAJOR" ]; then
echo "$file $ver"
MAX_MAJOR="$ver"
fi
break
done
for d in *;
do
if [ -d "$d" ]; then
pushd $d > /dev/null
check
popd > /dev/null
fi
done
echo -e "\r\e[K"
popd > /dev/null
case $MAX_MAJOR in
46)
echo "Java 1.2"
;;
47)
echo "Java 1.3"
;;
48)
echo "Java 1.4"
;;
49)
echo "Java 1.5"
;;
50)
echo "Java 6"
;;
51)
echo "Java 7"
;;
52)
echo "Java 8"
;;
53)
echo "Java 9"
;;
54)
echo "Java 10"
;;
55)
echo "Java 11"
;;
54)
echo "Java 12"
;;
*)
echo "Other Java version"
;;
esac