Skip to content

Commit ae4f544

Browse files
vogellaakurtakov
authored andcommitted
Remove activator from org.eclipse.search.tests
Activator is not required for the tests and can be replaced with FrameworkUtil for bundleContext access.
1 parent 78615b8 commit ae4f544

File tree

10 files changed

+49
-48
lines changed

10 files changed

+49
-48
lines changed

tests/org.eclipse.search.tests/META-INF/MANIFEST.MF

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.search.tests;singleton:=true
55
Bundle-Version: 3.11.600.qualifier
6-
Bundle-Activator: org.eclipse.search.tests.SearchTestPlugin
76
Bundle-Vendor: %providerName
87
Bundle-Localization: plugin
98
Export-Package: org.eclipse.search.core.tests;x-internal:=true,

tests/org.eclipse.search.tests/src/org/eclipse/search/core/tests/LineConversionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.eclipse.jface.text.Position;
3737

3838
import org.eclipse.search.internal.ui.SearchPlugin;
39-
import org.eclipse.search.tests.SearchTestPlugin;
39+
import org.eclipse.search.tests.SearchTestUtil;
4040

4141
import org.eclipse.search2.internal.ui.text.PositionTracker;
4242

@@ -70,7 +70,7 @@ private String getFileContents() {
7070

7171
@Test
7272
public void testConvertToCharacter() throws Exception {
73-
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), fFile);
73+
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), fFile);
7474
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
7575
IDocument doc= fb.getDocument();
7676

@@ -97,7 +97,7 @@ public void testConvertToCharacter() throws Exception {
9797

9898
@Test
9999
public void testBogusLines() throws Exception {
100-
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), fFile);
100+
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), fFile);
101101
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
102102
IDocument doc= fb.getDocument();
103103

@@ -106,7 +106,7 @@ public void testBogusLines() throws Exception {
106106
}
107107

108108
public void atestLineOffsets() throws Exception {
109-
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), fFile);
109+
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), fFile);
110110
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
111111
IDocument doc= fb.getDocument();
112112

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.zip.ZipEntry;
2626
import java.util.zip.ZipFile;
2727

28+
import org.osgi.framework.Bundle;
29+
2830
import org.eclipse.core.runtime.FileLocator;
2931
import org.eclipse.core.runtime.IPath;
3032
import org.eclipse.core.runtime.Plugin;
@@ -157,6 +159,18 @@ public static File getFileInPlugin(Plugin plugin, IPath path) {
157159
}
158160
}
159161

