Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always run asnyc if the workspace tree is locked #1261

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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$
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -50,18 +52,37 @@ public class ClasspathContributorTest {
@Test
public void testAdditionalClasspathEntries() throws Exception {
IProject project = ProjectUtils.importTestProject("tests/projects/" + ClasspathResolverTest.bundleName);
List<IClasspathEntry> 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<IClasspathEntry> 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) {
Expand Down
Loading