Skip to content

Commit a5bbdf4

Browse files
EcljpseB0Tjukzi
authored andcommitted
clean CharsetManagerJob shutdown #1427
To prevent logging exception on shutdown at end of Junit tests: 'Workspace was not properly initialized or has already shutdown.' #1427
1 parent 8969f83 commit a5bbdf4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/CharsetDeltaJob.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public void shutdown() {
240240
try {
241241
// try to prevent execution of this job to avoid "already shutdown.":
242242
cancel();
243+
wakeUp();
243244
// if job is already running wait for it to finish:
244245
join(3000, null);
245246
} catch (InterruptedException e) {

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/CharsetManager.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public CharsetManagerJob() {
6868
super(Messages.resources_charsetUpdating);
6969
setSystem(true);
7070
setPriority(Job.INTERACTIVE);
71+
setRule(workspace.getRoot());
7172
}
7273

7374
@Override
@@ -102,7 +103,7 @@ protected IStatus run(IProgressMonitor monitor) {
102103
workspace.prepareOperation(rule, monitor);
103104
workspace.beginOperation(true);
104105
Map.Entry<IProject, Boolean> next;
105-
while ((next = getNextChange()) != null) {
106+
while (!monitor.isCanceled() && ((next = getNextChange()) != null)) {
106107
//just exit if the system is shutting down or has been shut down
107108
//it is too late to change the workspace at this point anyway
108109
if (systemBundle.getState() != Bundle.ACTIVE)
@@ -143,6 +144,16 @@ public boolean shouldRun() {
143144
return !asyncChanges.isEmpty();
144145
}
145146
}
147+
148+
public void shutDown() {
149+
cancel();
150+
wakeUp();
151+
try {
152+
join(3000, null);
153+
} catch (OperationCanceledException | InterruptedException ignored) {
154+
// nothing
155+
}
156+
}
146157
}
147158

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

496507
@Override
497508
public void shutdown(IProgressMonitor monitor) {
509+
if (job != null) {
510+
job.shutDown();
511+
}
498512
InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES)
499513
.removePreferenceChangeListener(preferenceChangeListener);
500514

0 commit comments

Comments
 (0)