adds update functionality for SCViewer

This commit is contained in:
Eyck Jentzsch 2022-09-30 14:23:54 +02:00
parent a1094ff870
commit 31fd54c6be
7 changed files with 151 additions and 13 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType"> <launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<intAttribute key="M2_COLORS" value="0"/>
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/> <booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
<stringAttribute key="M2_GOALS" value="package"/> <stringAttribute key="M2_GOALS" value="package"/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/> <booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
@ -12,6 +13,9 @@
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/> <booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/> <stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/> <booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc:com.minres.scviewer.parent}"/> <stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc:com.minres.scviewer.parent}"/>
</launchConfiguration> </launchConfiguration>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType"> <launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<intAttribute key="M2_COLORS" value="0"/>
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/> <booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
<stringAttribute key="M2_GOALS" value="tycho-versions:set-version tycho-versions:update-pom"/> <stringAttribute key="M2_GOALS" value="tycho-versions:set-version tycho-versions:update-pom"/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/> <booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
@ -15,6 +16,9 @@
<stringAttribute key="M2_USER_SETTINGS" value=""/> <stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/> <booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<stringAttribute key="bad_container_name" value="/com.minres.scviewer.parent/.launch"/> <stringAttribute key="bad_container_name" value="/com.minres.scviewer.parent/.launch"/>
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc:com.minres.scviewer.parent}"/> <stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc:com.minres.scviewer.parent}"/>
</launchConfiguration> </launchConfiguration>

View File

@ -56,7 +56,7 @@
<children xsi:type="menu:HandledMenuItem" xmi:id="_JTXBgYl_EeWxJ_wPkM6yGQ" elementId="" label="Preferences" command="_AxH6sIl_EeWxJ_wPkM6yGQ"/> <children xsi:type="menu:HandledMenuItem" xmi:id="_JTXBgYl_EeWxJ_wPkM6yGQ" elementId="" label="Preferences" command="_AxH6sIl_EeWxJ_wPkM6yGQ"/>
</children> </children>
<children xsi:type="menu:Menu" xmi:id="_95QGxHNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.menu.help" label="Help"> <children xsi:type="menu:Menu" xmi:id="_95QGxHNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.menu.help" label="Help">
<children xsi:type="menu:HandledMenuItem" xmi:id="_UQRi0B07EeuiP60JNw0iiA" elementId="com.minres.scviewer.e4.application.handledmenuitem.checkforupdate" visible="false" label="Check for Update" enabled="false" command="_-9ED4B06EeuiP60JNw0iiA"/> <children xsi:type="menu:HandledMenuItem" xmi:id="_UQRi0B07EeuiP60JNw0iiA" elementId="com.minres.scviewer.e4.application.handledmenuitem.checkforupdate" label="Check for Update" enabled="false" command="_-9ED4B06EeuiP60JNw0iiA"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_qJS-MHCOEeyub8CfGE1sGA" label="Help Content" command="_RdUMoHCOEeyub8CfGE1sGA"/> <children xsi:type="menu:HandledMenuItem" xmi:id="_qJS-MHCOEeyub8CfGE1sGA" label="Help Content" command="_RdUMoHCOEeyub8CfGE1sGA"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_95QGxXNmEeWBq8z1Dv39LA" label="Web Help" command="_lqjIYEYEEeyPM8G0E2EYww"/> <children xsi:type="menu:HandledMenuItem" xmi:id="_95QGxXNmEeWBq8z1Dv39LA" label="Web Help" command="_lqjIYEYEEeyPM8G0E2EYww"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_4xtmgEYEEeyPM8G0E2EYww" label="About" command="_95PfxnNmEeWBq8z1Dv39LA"/> <children xsi:type="menu:HandledMenuItem" xmi:id="_4xtmgEYEEeyPM8G0E2EYww" label="About" command="_95PfxnNmEeWBq8z1Dv39LA"/>

View File

