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 DisableCommand extends ScriptedCommand { 35 36 private IConfiguredSite targetSite; 37 private IFeature feature; 38 39 public DisableCommand( 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, true); 73 if (features == null || features.length == 0) { 74 throw new Exception (NLS.bind(Messages.Standalone_noFeatures3, (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 feature = features[i]; 86 break; 87 } 88 } 89 if (feature == null) { 90 throw new Exception (NLS.bind(Messages.Standalone_noFeatures4, (new String [] { featureId, version }))); 91 } 92 93 } catch (MalformedURLException e) { 94 throw e; 95 } catch (CoreException e) { 96 throw e; 97 } 98 } 99 100 102 public boolean run(IProgressMonitor monitor) { 103 IStatus status = OperationsManager.getValidator().validatePlatformConfigValid(); 105 if (status != null) { 106 UpdateCore.log(status); 107 return false; 108 } 109 if (isVerifyOnly()) { 110 status = 111 OperationsManager.getValidator().validatePendingUnconfig( 112 feature); 113 if (status != null && status.getCode() == IStatus.WARNING) 114 UpdateCore.log(status); 115 return status == null || status.getCode() == IStatus.WARNING; 116 } 117 118 final IUnconfigFeatureOperation configOperation = 119 OperationsManager.getOperationFactory().createUnconfigOperation( 120 targetSite, 121 feature); 122 123 try { 124 configOperation.execute(monitor, this); 125 return true; 126 } catch (CoreException e) { 127 StandaloneUpdateApplication.exceptionLogged(); 128 UpdateCore.log(e); 129 return false; 130 } catch (InvocationTargetException e) { 131 StandaloneUpdateApplication.exceptionLogged(); 132 UpdateCore.log(e); 133 return false; 134 } 135 } 136 137 } 138 | Popular Tags |