View | Details | Raw Unified | Return to bug 366544
Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaIndexTests.java (-17 / +20 lines)
Lines 169-177 Link Here
169
	}
169
	}
170
	
170
	
171
	// Test that the same index file is used even after restarting
171
	// Test that the same index file is used even after restarting
172
	public void _testUseIndexInternalJarAfterRestart() throws IOException, CoreException {
172
	public void testUseIndexInternalJarAfterRestart() throws IOException, CoreException {
173
		String indexFilePath = getExternalResourcePath("Test.index");
173
		String indexFilePath = getExternalResourcePath("Test.index");
174
		String jarFilePath = "/P/Test.jar";
174
		String jarFilePath = "/P/Test.jar";
175
		String fullJarPath = getWorkspacePath() + jarFilePath;
175
		try {
176
		try {
176
			IJavaProject p = createJavaProject("P");
177
			IJavaProject p = createJavaProject("P");
177
			createJar(new String[] {
178
			createJar(new String[] {
Lines 179-186 Link Here
179
					"package pkg;\n" +
180
					"package pkg;\n" +
180
					"public class Test {\n" +
181
					"public class Test {\n" +
181
					"  protected Test(int i) {}\n" +
182
					"  protected Test(int i) {}\n" +
182
					"}"}, jarFilePath);
183
					"}"}, fullJarPath);
183
			JavaIndexer.generateIndexForJar(jarFilePath, indexFilePath);
184
			p.getProject().refreshLocal(1, null);
185
			JavaIndexer.generateIndexForJar(fullJarPath, indexFilePath);
184
			long modified = new File(indexFilePath).lastModified();
186
			long modified = new File(indexFilePath).lastModified();
185
			IPath libPath = new Path(jarFilePath);
187
			IPath libPath = new Path(jarFilePath);
186
			IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, "file:///"+indexFilePath);
188
			IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, "file:///"+indexFilePath);
Lines 189-205 Link Here
189
			waitUntilIndexesReady();
191
			waitUntilIndexesReady();
190
			
192
			
191
			search("Test", TYPE, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p}));
193
			search("Test", TYPE, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p}));
192
			assertSearchResults("\\P\\Test.jar pkg.Test");
194
			assertSearchResults("Test.jar pkg.Test [No source]");
195
			java.io.File indexFile = JavaModelManager.getIndexManager().getIndex(libPath, false, false).getIndexFile();
196
			assertEquals(indexFilePath,indexFile.toString());
193
			
197
			
194
			simulateExitRestart();
198
			simulateExitRestart();
195
			getJavaModel().refreshExternalArchives(null, null);
196
			waitUntilIndexesReady();
199
			waitUntilIndexesReady();
197
			
200
			
198
			this.resultCollector = new JavaSearchResultCollector();
201
			this.resultCollector = new JavaSearchResultCollector();
199
			search("Test", TYPE, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p}));
202
			search("Test", TYPE, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p}));
200
			assertSearchResults("\\P\\Test.jar pkg.Test");
203
			assertSearchResults("Test.jar pkg.Test [No source]");
201
			
204
			
202
			java.io.File indexFile = JavaModelManager.getIndexManager().getIndex(libPath, false, false).getIndexFile();
205
			indexFile = JavaModelManager.getIndexManager().getIndex(libPath, false, false).getIndexFile();
203
			assertEquals(indexFilePath,indexFile.toString());
206
			assertEquals(indexFilePath,indexFile.toString());
204
			// Ensure that the file is not modified
207
			// Ensure that the file is not modified
205
			assertEquals(modified, new File(indexFilePath).lastModified());
208
			assertEquals(modified, new File(indexFilePath).lastModified());
Lines 593-601 Link Here
593
	}
596
	}
594
	
597
	
595
	// Test changing the classpath	
598
	// Test changing the classpath	
