1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.search.internal.core.text;
import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.jface.util.Assert;
import org.eclipse.search.internal.core.ISearchScope;
import org.eclipse.search.internal.ui.SearchMessages;
import org.eclipse.search.ui.NewSearchUI;
public class TextSearchEngine {
/**
* Search for the given pattern.
*/
public IStatus search(IWorkspace workspace, ISearchScope scope, boolean visitDerived, ITextSearchResultCollector collector, MatchLocator matchLocator) {
Assert.isNotNull(workspace);
Assert.isNotNull(scope);
Assert.isNotNull(collector);
Assert.isNotNull(matchLocator);
IProgressMonitor monitor= collector.getProgressMonitor();
IProject[] projects= workspace.getRoot().getProjects();
Collection openProjects= new ArrayList(10);
for (int i= 0; i < projects.length; i++) {
IProject project= projects[i];
if (project.isOpen())
openProjects.add(project);
}
String message= SearchMessages.getString("TextSearchEngine.statusMessage"); //$NON-NLS-1$
MultiStatus status= new MultiStatus(NewSearchUI.PLUGIN_ID, IStatus.OK, message, null);
if (!openProjects.isEmpty()) {
int amountOfWork= (new AmountOfWorkCalculator(status, visitDerived)).process(openProjects, scope);
try {
monitor.beginTask("", amountOfWork); //$NON-NLS-1$
if (amountOfWork > 0) {
Integer[] args= new Integer[] {new Integer(1), new Integer(amountOfWork)};
monitor.setTaskName(SearchMessages.getFormattedString("TextSearchEngine.scanning", args)); //$NON-NLS-1$
}
collector.aboutToStart();
TextSearchVisitor visitor= new TextSearchVisitor(matchLocator, scope, visitDerived, collector, status, amountOfWork);
visitor.process(openProjects);
} catch (CoreException ex) {
status.add(ex.getStatus());
} finally {
monitor.done();
try {
collector.done();
} catch (CoreException ex) {
status.add(ex.getStatus());
}
}
}
return status;
}
}
|