diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java index 916f317..248b7aa 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java @@ -2831,6 +2831,7 @@ JavaModelManager.doNotUse(); // reset the MANAGER singleton JavaModelManager.getJavaModelManager().startup(); new JavaCorePreferenceInitializer().initializeDefaultPreferences(); + JavaCore.initializeAfterLoad(null); } /** * Starts listening to element deltas, and queues them in fgDeltas. diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaIndexTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaIndexTests.java index 1893d3f..65dd51d 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaIndexTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaIndexTests.java @@ -863,4 +863,71 @@ deleteProject("ForIndex"); } } -} + + public void testManagingPreBuildIndexFile() throws CoreException, IOException { + + // locate the JDT core preference + String prefNodeName = "org.eclipse.jdt.core"; + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(prefNodeName); + if(prefs == null) { + fail("The preferences for '" + prefNodeName + "' could not be located."); + } + // create the pre-built index + File indexFile = null; + String jarFilePath = getExternalResourcePath("Test.jar"); + File jarFile = new File(jarFilePath); + IJavaProject p = null; + try { + createJar(new String[] { + "pkg/Test.java", + "package pkg;\n" + + "public class Test {\n" + + " protected Test(int i) {}\n" + + " protected void helloWorld() {}\n" + + "}"}, jarFilePath); + indexFile = new File(getExternalResourcePath("Test.index")); + JavaIndexer.generateIndexForJar(jarFilePath, indexFile.getAbsolutePath()); + // create project P and add the Test.jar to the classpath (associate the index to it) + p = createJavaProject("P"); + Path libPath = new Path(jarFilePath); + IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, indexFile.toURI().toURL().toString()); + IClasspathEntry entry = JavaCore.newLibraryEntry(libPath, null, null, null, new IClasspathAttribute[]{attribute}, false); + this.setClasspath(p, new IClasspathEntry[] {entry}); + AbstractJavaModelTests.waitUntilIndexesReady(); + // verify the current index is correct + this.resultCollector = new JavaSearchResultCollector(); + this.search("helloWorld", METHOD, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p})); + this.assertSearchResults(getExternalPath() + "Test.jar void pkg.Test.helloWorld()"); + // restart the product so the index manager enables management of pre-build indexes + prefs.put(JavaCore.MANAGE_PREBUILT_INDEXES, JavaCore.ENABLED); + this.simulateExit(); + // update the class file (when the product is not running) by changing + // the method signature (simulate the contents of a JAR file changing) + createJar(new String[] { + "pkg/Test.java", + "package pkg;\n" + + "public class Test {\n" + + " protected Test(int i) {}\n" + + " protected void helloWorld(int i) {}\n" + + "}"}, jarFilePath); + this.simulateRestart(); + AbstractJavaModelTests.waitUntilIndexesReady(); + // verify that the index is updated + this.resultCollector = new JavaSearchResultCollector(); + this.search("helloWorld", METHOD, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p})); + this.assertSearchResults(getExternalPath() + "Test.jar void pkg.Test.helloWorld(int)"); + } + finally { + // restart the product so the index manager disables management of pre-build indexes + prefs.put(JavaCore.MANAGE_PREBUILT_INDEXES, JavaCore.DISABLED); + // clean-up artifacts that were created + if(p != null) { + deleteProject("P"); + } + if (indexFile != null) { + indexFile.delete(); + } + jarFile.delete(); + } + } +} \ No newline at end of file