From 31fd54c6be015b77bab270f9f01c4bc1257b033a Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 30 Sep 2022 14:23:54 +0200 Subject: [PATCH] adds update functionality for SCViewer --- .launch/Build SCViewer.launch | 4 + .launch/Set SCViewer version.launch | 4 + .../Application.e4xmi | 2 +- .../application/handlers/UpdateHandler.java | 134 ++++++++++++++++-- .../scviewer.product | 4 +- .../com.minres.scviewer.target.target | 4 +- .../category.xml | 12 ++ 7 files changed, 151 insertions(+), 13 deletions(-) diff --git a/.launch/Build SCViewer.launch b/.launch/Build SCViewer.launch index 267d93e..6f30297 100644 --- a/.launch/Build SCViewer.launch +++ b/.launch/Build SCViewer.launch @@ -1,5 +1,6 @@ + @@ -12,6 +13,9 @@ + + + diff --git a/.launch/Set SCViewer version.launch b/.launch/Set SCViewer version.launch index cf907bd..d293261 100644 --- a/.launch/Set SCViewer version.launch +++ b/.launch/Set SCViewer version.launch @@ -1,5 +1,6 @@ + @@ -15,6 +16,9 @@ + + + diff --git a/plugins/com.minres.scviewer.e4.application/Application.e4xmi b/plugins/com.minres.scviewer.e4.application/Application.e4xmi index b4b56a0..f896b0f 100644 --- a/plugins/com.minres.scviewer.e4.application/Application.e4xmi +++ b/plugins/com.minres.scviewer.e4.application/Application.e4xmi @@ -56,7 +56,7 @@ - + diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/UpdateHandler.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/UpdateHandler.java index 1c26b8d..077ac14 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/UpdateHandler.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/UpdateHandler.java @@ -1,24 +1,140 @@ - package com.minres.scviewer.e4.application.handlers; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.net.URISyntaxException; + +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.di.UISynchronize; import org.eclipse.e4.ui.workbench.IWorkbench; import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.operations.ProvisioningJob; import org.eclipse.equinox.p2.operations.ProvisioningSession; import org.eclipse.equinox.p2.operations.UpdateOperation; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; public class UpdateHandler { + + boolean cancelled = false; + @Execute - public void execute(IProvisioningAgent agent, UISynchronize synchronize, IWorkbench workbench) { - ProvisioningSession session = new ProvisioningSession(agent); - UpdateOperation operation = new UpdateOperation(session); - IStatus status = operation.resolveModal(null); - if(status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) { - MessageDialog.openInformation(null, "Information", "Nothing to update"); + public void execute(IProvisioningAgent agent, UISynchronize sync, IWorkbench workbench) { + // update using a progress monitor + IRunnableWithProgress runnable = new IRunnableWithProgress() { + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + update(agent, monitor, sync, workbench); + } + }; + try { + new ProgressMonitorDialog(null).run(true, true, runnable); + } catch (InvocationTargetException | InterruptedException e) { + e.printStackTrace(); } } - -} \ No newline at end of file + + private IStatus update(IProvisioningAgent agent, IProgressMonitor monitor, UISynchronize sync, + IWorkbench workbench) { + ProvisioningSession session = new ProvisioningSession(agent); + // update the whole running profile, otherwise specify IUs + UpdateOperation operation = new UpdateOperation(session); + try { + operation.getProvisioningContext().setArtifactRepositories(new URI("http://https://minres.github.io/SCViewer/repository")); + operation.getProvisioningContext().setMetadataRepositories(new URI("http://https://minres.github.io/SCViewer/repository")); + } catch (URISyntaxException e) {} + SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200); + // check if updates are available + IStatus status = operation.resolveModal(sub.newChild(100)); + if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) { + showMessage(sync, "Nothing to update"); + return Status.CANCEL_STATUS; + } else { + ProvisioningJob provisioningJob = operation.getProvisioningJob(sub.newChild(100)); + if (provisioningJob != null) { + sync.syncExec(new Runnable() { + @Override + public void run() { + boolean performUpdate = MessageDialog.openQuestion(null, "Updates available", + "There are updates available. Do you want to install them now?"); + if (performUpdate) { + provisioningJob.addJobChangeListener(new JobChangeAdapter() { + @Override + public void done(IJobChangeEvent event) { + if (event.getResult().isOK()) { + sync.syncExec(new Runnable() { + + @Override + public void run() { + boolean restart = MessageDialog.openQuestion(null, + "Updates installed, restart?", + "Updates have been installed successfully, do you want to restart?"); + if (restart) { + workbench.restart(); + } + } + }); + } else { + showError(sync, event.getResult().getMessage()); + cancelled = true; + } + } + }); + // since we switched to the UI thread for interacting with the user + // we need to schedule the provisioning thread, otherwise it would + // be executed also in the UI thread and not in a background thread + provisioningJob.schedule(); + } else { + cancelled = true; + } + } + }); + } else { + if (operation.hasResolved()) { + showError(sync, "Couldn't get provisioning job: " + operation.getResolutionResult()); + } else { + showError(sync, "Couldn't resolve provisioning job"); + } + cancelled = true; + } + } + if (cancelled) { + // reset cancelled flag + cancelled = false; + return Status.CANCEL_STATUS; + } + return Status.OK_STATUS; + } + + private void showMessage(UISynchronize sync, final String message) { + // as the provision needs to be executed in a background thread + // we need to ensure that the message dialog is executed in + // the UI thread + sync.syncExec(new Runnable() { + + @Override + public void run() { + MessageDialog.openInformation(null, "Information", message); + } + }); + } + + private void showError(UISynchronize sync, final String message) { + // as the provision needs to be executed in a background thread + // we need to ensure that the message dialog is executed in + // the UI thread + sync.syncExec(new Runnable() { + @Override + public void run() { + MessageDialog.openError(null, "Error", message); + } + }); + } +} diff --git a/products/com.minres.scviewer.e4.product/scviewer.product b/products/com.minres.scviewer.e4.product/scviewer.product index 63caa8e..062b842 100644 --- a/products/com.minres.scviewer.e4.product/scviewer.product +++ b/products/com.minres.scviewer.e4.product/scviewer.product @@ -1,7 +1,7 @@ - + @@ -63,7 +63,7 @@ - + diff --git a/releng/com.minres.scviewer.target/com.minres.scviewer.target.target b/releng/com.minres.scviewer.target/com.minres.scviewer.target.target index e77999c..d36c8ee 100644 --- a/releng/com.minres.scviewer.target/com.minres.scviewer.target.target +++ b/releng/com.minres.scviewer.target/com.minres.scviewer.target.target @@ -12,6 +12,8 @@ + + @@ -26,7 +28,7 @@ - + diff --git a/releng/com.minres.scviewer.updateSite/category.xml b/releng/com.minres.scviewer.updateSite/category.xml index 204beb5..9eaf4bb 100644 --- a/releng/com.minres.scviewer.updateSite/category.xml +++ b/releng/com.minres.scviewer.updateSite/category.xml @@ -18,6 +18,15 @@ + + + + + + + + + Viewer for transaction recording outputs of the SystemC Verification (SCV) library @@ -29,4 +38,7 @@ + + +