1 11 package org.eclipse.update.internal.operations; 12 13 import java.util.HashSet ; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.update.configuration.*; 18 import org.eclipse.update.core.*; 19 import org.eclipse.update.internal.core.Messages; 20 import org.eclipse.update.operations.*; 21 22 26 public class InstallOperation 27 extends FeatureOperation 28 implements IInstallFeatureOperation { 29 30 public boolean equals(Object arg) { 31 if (arg == null) { 32 return false; 33 } 34 35 if (!(arg instanceof InstallOperation)) { 36 return false; 37 } 38 39 InstallOperation io = (InstallOperation)arg; 40 41 return io.getFeature().getVersionedIdentifier().equals(this.getFeature().getVersionedIdentifier()); 42 } 43 44 public int hashCode() { 45 return super.getFeature().hashCode(); 47 } 48 49 private IFeatureReference[] optionalFeatures; 50 private IFeature[] unconfiguredOptionalFeatures; 51 private IVerificationListener verifier; 52 53 61 public InstallOperation( 62 IConfiguredSite site, 63 IFeature feature, 64 IFeatureReference[] optionalFeatures, 65 IFeature[] unconfiguredOptionalElements, 66 IVerificationListener verifier) { 67 super(site, feature); 68 IFeature[] installed = UpdateUtils.getInstalledFeatures(feature); 69 if (installed.length > 0) 70 this.oldFeature = installed[0]; 71 this.unconfiguredOptionalFeatures = unconfiguredOptionalElements; 72 this.optionalFeatures = optionalFeatures; 73 this.verifier = verifier; 74 } 75 76 public IFeatureReference[] getOptionalFeatures() { 77 return optionalFeatures; 78 } 79 80 public boolean execute(IProgressMonitor pm, IOperationListener listener) 81 throws CoreException { 82 83 boolean reinstall = false; 84 if (oldFeature != null 85 && feature.getVersionedIdentifier().equals( 86 oldFeature.getVersionedIdentifier())) 87 reinstall = true; 88 89 setOptionalFeatures(); 90 91 if (optionalFeatures == null) 92 targetSite.install(feature, verifier, pm); 93 else 94 targetSite.install(feature, optionalFeatures, verifier, pm); 95 96 if (!reinstall) { 97 98 if (oldFeature != null) { preserveOptionalState(); 100 101 boolean oldSuccess = unconfigure(oldFeature, null); if (!oldSuccess) { 103 IInstallConfiguration config = SiteManager.getLocalSite().getCurrentConfiguration(); 104 if (!UpdateUtils.isNestedChild(config, oldFeature)) { 105 String message = 107 NLS.bind(Messages.OperationsManager_error_old, (new String [] { oldFeature.getLabel() })); 108 IStatus status = 109 new Status( 110 IStatus.ERROR, 111 UpdateUtils.getPluginId(), 112 IStatus.OK, 113 message, 114 null); 115 throw new CoreException(status); 116 } 117 } 118 } 119 120 } 124 return true; 125 } 126 127 private void preserveOptionalState() { 128 if (unconfiguredOptionalFeatures == null) 129 return; 130 131 for (int i = 0; i < unconfiguredOptionalFeatures.length; i++) { 132 try { 133 IFeature localFeature = 135 UpdateUtils.getLocalFeature( 136 targetSite, 137 unconfiguredOptionalFeatures[i]); 138 if (localFeature != null) 139 targetSite.unconfigure(localFeature); 140 141 } catch (CoreException e) { 142 } 144 } 145 } 146 147 private void setOptionalFeatures() { 148 try { 149 if (optionalFeatures == null && UpdateUtils.hasOptionalFeatures(feature) ) { 151 JobRoot jobRoot = new JobRoot(this); 152 IInstallConfiguration config = SiteManager.getLocalSite().getCurrentConfiguration(); 153 HashSet set = new HashSet (); 154 boolean update = oldFeature != null; 155 boolean patch = UpdateUtils.isPatch(feature); 156 FeatureHierarchyElement[] elements = jobRoot.getElements(); 157 for (int i = 0; i < elements.length; i++) { 158 elements[i].addCheckedOptionalFeatures(update, patch, config, set); 159 } 160 optionalFeatures = new IFeatureReference[set.size()]; 161 set.toArray(optionalFeatures); 162 unconfiguredOptionalFeatures = jobRoot.getUnconfiguredOptionalFeatures(config, targetSite); 163 } 164 } catch (CoreException e) { 165 UpdateUtils.logException(e); 166 } 167 } 168 } 169 | Popular Tags |