Skip to content

Commit 9a64872

Browse files
committed
Cancel the search as soon as we have a match
Currently the search is performed over the whole project (what might take long depending on project size), but actually we are only interested in any match. THis now uses a ProgressMonitorWrapper that reports cancellation to the search once we found a first positive hit.
1 parent a3ce017 commit 9a64872

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/GatherUnusedDependenciesOperation.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.core.resources.IProject;
3232
import org.eclipse.core.runtime.CoreException;
3333
import org.eclipse.core.runtime.IProgressMonitor;
34+
import org.eclipse.core.runtime.ProgressMonitorWrapper;
3435
import org.eclipse.core.runtime.SubMonitor;
3536
import org.eclipse.jdt.core.IJavaProject;
3637
import org.eclipse.jdt.core.JavaCore;
@@ -187,8 +188,27 @@ private boolean isPackageReferenced(ImportPackageObject pkg, IJavaProject javaPr
187188
SearchPattern pattern = SearchPattern.createPattern(packageName, IJavaSearchConstants.PACKAGE,
188189
IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH);
189190
if (pattern != null) {
190-
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
191-
searchScope, requestor, monitor);
191+
ProgressMonitorWrapper wrapper = new ProgressMonitorWrapper(monitor) {
192+
193+
@Override
194+
public boolean isCanceled() {
195+
return monitor.isCanceled() || requestor.used;
196+
}
197+
198+
@Override
199+
public void setCanceled(boolean b) {
200+
}
201+
};
202+
try {
203+
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
204+
searchScope, requestor, wrapper);
205+
} catch (org.eclipse.core.runtime.OperationCanceledException e) {
206+
if (monitor.isCanceled()) {
207+
// the the user really canceled, rethrow it here,
208+
// otherwise we just found a match!
209+
throw e;
210+
}
211+
}
192212
return requestor.used;
193213
}
194214
} catch (CoreException e) {
@@ -352,10 +372,10 @@ private void minimizeDependencies(Map<String, IPluginImport> usedPlugins, List<I
352372
}
353373

354374
private static class Requestor extends SearchRequestor {
355-
boolean used;
375+
volatile boolean used;
356376

357377
@Override
358-
public void acceptSearchMatch(SearchMatch match) throws CoreException {
378+
public void acceptSearchMatch(SearchMatch match) {
359379
used = true;
360380
}
361381
}

0 commit comments

Comments
 (0)