How to remove old versions of Eclipse plugins?
After update, old Eclipse plugins remain in "plugins" folder (there are also leftovers in "features" folder).
Is there a way to remove those automatically?
To get rid of the old plugins you have to clear the Installation History. Go to Help | About Eclipse | Installation Details | Installation History and select all the old stuff. Then click delete and restart. Voila. This works with Eclipse Helios (3.6)
I also want to remove old plugins, but still found no answer today, so I wrote a quick and dirty script guess-old-eclipse-plugins.sh
to handle old plugins.
This script will scan plugins directory under Eclipse directory. and will generate a remove-old-eclipse-plugins.txt
file which can be used to remove old plugins.
This script is tested under Cygwin 1.7.15 on Windows XP.
guess-old-eclipse-plugins.sh
PluginsDir=plugins
FeaturesDir=features
PluginIDSeparator=_
RemovingScriptFileName=remove-old-eclipse-plugins.txt
rm -rf $RemovingScriptFileName
#for dir in $PluginsDir $FeaturesDir
for dir in $PluginsDir # $FeaturesDir: most file names in features dir contains more than 1 _ character
do
echo "Processing [$dir] directory..."
# split PluginID from filename
# (not reliable, but general working. (ex: will get one junit PluginID because there're move than 1 _ characters in file name))
file_list=$(ls $dir);
echo "$file_list" | cut -f1 -d $PluginIDSeparator > $dir-all.txt
echo "$file_list" | cut -f1 -d $PluginIDSeparator | uniq > $dir-uniq.txt
# get the PluginList which VERY POSSIBLY has old versions
diff_result=$(diff -U 0 $dir-uniq.txt $dir-all.txt)
plugins_which_has_old_versions=$(echo "$diff_result" | grep -e "^+[^+]" | cut -f 2 -d +)
#
for p in $(echo "$plugins_which_has_old_versions")
do
echo "$p"
i=0
for f in $(ls -d -t $dir/$p$PluginIDSeparator*) # use 'ls' command, can sort result by file time, but can not handle file name contains special characters (white space) when using wildcard
#for f in $(find $dir -name "$p$PluginIDSeparator*") # use 'find' command
do
if [ -d $f ]
then
# should use rm -rf
echo -n "[D]"
else
echo -n " "
fi
echo -n "$f"
((i++))
if [ $i -eq 1 ]
then
echo ""
continue # first file, the newest version
fi
echo " [old]"
echo "rm -rf $f" >> $RemovingScriptFileName
done
echo
done
done
IMPORTANT NOTICE
Before use the generated remove-old-eclipse-plugins.txt
file to remove plugins, make sure all the listed plugins in it are REALLY old plugins. Because, this script can't handle file name contains more than 1 _
characters. For example: JUnit v3 and v4 plugins are 2 different plugins, but the script will treat it as same plugins because these 2 file names use same org.junit_
prefix.
org.junit
[D]plugins/org.junit_3.8.2.v3_8_2_v20100427-1100
[D]plugins/org.junit_4.8.2.v4_8_2_v20110321-1705 [old] <-- wrong
So, use it VERY CAREFULLY , remove the wrong part before use it, or your Eclipse IDE may not work properly.
Sample output
$ ./guess-old-eclipse-plugins.sh
Processing [plugins] directory...
org.eclipse.gef
plugins/org.eclipse.gef_3.7.2.v20111106-2020.jar
plugins/org.eclipse.gef_3.6.2.v20110110-2020.jar [old]
org.eclipse.help.base
plugins/org.eclipse.help.base_3.6.2.v201202080800.jar
plugins/org.eclipse.help.base_3.5.3.v201102101200.jar [old]
org.eclipse.help.ui
plugins/org.eclipse.help.ui_3.5.101.r37_20110819.jar
plugins/org.eclipse.help.ui_3.5.3.r36_20101116.jar [old]
...
Sample generated script
rm -rf plugins/org.eclipse.gef_3.6.2.v20110110-2020.jar
rm -rf plugins/org.eclipse.help.base_3.5.3.v201102101200.jar
rm -rf plugins/org.eclipse.help.ui_3.5.3.r36_20101116.jar
rm -rf plugins/org.eclipse.help.webapp_3.5.3.r36_20101130.jar
rm -rf plugins/org.eclipse.jdt.apt.core_3.3.402.R36_v20110120-1000.jar
rm -rf plugins/org.eclipse.jdt.debug.ui_3.5.2.v20100928a_r362.jar
I've modified the script to allow for all dropins, features, and plugins. First it relies on reverse sort to guess the most recent canonical plugin version.
Next it reduces that qualified plugin version name to a canonical plugin sed expression. If the plugin is the first match for this expression it stores its pattern and keeps it, otherwise it is an old stale version and it flags it for deletion.
# scan_old_plugins.sh # script to scan for duplicate old eclipse features, plugins and dropins # generates a "clean-old-plugins.sh" script to clean old versions. # warning: DANGEROUS! review clean-old-plugins script before running it. DropinsDir=dropins FeaturesDir=features PluginsDir=plugins CanonicalPluginsFile=sed_canonical_plugins.sh CleanPluginScriptFile=clean_old_plugins.sh echo "" > $CanonicalPluginsFile echo "" > $CleanPluginScriptFile #for dir in $PluginsDir for dir in $FeaturesDir $PluginsDir $DropinsDir do echo "Processing [$dir] directory..." # file_list=$(ls -1 $dir | sort -r); echo "$file_list" > $dir-all.txt # for p in $(echo "$file_list") do v=$(echo $p | sed -e 's/_[0-9._-]*/_.*/g' | sed -e 's/[0-9][0-9]*/.*/g') g=$(grep -l "$v" $CanonicalPluginsFile | head -1 | awk '{print $1}') if [ "$g" = "" ]; then echo "$p=keep"; echo "$v=$p" >> $CanonicalPluginsFile else echo "$p=stale"; echo "rm -rf $p" >> $CleanPluginScriptFile fi done done链接地址: http://www.djcxy.com/p/90594.html
上一篇: Eclipse刷新工作区需要永久
下一篇: 如何删除旧版本的Eclipse插件?