596
	public void _testChangeClasspathForInternalJar() throws CoreException, IOException {
599
	public void testChangeClasspathForInternalJar() throws CoreException, IOException {
597
		String indexFilePath = getExternalResourcePath("Test.index");
600
		String indexFilePath = getExternalResourcePath("Test.index");
598
		String jarFilePath = "/P/Test.jar";
601
		String jarFilePath = "/P/Test.jar";
602
		String fullJarPath = getWorkspacePath() + jarFilePath;
599
		try {
603
		try {
600
			IJavaProject p = createJavaProject("P");
604
			IJavaProject p = createJavaProject("P");
601
			createJar(new String[] {
605
			createJar(new String[] {
Lines 603-610 Link Here
603
					"package pkg;\n" +
607
					"package pkg;\n" +
604
					"public class Test {\n" +
608
					"public class Test {\n" +
605
					"  protected Test(int i) {}\n" +
609
					"  protected Test(int i) {}\n" +
606
					"}"}, jarFilePath);
610
					"}"}, fullJarPath);
607
			JavaIndexer.generateIndexForJar(jarFilePath, indexFilePath);
611
			JavaIndexer.generateIndexForJar(fullJarPath, indexFilePath);
608
			createJar(new String[] {
612
			createJar(new String[] {
609
					"pkg/Test.java",
613
					"pkg/Test.java",
610
					"package pkg;\n" +
614
					"package pkg;\n" +
Lines 615-628 Link Here
615
					"package pkg;\n" +
619
					"package pkg;\n" +
616
					"public class NewTest {\n" +
620
					"public class NewTest {\n" +
617
					"  protected NewTest(int i) {}\n" +
621
					"  protected NewTest(int i) {}\n" +
618
					"}"}, jarFilePath);
622
					"}"}, fullJarPath);
623
			p.getProject().refreshLocal(1, null);
619
			Path libPath = new Path(jarFilePath);
624
			Path libPath = new Path(jarFilePath);
620
			
625
			
621
			IClasspathEntry entry = JavaCore.newLibraryEntry(libPath, null, null, null, null, false);
626
			IClasspathEntry entry = JavaCore.newLibraryEntry(libPath, null, null, null, null, false);
622
			setClasspath(p, new IClasspathEntry[] {entry});
627
			setClasspath(p, new IClasspathEntry[] {entry});
623
			waitUntilIndexesReady();
628
			waitUntilIndexesReady();
624
			search("NewTest", TYPE, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p}));
629
			search("NewTest", TYPE, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p}));
625
			assertSearchResults("\\P\\Test.jar pkg.NewTest");
630
			assertSearchResults("Test.jar pkg.NewTest [No source]");
626
			
631
			
627
			IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, "file:///"+indexFilePath);
632
			IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, "file:///"+indexFilePath);
628
			entry = JavaCore.newLibraryEntry(libPath, null, null, null, new IClasspathAttribute[]{attribute}, false);
633
			entry = JavaCore.newLibraryEntry(libPath, null, null, null, new IClasspathAttribute[]{attribute}, false);
Lines 637-645 Link Here
637
			waitUntilIndexesReady();
642
			waitUntilIndexesReady();
638
			this.resultCollector = new JavaSearchResultCollector();
643
			this.resultCollector = new JavaSearchResultCollector();
639
			search("NewTest", TYPE, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p}));
644
			search("NewTest", TYPE, DECLARATIONS, EXACT_RULE, SearchEngine.createJavaSearchScope(new IJavaElement[]{p}));
640
			assertSearchResults("\\P\\Test.jar pkg.NewTest");
645
			assertSearchResults("Test.jar pkg.NewTest [No source]");	
641
			
642
			
643
		} finally {
646
		} finally {
644
			deleteProject("P");
647
			deleteProject("P");
645
			new File(indexFilePath).delete();
648
			new File(indexFilePath).delete();
Lines 766-772 Link Here
766
	}
769
	}
767
	
770
	
768
	// Test that it works if the index file is in the jar file
771
	// Test that it works if the index file is in the jar file
