Skip to content

Commit c25dc70

Browse files
committed
Always run in a Job in PluginModelManager
Currently there is a TODO that classpath updates should better always run in a job instead of synchronous to the call. As asynchronous is often needed anyways this now finally resolves this TODO and aims to perform the action always in a background job.
1 parent 083ff01 commit c25dc70

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java

+9-32
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.eclipse.core.resources.ResourcesPlugin;
3838
import org.eclipse.core.runtime.Adapters;
3939
import org.eclipse.core.runtime.CoreException;
40-
import org.eclipse.core.runtime.ILog;
4140
import org.eclipse.core.runtime.IProgressMonitor;
4241
import org.eclipse.core.runtime.IStatus;
4342
import org.eclipse.core.runtime.MultiStatus;
@@ -117,12 +116,10 @@ protected IStatus run(IProgressMonitor monitor) {
117116
/**
118117
* Queues more projects/containers.
119118
*/
120-
void add(IJavaProject[] projects, IClasspathContainer[] containers) {
119+
void add(IJavaProject project, IClasspathContainer container) {
121120
synchronized (fProjects) {
122-
for (int i = 0; i < containers.length; i++) {
123-
fProjects.add(projects[i]);
124-
fContainers.add(containers[i]);
125-
}
121+
fProjects.add(project);
122+
fContainers.add(container);
126123
}
127124
}
128125

@@ -299,7 +296,7 @@ private void modelsChangedSynchronized(IModelProviderEvent e) {
299296
}
300297
// trigger a classpath update for all workspace plug-ins affected by the
301298
// processed batch of changes, run asynch for manifest changes
302-
updateAffectedEntries(stateDelta, (e.getEventTypes() & IModelProviderEvent.MODELS_CHANGED) != 0);
299+
updateAffectedEntries(stateDelta);
303300
fireStateDelta(stateDelta);
304301

305302
}
@@ -314,9 +311,8 @@ private void modelsChangedSynchronized(IModelProviderEvent e) {
314311
*
315312
* @param delta a state delta containing a list of bundles affected by the processed
316313
* changes, may be <code>null</code> to indicate the entire target has changed
317-
* @param runAsynch whether classpath updates should be done in an asynchronous job
318314
*/
319-
private void updateAffectedEntries(StateDelta delta, boolean runAsynch) {
315+
private void updateAffectedEntries(StateDelta delta) {
320316
Map<IJavaProject, RequiredPluginsClasspathContainer> map = new HashMap<>();
321317
if (delta == null) {
322318
// if the delta is null, then the entire target changed.
@@ -374,29 +370,10 @@ private void updateAffectedEntries(StateDelta delta, boolean runAsynch) {
374370

375371
if (!map.isEmpty()) {
376372
// update class path for all affected workspace plug-ins in one operation
377-
Iterator<Entry<IJavaProject, RequiredPluginsClasspathContainer>> iterator = map.entrySet().iterator();
378-
IJavaProject[] projects = new IJavaProject[map.size()];
379-
IClasspathContainer[] containers = new IClasspathContainer[projects.length];
380-
int index = 0;
381-
while (iterator.hasNext()) {
382-
Entry<IJavaProject, RequiredPluginsClasspathContainer> entry = iterator.next();
383-
projects[index] = entry.getKey();
384-
containers[index] = entry.getValue();
385-
index++;
386-
}
387-
// TODO Consider always running in a job - better reporting and cancellation options
388-
if (runAsynch || ResourcesPlugin.getWorkspace().isTreeLocked()) {
389-
// We may be in the UI thread, so the classpath is updated in a job to avoid blocking (bug 376135)
390-
fUpdateJob.add(projects, containers);
391-
fUpdateJob.schedule();
392-
} else {
393-
// else update synchronously
394-
try {
395-
JavaCore.setClasspathContainer(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH, projects, containers, null);
396-
} catch (JavaModelException e) {
397-
ILog.get().error("Setting classpath containers failed!", e); //$NON-NLS-1$
398-
}
373+
for (Entry<IJavaProject, RequiredPluginsClasspathContainer> entry : map.entrySet()) {
374+
fUpdateJob.add(entry.getKey(), entry.getValue());
399375
}
376+
fUpdateJob.schedule();
400377
}
401378
}
402379

@@ -640,7 +617,7 @@ private void initializeTable(IProgressMonitor monitor) {
640617
PDECore.getDefault().getExtensionsRegistry().targetReloaded();
641618
if (oldState != null) {
642619
// Need to update classpath entries
643-
updateAffectedEntries(null, true);
620+
updateAffectedEntries(null);
644621
}
645622

646623
// Fire a state change event to touch all projects if the target content has changed since last model init

0 commit comments

Comments
 (0)