Created
June 5, 2014 11:48
-
-
Save thvitt/3362f6fb9d2ee6aa23c3 to your computer and use it in GitHub Desktop.
Reports on the Java class versions in an Eclipse RCP app.
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 | |
# This is a simple script to check every class file that somehow got into a | |
# Eclipse RCP application for its required java version. | |
# | |
# Run it in a RCP or p2 repo directory and it checks every .class file in the | |
# plugins for the required java version using file(1). The results will be | |
# written to two (redundant) reports. | |
# | |
# The script is able to handle standard bundled plugins as well as expanded | |
# plugins and nested jars. | |
# | |
# Requires file(1) and a bunch of other unix tools. Tries to output a | |
# human-readable java version number (like 1.6), but if file doesn't decode it, | |
# the internal class version is used, see | |
# http://en.wikipedia.org/wiki/Java_class_file#General_layout | |
plugindir=. | |
workdir=`mktemp -d --tmpdir javaver-XXXXX` | |
byPlugin=`readlink -f .`/Java-Versions-By-Plugin.txt | |
byVersion=`readlink -f .`/Plugins-By-Java-Version.txt | |
# workout real plugin directory. Either argument or cwd | |
if [ $# -ge 1 ] | |
then | |
plugindir="$1" | |
fi | |
if [ -d "$plugindir/plugins" ] | |
then | |
plugindir="$plugindir/plugins" | |
fi | |
log() { | |
echo "$@" >&2 | |
} | |
check_plugin() { | |
plugin="$1" | |
dir="$2" | |
subjar="$3" | |
log -n "$plugin $subjar: " | |
if [ "$subjar" = "" ] | |
then | |
echo -n "$plugin: " >> "$byPlugin" | |
else | |
echo -n "$plugin/$subjar: " >> "$byPlugin" | |
fi | |
find "$dir" -name '*.class' -print0 \ | |
| xargs -0 --no-run-if-empty file \ | |
| sed -e 's/.*(Java \(.*\)).*/\1/' \ | |
-e 's/.*, version \([0-9][0-9]\.[0-9]\).*/\1/' \ | |
| sort --unique \ | |
| while read version | |
do | |
echo "$plugin" >> "$workdir/Java-$version.txt" | |
log -n "$version " | |
echo -n "$version " >> "$byPlugin" | |
done | |
log | |
echo >> "$byPlugin" | |
# check subjars | |
find "$dir" -name '*.jar' | while read jar | |
do | |
log -n " - " | |
sjar="`basename ${jar}`" | |
jdir="$workdir/${plugin}___`basename ${jar} .jar`" | |
mkdir "$jdir" | |
fulljar="`readlink -f $jar`" | |
( cd "$jdir" && jar xf "$fulljar" ) | |
check_plugin "$plugin" "$jdir" "$sjar" | |
rm -rf "$jdir" | |
done | |
} | |
cd "$plugindir" | |
for plugin in * | |
do | |
if [ -d "$plugin" ] | |
then | |
check_plugin "$plugin" "$plugin" | |
else | |
jar="$plugin" | |
plugin="`basename $jar .jar`" | |
if [ "$plugin" != "$jar" ] | |
then | |
dir="$workdir/$plugin" | |
mkdir "$dir" | |
fulljar="`readlink -f $jar`" | |
( cd "$dir" && jar xf "$fulljar" ) | |
check_plugin "$plugin" "$dir" | |
rm -rf "$dir" | |
else | |
log "(Skipping $jar)" | |
fi | |
fi | |
done | |
for ver in "$workdir"/Java-*.txt | |
do | |
echo | |
echo | |
echo "## `basename $ver .txt`" | |
echo | |
cat "$ver" | |
done > "$byVersion" | |
rm -rf "$workdir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment