Lines 20-25
Link Here
|
20 |
|
20 |
|
21 |
import org.eclipse.core.resources.IFile; |
21 |
import org.eclipse.core.resources.IFile; |
22 |
import org.eclipse.core.resources.IResource; |
22 |
import org.eclipse.core.resources.IResource; |
|
|
23 |
import org.eclipse.core.resources.IResourceChangeEvent; |
24 |
import org.eclipse.core.resources.IResourceChangeListener; |
23 |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
25 |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
24 |
import org.eclipse.core.runtime.CoreException; |
26 |
import org.eclipse.core.runtime.CoreException; |
25 |
import org.eclipse.core.runtime.IPath; |
27 |
import org.eclipse.core.runtime.IPath; |
Lines 10920-10932
Link Here
|
10920 |
* If any javaLikeNames are deleted, this ensures that the index file is regenerated. |
10922 |
* If any javaLikeNames are deleted, this ensures that the index file is regenerated. |
10921 |
*/ |
10923 |
*/ |
10922 |
public void testBug286379c() throws CoreException { |
10924 |
public void testBug286379c() throws CoreException { |
|
|
10925 |
class TestResourceChangeListener implements IResourceChangeListener { |
10926 |
boolean valid = false; |
10927 |
public void resourceChanged(IResourceChangeEvent event) { |
10928 |
System.out.println("ResourceChangeEvent event:"); |
10929 |
System.out.println(" - event type: "+event.getType()); |
10930 |
System.out.println(" - resource: "+event.getResource()); |
10931 |
this.valid = true; |
10932 |
} |
10933 |
} |
10934 |
|
10923 |
IContentType javaContentType = Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE); |
10935 |
IContentType javaContentType = Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE); |
|
|
10936 |
TestResourceChangeListener changeListener = new TestResourceChangeListener(); |
10924 |
try { |
10937 |
try { |
10925 |
// Create resource and wait for the refresh as we do not want the |
10938 |
// Create resource |
10926 |
// indexing to be triggered by the resource change event after the |
10939 |
createJavaProject("P"); |
10927 |
// Java Source content type will be added |
|
|
10928 |
IJavaProject proj = createJavaProject("P"); |
10929 |
IPath projPath = proj.getPath(); |
10930 |
createFolder("/P/p"); |
10940 |
createFolder("/P/p"); |
10931 |
createFile( |
10941 |
createFile( |
10932 |
"/P/p/Xtorem.torem", |
10942 |
"/P/p/Xtorem.torem", |
Lines 10934-10947
Link Here
|
10934 |
"public class Xtorem {\n" + |
10944 |
"public class Xtorem {\n" + |
10935 |
"}" |
10945 |
"}" |
10936 |
); |
10946 |
); |
10937 |
refresh(proj); |
|
|
10938 |
|
10947 |
|
10939 |
// Wait to be sure that indexes are ready as we want to see whether |
10948 |
// Wait to be sure that indexes are ready after the resource creation |
10940 |
// they'll be updated or not while adding a Java Source content type |
|
|
10941 |
waitUntilIndexesReady(); |
10949 |
waitUntilIndexesReady(); |
10942 |
|
10950 |
|
|
|
10951 |
// Add the resource listener |
10952 |
getWorkspace().addResourceChangeListener(changeListener, IResourceChangeEvent.POST_CHANGE); |
10953 |
|
10954 |
// Change the file extension |
10943 |
assertNotNull("We should have got a Java Source a content type!", javaContentType); |
10955 |
assertNotNull("We should have got a Java Source a content type!", javaContentType); |
10944 |
javaContentType.addFileSpec("torem", IContentType.FILE_EXTENSION_SPEC); |
10956 |
javaContentType.addFileSpec("torem", IContentType.FILE_EXTENSION_SPEC); |
|
|
10957 |
|
10958 |
// Wait for all the resource event before continuing |
10959 |
// Note that if we are not waiting for this event occurring then the search may |
10960 |
// fail as we don't get any specific event from the platform to refresh the indexes. |
10961 |
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=118619 |
10962 |
int counter = 0; |
10963 |
while (!changeListener.valid) { |
10964 |
try { |
10965 |
Thread.sleep(100); |
10966 |
} |
10967 |
catch (InterruptedException ie) { |
10968 |
// skip |
10969 |
} |
10970 |
assertTrue("We should have got a resource event within a 10s delay!", counter++ < 100); |
10971 |
} |
10972 |
|
10973 |
// Search for the new type with new extension |
10945 |
TypeNameMatchCollector collector = new TypeNameMatchCollector(); |
10974 |
TypeNameMatchCollector collector = new TypeNameMatchCollector(); |
10946 |
new SearchEngine().searchAllTypeNames( |
10975 |
new SearchEngine().searchAllTypeNames( |
10947 |
null, |
10976 |
null, |
Lines 10950-10964
Link Here
|
10950 |
collector, |
10979 |
collector, |
10951 |
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, |
10980 |
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, |
10952 |
null); |
10981 |
null); |
10953 |
// Actually it would be great if we could get the file in the search result, |
10982 |
assertSearchResults("Unexpected search results!", |
10954 |
// but currently this doesn't happen as we don't get the appropriate delta |
10983 |
"Xtorem (not open) [in Xtorem.torem [in p [in <project root> [in P]]]]", |
10955 |
// events from the platform. We should change the test if this is fixed. |
10984 |
collector); |
10956 |
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=118619 |
|
|
10957 |
assertSearchResults("No search results expected", "", collector, false /*do not fail if not equals (debug bug 293697)*/); |
10958 |
|
10985 |
|
10959 |
// Restarting should make the search to succeed. |
10986 |
// Delete the file specification |
|
|
10987 |
javaContentType.removeFileSpec("torem", IContentType.FILE_EXTENSION_SPEC); |
10988 |
|
10989 |
// Restarting should update the index file to remove the references of any .torem files |
10960 |
simulateExit(); |
10990 |
simulateExit(); |
10961 |
simulateRestart(); |
10991 |
simulateRestart(); |
|
|
10992 |
waitUntilIndexesReady(); |
10993 |
|
10994 |
// Search for the new type with new extension |
10962 |
collector = new TypeNameMatchCollector(); |
10995 |
collector = new TypeNameMatchCollector(); |
10963 |
new SearchEngine().searchAllTypeNames( |
10996 |
new SearchEngine().searchAllTypeNames( |
10964 |
null, |
10997 |
null, |
Lines 10967-10997
Link Here
|
10967 |
collector, |
11000 |
collector, |
10968 |
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, |
11001 |
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, |
10969 |
null); |
11002 |
null); |
10970 |
String expected = "Xtorem (not open) [in Xtorem.torem [in p [in <project root> [in P]]]]"; |
11003 |
assertSearchResults("No search results expected", "", collector); |
10971 |
assertSearchResults(expected, collector); |
|
|
10972 |
javaContentType.removeFileSpec("torem", IContentType.FILE_EXTENSION_SPEC); |
10973 |
|
10974 |
// Get the time stamp of the index file |
10975 |
IndexManager manager = JavaModelManager.getIndexManager(); |
10976 |
Index index = manager.getIndex(projPath, true, false); |
10977 |
File indexFile = index.getIndexFile(); |
10978 |
long lastModified = indexFile.lastModified(); |
10979 |
|
10980 |
// Restarting should update the index file to remove the references of any .torem files |
10981 |
simulateExit(); |
10982 |
try { |
10983 |
Thread.sleep(1500); // wait more than one second to be sure that modified time will be different |
10984 |
} |
10985 |
catch (InterruptedException ie) { |
10986 |
// skip |
10987 |
} |
10988 |
simulateRestart(); |
10989 |
|
10990 |
waitUntilIndexesReady(); |
10991 |
Index newIndex = manager.getIndex(projPath , true, false); |
10992 |
assertTrue("Index file should be changed!!!", newIndex.getIndexFile().lastModified() - lastModified != 0); |
10993 |
|
10994 |
} finally { |
11004 |
} finally { |
|
|
11005 |
getWorkspace().removeResourceChangeListener(changeListener); |
10995 |
if (javaContentType != null) |
11006 |
if (javaContentType != null) |
10996 |
javaContentType.removeFileSpec("torem", IContentType.FILE_EXTENSION_SPEC); |
11007 |
javaContentType.removeFileSpec("torem", IContentType.FILE_EXTENSION_SPEC); |
10997 |
deleteProject("P"); |
11008 |
deleteProject("P"); |