After update, old Eclipse plugins remain in \"plugins\" folder (there are also leftovers in \"features\" folder).
Is there a way to remove those automatically?
I use the following command:
eclipse -application org.eclipse.equinox.p2.garbagecollector.application -profile epp.package.jee
Notes:
This is documented in Equinox/p2/FAQ, see "Why aren't bundles being removed when their associated feature has been removed?"
The FAQ answer references an Eclipse Community Forum thread "Plug-in jar remains after feature uninstall" (June 2010) as the origin for this recipe.
The recipe is still valid nowadays, with Eclipse 4.8 Photon.
The -profile
argument depends on what packaging of Eclipse IDE you are using. The above one (epp.package.jee
) is for "Eclipse for Java EE Developers". I found it in the file configuration/config.ini
. The relevant line there is the following:
eclipse.p2.profile=epp.package.jee
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
With Ganymede (3.4), the correct way to manage your plugins would be to drop them in the 'dropins' folder:
\[eclipse\]/dropins/eclemma1.3.1/eclipse/(plugins|features)
That plugin will be detected by the 'p2' provisioning mechanism and used, but not copied in the plugins and features directories of eclipse. It stays in the dropins folder.
When you will drop eclemma1.3.2, all you have to do is delete eclemma1.3.1 from your dropins directory, and that old version is gone.
I've created a script in python to move the old plugins to a backup folder, so if something goes wrong it can go back. The script has two modes of operation: Manual mode asks you what to do with each duplicated plugin detected, and automatic only question in cases where the length of the string has changed and therefore may have changed the system, or version numbering.
I hope this helps someone
# -*- coding: utf-8 -*-
import os
import re
from datetime import datetime
directory="C:\\eclipse64\\plugins"
dirBackup="C:\\eclipse64\\PluginsBackup" #This folder is a kind of recycle bin for save deleted plugins. In case you have problems running eclipse after remove them you can restore them. If you don't detect any problem you can erase this folder to save disk space
manual=False #Verifying deletion of each plugin manually (True) or automatic (False)
def globRegEx(directory,pat,absolutePath=True,type_=0):
'''Function that given a directory and a regular pattern returns a list of files that meets the pattern
:param str directory: Base path where we search for files that meet the pattern
:param str pat: Regular expression that selected files must match
:param bool absolutePath: Optional parameter that indicates if the returned list contains absolute (True) or relative paths (False)
:param int type_: Type of selection 0: selects files and directories 1: only selects files 2: only selects directories
:return: a list with the paths that meet the regular pattern
'''
names=os.listdir(directory)
pat=re.compile(pat)
res=[]
for name in names:
if pat.match(name):
path=directory+os.sep+name
if type_==1 and os.path.isfile(path):
res.append(path if absolutePath else name)
elif type_==2 and os.path.isdir(path):
res.append(path if absolutePath else name)
elif type_==0:
res.append(path if absolutePath else name)
return(res)
def processRepeated(repList):
''' this function is responsible for leaving only the newer version of the plugin
'''
if repList and len(repList)>1: #If the plugin is repeated
repList.sort(reverse=True)
print("Repeated plugins found:")
min=len(repList[0]) # If strings haven't got the same length indicates a change in the numeration version system
max=min
newer=datetime.fromtimestamp(0)
sel=0
for i,path in enumerate(repList):
lr=len(path)
modifDate=datetime.fromtimestamp((os.path.getctime(path)))
if modifDate>newer: #Keep the last creation date and its index
newer=modifDate
sel=i+1
if lr<min:
min=lr
elif lr>max:
max=lr
print(str(i+1) + " " + modifDate.strftime("%Y-%m-%d") + ": " + path)
print(" ")
if manual or min!=max: #If manual mode is enabled or if there is a string length diference between different version of plugins
selec=raw_input("Which version do you want to keep?: ["+str(sel)+"] ")
if selec:
selec=int(selec)
else:
selec=sel #Newer is the Default value
else:
selec=1
del(repList[selec-1]) #Delete selected plugin from the list
for path in repList: #Move the rest of the list to the backup folder
print("Deleting: "+ path)
os.renames(path,os.path.join(dirBackup,os.path.basename(path)))
print("-------------------------------------\n\n")
def main():
filePlugins=globRegEx(directory,"^.*$",False,1) #Creates a list with all the files only
dirPlugins=globRegEx(directory,"^.*$",False,2) #Creates a list with all the folders only
#Process files first
for plugin in filePlugins:
m=re.match(r"(.*_)\d.*?\.jar$",plugin) #Creates the glob pattern
if m:
patAux=m.groups()[0]+".*?\.jar$"
find=globRegEx(directory,patAux,True,1)
processRepeated(find)
#Now Directories
for plugin in dirPlugins:
m=re.match(r"(.*_)\d.*$",plugin) #Creates the glob pattern
if m:
patAux=m.groups()[0]+".*$"
find=globRegEx(directory,patAux,True,2)
processRepeated(find)
if __name__=="__main__":
main()
Eclipse allows you to revert back to any previous configuration (go to the Help menu, then "Software Updates"). My guess is that Eclipse won't remove these old versions, or this functionality would no longer work.
If when you restart Eclipse you provide the "-clean" argument, it performs various cleanup operations, but for reasons stated above I don't think it will remove old plugins/features.