kootoye 2015-01-16
Butwhyaren'tuninstalledbundles/featuresimmediatelyremoved?
p2doesnotimmediatelyremovebundlesonuninstallforseveralreasons:
Minimizingwaste:Byretainingthebundles,p2cansavetimeandbandwidthtoshouldthesebundlesbere-installed.
Forsafety:Manybundlesdonotproperlysupporthot-swappingandremoval.Writingbundlesthatcanbeuninstalledcompletelyissurprisinglydifficult,andevenhardertotest.
Inpracticethetimingofdeletionshouldnotmatterasp2ensuresthatthebundleswillnotbere-installed(modulotheorg.eclipse.update.configuratorissuedescribedelsewhereinthisFAQ).
p2doesperiodicallyperformagarbagecollectionofuninstalledfeaturesandbundles,typicallyafterhavingperformedanotheruninstall.SeeelsewhereinthisFAQfordetailsonhowtoexplicitlyrequestagarbagecollect.
Whyaren'tbundlesbeingremovedwhentheirassociatedfeaturehasbeenremoved?
Therearetwoaspectstothisproblem.
First,youshouldensurethatfeaturesarerecordedwheninstallingafeaturebyspecifyingthe"org.eclipse.update.install.features=true"property,suchthatthebundleshavearecordeddependencyagainstthefeature.Thispropertyisnotthedefault,soifyouareusingthep2directormanuallyitisworthverifying.
Second,youmustinvokethep2garbagecollector.[1]Bydefault,p2onlyperformsagarbagecollectatitsdiscretion.Normallythisisfinesincetheactualbundlestobeloadedarestillknownandmanaged(eitherintheconfig.inifileorbythesimpleconfigurator).
Youcancauseagarbagecollectinoneof3ways:
ConfigureyourproducttoinvokeaGConstartupbyaddingthefollowinglinetoyourproduct'splugin_customization.ini(requirestheorg.eclipse.equinox.p2.ui.sdk.schedulerbundle):
org.eclipse.equinox.p2.ui.sdk.scheduler/gcOnStartup=true
Runthegarbagecollectorapplication:[2]
eclipse-applicationorg.eclipse.equinox.p2.garbagecollector.application-profileSDKProfile
Explicitlyinvokethep2garbagecollectionfromcode:
IProvisioningAgentProviderprovider=//obtaintheIProvisioningAgentProviderusingOSGiservices
IProvisioningAgentagent=provider.createAgent(null);//null=locationforrunningsystem
if(agent==null)thrownewRuntimeException("Locationwasnotprovisionedbyp2");
IProfileRegistryprofileRegistry=(IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
if(profileRegistry==null)thrownewRuntimeException("Unabletoacquiretheprofileregistryservice.");
//canalsouseIProfileRegistry.SELFforthecurrentprofile
IProfileprofile=profileRegistry.getProfile("SDKProfile");
GarbageCollectorgc=(GarbageCollector)agent.getService(GarbageCollector.SERVICE_NAME);
gc.runGC(profile);
转自:https://wiki.eclipse.org/Equinox/p2/FAQ#cite_note-2