1 11 package org.eclipse.pde.internal.ui.wizards.provisioner.update; 12 13 import java.io.File ; 14 import java.lang.reflect.InvocationTargetException ; 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.jface.operation.IRunnableWithProgress; 23 import org.eclipse.jface.wizard.Wizard; 24 import org.eclipse.pde.internal.ui.PDEPlugin; 25 import org.eclipse.pde.internal.ui.PDEPluginImages; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 import org.eclipse.pde.ui.IProvisionerWizard; 28 import org.eclipse.update.configuration.IConfiguredSite; 29 import org.eclipse.update.configuration.IInstallConfiguration; 30 import org.eclipse.update.configuration.ILocalSite; 31 import org.eclipse.update.core.IFeature; 32 import org.eclipse.update.core.IFeatureReference; 33 import org.eclipse.update.core.ISite; 34 import org.eclipse.update.core.SiteManager; 35 import org.eclipse.update.operations.IInstallFeatureOperation; 36 import org.eclipse.update.operations.IOperation; 37 import org.eclipse.update.operations.IOperationListener; 38 import org.eclipse.update.operations.OperationsManager; 39 40 public class UpdateSiteProvisionerWizard extends Wizard implements 41 IProvisionerWizard { 42 43 class UpdateSiteDownloader implements IRunnableWithProgress, IOperationListener { 44 45 private IUpdateSiteProvisionerEntry[] entries; 46 47 public UpdateSiteDownloader(IUpdateSiteProvisionerEntry[] entries) { 48 this.entries = entries; 49 } 50 51 public void run(IProgressMonitor monitor) 52 throws InvocationTargetException , InterruptedException { 53 54 try { 55 monitor.beginTask(PDEUIMessages.UpdateSiteDownloader_message, entries.length); 56 for(int i = 0; i < entries.length; i++) { 57 IUpdateSiteProvisionerEntry entry = entries[i]; 58 File sitePath = new File (entry.getInstallLocation()); 59 URL remoteSiteURL = new URL (entry.getSiteLocation()); 60 ISite site = SiteManager.getSite(sitePath.toURL(), null); 61 IConfiguredSite csite = site.getCurrentConfiguredSite(); 62 63 if(csite == null) { 64 ILocalSite localSite = SiteManager.getLocalSite(); 65 IInstallConfiguration config = localSite.getCurrentConfiguration(); 66 csite = config.createConfiguredSite(sitePath); 67 csite.verifyUpdatableStatus(); 68 71 } 72 73 ISite remoteSite = SiteManager.getSite(remoteSiteURL, null); 74 75 IFeatureReference[] references = 76 remoteSite.getFeatureReferences(); 77 for(int j = 0; j < references.length; j++) { 78 IFeatureReference reference = references[j]; 79 IFeature feature = reference.getFeature(null); 80 IInstallFeatureOperation operation = 81 OperationsManager.getOperationFactory().createInstallOperation(csite, feature, null, null, null); 82 operation.execute(monitor, this); 83 } 84 monitor.worked(1); 85 } 86 } catch (MalformedURLException e) { 87 PDEPlugin.log(e); 88 } catch (CoreException e) { 89 PDEPlugin.log(e); 90 } finally { 91 monitor.done(); 92 } 93 } 94 95 public boolean afterExecute(IOperation operation, Object data) { 96 return true; 97 } 98 99 public boolean beforeExecute(IOperation operation, Object data) { 100 return true; 101 } 102 103 } 104 105 private File [] fDirs = null; 106 private UpdateSiteProvisionerPage fPage; 107 108 public UpdateSiteProvisionerWizard() { 109 setDialogSettings(PDEPlugin.getDefault().getDialogSettings()); 110 setWindowTitle(PDEUIMessages.UpdateSiteProvisionerWizard_title); 111 setNeedsProgressMonitor(true); 112 setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWSITEPRJ_WIZ); 113 } 114 115 public void addPages() { 116 fPage = new UpdateSiteProvisionerPage("update site"); addPage(fPage); 118 } 119 120 public boolean performFinish() { 121 List dirs = new ArrayList (); 122 try { 123 IUpdateSiteProvisionerEntry[] entries = fPage.getEntries(); 124 getContainer().run(false, false, new UpdateSiteDownloader(entries)); 125 126 for(int i = 0; i < entries.length; i++) { 127 IUpdateSiteProvisionerEntry entry = entries[i]; 128 File file = new File (entry.getInstallLocation(), "eclipse"); if(file.exists()) 130 dirs.add(file); 131 } 132 fDirs = (File []) dirs.toArray(new File [dirs.size()]); 133 } catch (InvocationTargetException e) { 134 PDEPlugin.log(e); 135 } catch (InterruptedException e) { 136 return false; 137 } 138 return true; 139 } 140 141 public File [] getLocations() { 142 return fDirs; 143 } 144 145 } 146 | Popular Tags |