use of org.eclipse.equinox.p2.engine.IProvisioningPlan in project webtools.servertools by eclipse.
the class ExtensionWizardPage method handleSelection.
protected void handleSelection(Extension sel) {
extension = sel;
if (extension == null)
licensePage.updateForPlan(new IInstallableUnit[0], null);
else {
try {
getContainer().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final IProvisioningPlan plan = extension.getProvisioningPlan(true, monitor);
if (plan != null && plan.getStatus().isOK()) {
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
licensePage.updateForPlan(extension.getIUs(), plan);
nextPage = licensePage;
((ExtensionWizard) getWizard()).setSecondPage(nextPage);
}
});
} else {
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
errorPage.setStatus(plan.getStatus());
}
});
nextPage = errorPage;
((ExtensionWizard) getWizard()).setSecondPage(nextPage);
}
monitor.done();
}
});
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Error verifying license", e);
}
}
setPageComplete(extension != null);
}
use of org.eclipse.equinox.p2.engine.IProvisioningPlan in project webtools.servertools by eclipse.
the class ExtensionUtility method refreshExtension.
public static ErrorMessage refreshExtension(final String extensionId, String uri, IProgressMonitor monitor) {
ErrorMessage errorMessageObj = null;
if (extensionMap.get(extensionId) != null) {
if (extensionMapError.get(extensionId) == null)
return null;
}
ExtensionUpdateSite site = new ExtensionUpdateSite(uri, null, null);
try {
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask("", 1000);
monitor.subTask(Messages.fetchingRepository);
IProgressMonitor subMonitor = ProgressUtil.getSubMonitorFor(monitor, 500);
List<IServerExtension> list = site.getExtensions(subMonitor);
monitor.worked(500);
if (monitor.isCanceled())
return null;
boolean firstIteration = true;
for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
IServerExtension iServerExtension = (IServerExtension) iterator.next();
if (iServerExtension.getId().equals(extensionId)) {
Extension extension = (Extension) iServerExtension;
if (extensionMap.get(extensionId) != null && !firstIteration && extension.getVersion().compareTo(((Extension) extensionMap.get(extensionId)).getVersion()) <= 0)
continue;
subMonitor = ProgressUtil.getSubMonitorFor(monitor, 500);
monitor.subTask(Messages.validateInstall);
final IProvisioningPlan plan = extension.getProvisioningPlan(true, subMonitor);
if (monitor.isCanceled())
return null;
if (plan == null || !plan.getStatus().isOK()) {
if (plan != null) {
StringBuffer detailedErrorMsg = new StringBuffer();
IStatus[] statusList = plan.getStatus().getChildren();
for (int i = 0; i < statusList.length; i++) {
detailedErrorMsg.append(statusList[i].getMessage());
}
errorMessageObj = new ErrorMessage(Messages.validateInstallError, detailedErrorMsg.toString());
Activator.getDefault().getLog().log(new Status(IStatus.INFO, Activator.PLUGIN_ID, detailedErrorMsg.toString(), plan.getStatus().getException()));
} else {
errorMessageObj = new ErrorMessage(Messages.validateInstallError, Messages.fetchingRepositoryFailure);
Activator.getDefault().getLog().log(new Status(IStatus.INFO, Activator.PLUGIN_ID, "Could not get the provisioning plan", null));
}
}
extensionMap.put(extensionId, extension);
extensionMapError.put(extensionId, errorMessageObj);
firstIteration = false;
}
}
return errorMessageObj;
} catch (CoreException e) {
Trace.trace(Trace.SEVERE, "Could not refresh server adapter node.");
return new ErrorMessage(Messages.fetchingRepositoryFailure, e.getLocalizedMessage());
}
}
use of org.eclipse.equinox.p2.engine.IProvisioningPlan in project webtools.servertools by eclipse.
the class Extension method getProvisioningPlan.
public IProvisioningPlan getProvisioningPlan(boolean explain, IProgressMonitor monitor) {
if (plan != null)
return plan;
// long time = System.currentTimeMillis();
BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();
IPlanner planner = (IPlanner) ExtensionUtility.getService(bundleContext, IPlanner.SERVICE_NAME);
IProfileRegistry profileRegistry = (IProfileRegistry) ExtensionUtility.getService(bundleContext, IProfileRegistry.SERVICE_NAME);
IProfile profile = profileRegistry.getProfile(IProfileRegistry.SELF);
IProfile[] profiles = profileRegistry.getProfiles();
if (profile == null) {
// it happens sometime , possibility of bug in profileRegistry
for (int i = 0; i < profiles.length; i++) {
if (profiles[i].getProfileId().equals(IProfileRegistry.SELF)) {
profile = profiles[i];
break;
}
}
}
if (profile == null)
return null;
IProfileChangeRequest pcr = planner.createChangeRequest(profile);
pcr.add(iu);
IProvisioningAgent agent = ExtensionUtility.getAgent(bundleContext);
if (agent == null) {
return null;
}
// Get all the known repositories when installing the server adapter.
// If these repositories are not added, it can cause install problems if
// the server adapter relies on the list of available software install sites
URI[] knownRepositories = null;
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
if (manager != null) {
manager.addRepository(uri);
// Note: IRepositoryManager.REPOSITORIES_ALL will exclude the deselected update sites
knownRepositories = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
// A fall back in case known repositories returns null
if (knownRepositories == null) {
knownRepositories = new URI[] { uri };
}
} else {
knownRepositories = new URI[] { uri };
}
provContext = new ProvisioningContext(agent);
// Add the new URLs to both the Metadata and Artifact repositories.
// Note: only the IInstallableUnit that is passed into this class will be installed
// as a server adapter. For example, if multiple update site URLs for discovery server
// adapters are present, they will not be installed.
provContext.setMetadataRepositories(knownRepositories);
provContext.setArtifactRepositories(knownRepositories);
if (!explain)
// $NON-NLS-1$ //$NON-NLS-2$
provContext.setProperty("org.eclipse.equinox.p2.director.explain", "false");
// $NON-NLS-1$
provContext.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, "true");
plan = planner.getProvisioningPlan(pcr, provContext, monitor);
// System.out.println("Time: " + (System.currentTimeMillis() - time)); // TODO
return plan;
}
Aggregations