KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > scheduler > ScheduledPluginUninstall


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.scheduler;
12
13 import java.io.File JavaDoc;
14 import java.io.FileInputStream JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.lang.reflect.InvocationTargetException JavaDoc;
17 import java.net.URL JavaDoc;
18 import java.util.Enumeration JavaDoc;
19 import java.util.Properties JavaDoc;
20 import java.util.StringTokenizer JavaDoc;
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 JavaDoc platformXML = ConfiguratorUtils.getCurrentPlatformConfiguration().getConfigurationLocation();
37         
38         File JavaDoc f = new File JavaDoc(platformXML.getFile());
39
40         f = new File JavaDoc(f.getParentFile(), "toBeUninstalled"); //$NON-NLS-1$
41
try {
42             if (!f.exists()) {
43                 return;
44             }
45             FileInputStream JavaDoc fis = new FileInputStream JavaDoc(f);
46             Properties JavaDoc toBeUninstalled = new Properties JavaDoc();
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 JavaDoc featuresToBeDeleted = toBeUninstalled.elements();
56             int i = 0;
57             while(featuresToBeDeleted.hasMoreElements()) {
58                 String JavaDoc temp = (String JavaDoc)featuresToBeDeleted.nextElement();
59                 StringTokenizer JavaDoc stk = new StringTokenizer JavaDoc( temp, ";"); //$NON-NLS-1$
60
String JavaDoc targetSite = stk.nextToken();
61                 String JavaDoc 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 JavaDoc ioe) {
87             
88         } catch (CoreException e) {
89             // TODO Auto-generated catch block
90
e.printStackTrace();
91         } catch (InvocationTargetException JavaDoc e) {
92             // TODO Auto-generated catch block
93
e.printStackTrace();
94         }
95     }
96     
97
98 }
99
Popular Tags