How to correctly save the workspace.. [message #335867] |
Wed, 06 May 2009 22:38 |
Dan O'Connor Messages: 2 Registered: July 2009 |
Junior Member |
|
|
Hello..
I am working on an RCP project where by we have created our own
WorkbenchWindowAdvisor.
During startup the following gets printed to our log:
The workspace exited with unsaved changes in the previous session;
refreshing workspace to recover changes.
It seems no matter what I do during workbench shutdown I receive this
error during subsequent start-up operations?
My shutdown code is as follows:
@Override
public void postWindowClose() {
super.postWindowClose();
saveWorkspaceInfo();
}
private void saveWorkspaceInfo(){
final MultiStatus status = new MultiStatus(
Activator.PLUGIN_ID, 1,
"Error encountered saving workspace information", null);
WorkspaceModifyOperation operation = new
WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor)
throws CoreException, InvocationTargetException,
InterruptedException {
IWorkspaceRoot root =
ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = root.getProjects();
if(projects != null && projects.length > 0){
monitor.beginTask(StringUtil.format("Exiting {0}",
ProductUtil.getProductShortName()), (projects.length * 5));
for(int i = 0; i < projects.length; i++){
monitor.setTaskName(StringUtil.format("Exiting {0}
- Saving application data for {1}", ProductUtil.getProductShortName(),
projects[i].getName()));
if(projects[i].isOpen()){
try {
projects[i].close(monitor);
} catch (CoreException ce) {
//log
}
}
monitor.worked(5);
}
try {
status.merge(ResourcesPlugin.getWorkspace().save(true,
SubMonitor.convert(monitor)));
} catch (CoreException e) {
status.merge(e.getStatus());
}
monitor.done();
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().run(true,
false, operation);
} catch (InvocationTargetException e) {
status.merge(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1,
"An internal error occurred while saving the workspace
state",e.getTargetException()));
} catch (InterruptedException e) {
//Should not happen as the operation is not cancellable - but
just in case.
status.merge(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1,
"An internal error occurred while saving the workspace
state. The operation was interrupted by the user.", e));
}
if (!status.isOK()) {
ErrorDialog.openError(null, "An error was encountered when
saving the workspace state", null, status,
IStatus.ERROR | IStatus.WARNING);
Activator.getDefault().getLog().log(status); //Log to Eclipse
log also!
}
}
I added a breakpoint at:
org.eclipse.core.internal.resources.Workspace.beginOperation (boolean) and
I enable my breakpoint after the above code has executed.
The breakpoint is hit another 3 or 4 times after the above code has
executed suggesting that other workspace jobs are executing. It seems that
the following are the jobs that are not complete by the time the
workspace.save occurs:
org.eclipse.core.internal.resources.Workspace.close(IProgres sMonitor)
org.eclipse.core.internal.resources.ContentDescriptionManage r.getDescriptionFor(File,
ResourceInfo)
a long with one or two others.
Is there a way to save and close the workspace gracefully? Is there a
point in the lifecycle where I can latch in and perform the save
successfully?
Any help here would be greatly appreciated. This has me stumped!
Thanks,
-Dan
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05025 seconds