769
	public void _testIndexInJar() throws IOException, CoreException {
772
	public void testIndexInJar() throws IOException, CoreException {
770
		String indexFilePath = getExternalResourcePath("Test.index");
773
		String indexFilePath = getExternalResourcePath("Test.index");
771
		String jarFilePath = getExternalResourcePath("Test.jar");
774
		String jarFilePath = getExternalResourcePath("Test.jar");
772
		String indexZipPath =  getExternalResourcePath("TestIndex.zip");
775
		String indexZipPath =  getExternalResourcePath("TestIndex.zip");
Lines 783-789 Link Here
783
			
786
			
784
			IJavaProject p = createJavaProject("P");
787
			IJavaProject p = createJavaProject("P");
785
			Path libPath = new Path(jarFilePath);
788
			Path libPath = new Path(jarFilePath);
786
			String url = "jar:file:/"+indexZipPath+"!/Test.index";
789
			String url = "jar:file:"+indexZipPath+"!/Test.index";
787
			IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, url);
790
			IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, url);
788
			IClasspathEntry entry = JavaCore.newLibraryEntry(libPath, null, null, null, new IClasspathAttribute[]{attribute}, false);
791
			IClasspathEntry entry = JavaCore.newLibraryEntry(libPath, null, null, null, new IClasspathAttribute[]{attribute}, false);
789
			setClasspath(p, new IClasspathEntry[] {entry});
792
			setClasspath(p, new IClasspathEntry[] {entry});
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java (-1 / +62 lines)
Lines 53-58 Link Here
53
	/* can only replace a current state if its less than the new one */
53
	/* can only replace a current state if its less than the new one */
54
	// key = indexLocation path, value = index state integer
54
	// key = indexLocation path, value = index state integer
55
	private SimpleLookupTable indexStates = null;
55
	private SimpleLookupTable indexStates = null;
56
	private File indexNamesMapFile = new File(getSavedIndexesDirectory(), "indexNamesMap.txt"); //$NON-NLS-1$
56
	private File savedIndexNamesFile = new File(getSavedIndexesDirectory(), "savedIndexNames.txt"); //$NON-NLS-1$
57
	private File savedIndexNamesFile = new File(getSavedIndexesDirectory(), "savedIndexNames.txt"); //$NON-NLS-1$
57
	private File participantIndexNamesFile = new File(getSavedIndexesDirectory(), "participantsIndexNames.txt"); //$NON-NLS-1$
58
	private File participantIndexNamesFile = new File(getSavedIndexesDirectory(), "participantsIndexNames.txt"); //$NON-NLS-1$
58
	private boolean javaLikeNamesChanged = true;
59
	private boolean javaLikeNamesChanged = true;
Lines 394-399 Link Here
394
		this.javaLikeNamesChanged = false;
395
		this.javaLikeNamesChanged = false;
395
		deleteIndexFiles();
396
		deleteIndexFiles();
396
	}
397
	}
398
	readIndexMap();
397
	return this.indexStates;
399
	return this.indexStates;
398
}
400
}
399
private IPath getParticipantsContainer(IndexLocation indexLocation) {
401
private IPath getParticipantsContainer(IndexLocation indexLocation) {
Lines 517-523 Link Here
517
}
519
}
518
520
519
synchronized boolean addIndex(IPath containerPath, IndexLocation indexFile) {
521
synchronized boolean addIndex(IPath containerPath, IndexLocation indexFile) {
520
	this.indexStates.put(indexFile, REUSE_STATE);
522
	getIndexStates().put(indexFile, REUSE_STATE);
521
	this.indexLocations.put(containerPath, indexFile);
523
	this.indexLocations.put(containerPath, indexFile);
522
	Index index = getIndex(containerPath, indexFile, true, false);
524
	Index index = getIndex(containerPath, indexFile, true, false);
523
	if (index == null) {
525
	if (index == null) {
Lines 525-530 Link Here
525
		this.indexLocations.put(containerPath, null);
527
		this.indexLocations.put(containerPath, null);
526
		return false;
528
		return false;
527
	}
529
	}
530
	writeIndexMapFile();
528
	return true;
531
	return true;
529
}
532
}
530
533
Lines 906-911 Link Here
906
	return buffer.toString();
