Lines 863-866
Link Here
|
863 |
deleteProject("ForIndex"); |
863 |
deleteProject("ForIndex"); |
864 |
} |
864 |
} |
865 |
} |
865 |
} |
866 |
} |
866 |
|
|
|
867 |
public void testManagingPreBuildIndexFile() throws CoreException, IOException { |
868 |
|
869 |
// locate the JDT core preference |
870 |
String prefNodeName = "org.eclipse.jdt.core"; |
871 |
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(prefNodeName); |
872 |
if(prefs == null) { |
873 |
fail("The preferences for '" + prefNodeName + "' could not be located."); |
874 |
} |
875 |
// create the pre-built index |
876 |
File indexFile = null; |
877 |
String jarFilePath = getExternalResourcePath("Test.jar"); |
878 |
File jarFile = new File(jarFilePath); |
879 |
IJavaProject p = null; |
880 |
try { |
881 |
createJar(new String[] { |
882 |
"pkg/Test.java", |
883 |
"package pkg;\n" + |
884 |
"public class Test {\n" + |
885 |
" protected Test(int i) {}\n" + |
886 |
" protected void helloWorld() {}\n" + |
887 |
"}"}, jarFilePath); |
888 |
indexFile = new File(getExternalResourcePath("Test.index")); |
889 |
JavaIndexer.generateIndexForJar(jarFilePath, indexFile.getAbsolutePath()); |
890 |
// create project P and add the Test.jar to the classpath (associate the index to it) |
891 |
p = createJavaProject("P"); |
892 |
Path libPath = new Path(jarFilePath); |
893 |
IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, indexFile.toURI().toURL().toString()); |
894 |
IClasspathEntry entry = JavaCore.newLibraryEntry(libPath, null, null, null, new IClasspathAttribute[]{attribute}, false); |
895 |
this.setClasspath(p, new IClasspathEntry[] {entry}); |
896 |
AbstractJavaModelTests.waitUntilIndexesReady(); |
897 |
// verify the current index is correct |
898 |
this.resultCollector = new JavaSearchResultCollector(); |
899 |
this.search("helloWorld", METHOD, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p})); |
900 |
this.assertSearchResults(getExternalPath() + "Test.jar void pkg.Test.helloWorld()"); |
901 |
// enable the preference for JDT to manage pre-build index files |
902 |
prefs.put(JavaCore.MANAGE_PREBUILT_INDEXES, JavaCore.ENABLED); |
903 |
// update the JAR file (simulate the JAR file changing) |
904 |
createJar(new String[] { |
905 |
"pkg/Test.java", |
906 |
"package pkg;\n" + |
907 |
"public class Test {\n" + |
908 |
" protected Test(int i) {}\n" + |
909 |
" protected void helloWorld(int i) {}\n" + |
910 |
"}"}, jarFilePath); |
911 |
// restart the product so the index manager enables management of pre-build indexes |
912 |
this.simulateExitRestart(); |
913 |
// verify that the index is updated |
914 |
AbstractJavaModelTests.waitUntilIndexesReady(); |
915 |
this.resultCollector = new JavaSearchResultCollector(); |
916 |
this.search("helloWorld", METHOD, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p})); |
917 |
this.assertSearchResults(getExternalPath() + "Test.jar void pkg.Test.helloWorld(int)"); |
918 |
} |
919 |
finally { |
920 |
// restart the product so the index manager disables management of pre-build indexes |
921 |
prefs.put(JavaCore.MANAGE_PREBUILT_INDEXES, JavaCore.DISABLED); |
922 |
this.simulateExitRestart(); |
923 |
// clean-up artifacts that were created |
924 |
if(p != null) { |
925 |
deleteProject("P"); |
926 |
} |
927 |
if (indexFile != null) { |
928 |
indexFile.delete(); |
929 |
} |
930 |
jarFile.delete(); |
931 |
} |
932 |
} |
933 |
} |