162+
163+
public static File getFileInBundle(Bundle bundle, IPath path) {
164+
try {
165+
URL installURL= bundle.getEntry(path.toString());
166+
URL localURL= FileLocator.toFileURL(installURL);
167+
return new File(localURL.getFile());
168+
} catch (IOException e) {
169+
return null;
170+
}
171+
}
172+
173+
160174
public static File createTempFileInPlugin(Plugin plugin, IPath path) {
161175
IPath stateLocation= plugin.getStateLocation();
162176
stateLocation= stateLocation.append(path);

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import java.util.zip.ZipException;
2121
import java.util.zip.ZipFile;
2222

23+
import org.osgi.framework.FrameworkUtil;
24+
2325
import org.eclipse.core.runtime.CoreException;
26+
import org.eclipse.core.runtime.ILog;
2427
import org.eclipse.core.runtime.IPath;
2528
import org.eclipse.core.runtime.IProgressMonitor;
2629
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -76,7 +79,7 @@ public static void delete(final IResource resource) throws CoreException {
7679
i= MAX_RETRY;
7780
} catch (CoreException e) {
7881
if (i == MAX_RETRY - 1) {
79-
SearchTestPlugin.getDefault().getLog().log(e.getStatus());
82+
ILog.get().log(e.getStatus());
8083
throw e;
8184
}
8285
System.gc(); // help windows to really close file locks
@@ -171,7 +174,7 @@ public static IProject createLinkedProject(String projectName, Plugin plugin, IP
171174

172175
public static IProject createJUnitSourceProject(String projectName) throws CoreException, ZipException, IOException {
173176
IProject project= ResourceHelper.createProject(projectName);
174-
try (ZipFile zip= new ZipFile(FileTool.getFileInPlugin(SearchTestPlugin.getDefault(), IPath.fromOSString("testresources/junit37-noUI-src.zip")))) { //$NON-NLS-1$
177+
try (ZipFile zip= new ZipFile(FileTool.getFileInBundle(FrameworkUtil.getBundle(ResourceHelper.class), IPath.fromOSString("testresources/junit37-noUI-src.zip")))) { //$NON-NLS-1$
175178
FileTool.unzip(zip, project.getLocation().toFile());
176179
}
177180
project.refreshLocal(IResource.DEPTH_INFINITE, null);

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestPlugin.java renamed to tests/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestUtil.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,15 @@
2323
import org.eclipse.ui.PartInitException;
2424
import org.eclipse.ui.PlatformUI;
2525
import org.eclipse.ui.ide.IDE;
26-
import org.eclipse.ui.plugin.AbstractUIPlugin;
2726

2827
import org.eclipse.ui.editors.text.EditorsUI;
2928

30-
import org.eclipse.search.ui.NewSearchUI;
31-
32-
import org.eclipse.search2.internal.ui.SearchView;
33-
3429

3530
/**
36-
* Plugin class for search tests.
31+
* Util class for search tests.
3732
*/
38-
public class SearchTestPlugin extends AbstractUIPlugin {
39-
//The shared instance.
40-
private static SearchTestPlugin fgPlugin;
41-
42-
public SearchTestPlugin() {
43-
fgPlugin = this;
44-
}
33+
public class SearchTestUtil {
4534

46-
public static SearchTestPlugin getDefault() {
47-
return fgPlugin;
48-
}
49-
50-
public SearchView getSearchView() {
51-
return (SearchView) NewSearchUI.activateSearchResultView();
52-
}
5335

5436
public static void ensureWelcomePageClosed() {
5537
IWorkbenchWindow activeWorkbenchWindow= PlatformUI.getWorkbench().getActiveWorkbenchWindow();

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@
4343
import org.eclipse.search.internal.ui.text.FileMatch;
4444
import org.eclipse.search.internal.ui.text.FileSearchQuery;
4545
import org.eclipse.search.internal.ui.text.FileSearchResult;
46-
import org.eclipse.search.tests.SearchTestPlugin;
46+
import org.eclipse.search.tests.SearchTestUtil;
4747
import org.eclipse.search.ui.NewSearchUI;
4848
import org.eclipse.search.ui.text.AbstractTextSearchResult;
4949
import org.eclipse.search.ui.text.FileTextSearchScope;
5050
import org.eclipse.search.ui.text.Match;
5151

5252
import org.eclipse.search2.internal.ui.InternalSearchUI;
53+
import org.eclipse.search2.internal.ui.SearchView;
5354
import org.eclipse.search2.internal.ui.text.EditorAnnotationManager;
5455

5556
public class AnnotationManagerTest {
@@ -63,7 +64,7 @@ public class AnnotationManagerTest {
6364

6465
@Before
6566
public void setUp() {
66-
SearchTestPlugin.ensureWelcomePageClosed();
67+
SearchTestUtil.ensureWelcomePageClosed();
6768
EditorAnnotationManager.debugSetHighlighterType(EditorAnnotationManager.HIGHLIGHTER_ANNOTATION);
6869
String[] fileNamePattern= { "*.java" };
6970
FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(fileNamePattern, false);
@@ -89,7 +90,7 @@ public void testAddAnnotation() throws Exception {
8990
try {
9091
for (Object f : files) {
9192
IFile file = (IFile) f;
92-
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
93+
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
9394
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
9495
annotationModel.getAnnotationIterator();
9596
HashSet<Position> positions= new HashSet<>();
@@ -118,7 +119,7 @@ public void testBogusAnnotation() throws Exception {
118119
NewSearchUI.runQueryInForeground(null, fQuery1);
119120
FileSearchResult result= (FileSearchResult) fQuery1.getSearchResult();
120121
IFile file= (IFile) result.getElements()[0];
121-
SearchTestPlugin.openTextEditor(PlatformUI.getWorkbench().getWorkbenchWindows()[0].getPages()[0], file);
122+
SearchTestUtil.openTextEditor(PlatformUI.getWorkbench().getWorkbenchWindows()[0].getPages()[0], file);
122123
result.addMatch(new FileMatch(file));
123124
}
124125

@@ -132,7 +133,7 @@ public void testRemoveQuery() throws Exception {
132133
try {
133134
for (Object f : files) {
134135
IFile file = (IFile) f;
135-
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
136+
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
136137
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
137138
int annotationCount= 0;
138139
for (Iterator<Annotation> annotations= annotationModel.getAnnotationIterator(); annotations.hasNext();) {
@@ -157,7 +158,7 @@ public void testReplaceQuery() throws Exception {
157158
try {
158159
for (Object f : files) {
159160
IFile file = (IFile) f;
160-
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
161+
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
161162
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
162163
IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
163164
for (Iterator<Annotation> annotations= annotationModel.getAnnotationIterator(); annotations.hasNext();) {
@@ -180,11 +181,13 @@ public void testSwitchQuery() throws Exception {
180181
AbstractTextSearchResult result= (AbstractTextSearchResult) fQuery1.getSearchResult();
181182
Object[] files= result.getElements();
182183
NewSearchUI.runQueryInForeground(null, fQuery2);
183-
SearchTestPlugin.getDefault().getSearchView().showSearchResult(result);
184+
185+
SearchView activateSearchResultView= (SearchView) NewSearchUI.activateSearchResultView();
186+
activateSearchResultView.showSearchResult(result);
184187
try {
185188
for (Object f : files) {
186189
IFile file = (IFile) f;
187-
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
190+
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
188191
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
189192
IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
190193
for (Iterator<Annotation> annotations= annotationModel.getAnnotationIterator(); annotations.hasNext();) {

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import org.eclipse.search.internal.core.text.PatternConstructor;
4343
import org.eclipse.search.internal.ui.SearchPlugin;
4444
import org.eclipse.search.tests.ResourceHelper;
45-
import org.eclipse.search.tests.SearchTestPlugin;
45+
import org.eclipse.search.tests.SearchTestUtil;
4646
import org.eclipse.search.ui.text.FileTextSearchScope;
4747

4848
public class FileSearchTests {
@@ -240,10 +240,10 @@ private void testWildCards3(TestResultCollector collector) throws Exception {
240240

241241
IWorkbenchPage activePage= SearchPlugin.getActivePage();
242242
try {
243-
SearchTestPlugin.openTextEditor(activePage, openFile1);
244-
SearchTestPlugin.openTextEditor(activePage, openFile2);
245-
SearchTestPlugin.openTextEditor(activePage, openFile3);
246-
SearchTestPlugin.openTextEditor(activePage, openFile4);
243+
SearchTestUtil.openTextEditor(activePage, openFile1);
244+
SearchTestUtil.openTextEditor(activePage, openFile2);
245+
SearchTestUtil.openTextEditor(activePage, openFile3);
246+
SearchTestUtil.openTextEditor(activePage, openFile4);
247247

248248
long start= System.currentTimeMillis();
249249

@@ -339,7 +339,7 @@ private void testFileOpenInEditor(TestResultCollector collector) throws Exceptio
339339
IFile file2= ResourceHelper.createFile(folder, "file2", buf.toString());
340340

341341
try {
342-
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file2);
342+
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file2);
343343

344344
Pattern searchPattern= PatternConstructor.createPattern("hello", false, true);
345345

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.eclipse.ui.editors.text.EditorsUI;
3939

4040
import org.eclipse.search.internal.ui.SearchPlugin;
41-
import org.eclipse.search.tests.SearchTestPlugin;
41+
import org.eclipse.search.tests.SearchTestUtil;
4242
import org.eclipse.search.ui.NewSearchUI;
4343
import org.eclipse.search.ui.text.AbstractTextSearchResult;
4444
import org.eclipse.search.ui.text.FileTextSearchScope;
@@ -81,7 +81,7 @@ public void testLineBasedQuery() throws Exception {
8181
try {
8282
for (Object f : files) {
8383
IFile file= (IFile) f;
84-
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
84+
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
8585
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
8686
annotationModel.getAnnotationIterator();
8787
ArrayList<Position> positions= new ArrayList<>();

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/PositionTrackerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import org.eclipse.search.internal.ui.SearchPlugin;
4141
import org.eclipse.search.internal.ui.text.FileSearchQuery;
4242
import org.eclipse.search.internal.ui.text.FileSearchResult;
43-
import org.eclipse.search.tests.SearchTestPlugin;
43+
import org.eclipse.search.tests.SearchTestUtil;
4444
import org.eclipse.search.ui.NewSearchUI;
4545
import org.eclipse.search.ui.text.AbstractTextSearchResult;
4646
import org.eclipse.search.ui.text.FileTextSearchScope;
@@ -96,7 +96,7 @@ public void testInsertInsideMatch() throws Exception {
9696
private void checkInsertInsideMatch(FileSearchResult result, IFile file) throws PartInitException, BadLocationException {
9797
Match[] matches= result.getMatches(file);
9898
try {
99-
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
99+
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
100100
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
101101
Job.getJobManager().beginRule(file, null);
102102
IDocument doc= fb.getDocument();
@@ -129,7 +129,7 @@ private void checkInsertAtZero(AbstractTextSearchResult result, IFile file) thro
129129
originalStarts[i]= matches[i].getOffset();
130130
}
131131
try {
132-
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
132+
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
133133
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
134134
Job.getJobManager().beginRule(file, null);
135135
IDocument doc= fb.getDocument();

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SearchResultPageTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
import org.eclipse.search.internal.ui.text.FileSearchPage;
3838
import org.eclipse.search.internal.ui.text.FileSearchQuery;
39-
import org.eclipse.search.tests.SearchTestPlugin;
39+
import org.eclipse.search.tests.SearchTestUtil;
4040
import org.eclipse.search.ui.ISearchResultViewPart;
4141
import org.eclipse.search.ui.NewSearchUI;
4242
import org.eclipse.search.ui.text.AbstractTextSearchResult;
@@ -52,7 +52,7 @@ public class SearchResultPageTest {
5252

5353
@Before
5454
public void setUp() throws Exception {
55-
SearchTestPlugin.ensureWelcomePageClosed();
55+
SearchTestUtil.ensureWelcomePageClosed();
5656
String[] fileNamePatterns= { "*.java" };
5757
FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(fileNamePatterns, false);
5858

0 commit comments

Comments
 (0)