use of org.eclipse.equinox.p2.operations.ProvisioningSession in project knime-core by knime.
the class InstallMissingNodesJob method findExtensions.
private IStatus findExtensions(final IProgressMonitor monitor, final List<NodeAndBundleInformation> missingNodes, final Set<IInstallableUnit> featuresToInstall) {
ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
Bundle myself = FrameworkUtil.getBundle(getClass());
try {
IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) session.getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
for (URI uri : metadataManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)) {
if (!missingNodes.isEmpty()) {
IMetadataRepository repo = metadataManager.loadRepository(uri, monitor);
for (Iterator<NodeAndBundleInformation> it = missingNodes.iterator(); it.hasNext(); ) {
NodeAndBundleInformation info = it.next();
if (searchInRepository(repo, info, metadataManager, monitor, featuresToInstall)) {
it.remove();
}
}
}
}
return Status.OK_STATUS;
} catch (ProvisionException ex) {
NodeLogger.getLogger(getClass()).error("Could not create provisioning agent: " + ex.getMessage(), ex);
return new Status(IStatus.ERROR, myself.getSymbolicName(), "Could not query updates site for missing extensions", ex);
}
}
use of org.eclipse.equinox.p2.operations.ProvisioningSession in project knime-core by knime.
the class KNIMEApplication method checkForUpdates.
private boolean checkForUpdates() {
final IPreferenceStore prefStore = ProductPlugin.getDefault().getPreferenceStore();
if (prefStore.getBoolean(JUSTUPDATED)) {
prefStore.setValue(JUSTUPDATED, false);
return false;
}
final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
if (provUI.getRepositoryTracker() == null) {
LogHelper.log(new Status(IStatus.WARNING, ProductPlugin.getDefault().getBundle().getSymbolicName(), "Updating is not possible of KNIME is started from " + "within the IDE."));
return false;
}
final IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(ProductPlugin.getDefault().getBundle().getBundleContext(), IProvisioningAgent.SERVICE_NAME);
if (agent == null) {
LogHelper.log(new Status(IStatus.ERROR, ProductPlugin.getDefault().getBundle().getSymbolicName(), "No provisioning agent found. This application is " + "not set up for updates."));
}
final MutableBoolean restart = new MutableBoolean(false);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
ProvisioningSession session = new ProvisioningSession(agent);
UpdateOperation operation = new UpdateOperation(session);
SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200);
IStatus status = operation.resolveModal(sub.newChild(100));
if (status.getSeverity() == IStatus.CANCEL) {
throw new OperationCanceledException();
} else if (status.getSeverity() != IStatus.ERROR) {
ProvisioningJob job = operation.getProvisioningJob(null);
status = job.runModal(sub.newChild(100));
if (status.getSeverity() == IStatus.CANCEL) {
throw new OperationCanceledException();
}
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
// ok, just proceed
LogHelper.log(new Status(IStatus.INFO, ProductPlugin.getDefault().getBundle().getSymbolicName(), "No updates found."));
} else if (status.getSeverity() != IStatus.ERROR) {
prefStore.setValue(JUSTUPDATED, true);
restart.setValue(true);
} else {
LogHelper.log(status);
}
} else {
LogHelper.log(status);
}
}
};
try {
new ProgressMonitorDialog(null).run(true, true, runnable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
}
return restart.booleanValue();
}
Aggregations