Skip to content
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
3 changes: 1 addition & 2 deletions tests/org.eclipse.search.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.search.tests;singleton:=true
Bundle-Version: 3.11.600.qualifier
Bundle-Activator: org.eclipse.search.tests.SearchTestPlugin
Bundle-Version: 3.11.700.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.search.core.tests;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.eclipse.jface.text.Position;

import org.eclipse.search.internal.ui.SearchPlugin;
import org.eclipse.search.tests.SearchTestPlugin;
import org.eclipse.search.tests.SearchTestUtil;

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

Expand Down Expand Up @@ -70,7 +70,7 @@ private String getFileContents() {

@Test
public void testConvertToCharacter() throws Exception {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), fFile);
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), fFile);
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument doc= fb.getDocument();

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

@Test
public void testBogusLines() throws Exception {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), fFile);
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), fFile);
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument doc= fb.getDocument();

Expand All @@ -106,7 +106,7 @@ public void testBogusLines() throws Exception {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.osgi.framework.Bundle;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Plugin;
Expand Down Expand Up @@ -157,6 +159,18 @@ public static File getFileInPlugin(Plugin plugin, IPath path) {
}
}


public static File getFileInBundle(Bundle bundle, IPath path) {
try {
URL installURL= bundle.getEntry(path.toString());
URL localURL= FileLocator.toFileURL(installURL);
return new File(localURL.getFile());
} catch (IOException e) {
return null;
}
}