@ -1,24 +1,140 @@
package com.minres.scviewer.e4.application.handlers; 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.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.core.di.annotations.Execute;
import org.eclipse.e4.ui.di.UISynchronize; import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.workbench.IWorkbench; import org.eclipse.e4.ui.workbench.IWorkbench;
import org.eclipse.equinox.p2.core.IProvisioningAgent; 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.ProvisioningSession;
import org.eclipse.equinox.p2.operations.UpdateOperation; import org.eclipse.equinox.p2.operations.UpdateOperation;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
public class UpdateHandler { public class UpdateHandler {
boolean cancelled = false;
@Execute @Execute
public void execute(IProvisioningAgent agent, UISynchronize synchronize, IWorkbench workbench) { public void execute(IProvisioningAgent agent, UISynchronize sync, IWorkbench workbench) {
ProvisioningSession session = new ProvisioningSession(agent); // update using a progress monitor
UpdateOperation operation = new UpdateOperation(session); IRunnableWithProgress runnable = new IRunnableWithProgress() {
IStatus status = operation.resolveModal(null); @Override
if(status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
MessageDialog.openInformation(null, "Information", "Nothing to update"); update(agent, monitor, sync, workbench);
}
};
try {
new ProgressMonitorDialog(null).run(true, true, runnable);
} catch (InvocationTargetException | InterruptedException e) {
e.printStackTrace();
} }
} }
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);
}
});
}
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?> <?pde version="3.5"?>
<product name="SCViewer" uid="scviewer" id="com.minres.scviewer.e4.application.product" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.16.1" useFeatures="true" includeLaunchers="true"> <product name="SCViewer" uid="scviewer" id="com.minres.scviewer.e4.application.product" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.16.1" useFeatures="true" includeLaunchers="true" autoIncludeRequirements="true">
<configIni use="default"> <configIni use="default">
</configIni> </configIni>

View File

@ -12,6 +12,8 @@
<unit id="org.eclipse.rcptt.core.feature.group" version="0.0.0"/><!-- com.google.guave--> <unit id="org.eclipse.rcptt.core.feature.group" version="0.0.0"/><!-- com.google.guave-->
<unit id="org.eclipse.pde.feature.group" version="0.0.0"/> <!-- org.junit for testing --> <unit id="org.eclipse.pde.feature.group" version="0.0.0"/> <!-- org.junit for testing -->
<unit id="javax.servlet" version="0.0.0"/> <unit id="javax.servlet" version="0.0.0"/>
<unit id="org.eclipse.equinox.core.feature.feature.group" version="0.0.0"/>
<unit id="org.eclipse.equinox.p2.core.feature.feature.group" version="0.0.0"/>
</location> </location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit"> <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://www.opcoach.com/repository/2021-12/"/> <repository location="https://www.opcoach.com/repository/2021-12/"/>
@ -26,7 +28,7 @@
</location> </location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit"> <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="http://download.eclipse.org/nebula/releases/latest"/> <repository location="http://download.eclipse.org/nebula/releases/latest"/>
<unit id="org.eclipse.nebula.widgets.xviewer.feature.feature.group" version="1.1.0.202011020719"/> <unit id="org.eclipse.nebula.widgets.xviewer.feature.feature.group" version="1.1.0.202208171809"/>
</location> </location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit"> <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="http://download.eclipse.org/collections/10.4.0/repository"/> <repository location="http://download.eclipse.org/collections/10.4.0/repository"/>

View File

@ -18,6 +18,15 @@
<feature id="com.minres.scviewer.database.feature.source" version="0.0.0"> <feature id="com.minres.scviewer.database.feature.source" version="0.0.0">
<category name="devel_components.source"/> <category name="devel_components.source"/>
</feature> </feature>
<feature id="com.minres.scviewer.e4.feature">
<category name="ide_components_standalone"/>
</feature>
<feature id="com.minres.scviewer.e4.help.feature">
<category name="ide_components_standalone"/>
</feature>
<feature id="com.minres.scviewer.e4.platform.feature">
<category name="ide_components_standalone"/>
</feature>
<category-def name="ide_components" label="SCViewer"> <category-def name="ide_components" label="SCViewer">
<description> <description>
Viewer for transaction recording outputs of the SystemC Verification (SCV) library Viewer for transaction recording outputs of the SystemC Verification (SCV) library
@ -29,4 +38,7 @@
</description> </description>
</category-def> </category-def>
<category-def name="devel_components.source" label="Developer Resources (Source)"/> <category-def name="devel_components.source" label="Developer Resources (Source)"/>
<category-def name="ide_components_standalone" label="Standalone">
<category name="ide_components"/>
</category-def>
</site> </site>