diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java index 4511a39cd2..f983fa0e64 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java @@ -37,6 +37,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; @@ -384,7 +385,7 @@ private void updateAffectedEntries(StateDelta delta, boolean runAsynch) { index++; } // TODO Consider always running in a job - better reporting and cancellation options - if (runAsynch) { + if (runAsynch || ResourcesPlugin.getWorkspace().isTreeLocked()) { // We may be in the UI thread, so the classpath is updated in a job to avoid blocking (bug 376135) fUpdateJob.add(projects, containers); fUpdateJob.schedule(); @@ -393,6 +394,7 @@ private void updateAffectedEntries(StateDelta delta, boolean runAsynch) { try { JavaCore.setClasspathContainer(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH, projects, containers, null); } catch (JavaModelException e) { + ILog.get().error("Setting classpath containers failed!", e); //$NON-NLS-1$ } } } diff --git a/ui/org.eclipse.pde.ui.templates.tests/src/org/eclipse/pde/ui/templates/tests/TestPDETemplates.java b/ui/org.eclipse.pde.ui.templates.tests/src/org/eclipse/pde/ui/templates/tests/TestPDETemplates.java index c97f22cfd2..9898d2105c 100644 --- a/ui/org.eclipse.pde.ui.templates.tests/src/org/eclipse/pde/ui/templates/tests/TestPDETemplates.java +++ b/ui/org.eclipse.pde.ui.templates.tests/src/org/eclipse/pde/ui/templates/tests/TestPDETemplates.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.eclipse.core.resources.IFile; @@ -50,6 +51,7 @@ import org.eclipse.pde.ui.IFieldData; import org.eclipse.pde.ui.IPluginContentWizard; import org.eclipse.pde.ui.tests.util.TargetPlatformUtil; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; import org.junit.Assert; import org.junit.Assume; @@ -159,7 +161,26 @@ public IPath getLocationPath() { @Test public void configureProjectAndCheckMarkers() throws CoreException { project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); + long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(60); + Display current = Display.getCurrent(); + while (true) { + if (current != null) { + while (current.readAndDispatch()) { + Thread.onSpinWait(); + } + } + try { + assertErrorFree(); + break; + } catch (AssertionError e) { + if (System.currentTimeMillis() > deadline) { + throw e; + } + } + } + } + private void assertErrorFree() throws CoreException { IMarker[] markers = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); // ignore missing package export marker @@ -179,7 +200,9 @@ public void configureProjectAndCheckMarkers() throws CoreException { markers = new IMarker[0]; } - assertEquals("Template '" + template.getLabel() + "' generates errors.", 0, markers.length); + assertEquals("Template '" + template.getLabel() + "' generates errors: " + + Arrays.stream(markers).map(String::valueOf).collect(Collectors.joining(System.lineSeparator())), 0, + markers.length); } @Test diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathcontributor/ClasspathContributorTest.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathcontributor/ClasspathContributorTest.java index 6a69db850b..3d3f56d3ed 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathcontributor/ClasspathContributorTest.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathcontributor/ClasspathContributorTest.java @@ -18,8 +18,9 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import org.eclipse.core.resources.IProject; import org.eclipse.jdt.core.IClasspathContainer; @@ -30,6 +31,7 @@ import org.eclipse.pde.internal.core.PDECore; import org.eclipse.pde.ui.tests.classpathresolver.ClasspathResolverTest; import org.eclipse.pde.ui.tests.util.ProjectUtils; +import org.eclipse.swt.widgets.Display; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -50,18 +52,37 @@ public class ClasspathContributorTest { @Test public void testAdditionalClasspathEntries() throws Exception { IProject project = ProjectUtils.importTestProject("tests/projects/" + ClasspathResolverTest.bundleName); - List expected = new ArrayList<>(TestClasspathContributor.entries); - expected.addAll(TestClasspathContributor.entries2); - IJavaProject jProject = JavaCore.create(project); - IClasspathContainer container = JavaCore.getClasspathContainer(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH, jProject); - assertNotNull("Could not find PDE classpath container", container); - IClasspathEntry[] classpath = container.getClasspathEntries(); - for (IClasspathEntry element : classpath) { - if (!isPdeDependency(element)) { - assertTrue("Unexpected classpath entry found: " + element, expected.remove(element)); + long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(60); + while (true) { + Display current = Display.getCurrent(); + if (current != null) { + while (current.readAndDispatch()) { + Thread.onSpinWait(); + } + } + try { + List expected = new ArrayList<>(TestClasspathContributor.entries); + expected.addAll(TestClasspathContributor.entries2); + IJavaProject jProject = JavaCore.create(project); + IClasspathContainer container = JavaCore.getClasspathContainer(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH, + jProject); + assertNotNull("Could not find PDE classpath container", container); + IClasspathEntry[] classpath = container.getClasspathEntries(); + for (IClasspathEntry element : classpath) { + if (!isPdeDependency(element)) { + assertTrue("Unexpected classpath entry found: " + element, expected.remove(element)); + } + } + assertTrue("Expected classpath entry not found: " + + expected.stream().map(String::valueOf).collect(Collectors.joining(System.lineSeparator())), + expected.isEmpty()); + break; + } catch (AssertionError e) { + if (System.currentTimeMillis() > deadline) { + throw e; + } } } - assertTrue("Expected classpath entry not found: " + Arrays.toString(expected.toArray()), expected.isEmpty()); } private boolean isPdeDependency(IClasspathEntry element) {