### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model diff --git src/org/eclipse/jdt/core/tests/model/JavaIndexTests.java src/org/eclipse/jdt/core/tests/model/JavaIndexTests.java index 1893d3f..32806ff 100644 --- src/org/eclipse/jdt/core/tests/model/JavaIndexTests.java +++ src/org/eclipse/jdt/core/tests/model/JavaIndexTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 IBM Corporation and others. + * Copyright (c) 2012, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -33,6 +33,7 @@ import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.UserLibraryClasspathContainer; +import org.eclipse.jdt.internal.core.search.indexing.IndexManager; import org.osgi.service.prefs.BackingStoreException; public class JavaIndexTests extends AbstractJavaSearchTests { @@ -863,4 +864,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 + System.setProperty(IndexManager.MANAGE_PRODUCT_INDEXES_PROPERTY, Boolean.TRUE.toString()); + 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(); + JavaCore.initializeAfterLoad(null); + 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 + System.setProperty(IndexManager.MANAGE_PRODUCT_INDEXES_PROPERTY, Boolean.FALSE.toString()); + // clean-up artifacts that were created + if(p != null) { + deleteProject("P"); + } + if (indexFile != null) { + indexFile.delete(); + } + jarFile.delete(); + } + } }