public static File createTempFileInPlugin(Plugin plugin, IPath path) {
IPath stateLocation= plugin.getStateLocation();
stateLocation= stateLocation.append(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import org.osgi.framework.FrameworkUtil;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
Expand Down Expand Up @@ -76,7 +79,7 @@ public static void delete(final IResource resource) throws CoreException {
i= MAX_RETRY;
} catch (CoreException e) {
if (i == MAX_RETRY - 1) {
SearchTestPlugin.getDefault().getLog().log(e.getStatus());
ILog.get().log(e.getStatus());
throw e;
}
System.gc(); // help windows to really close file locks
Expand Down Expand Up @@ -171,7 +174,7 @@ public static IProject createLinkedProject(String projectName, Plugin plugin, IP

public static IProject createJUnitSourceProject(String projectName) throws CoreException, ZipException, IOException {
IProject project= ResourceHelper.createProject(projectName);
try (ZipFile zip= new ZipFile(FileTool.getFileInPlugin(SearchTestPlugin.getDefault(), IPath.fromOSString("testresources/junit37-noUI-src.zip")))) { //$NON-NLS-1$
try (ZipFile zip= new ZipFile(FileTool.getFileInBundle(FrameworkUtil.getBundle(ResourceHelper.class), IPath.fromOSString("testresources/junit37-noUI-src.zip")))) { //$NON-NLS-1$
FileTool.unzip(zip, project.getLocation().toFile());
}
project.refreshLocal(IResource.DEPTH_INFINITE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,15 @@
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.plugin.AbstractUIPlugin;

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

import org.eclipse.search.ui.NewSearchUI;

import org.eclipse.search2.internal.ui.SearchView;


/**
* Plugin class for search tests.
* Util class for search tests.
*/
public class SearchTestPlugin extends AbstractUIPlugin {
//The shared instance.
private static SearchTestPlugin fgPlugin;

public SearchTestPlugin() {
fgPlugin = this;
}
public class SearchTestUtil {

public static SearchTestPlugin getDefault() {
return fgPlugin;
}

public SearchView getSearchView() {
return (SearchView) NewSearchUI.activateSearchResultView();
}

public static void ensureWelcomePageClosed() {
IWorkbenchWindow activeWorkbenchWindow= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
import org.eclipse.search.internal.ui.text.FileMatch;
import org.eclipse.search.internal.ui.text.FileSearchQuery;
import org.eclipse.search.internal.ui.text.FileSearchResult;
import org.eclipse.search.tests.SearchTestPlugin;
import org.eclipse.search.tests.SearchTestUtil;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.FileTextSearchScope;
import org.eclipse.search.ui.text.Match;

import org.eclipse.search2.internal.ui.InternalSearchUI;
import org.eclipse.search2.internal.ui.SearchView;
import org.eclipse.search2.internal.ui.text.EditorAnnotationManager;

public class AnnotationManagerTest {
Expand All @@ -63,7 +64,7 @@ public class AnnotationManagerTest {

@Before
public void setUp() {
SearchTestPlugin.ensureWelcomePageClosed();
SearchTestUtil.ensureWelcomePageClosed();
EditorAnnotationManager.debugSetHighlighterType(EditorAnnotationManager.HIGHLIGHTER_ANNOTATION);
String[] fileNamePattern= { "*.java" };
FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(fileNamePattern, false);
Expand All @@ -89,7 +90,7 @@ public void testAddAnnotation() throws Exception {
try {
for (Object f : files) {
IFile file = (IFile) f;
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
annotationModel.getAnnotationIterator();
HashSet<Position> positions= new HashSet<>();
Expand Down Expand Up @@ -118,7 +119,7 @@ public void testBogusAnnotation() throws Exception {
NewSearchUI.runQueryInForeground(null, fQuery1);
FileSearchResult result= (FileSearchResult) fQuery1.getSearchResult();
IFile file= (IFile) result.getElements()[0];
SearchTestPlugin.openTextEditor(PlatformUI.getWorkbench().getWorkbenchWindows()[0].getPages()[0], file);
SearchTestUtil.openTextEditor(PlatformUI.getWorkbench().getWorkbenchWindows()[0].getPages()[0], file);
result.addMatch(new FileMatch(file));
}

Expand All @@ -132,7 +133,7 @@ public void testRemoveQuery() throws Exception {
try {
for (Object f : files) {
IFile file = (IFile) f;
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
int annotationCount= 0;
for (Iterator<Annotation> annotations= annotationModel.getAnnotationIterator(); annotations.hasNext();) {
Expand All @@ -157,7 +158,7 @@ public void testReplaceQuery() throws Exception {
try {
for (Object f : files) {
IFile file = (IFile) f;
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
for (Iterator<Annotation> annotations= annotationModel.getAnnotationIterator(); annotations.hasNext();) {
Expand All @@ -180,11 +181,13 @@ public void testSwitchQuery() throws Exception {
AbstractTextSearchResult result= (AbstractTextSearchResult) fQuery1.getSearchResult();
Object[] files= result.getElements();
NewSearchUI.runQueryInForeground(null, fQuery2);
SearchTestPlugin.getDefault().getSearchView().showSearchResult(result);

SearchView activateSearchResultView= (SearchView) NewSearchUI.activateSearchResultView();
activateSearchResultView.showSearchResult(result);
try {
for (Object f : files) {
IFile file = (IFile) f;
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
for (Iterator<Annotation> annotations= annotationModel.getAnnotationIterator(); annotations.hasNext();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.eclipse.search.internal.core.text.PatternConstructor;
import org.eclipse.search.internal.ui.SearchPlugin;
import org.eclipse.search.tests.ResourceHelper;
import org.eclipse.search.tests.SearchTestPlugin;
import org.eclipse.search.tests.SearchTestUtil;
import org.eclipse.search.ui.text.FileTextSearchScope;

public class FileSearchTests {
Expand Down Expand Up @@ -240,10 +240,10 @@ private void testWildCards3(TestResultCollector collector) throws Exception {

IWorkbenchPage activePage= SearchPlugin.getActivePage();
try {
SearchTestPlugin.openTextEditor(activePage, openFile1);
SearchTestPlugin.openTextEditor(activePage, openFile2);
SearchTestPlugin.openTextEditor(activePage, openFile3);
SearchTestPlugin.openTextEditor(activePage, openFile4);
SearchTestUtil.openTextEditor(activePage, openFile1);
SearchTestUtil.openTextEditor(activePage, openFile2);
SearchTestUtil.openTextEditor(activePage, openFile3);
SearchTestUtil.openTextEditor(activePage, openFile4);

long start= System.currentTimeMillis();

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

try {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file2);
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file2);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.eclipse.ui.editors.text.EditorsUI;

import org.eclipse.search.internal.ui.SearchPlugin;
import org.eclipse.search.tests.SearchTestPlugin;
import org.eclipse.search.tests.SearchTestUtil;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.FileTextSearchScope;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void testLineBasedQuery() throws Exception {
try {
for (Object f : files) {
IFile file= (IFile) f;
ITextEditor editor= (ITextEditor)SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
ITextEditor editor= (ITextEditor)SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
annotationModel.getAnnotationIterator();
ArrayList<Position> positions= new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.eclipse.search.internal.ui.SearchPlugin;
import org.eclipse.search.internal.ui.text.FileSearchQuery;
import org.eclipse.search.internal.ui.text.FileSearchResult;
import org.eclipse.search.tests.SearchTestPlugin;
import org.eclipse.search.tests.SearchTestUtil;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.FileTextSearchScope;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void testInsertInsideMatch() throws Exception {
private void checkInsertInsideMatch(FileSearchResult result, IFile file) throws PartInitException, BadLocationException {
Match[] matches= result.getMatches(file);
try {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
Job.getJobManager().beginRule(file, null);
IDocument doc= fb.getDocument();
Expand Down Expand Up @@ -129,7 +129,7 @@ private void checkInsertAtZero(AbstractTextSearchResult result, IFile file) thro
originalStarts[i]= matches[i].getOffset();
}
try {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
SearchTestUtil.openTextEditor(SearchPlugin.getActivePage(), file);
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
Job.getJobManager().beginRule(file, null);
IDocument doc= fb.getDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import org.eclipse.search.internal.ui.text.FileSearchPage;
import org.eclipse.search.internal.ui.text.FileSearchQuery;
import org.eclipse.search.tests.SearchTestPlugin;
import org.eclipse.search.tests.SearchTestUtil;
import org.eclipse.search.ui.ISearchResultViewPart;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
Expand All @@ -52,7 +52,7 @@ public class SearchResultPageTest {

@Before
public void setUp() throws Exception {
SearchTestPlugin.ensureWelcomePageClosed();
SearchTestUtil.ensureWelcomePageClosed();
String[] fileNamePatterns= { "*.java" };
FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(fileNamePatterns, false);

Expand Down
Loading