Skip to content

Commit 083ff01

Browse files
committed
Always run asnyc if the workspace tree is locked
Setting a classpath container to a project while the workspace tree is locked has the effect that the container is updated but the project is not build at all. This overrides the hint to run async in such case to make sure the project is build appropriately.
1 parent 8046286 commit 083ff01

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
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;
4041
import org.eclipse.core.runtime.IProgressMonitor;
4142
import org.eclipse.core.runtime.IStatus;
4243
import org.eclipse.core.runtime.MultiStatus;
@@ -384,7 +385,7 @@ private void updateAffectedEntries(StateDelta delta, boolean runAsynch) {
384385
index++;
385386
}
386387
// TODO Consider always running in a job - better reporting and cancellation options
387-
if (runAsynch) {
388+
if (runAsynch || ResourcesPlugin.getWorkspace().isTreeLocked()) {
388389
// We may be in the UI thread, so the classpath is updated in a job to avoid blocking (bug 376135)
389390
fUpdateJob.add(projects, containers);
390391
fUpdateJob.schedule();
@@ -393,6 +394,7 @@ private void updateAffectedEntries(StateDelta delta, boolean runAsynch) {
393394
try {
394395
JavaCore.setClasspathContainer(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH, projects, containers, null);
395396
} catch (JavaModelException e) {
397+
ILog.get().error("Setting classpath containers failed!", e); //$NON-NLS-1$
396398
}
397399
}
398400
}

ui/org.eclipse.pde.ui.templates.tests/src/org/eclipse/pde/ui/templates/tests/TestPDETemplates.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Arrays;
2222
import java.util.Collection;
2323
import java.util.Set;
24+
import java.util.concurrent.TimeUnit;
2425
import java.util.stream.Collectors;
2526

2627
import org.eclipse.core.resources.IFile;
@@ -50,6 +51,7 @@
5051
import org.eclipse.pde.ui.IFieldData;
5152
import org.eclipse.pde.ui.IPluginContentWizard;
5253
import org.eclipse.pde.ui.tests.util.TargetPlatformUtil;
54+
import org.eclipse.swt.widgets.Display;
5355
import org.eclipse.ui.PlatformUI;
5456
import org.junit.Assert;
5557
import org.junit.Assume;
@@ -159,7 +161,26 @@ public IPath getLocationPath() {
159161
@Test
160162
public void configureProjectAndCheckMarkers() throws CoreException {
161163
project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
164+
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(60);
165+
Display current = Display.getCurrent();
166+
while (true) {
167+
if (current != null) {
168+
while (current.readAndDispatch()) {
169+
Thread.onSpinWait();
170+
}
171+
}
172+
try {
173+
assertErrorFree();
174+
break;
175+
} catch (AssertionError e) {
176+
if (System.currentTimeMillis() > deadline) {
177+
throw e;
178+
}
179+
}
180+
}
181+
}
162182

183+
private void assertErrorFree() throws CoreException {
163184
IMarker[] markers = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
164185

165186
// ignore missing package export marker
@@ -179,7 +200,9 @@ public void configureProjectAndCheckMarkers() throws CoreException {
179200
markers = new IMarker[0];
180201
}
181202

182-
assertEquals("Template '" + template.getLabel() + "' generates errors.", 0, markers.length);
203+
assertEquals("Template '" + template.getLabel() + "' generates errors: "
204+
+ Arrays.stream(markers).map(String::valueOf).collect(Collectors.joining(System.lineSeparator())), 0,
205+
markers.length);
183206
}
184207

185208
@Test

ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathcontributor/ClasspathContributorTest.java

+32-11
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
import static org.junit.Assert.assertTrue;
1919

2020
import java.util.ArrayList;
21-
import java.util.Arrays;
2221
import java.util.List;
22+
import java.util.concurrent.TimeUnit;
23+
import java.util.stream.Collectors;
2324

2425
import org.eclipse.core.resources.IProject;
2526
import org.eclipse.jdt.core.IClasspathContainer;
@@ -30,6 +31,7 @@
3031
import org.eclipse.pde.internal.core.PDECore;
3132
import org.eclipse.pde.ui.tests.classpathresolver.ClasspathResolverTest;
3233
import org.eclipse.pde.ui.tests.util.ProjectUtils;
34+
import org.eclipse.swt.widgets.Display;
3335
import org.junit.ClassRule;
3436
import org.junit.Rule;
3537
import org.junit.Test;
@@ -50,18 +52,37 @@ public class ClasspathContributorTest {
5052
@Test
5153
public void testAdditionalClasspathEntries() throws Exception {
5254
IProject project = ProjectUtils.importTestProject("tests/projects/" + ClasspathResolverTest.bundleName);
53-
List<IClasspathEntry> expected = new ArrayList<>(TestClasspathContributor.entries);
54-
expected.addAll(TestClasspathContributor.entries2);
55-
IJavaProject jProject = JavaCore.create(project);
56-
IClasspathContainer container = JavaCore.getClasspathContainer(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH, jProject);
57-
assertNotNull("Could not find PDE classpath container", container);
58-
IClasspathEntry[] classpath = container.getClasspathEntries();
59-
for (IClasspathEntry element : classpath) {
60-
if (!isPdeDependency(element)) {
61-
assertTrue("Unexpected classpath entry found: " + element, expected.remove(element));
55+
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(60);
56+
while (true) {
57+
Display current = Display.getCurrent();
58+
if (current != null) {
59+
while (current.readAndDispatch()) {
60+
Thread.onSpinWait();
61+
}
62+
}
63+
try {
64+
List<IClasspathEntry> expected = new ArrayList<>(TestClasspathContributor.entries);
65+
expected.addAll(TestClasspathContributor.entries2);
66+
IJavaProject jProject = JavaCore.create(project);
67+
IClasspathContainer container = JavaCore.getClasspathContainer(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH,
68+
jProject);
69+
assertNotNull("Could not find PDE classpath container", container);
70+
IClasspathEntry[] classpath = container.getClasspathEntries();
71+
for (IClasspathEntry element : classpath) {
72+
if (!isPdeDependency(element)) {
73+
assertTrue("Unexpected classpath entry found: " + element, expected.remove(element));
74+
}
75+
}
76+
assertTrue("Expected classpath entry not found: "
77+
+ expected.stream().map(String::valueOf).collect(Collectors.joining(System.lineSeparator())),
78+
expected.isEmpty());
79+
break;
80+
} catch (AssertionError e) {
81+
if (System.currentTimeMillis() > deadline) {
82+
throw e;
83+
}
6284
}
6385
}
64-
assertTrue("Expected classpath entry not found: " + Arrays.toString(expected.toArray()), expected.isEmpty());
6586
}
6687

6788
private boolean isPdeDependency(IClasspathEntry element) {

0 commit comments

Comments
 (0)