1 11 package org.eclipse.update.internal.scheduler; 12 13 import java.io.File ; 14 import java.io.FileInputStream ; 15 import java.io.IOException ; 16 import java.lang.reflect.InvocationTargetException ; 17 import java.net.URL ; 18 import java.util.Enumeration ; 19 import java.util.Properties ; 20 import java.util.StringTokenizer ; 21 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.ui.IStartup; 24 import org.eclipse.update.configuration.IConfiguredSite; 25 import org.eclipse.update.configurator.ConfiguratorUtils; 26 import org.eclipse.update.core.IFeature; 27 import org.eclipse.update.core.IFeatureReference; 28 import org.eclipse.update.core.SiteManager; 29 import org.eclipse.update.internal.operations.OperationFactory; 30 import org.eclipse.update.operations.IOperation; 31 import org.eclipse.update.operations.OperationsManager; 32 33 public class ScheduledPluginUninstall implements IStartup { 34 35 public void earlyStartup() { 36 URL platformXML = ConfiguratorUtils.getCurrentPlatformConfiguration().getConfigurationLocation(); 37 38 File f = new File (platformXML.getFile()); 39 40 f = new File (f.getParentFile(), "toBeUninstalled"); try { 42 if (!f.exists()) { 43 return; 44 } 45 FileInputStream fis = new FileInputStream (f); 46 Properties toBeUninstalled = new Properties (); 47 toBeUninstalled.load(fis); 48 fis.close(); 49 50 IFeature[] features = new IFeature[toBeUninstalled.size()]; 51 IConfiguredSite[] configuredSites = new IConfiguredSite[toBeUninstalled.size()]; 52 53 IConfiguredSite[] sites = SiteManager.getLocalSite().getCurrentConfiguration().getConfiguredSites(); 54 55 Enumeration featuresToBeDeleted = toBeUninstalled.elements(); 56 int i = 0; 57 while(featuresToBeDeleted.hasMoreElements()) { 58 String temp = (String )featuresToBeDeleted.nextElement(); 59 StringTokenizer stk = new StringTokenizer ( temp, ";"); String targetSite = stk.nextToken(); 61 String featureName = stk.nextToken(); 62 for(int j = 0; j < sites.length; j++) { 63 if (sites[j].getSite().getURL().toString().equals(targetSite)) { 64 configuredSites[i] = sites[j]; 65 IFeatureReference[] siteFeatures = configuredSites[i].getFeatureReferences(); 66 for(int k = 0; k < siteFeatures.length; k++) { 67 if (siteFeatures[k].getVersionedIdentifier().toString().equals(featureName)) { 68 features[i] = siteFeatures[k].getFeature(null); 69 70 break; 71 } 72 } 73 74 } 75 } 76 i++; 77 } 78 79 80 IOperation uninstallFeaturesOperation = 81 ((OperationFactory)OperationsManager.getOperationFactory()).createUninstallFeaturesOperation( configuredSites, features); 82 83 uninstallFeaturesOperation.execute(null, null); 84 85 f.delete(); 86 } catch (IOException ioe) { 87 88 } catch (CoreException e) { 89 e.printStackTrace(); 91 } catch (InvocationTargetException e) { 92 e.printStackTrace(); 94 } 95 } 96 97 98 } 99 | Popular Tags |