001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.provisioner.update;
011:
012: import java.io.File;
013: import java.lang.reflect.InvocationTargetException;
014: import java.net.MalformedURLException;
015: import java.net.URL;
016: import java.util.ArrayList;
017: import java.util.List;
018:
019: import org.eclipse.core.runtime.CoreException;
020: import org.eclipse.core.runtime.IProgressMonitor;
021: import org.eclipse.jface.operation.IRunnableWithProgress;
022: import org.eclipse.jface.wizard.Wizard;
023: import org.eclipse.pde.internal.ui.PDEPlugin;
024: import org.eclipse.pde.internal.ui.PDEPluginImages;
025: import org.eclipse.pde.internal.ui.PDEUIMessages;
026: import org.eclipse.pde.ui.IProvisionerWizard;
027: import org.eclipse.update.configuration.IConfiguredSite;
028: import org.eclipse.update.configuration.IInstallConfiguration;
029: import org.eclipse.update.configuration.ILocalSite;
030: import org.eclipse.update.core.IFeature;
031: import org.eclipse.update.core.IFeatureReference;
032: import org.eclipse.update.core.ISite;
033: import org.eclipse.update.core.SiteManager;
034: import org.eclipse.update.operations.IInstallFeatureOperation;
035: import org.eclipse.update.operations.IOperation;
036: import org.eclipse.update.operations.IOperationListener;
037: import org.eclipse.update.operations.OperationsManager;
038:
039: public class UpdateSiteProvisionerWizard extends Wizard implements
040: IProvisionerWizard {
041:
042: class UpdateSiteDownloader implements IRunnableWithProgress,
043: IOperationListener {
044:
045: private IUpdateSiteProvisionerEntry[] entries;
046:
047: public UpdateSiteDownloader(
048: IUpdateSiteProvisionerEntry[] entries) {
049: this .entries = entries;
050: }
051:
052: public void run(IProgressMonitor monitor)
053: throws InvocationTargetException, InterruptedException {
054:
055: try {
056: monitor.beginTask(
057: PDEUIMessages.UpdateSiteDownloader_message,
058: entries.length);
059: for (int i = 0; i < entries.length; i++) {
060: IUpdateSiteProvisionerEntry entry = entries[i];
061: File sitePath = new File(entry.getInstallLocation());
062: URL remoteSiteURL = new URL(entry.getSiteLocation());
063: ISite site = SiteManager.getSite(sitePath.toURL(),
064: null);
065: IConfiguredSite csite = site
066: .getCurrentConfiguredSite();
067:
068: if (csite == null) {
069: ILocalSite localSite = SiteManager
070: .getLocalSite();
071: IInstallConfiguration config = localSite
072: .getCurrentConfiguration();
073: csite = config.createConfiguredSite(sitePath);
074: csite.verifyUpdatableStatus();
075: // if (!status.isOK())
076: // System.out.println("status is not good");
077:
078: }
079:
080: ISite remoteSite = SiteManager.getSite(
081: remoteSiteURL, null);
082:
083: IFeatureReference[] references = remoteSite
084: .getFeatureReferences();
085: for (int j = 0; j < references.length; j++) {
086: IFeatureReference reference = references[j];
087: IFeature feature = reference.getFeature(null);
088: IInstallFeatureOperation operation = OperationsManager
089: .getOperationFactory()
090: .createInstallOperation(csite, feature,
091: null, null, null);
092: operation.execute(monitor, this );
093: }
094: monitor.worked(1);
095: }
096: } catch (MalformedURLException e) {
097: PDEPlugin.log(e);
098: } catch (CoreException e) {
099: PDEPlugin.log(e);
100: } finally {
101: monitor.done();
102: }
103: }
104:
105: public boolean afterExecute(IOperation operation, Object data) {
106: return true;
107: }
108:
109: public boolean beforeExecute(IOperation operation, Object data) {
110: return true;
111: }
112:
113: }
114:
115: private File[] fDirs = null;
116: private UpdateSiteProvisionerPage fPage;
117:
118: public UpdateSiteProvisionerWizard() {
119: setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
120: setWindowTitle(PDEUIMessages.UpdateSiteProvisionerWizard_title);
121: setNeedsProgressMonitor(true);
122: setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWSITEPRJ_WIZ);
123: }
124:
125: public void addPages() {
126: fPage = new UpdateSiteProvisionerPage("update site"); //$NON-NLS-1$
127: addPage(fPage);
128: }
129:
130: public boolean performFinish() {
131: List dirs = new ArrayList();
132: try {
133: IUpdateSiteProvisionerEntry[] entries = fPage.getEntries();
134: getContainer().run(false, false,
135: new UpdateSiteDownloader(entries));
136:
137: for (int i = 0; i < entries.length; i++) {
138: IUpdateSiteProvisionerEntry entry = entries[i];
139: File file = new File(entry.getInstallLocation(),
140: "eclipse"); //$NON-NLS-1$
141: if (file.exists())
142: dirs.add(file);
143: }
144: fDirs = (File[]) dirs.toArray(new File[dirs.size()]);
145: } catch (InvocationTargetException e) {
146: PDEPlugin.log(e);
147: } catch (InterruptedException e) {
148: return false;
149: }
150: return true;
151: }
152:
153: public File[] getLocations() {
154: return fDirs;
155: }
156:
157: }
|