org.eclipse.equinox.p2.operations.ProvisioningJob Java Examples

The following examples show how to use org.eclipse.equinox.p2.operations.ProvisioningJob. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: P2Util.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Download and install application updates.
 * 
 * @param agent
 * @param monitor
 * @return
 * @throws OperationCanceledException
 */
public static IStatus installUpdates(IProvisioningAgent agent, IProgressMonitor monitor)
	throws OperationCanceledException{
	ProvisioningSession session = new ProvisioningSession(agent);
	UpdateOperation operation = new UpdateOperation(session);
	SubMonitor sub = SubMonitor.convert(monitor, "Installing updates ...", 200);
	operation.resolveModal(sub.newChild(100));
	ProvisioningJob job = operation.getProvisioningJob(monitor);
	return job.runModal(sub.newChild(100));
}
 
Example #2
Source File: UpdateManager.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
/**
 * Install selected updates in to developer studio. Note: call
 * {@link #setSelectedUpdates(List) setSelectedUpdates} first.
 * 
 * @param monitor
 */
public void installSelectedUpdates(IProgressMonitor monitor) {
	SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_26, 2);
	URI[] repos = new URI[] { getDevStudioUpdateSite() };
	session = new ProvisioningSession(p2Agent);
	updateOperation = new UpdateOperation(session);
	updateOperation.getProvisioningContext().setArtifactRepositories(repos);
	updateOperation.getProvisioningContext().setMetadataRepositories(repos);

	updateOperation.setSelectedUpdates(selectedUpdates);
	IStatus status = updateOperation.resolveModal(progress.newChild(1));
	if (status.getSeverity() == IStatus.CANCEL) {
		throw new OperationCanceledException();
	} else if (status.getSeverity() == IStatus.ERROR) {
		String message = status.getChildren()[0].getMessage();
		UpdateMetaFileReaderJob.promptUserError(message, Messages.UpdateManager_27);
		log.error(Messages.UpdateManager_27 + message);
	} else {
		final ProvisioningJob provisioningJob = updateOperation.getProvisioningJob(progress.newChild(1));
		if (provisioningJob != null) {
			provisioningJob.addJobChangeListener(new JobChangeAdapter() {
				@Override
				public void done(IJobChangeEvent arg0) {
					Display.getDefault().syncExec(new Runnable() {
						@Override
						public void run() {
							boolean restart = MessageDialog.openQuestion(Display.getDefault().getActiveShell(),
									Messages.UpdateManager_28,
									Messages.UpdateManager_29 + Messages.UpdateManager_30);
							if (restart) {
								PlatformUI.getWorkbench().restart();
							}
						}
					});
				}
			});
			provisioningJob.schedule();
			Display.getDefault().syncExec(new Runnable() {
				@Override
				public void run() {
					try {
						PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
								.showView(IProgressConstants.PROGRESS_VIEW_ID);
					} catch (PartInitException e) {
						log.error(e);
					}
				}
			});
		} else {
			log.error(Messages.UpdateManager_31);
		}
	}
}
 
Example #3
Source File: UpdateManager.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
/**
 * Install selected features in to developer studio. Note: call
 * {@link #setSelectedFeaturesToInstall(List) setSelectedFeaturesToInstall}
 * first.
 * 
 * @param monitor
 */
public void installSelectedFeatures(IProgressMonitor monitor) {
	SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_32, 2);

	URI[] repos = new URI[] { getDevStudioReleaseSite() };
	session = new ProvisioningSession(p2Agent);
	installOperation = new InstallOperation(session, selectedFeatures);
	installOperation.getProvisioningContext().setArtifactRepositories(repos);
	installOperation.getProvisioningContext().setMetadataRepositories(repos);
	IStatus status = installOperation.resolveModal(progress.newChild(1));
	if (status.getSeverity() == IStatus.CANCEL || progress.isCanceled()) {
		throw new OperationCanceledException();
	} else if (status.getSeverity() == IStatus.ERROR) {
		String message = status.getChildren()[0].getMessage();
		log.error(Messages.UpdateManager_33 + message);
		UpdateMetaFileReaderJob.promptUserError(message, Messages.UpdateManager_33);
	} else {
		ProvisioningJob provisioningJob = installOperation.getProvisioningJob(progress.newChild(1));
		if (provisioningJob != null) {
			provisioningJob.addJobChangeListener(new JobChangeAdapter() {
				@Override
				public void done(IJobChangeEvent arg0) {
					Display.getDefault().syncExec(new Runnable() {
						@Override
						public void run() {
							boolean restart = MessageDialog.openQuestion(Display.getDefault().getActiveShell(),
									Messages.UpdateManager_34,
									Messages.UpdateManager_35 + Messages.UpdateManager_36);
							if (restart) {
								PlatformUI.getWorkbench().restart();
							}
						}
					});
				}
			});
			provisioningJob.schedule();
			Display.getDefault().syncExec(new Runnable() {
				@Override
				public void run() {
					try {
						PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
								.showView(IProgressConstants.PROGRESS_VIEW_ID);
					} catch (PartInitException e) {
						log.error(e);
					}
				}
			});
		} else {
			log.error(Messages.UpdateManager_37);
		}
	}
}