1 11 package org.eclipse.update.standalone; 12 import java.io.*; 13 import java.lang.reflect.*; 14 import java.net.*; 15 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.update.configuration.*; 19 import org.eclipse.update.core.*; 20 import org.eclipse.update.internal.core.*; 21 import org.eclipse.update.internal.operations.*; 22 import org.eclipse.update.operations.*; 23 24 34 public class UninstallCommand extends ScriptedCommand { 35 36 private IConfiguredSite targetSite; 37 private IFeature feature; 38 39 public UninstallCommand( 40 String featureId, 41 String version, 42 String toSite, 43 String verifyOnly) 44 throws Exception { 45 46 super(verifyOnly); 47 48 try { 49 IConfiguredSite[] sites = getConfiguration().getConfiguredSites(); 50 51 if (toSite != null) { 53 URL toSiteURL = new File(toSite).toURL(); 54 if (SiteManager.getSite(toSiteURL, null) == null) { 55 throw new Exception (Messages.Standalone_noSite + toSite); 56 } 57 targetSite = 58 SiteManager 59 .getSite(toSiteURL, null) 60 .getCurrentConfiguredSite(); 61 } 62 if (targetSite == null) { 63 for (int i = 0; i < sites.length; i++) { 64 if (sites[i].isProductSite()) { 65 targetSite = sites[i]; 66 break; 67 } 68 } 69 } 70 71 IFeature[] features = 72 UpdateUtils.searchSite(featureId, targetSite, false); 73 if (features == null || features.length == 0) { 74 throw new Exception (NLS.bind(Messages.Standalone_noFeatures1, (new String [] { featureId }))); 75 } 76 if (version == null || version.trim().length() == 0) 77 feature = features[0]; else 79 for (int i = 0; features != null && i < features.length; i++) { 80 if (features[i] 81 .getVersionedIdentifier() 82 .getVersion() 83 .toString() 84 .equals(version) 85 && !targetSite.isConfigured(features[i])) { 86 feature = features[i]; 87 break; 88 } 89 } 90 if (feature == null) { 91 throw new Exception (NLS.bind(Messages.Standalone_noFeatures2, (new String [] { featureId, version }))); 92 } 93 94 } catch (MalformedURLException e) { 95 throw e; 96 } catch (CoreException e) { 97 throw e; 98 } 99 } 100 101 103 public boolean run(IProgressMonitor monitor) { 104 IStatus status = OperationsManager.getValidator().validatePlatformConfigValid(); 106 if (status != null) { 107 UpdateCore.log(status); 108 return false; 109 } 110 if (InstallRegistry.getInstance().get("feature_"+ feature.getVersionedIdentifier()) == null) { StandaloneUpdateApplication.exceptionLogged(); 112 UpdateCore.log(Utilities.newCoreException(NLS.bind(Messages.UninstallCommand_featureNotInstalledByUM, (new String [] { feature.toString() })),null)); 113 return false; 114 } 115 116 if (isVerifyOnly()) { 117 return true; 119 } 120 121 final IUninstallFeatureOperation uninstallOperation = 122 OperationsManager.getOperationFactory().createUninstallOperation( 123 targetSite, 124 feature); 125 126 try { 127 uninstallOperation.execute(monitor, this); 128 return true; 129 } catch (CoreException e) { 130 StandaloneUpdateApplication.exceptionLogged(); 131 UpdateCore.log(e); 132 return false; 133 } catch (InvocationTargetException e) { 134 StandaloneUpdateApplication.exceptionLogged(); 135 UpdateCore.log(e); 136 return false; 137 } 138 } 139 140 } 141 | Popular Tags |