Skip to content

Commit

Permalink
STS-2472: wrapping getResolvedClasspath into a job to avoid too broad…
Browse files Browse the repository at this point in the history
… locking
  • Loading branch information
Martin Lippert committed Feb 29, 2012
1 parent caf1a19 commit f872407
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.jdt.core.ElementChangedEvent;
Expand Down Expand Up @@ -124,7 +126,7 @@ private static void addClassPathUrls(IProject project, List<URL> paths, Set<IPro
if (JdtUtils.isJavaProject(project)) {
IJavaProject jp = JavaCore.create(project);
// configured classpath
IClasspathEntry[] classpath = jp.getResolvedClasspath(true);
IClasspathEntry[] classpath = safeGetResolvedClasspath(jp);

// add class path entries
for (int i = 0; i < classpath.length; i++) {
Expand Down Expand Up @@ -170,7 +172,27 @@ else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
catch (Exception e) {
// ignore
}
}
}

/**
* Gets the resolved classpath in a safe manner by first grabbing the build rule
* to prevent deadlock.
* @param jp
* @return resolved classpath of the project
*/
protected static IClasspathEntry[] safeGetResolvedClasspath(final IJavaProject jp) {
final IClasspathEntry[][] cp = new IClasspathEntry[1][];
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
cp[0] = jp.getResolvedClasspath(true);
}
}, ResourcesPlugin.getWorkspace().getRuleFactory().buildRule(), IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e) {
SpringCore.log(e);
}
return cp[0];
}

private static void addUri(List<URL> paths, URI uri) throws MalformedURLException {
File file = new File(uri);
Expand Down

0 comments on commit f872407

Please sign in to comment.