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 EnableCommand extends ScriptedCommand { 35 36 private IConfiguredSite targetSite; 37 private IFeature feature; 38 39 public EnableCommand( 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 111 if (isVerifyOnly()) { 112 status = 113 OperationsManager.getValidator().validatePendingConfig(feature); 114 if (status != null && status.getCode() == IStatus.WARNING) 115 UpdateCore.log(status); 116 return status == null || status.getCode() == IStatus.WARNING; 117 } 118 119 final IConfigFeatureOperation configOperation = 120 OperationsManager.getOperationFactory().createConfigOperation( 121 targetSite, 122 feature); 123 124 try { 125 configOperation.execute(monitor, this); 126 return true; 127 } catch (CoreException e) { 128 StandaloneUpdateApplication.exceptionLogged(); 129 UpdateCore.log(e); 130 return false; 131 } catch (InvocationTargetException e) { 132 StandaloneUpdateApplication.exceptionLogged(); 133 UpdateCore.log(e); 134 return false; 135 } 136 } 137 138 } 139 | Popular Tags |