eclipse.platform icon indicating copy to clipboard operation
eclipse.platform copied to clipboard

The workspace will exit with unsaved changes in this session.

Open laeubi opened this issue 2 years ago • 1 comments

I regularly get "The workspace will exit with unsaved changes in this session." when using Eclipse in an embedded environment (Tycho) but this can also be seen in various test-cases of platform itself.

The problem seems to that the Workspace expect that "something" is happen on shutdown and even though there is the WorkspaceSave job that regularly saves the state it seem not to happen on shutdown of the bundle.

Currently I do ResourcesPlugin.getWorkspace().save(true, new NullProgressMonitor()); in the user code, but this has of course several drawbacks:

  1. If I do not use the workspace at all this call would init the workspace just to save it
  2. After that call theoretically something can "dirty" the workspace again

What I'm wondering is if the ResourcePlugin itself in its shutdown sequence can't perform that action itself? The plugin itself should be able to best decide if/what needs to be saved and at the moment it seems to be already notice that there was a change ...

Another option of course would be to have some TRANSIENT_WORKSPACE preference one can set that tells the ResourcePlugin to never persist any changes (what would be fine for tests and for Tycho as well).

laeubi avatar Nov 18 '23 06:11 laeubi

In general, I like the idea(s), but I see some problems in realizing the. And I am wondering how severe this problem is, because usually a workspace is only closed after a complete test run (i.e., after all tests in one plugin were executed). So the message should only occur after all tests in a plugin are executed. The only exception I know are session tests.

What I'm wondering is if the ResourcePlugin itself in its shutdown sequence can't perform that action itself? The plugin itself should be able to best decide if/what needs to be saved and at the moment it seems to be already notice that there was a change

This action would probably have to be performed when closing the workspace, as this is the last point in time where changes have been processed and the workspace can still reasonable be saved: https://github.com/eclipse-platform/eclipse.platform/blob/b345854ba79a6b4adaff0c839d7e5fad9e2d92ee/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java#L702-L703

After that, the workspace is cleaned, so the ResourcesPlugin could not perform the save operation anymore: https://github.com/eclipse-platform/eclipse.platform/blob/b345854ba79a6b4adaff0c839d7e5fad9e2d92ee/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java#L716

Changing the behavior of Workspace.close() might have unintended side effects. First, I could imagine that performing a full save while closing is problematic because such a save operation might trigger further tasks / listeners (although I am not totally sure about that). Second, the documentation of Workspace.close() explicitly states that "The state of this workspace is not saved before the workspace is shut down.", so changing that behavior would break API.

Another option of course would be to have some TRANSIENT_WORKSPACE preference one can set that tells the ResourcePlugin to never persist any changes (what would be fine for tests and for Tycho as well).

So this would means that in case this property is set, the error is simply not printed, right? That cannot be applied to all tests, since the WorkspaceSessionTests currently rely on the workspace not being saved and some of the tests explicitly close the workspace without saving, as they want to test specific restoration behavior.

HeikoKlare avatar Nov 20 '23 10:11 HeikoKlare