909
	return buffer.toString();
907
}
910
}
908
911
912
private void readIndexMap() {
913
	try {
914
		char[] indexMaps = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.indexNamesMapFile, null);
915
		if (indexMaps.length > 0) {
916
			char[][] names = CharOperation.splitOn('\n', indexMaps);
917
			if (names.length >= 3) {
918
				// First line is DiskIndex signature (see writeIndexMapFile())
919
				String savedSignature = DiskIndex.SIGNATURE;
920
				if (savedSignature.equals(new String(names[0]))) {
921
					for (int i = 1, l = names.length-1 ; i < l ; i+=2) {
922
						IndexLocation indexPath = IndexLocation.createIndexLocation(new URL(new String(names[i])));
923
						this.indexLocations.put(new Path(new String(names[i+1])), indexPath );
924
						this.indexStates.put(indexPath, REUSE_STATE);
925
					}
926
				}
927
					
928
			}
929
		}
930
	} catch (IOException ignored) {
931
		if (VERBOSE)
932
			Util.verbose("Failed to read saved index file names"); //$NON-NLS-1$
933
	}
934
	return;
935
}
909
private char[][] readIndexState(String dirOSString) {
936
private char[][] readIndexState(String dirOSString) {
910
	try {
937
	try {
911
		char[] savedIndexNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.savedIndexNamesFile, null);
938
		char[] savedIndexNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.savedIndexNamesFile, null);
Lines 963-968 Link Here
963
	if (!changed) return;
990
	if (!changed) return;
964
991
965
	writeSavedIndexNamesFile();
992
	writeSavedIndexNamesFile();
993
	writeIndexMapFile();
966
}
994
}
967
private synchronized void updateIndexState(IndexLocation indexLocation, Integer indexState) {
995
private synchronized void updateIndexState(IndexLocation indexLocation, Integer indexState) {
968
	if (indexLocation == null)
996
	if (indexLocation == null)
Lines 1037-1042 Link Here
1037
		}
1065
		}
1038
	}
1066
	}
1039
}
1067
}
1068
private void writeIndexMapFile() {
1069
	BufferedWriter writer = null;
1070
	try {
1071
		writer = new BufferedWriter(new FileWriter(this.indexNamesMapFile));
1072
		writer.write(DiskIndex.SIGNATURE);
1073
		writer.write('\n');
1074
		Object[] keys = this.indexStates.keyTable;
1075
		Object[] states = this.indexStates.valueTable;
1076
		for (int i = 0, l = states.length; i < l; i++) {
1077
			IndexLocation location = (IndexLocation)keys[i];
1078
			if (location != null && states[i] == REUSE_STATE) {
1079
				IPath container = (IPath)this.indexLocations.keyForValue(location);
1080
				if (container != null) {
1081
					writer.write(location.toString());
1082
					writer.write('\n');
1083
					writer.write(container.toOSString());
1084
					writer.write('\n');
1085
				}
1086
			}
1087
		}
1088
	} catch (IOException ignored) {
1089
		if (VERBOSE)
1090
			Util.verbose("Failed to write saved index file names", System.err); //$NON-NLS-1$
1091
	} finally {
1092
		if (writer != null) {
1093
			try {
1094
				writer.close();
1095
			} catch (IOException e) {
1096
				// ignore
1097
			}
1098
		}
1099
	}
1100
}
1040
private void writeParticipantsIndexNamesFile() {
1101
private void writeParticipantsIndexNamesFile() {
1041
	BufferedWriter writer = null;
1102
	BufferedWriter writer = null;
1042
	try {
1103
	try {

Return to bug 366544