1313 *******************************************************************************/
1414package org .eclipse .pde .internal .core ;
1515
16+ import java .util .LinkedHashSet ;
17+ import java .util .Set ;
18+
1619import org .eclipse .core .resources .IProject ;
1720import org .eclipse .core .runtime .CoreException ;
1821import org .eclipse .core .runtime .IPath ;
22+ import org .eclipse .core .runtime .IProgressMonitor ;
1923import org .eclipse .core .runtime .IStatus ;
2024import org .eclipse .core .runtime .Status ;
2125import 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