Skip to content

Commit

Permalink
clean CharsetManagerJob shutdown eclipse-platform#1427
Browse files Browse the repository at this point in the history
To prevent logging exception on shutdown at end of Junit tests:
'Workspace was not properly initialized or has already shutdown.'

eclipse-platform#1427
  • Loading branch information
EcljpseB0T authored and jukzi committed Jun 18, 2024
1 parent 8969f83 commit a5bbdf4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void shutdown() {
try {
// try to prevent execution of this job to avoid "already shutdown.":
cancel();
wakeUp();
// if job is already running wait for it to finish:
join(3000, null);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public CharsetManagerJob() {
super(Messages.resources_charsetUpdating);
setSystem(true);
setPriority(Job.INTERACTIVE);
setRule(workspace.getRoot());
}

@Override
Expand Down Expand Up @@ -102,7 +103,7 @@ protected IStatus run(IProgressMonitor monitor) {
workspace.prepareOperation(rule, monitor);
workspace.beginOperation(true);
Map.Entry<IProject, Boolean> next;
while ((next = getNextChange()) != null) {
while (!monitor.isCanceled() && ((next = getNextChange()) != null)) {
//just exit if the system is shutting down or has been shut down
//it is too late to change the workspace at this point anyway
if (systemBundle.getState() != Bundle.ACTIVE)
Expand Down Expand Up @@ -143,6 +144,16 @@ public boolean shouldRun() {
return !asyncChanges.isEmpty();
}
}

public void shutDown() {
cancel();
wakeUp();
try {
join(3000, null);
} catch (OperationCanceledException | InterruptedException ignored) {
// nothing
}
}
}

private class ResourceChangeListener implements IResourceChangeListener {
Expand Down Expand Up @@ -495,6 +506,9 @@ private void setCharsetForHasFailed(IPath resourcePath, BackingStoreException e)

@Override
public void shutdown(IProgressMonitor monitor) {
if (job != null) {
job.shutDown();
}
InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES)
.removePreferenceChangeListener(preferenceChangeListener);

Expand Down

0 comments on commit a5bbdf4

Please sign in to comment.