1 11 package org.eclipse.update.internal.operations; 12 13 import java.lang.reflect.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.update.core.*; 17 import org.eclipse.update.core.model.*; 18 import org.eclipse.update.internal.core.*; 19 import org.eclipse.update.operations.*; 20 21 public class BatchInstallOperation 22 extends Operation 23 implements IBatchOperation { 24 25 protected IInstallFeatureOperation[] operations; 26 27 public BatchInstallOperation(IInstallFeatureOperation[] operations) { 28 super(); 29 this.operations = operations; 30 } 31 32 35 public IFeatureOperation[] getOperations() { 36 return operations; 37 } 38 39 42 public boolean execute(IProgressMonitor monitor, IOperationListener listener) throws CoreException, InvocationTargetException { 43 int installCount = 0; 44 45 if (operations == null || operations.length == 0) 46 return false; 47 48 IStatus status = OperationsManager.getValidator().validatePendingChanges(operations); 49 if (status != null && status.getCode() == IStatus.ERROR) { 50 throw new CoreException(status); 51 } 52 53 66 OperationsManager.setInProgress(true); 67 if (monitor == null) 68 monitor = new NullProgressMonitor(); 69 70 try { 71 if (listener != null) 72 listener.beforeExecute(this, null); 73 74 monitor.beginTask( 75 Messages.OperationsManager_installing, 76 operations.length); 77 for (int i = 0; i < operations.length; i++) { 78 SubProgressMonitor subMonitor = 79 new SubProgressMonitor( 80 monitor, 81 1, 82 SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); 83 84 operations[i].execute(subMonitor, listener); 85 OperationsManager.addPendingOperation(operations[i]); 86 87 operations[i].markProcessed(); 88 if (listener != null) 89 listener.afterExecute(operations[i], null); 90 91 installCount++; 93 } 94 return SiteManager.getLocalSite().save(); 95 } catch (InstallAbortedException e) { 96 if (installCount > 0) { 98 try { 99 SiteManager.getLocalSite().save(); 100 } catch (CoreException ce) { 101 UpdateUtils.logException(ce); 102 } 103 } 104 throw new InvocationTargetException(e); 105 } catch (CoreException e) { 106 if (installCount > 0) { 108 try { 109 SiteManager.getLocalSite().save(); 110 } catch (CoreException ce) { 111 UpdateUtils.logException(ce); 112 } 113 } 114 throw new InvocationTargetException(e); 115 } finally { 116 OperationsManager.setInProgress(false); 117 monitor.done(); 118 } 119 } 120 } 121 | Popular Tags |