|
Lines 11-24
Link Here
|
| 11 |
package org.eclipse.pde.internal.ui.samples; |
11 |
package org.eclipse.pde.internal.ui.samples; |
| 12 |
|
12 |
|
| 13 |
import java.lang.reflect.InvocationTargetException; |
13 |
import java.lang.reflect.InvocationTargetException; |
|
|
14 |
import java.net.URI; |
| 15 |
import java.net.URISyntaxException; |
| 16 |
import java.util.Collection; |
| 14 |
import java.util.Properties; |
17 |
import java.util.Properties; |
| 15 |
import org.eclipse.core.runtime.*; |
18 |
import org.eclipse.core.runtime.*; |
|
|
19 |
import org.eclipse.equinox.p2.core.IProvisioningAgent; |
| 20 |
import org.eclipse.equinox.p2.core.ProvisionException; |
| 21 |
import org.eclipse.equinox.p2.engine.IProfile; |
| 22 |
import org.eclipse.equinox.p2.engine.IProfileRegistry; |
| 23 |
import org.eclipse.equinox.p2.operations.InstallOperation; |
| 24 |
import org.eclipse.equinox.p2.operations.ProvisioningJob; |
| 25 |
import org.eclipse.equinox.p2.query.IQuery; |
| 26 |
import org.eclipse.equinox.p2.query.QueryUtil; |
| 27 |
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; |
| 28 |
import org.eclipse.equinox.p2.ui.ProvisioningUI; |
| 16 |
import org.eclipse.jface.action.Action; |
29 |
import org.eclipse.jface.action.Action; |
| 17 |
import org.eclipse.jface.dialogs.MessageDialog; |
30 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 18 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
31 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
| 19 |
import org.eclipse.jface.window.Window; |
32 |
import org.eclipse.jface.window.Window; |
| 20 |
import org.eclipse.jface.wizard.WizardDialog; |
33 |
import org.eclipse.jface.wizard.WizardDialog; |
| 21 |
import org.eclipse.pde.internal.core.util.VersionUtil; |
|
|
| 22 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
34 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
| 23 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
35 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
| 24 |
import org.eclipse.swt.widgets.Shell; |
36 |
import org.eclipse.swt.widgets.Shell; |
|
Lines 26-35
Link Here
|
| 26 |
import org.eclipse.ui.WorkbenchException; |
38 |
import org.eclipse.ui.WorkbenchException; |
| 27 |
import org.eclipse.ui.intro.IIntroSite; |
39 |
import org.eclipse.ui.intro.IIntroSite; |
| 28 |
import org.eclipse.ui.intro.config.*; |
40 |
import org.eclipse.ui.intro.config.*; |
| 29 |
import org.eclipse.update.configurator.ConfiguratorUtils; |
|
|
| 30 |
import org.eclipse.update.configurator.IPlatformConfiguration; |
| 31 |
import org.eclipse.update.standalone.InstallCommand; |
| 32 |
import org.osgi.framework.Version; |
| 33 |
|
41 |
|
| 34 |
public class ShowSampleAction extends Action implements IIntroAction { |
42 |
public class ShowSampleAction extends Action implements IIntroAction { |
| 35 |
private static final String SAMPLE_FEATURE_ID = "org.eclipse.sdk.samples"; //$NON-NLS-1$ |
43 |
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$ |
45 |
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; |
46 |
private String sampleId; |
| 39 |
|
47 |
|
|
|
48 |
private ProvisioningUI provUI; |
| 49 |
|
| 40 |
/** |
50 |
/** |
| 41 |
* |
51 |
* |
| 42 |
*/ |
52 |
*/ |
| 43 |
public ShowSampleAction() { |
53 |
public ShowSampleAction() { |
|
|
54 |
provUI = ProvisioningUI.getDefaultUI(); |
| 44 |
} |
55 |
} |
| 45 |
|
56 |
|
| 46 |
public void run(IIntroSite site, Properties params) { |
57 |
public void run(IIntroSite site, Properties params) { |
|
Lines 119-147
Link Here
|
| 119 |
return false; |
130 |
return false; |
| 120 |
} |
131 |
} |
| 121 |
|
132 |
|
|
|
133 |
/** |
| 134 |
* Returns <code>true</code> if the sample feature is already installed, and |
| 135 |
* <code>false</code> otherwise. |
| 136 |
*/ |
| 122 |
private boolean checkFeature() { |
137 |
private boolean checkFeature() { |
| 123 |
IPlatformConfiguration config = ConfiguratorUtils.getCurrentPlatformConfiguration(); |
138 |
IProvisioningAgent agent = provUI.getSession().getProvisioningAgent(); |
| 124 |
IPlatformConfiguration.IFeatureEntry[] features = config.getConfiguredFeatureEntries(); |
139 |
IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); |
| 125 |
Version sampleVersion = new Version(SAMPLE_FEATURE_VERSION); |
140 |
IProfile profile = registry.getProfile(provUI.getProfileId()); |
| 126 |
for (int i = 0; i < features.length; i++) { |
141 |
return !profile.query(getSampleFeatureQuery(), null).isEmpty(); |
| 127 |
String id = features[i].getFeatureIdentifier(); |
|
|
| 128 |
if (SAMPLE_FEATURE_ID.equals(id)) { |
| 129 |
String version = features[i].getFeatureVersion(); |
| 130 |
Version fversion = Version.parseVersion(version); |
| 131 |
if (VersionUtil.isCompatibleWith(fversion, sampleVersion)) |
| 132 |
return true; |
| 133 |
} |
| 134 |
} |
| 135 |
return false; |
| 136 |
} |
142 |
} |
| 137 |
|
143 |
|
|
|
144 |
IQuery getSampleFeatureQuery() { |
| 145 |
return QueryUtil.createIUQuery(SAMPLE_FEATURE_ID, org.eclipse.equinox.p2.metadata.Version.parseVersion(SAMPLE_FEATURE_VERSION)); |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Download the sample feature, returning <code>true</code> if the feature |
| 150 |
* was installed successfully, and <code>false</code> otherwise. |
| 151 |
*/ |
| 138 |
private boolean downloadFeature() { |
152 |
private boolean downloadFeature() { |
| 139 |
IRunnableWithProgress op = new IRunnableWithProgress() { |
153 |
IRunnableWithProgress op = new IRunnableWithProgress() { |
| 140 |
public void run(IProgressMonitor monitor) throws InvocationTargetException { |
154 |
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { |
| 141 |
try { |
155 |
try { |
| 142 |
InstallCommand command = new InstallCommand(SAMPLE_FEATURE_ID, SAMPLE_FEATURE_VERSION, UPDATE_SITE, null, "false"); //$NON-NLS-1$ |
156 |
SubMonitor sub = SubMonitor.convert(monitor, 100); |
| 143 |
command.run(monitor); |
157 |
InstallOperation operation = createInstallOperation(sub.newChild(10)); |
| 144 |
command.applyChangesNow(); |
158 |
operation.resolveModal(sub.newChild(20)); |
|
|
159 |
IStatus status = operation.getResolutionResult(); |
| 160 |
if (status.getSeverity() == IStatus.CANCEL) { |
| 161 |
throw new InterruptedException(); |
| 162 |
} else if (!(status.isOK() || status.getSeverity() == IStatus.INFO)) { |
| 163 |
throw new CoreException(status); |
| 164 |
} |
| 165 |
ProvisioningJob job = operation.getProvisioningJob(null); |
| 166 |
status = job.runModal(sub.newChild(70)); |
| 167 |
if (!(status.isOK() || status.getSeverity() == IStatus.INFO)) { |
| 168 |
throw new CoreException(status); |
| 169 |
} |
| 145 |
} catch (Exception e) { |
170 |
} catch (Exception e) { |
| 146 |
throw new InvocationTargetException(e); |
171 |
throw new InvocationTargetException(e); |
| 147 |
} |
172 |
} |
|
Lines 157-160
Link Here
|
| 157 |
} |
182 |
} |
| 158 |
return true; |
183 |
return true; |
| 159 |
} |
184 |
} |
|
|
185 |
|
| 186 |
/** |
| 187 |
* Returns a Collection<IInstallableUnit> of the installable units that contain the samples |
| 188 |
* to be installed. |
| 189 |
*/ |
| 190 |
protected Collection findSampleIUs(URI location, SubMonitor monitor) throws ProvisionException { |
| 191 |
IMetadataRepository repository = provUI.loadMetadataRepository(location, false, monitor.newChild(5)); |
| 192 |
return repository.query(getSampleFeatureQuery(), monitor.newChild(5)).toUnmodifiableSet(); |
| 193 |
} |
| 194 |
|
| 195 |
protected IProvisioningAgent getProvisioningAgent() { |
| 196 |
|
| 197 |
return null; |
| 198 |
} |
| 199 |
|
| 200 |
InstallOperation createInstallOperation(SubMonitor monitor) throws URISyntaxException, ProvisionException { |
| 201 |
URI repositoryLocation = new URI(UPDATE_SITE); |
| 202 |
Collection sampleIUs = findSampleIUs(repositoryLocation, monitor); |
| 203 |
URI[] repos = new URI[] {repositoryLocation}; |
| 204 |
InstallOperation operation = provUI.getInstallOperation(sampleIUs, repos); |
| 205 |
return operation; |
| 206 |
} |
| 160 |
} |
207 |
} |