|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 10-35
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.pde.internal.ui.samples; |
11 |
package org.eclipse.pde.internal.ui.samples; |
| 12 |
|
12 |
|
|
|
13 |
import java.io.IOException; |
| 13 |
import java.lang.reflect.InvocationTargetException; |
14 |
import java.lang.reflect.InvocationTargetException; |
|
|
15 |
import java.net.URI; |
| 16 |
import java.net.URISyntaxException; |
| 17 |
import java.util.Collection; |
| 14 |
import java.util.Properties; |
18 |
import java.util.Properties; |
| 15 |
import org.eclipse.core.runtime.*; |
19 |
import org.eclipse.core.runtime.*; |
|
|
20 |
import org.eclipse.equinox.internal.provisional.configurator.Configurator; |
| 21 |
import org.eclipse.equinox.p2.core.IProvisioningAgent; |
| 22 |
import org.eclipse.equinox.p2.core.ProvisionException; |
| 23 |
import org.eclipse.equinox.p2.engine.IProfile; |
| 24 |
import org.eclipse.equinox.p2.engine.IProfileRegistry; |
| 25 |
import org.eclipse.equinox.p2.operations.InstallOperation; |
| 26 |
import org.eclipse.equinox.p2.operations.ProvisioningJob; |
| 27 |
import org.eclipse.equinox.p2.query.IQuery; |
| 28 |
import org.eclipse.equinox.p2.query.QueryUtil; |
| 29 |
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; |
| 30 |
import org.eclipse.equinox.p2.ui.ProvisioningUI; |
| 16 |
import org.eclipse.jface.action.Action; |
31 |
import org.eclipse.jface.action.Action; |
| 17 |
import org.eclipse.jface.dialogs.MessageDialog; |
32 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 18 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
33 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
| 19 |
import org.eclipse.jface.window.Window; |
34 |
import org.eclipse.jface.window.Window; |
| 20 |
import org.eclipse.jface.wizard.WizardDialog; |
35 |
import org.eclipse.jface.wizard.WizardDialog; |
| 21 |
import org.eclipse.pde.internal.core.util.VersionUtil; |
36 |
import org.eclipse.pde.internal.ui.*; |
| 22 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
|
|
| 23 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
| 24 |
import org.eclipse.swt.widgets.Shell; |
37 |
import org.eclipse.swt.widgets.Shell; |
| 25 |
import org.eclipse.ui.PlatformUI; |
38 |
import org.eclipse.ui.PlatformUI; |
| 26 |
import org.eclipse.ui.WorkbenchException; |
39 |
import org.eclipse.ui.WorkbenchException; |
| 27 |
import org.eclipse.ui.intro.IIntroSite; |
40 |
import org.eclipse.ui.intro.IIntroSite; |
| 28 |
import org.eclipse.ui.intro.config.*; |
41 |
import org.eclipse.ui.intro.config.*; |
| 29 |
import org.eclipse.update.configurator.ConfiguratorUtils; |
42 |
import org.osgi.framework.BundleContext; |
| 30 |
import org.eclipse.update.configurator.IPlatformConfiguration; |
43 |
import org.osgi.framework.ServiceReference; |
| 31 |
import org.eclipse.update.standalone.InstallCommand; |
|
|
| 32 |
import org.osgi.framework.Version; |
| 33 |
|
44 |
|
| 34 |
public class ShowSampleAction extends Action implements IIntroAction { |
45 |
public class ShowSampleAction extends Action implements IIntroAction { |
| 35 |
private static final String SAMPLE_FEATURE_ID = "org.eclipse.sdk.samples"; //$NON-NLS-1$ |
46 |
private static final String SAMPLE_FEATURE_ID = "org.eclipse.sdk.samples"; //$NON-NLS-1$ |
|
Lines 37-46
Link Here
|
| 37 |
private static final String UPDATE_SITE = "http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/pde-ui-home/samples/"; //$NON-NLS-1$ |
48 |
private static final String UPDATE_SITE = "http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/pde-ui-home/samples/"; //$NON-NLS-1$ |
| 38 |
private String sampleId; |
49 |
private String sampleId; |
| 39 |
|
50 |
|
|
|
51 |
private ProvisioningUI provUI; |
| 52 |
|
| 40 |
/** |
53 |
/** |
| 41 |
* |
54 |
* |
| 42 |
*/ |
55 |
*/ |
| 43 |
public ShowSampleAction() { |
56 |
public ShowSampleAction() { |
|
|
57 |
provUI = ProvisioningUI.getDefaultUI(); |
| 44 |
} |
58 |
} |
| 45 |
|
59 |
|
| 46 |
public void run(IIntroSite site, Properties params) { |
60 |
public void run(IIntroSite site, Properties params) { |
|
Lines 109-116
Link Here
|
| 109 |
private void enableActivities(IConfigurationElement sample) { |
123 |
private void enableActivities(IConfigurationElement sample) { |
| 110 |
} |
124 |
} |
| 111 |
|
125 |
|
|
|
126 |
/** |
| 127 |
* Ensure the sample feature is present. If not present, attempt to install it. |
| 128 |
* |
| 129 |
* @return <code>true</code> if the sample features are present, and |
| 130 |
* <code>false</code> otherwise. |
| 131 |
*/ |
| 112 |
private boolean ensureSampleFeaturePresent() { |
132 |
private boolean ensureSampleFeaturePresent() { |
| 113 |
if (checkFeature()) |
133 |
IProfile profile = getProfile(); |
|
|
134 |
if (profile == null) |
| 135 |
return false; |
| 136 |
if (checkFeature(profile)) |
| 114 |
return true; |
137 |
return true; |
| 115 |
// the feature is not present - ask to download |
138 |
// the feature is not present - ask to download |
| 116 |
if (MessageDialog.openQuestion(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.ShowSampleAction_msgTitle, PDEUIMessages.ShowSampleAction_msgDesc)) { |
139 |
if (MessageDialog.openQuestion(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.ShowSampleAction_msgTitle, PDEUIMessages.ShowSampleAction_msgDesc)) { |
|
Lines 119-147
Link Here
|
| 119 |
return false; |
142 |
return false; |
| 120 |
} |
143 |
} |
| 121 |
|
144 |
|
| 122 |
private boolean checkFeature() { |
145 |
private boolean checkFeature(IProfile profile) { |
| 123 |
IPlatformConfiguration config = ConfiguratorUtils.getCurrentPlatformConfiguration(); |
146 |
return !profile.query(getSampleFeatureQuery(), null).isEmpty(); |
| 124 |
IPlatformConfiguration.IFeatureEntry[] features = config.getConfiguredFeatureEntries(); |
147 |
} |
| 125 |
Version sampleVersion = new Version(SAMPLE_FEATURE_VERSION); |
148 |
|
| 126 |
for (int i = 0; i < features.length; i++) { |
149 |
/** |
| 127 |
String id = features[i].getFeatureIdentifier(); |
150 |
* Returns <code>true</code> if the sample feature is already installed, or if |
| 128 |
if (SAMPLE_FEATURE_ID.equals(id)) { |
151 |
* it won't be possible to install the feature (required services are missing). Returns |
| 129 |
String version = features[i].getFeatureVersion(); |
152 |
* <code>false</code> if the features are missing and should be installed. |
| 130 |
Version fversion = Version.parseVersion(version); |
153 |
*/ |
| 131 |
if (VersionUtil.isCompatibleWith(fversion, sampleVersion)) |
154 |
private IProfile getProfile() { |
| 132 |
return true; |
155 |
IProvisioningAgent agent = provUI.getSession().getProvisioningAgent(); |
| 133 |
} |
156 |
if (agent == null) |
| 134 |
} |
157 |
return null; |
| 135 |
return false; |
158 |
IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); |
|
|
159 |
if (registry == null) |
| 160 |
return null; |
| 161 |
return registry.getProfile(provUI.getProfileId()); |
| 162 |
} |
| 163 |
|
| 164 |
IQuery getSampleFeatureQuery() { |
| 165 |
return QueryUtil.createIUQuery(SAMPLE_FEATURE_ID, org.eclipse.equinox.p2.metadata.Version.parseVersion(SAMPLE_FEATURE_VERSION)); |
| 136 |
} |
166 |
} |
| 137 |
|
167 |
|
|
|
168 |
/** |
| 169 |
* Download the sample feature, returning <code>true</code> if the feature |
| 170 |
* was installed successfully, and <code>false</code> otherwise. |
| 171 |
*/ |
| 138 |
private boolean downloadFeature() { |
172 |
private boolean downloadFeature() { |
| 139 |
IRunnableWithProgress op = new IRunnableWithProgress() { |
173 |
IRunnableWithProgress op = new IRunnableWithProgress() { |
| 140 |
public void run(IProgressMonitor monitor) throws InvocationTargetException { |
174 |
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { |
| 141 |
try { |
175 |
try { |
| 142 |
InstallCommand command = new InstallCommand(SAMPLE_FEATURE_ID, SAMPLE_FEATURE_VERSION, UPDATE_SITE, null, "false"); //$NON-NLS-1$ |
176 |
SubMonitor sub = SubMonitor.convert(monitor, PDEUIMessages.ShowSampleAction_installing, 100); |
| 143 |
command.run(monitor); |
177 |
InstallOperation operation = createInstallOperation(sub.newChild(10)); |
| 144 |
command.applyChangesNow(); |
178 |
operation.resolveModal(sub.newChild(20)); |
|
|
179 |
IStatus status = operation.getResolutionResult(); |
| 180 |
if (status.getSeverity() == IStatus.CANCEL) { |
| 181 |
throw new InterruptedException(); |
| 182 |
} else if (!(status.isOK() || status.getSeverity() == IStatus.INFO)) { |
| 183 |
throw new CoreException(status); |
| 184 |
} |
| 185 |
ProvisioningJob job = operation.getProvisioningJob(null); |
| 186 |
status = job.runModal(sub.newChild(70)); |
| 187 |
if (!(status.isOK() || status.getSeverity() == IStatus.INFO)) { |
| 188 |
throw new CoreException(status); |
| 189 |
} |
| 190 |
applyConfiguration(); |
| 145 |
} catch (Exception e) { |
191 |
} catch (Exception e) { |
| 146 |
throw new InvocationTargetException(e); |
192 |
throw new InvocationTargetException(e); |
| 147 |
} |
193 |
} |
|
Lines 157-160
Link Here
|
| 157 |
} |
203 |
} |
| 158 |
return true; |
204 |
return true; |
| 159 |
} |
205 |
} |
|
|
206 |
|
| 207 |
/** |
| 208 |
* Returns a Collection<IInstallableUnit> of the installable units that contain the samples |
| 209 |
* to be installed. |
| 210 |
*/ |
| 211 |
protected Collection findSampleIUs(URI location, SubMonitor monitor) throws ProvisionException { |
| 212 |
IMetadataRepository repository = provUI.loadMetadataRepository(location, false, monitor.newChild(5)); |
| 213 |
return repository.query(getSampleFeatureQuery(), monitor.newChild(5)).toUnmodifiableSet(); |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Creates the operation that will install the sample features in the running platform. |
| 218 |
*/ |
| 219 |
InstallOperation createInstallOperation(SubMonitor monitor) throws URISyntaxException, ProvisionException { |
| 220 |
URI repositoryLocation = new URI(UPDATE_SITE); |
| 221 |
Collection sampleIUs = findSampleIUs(repositoryLocation, monitor); |
| 222 |
URI[] repos = new URI[] {repositoryLocation}; |
| 223 |
InstallOperation operation = provUI.getInstallOperation(sampleIUs, repos); |
| 224 |
return operation; |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Apply the profile changes to the currently running configuration. |
| 229 |
*/ |
| 230 |
void applyConfiguration() throws CoreException { |
| 231 |
BundleContext context = PDEPlugin.getDefault().getBundle().getBundleContext(); |
| 232 |
ServiceReference reference = context.getServiceReference(Configurator.class.getName()); |
| 233 |
Configurator configurator = (Configurator) context.getService(reference); |
| 234 |
try { |
| 235 |
configurator.applyConfiguration(); |
| 236 |
} catch (IOException e) { |
| 237 |
throw new CoreException(new Status(IStatus.ERROR, IPDEUIConstants.PLUGIN_ID, "Unexpected failure applying configuration", e)); //$NON-NLS-1$ |
| 238 |
} finally { |
| 239 |
context.ungetService(reference); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 160 |
} |
243 |
} |