Skip to content

Commit f6219a5

Browse files
committed
Improve RequiredPluginsInitializer.initialize
- Collect deferred projects to be processed by a single job. #1667
1 parent 2decd24 commit f6219a5

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

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

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
*******************************************************************************/
1414
package org.eclipse.pde.internal.core;
1515

16+
import java.util.LinkedHashSet;
17+
import java.util.Set;
18+
1619
import org.eclipse.core.resources.IProject;
1720
import org.eclipse.core.runtime.CoreException;
1821
import org.eclipse.core.runtime.IPath;
22+
import org.eclipse.core.runtime.IProgressMonitor;
1923
import org.eclipse.core.runtime.IStatus;
2024
import org.eclipse.core.runtime.Status;
2125
import org.eclipse.core.runtime.jobs.Job;
@@ -35,24 +39,59 @@ public class RequiredPluginsInitializer extends ClasspathContainerInitializer {
3539
}
3640
});
3741

42+
private static final DeferredClasspathContainerInitializerJob deferredClasspathContainerInitializerJob = new DeferredClasspathContainerInitializerJob();
43+
44+
private static class DeferredClasspathContainerInitializerJob extends Job {
45+
46+
private final Set<IJavaProject> projects = new LinkedHashSet<>();
47+
48+
public DeferredClasspathContainerInitializerJob() {
49+
// This name is not displayed to a user.
50+
super("DeferredClasspathContainerInitializerJob"); //$NON-NLS-1$
51+
setSystem(true);
52+
}
53+
54+
public synchronized void initialize(IJavaProject project) {
55+
if (projects.add(project)) {
56+
schedule();
57+
}
58+
}
59+
60+
private synchronized IJavaProject[] consumeProjects() {
61+
try {
62+
return projects.toArray(IJavaProject[]::new);
63+
} finally {
64+
projects.clear();
65+
}
66+
}
67+
68+
@Override
69+
protected IStatus run(IProgressMonitor monitor) {
70+
for (IJavaProject project : consumeProjects()) {
71+
try {
72+
setupClasspath(project);
73+
} catch (JavaModelException e) {
74+
PDECore.log(e);
75+
}
76+
}
77+
return Status.OK_STATUS;
78+
}
79+
}
80+
3881
@Override
3982
public void initialize(IPath containerPath, IJavaProject javaProject) throws CoreException {
4083
if (Job.getJobManager().isSuspended()) {
4184
// if the jobmanager is currently suspended we can't use the
4285
// schedule/join pattern here, instead we must retry the requested
4386
// action once jobs are enabled again, this will the possibly
4487
// trigger a rebuild if required or notify other listeners.
45-
Job job = Job.create(PDECoreMessages.PluginModelManager_InitializingPluginModels, m -> {
46-
setupClasspath(javaProject);
47-
});
48-
job.setSystem(true);
49-
job.schedule();
88+
deferredClasspathContainerInitializerJob.initialize(javaProject);
5089
} else {
5190
setupClasspath(javaProject);
5291
}
5392
}
5493

55-
protected void setupClasspath(IJavaProject javaProject) throws JavaModelException {
94+
protected static void setupClasspath(IJavaProject javaProject) throws JavaModelException {
5695
IProject project = javaProject.getProject();
5796
// The first project to be built may initialize the PDE models, potentially long running, so allow cancellation
5897
PluginModelManager manager = PDECore.getDefault().getModelManager();

0 commit comments

Comments
 (0)