View | Details | Raw Unified | Return to bug 356620 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 1025-1031 Link Here
1025
1025
1026
		// Index the output location as it is a library for the project
1026
		// Index the output location as it is a library for the project
1027
		IndexManager indexManager = JavaModelManager.getIndexManager();
1027
		IndexManager indexManager = JavaModelManager.getIndexManager();
1028
		indexManager.indexLibrary(new Path("/P1/bin"), project.getProject());
1028
		indexManager.indexLibrary(new Path("/P1/bin"), project.getProject(), null);
1029
		waitUntilIndexesReady();
1029
		waitUntilIndexesReady();
1030
1030
1031
		// Search for all types
1031
		// Search for all types
(-)a/org.eclipse.jdt.core/META-INF/MANIFEST.MF (+1 lines)
Lines 17-22 Link Here
17
 org.eclipse.jdt.core.jdom,
17
 org.eclipse.jdt.core.jdom,
18
 org.eclipse.jdt.core.search,
18
 org.eclipse.jdt.core.search,
19
 org.eclipse.jdt.core.util,
19
 org.eclipse.jdt.core.util,
20
 org.eclipse.jdt.core.index,
20
 org.eclipse.jdt.internal.codeassist;x-internal:=true,
21
 org.eclipse.jdt.internal.codeassist;x-internal:=true,
21
 org.eclipse.jdt.internal.codeassist.complete;x-internal:=true,
22
 org.eclipse.jdt.internal.codeassist.complete;x-internal:=true,
22
 org.eclipse.jdt.internal.codeassist.impl;x-internal:=true,
23
 org.eclipse.jdt.internal.codeassist.impl;x-internal:=true,
(-)a/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/messages.properties (-1 / +5 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2006 IBM Corporation and others.
2
# Copyright (c) 2000, 2011 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 19-21 Link Here
19
checkDebugAttributes.property.argument.cannot.be.null=The property argument cannot be null
19
checkDebugAttributes.property.argument.cannot.be.null=The property argument cannot be null
20
checkDebugAttributes.ioexception.occured=IOException occurred while reading 
20
checkDebugAttributes.ioexception.occured=IOException occurred while reading 
21
checkDebugAttributes.file.argument.must.be.a.classfile.or.a.jarfile=The file argument must be a .class or a .jar file
21
checkDebugAttributes.file.argument.must.be.a.classfile.or.a.jarfile=The file argument must be a .class or a .jar file
22
23
buildJarIndex.jarFile.cannot.be.null=The jar file argument cannot be null
24
buildJarIndex.indexFile.cannot.be.null=The index file argument cannot be null
25
buildJarIndex.ioexception.occured=IOException - {0}
(-)a/org.eclipse.jdt.core/build.properties (-2 / +3 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2010 IBM Corporation and others.
2
# Copyright (c) 2000, 2011 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 24-30 Link Here
24
                   org.eclipse.jdt.core.jdom.*,\
24
                   org.eclipse.jdt.core.jdom.*,\
25
                   org.eclipse.jdt.core.dom.*,\
25
                   org.eclipse.jdt.core.dom.*,\
26
                   org.eclipse.jdt.core.dom.rewrite.*,\
26
                   org.eclipse.jdt.core.dom.rewrite.*,\
27
                   org.eclipse.jdt.core.search.*
27
                   org.eclipse.jdt.core.search.*,\
28
                   org.eclipse.jdt.core.index.*
28
source.. =   batch/,\
29
source.. =   batch/,\
29
	         codeassist/,\
30
	         codeassist/,\
30
	         compiler/,\
31
	         compiler/,\
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2010 IBM Corporation and others.
2
 * Copyright (c) 2005, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 58-63 Link Here
58
	 * @since 3.1
58
	 * @since 3.1
59
	 */
59
	 */
60
	String JAVADOC_LOCATION_ATTRIBUTE_NAME = "javadoc_location"; //$NON-NLS-1$
60
	String JAVADOC_LOCATION_ATTRIBUTE_NAME = "javadoc_location"; //$NON-NLS-1$
61
	
62
	/**
63
	 * Constant for the name of the index location attribute.
64
	 * 
65
	 * <p>The value for this attribute has to be the string representation of a URL.
66
	 * It should point to an existing index file in a folder or a jar.</p>
67
	 * 
68
	 * @since 3.8
69
	 */
70
	String INDEX_LOCATION_ATTRIBUTE_NAME = "index_location"; //$NON-NLS-1$
61
71
62
	/**
72
	/**
63
	 * Constant for the name of the optional attribute. The possible values
73
	 * Constant for the name of the optional attribute. The possible values
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaElementDelta.java (+26 lines)
Lines 57-62 Link Here
57
 * <li>{@link #F_SOURCEDETACHED} - The source attachment path or the source attachment root path
57
 * <li>{@link #F_SOURCEDETACHED} - The source attachment path or the source attachment root path
58
 * of a classpath entry corresponding to the element was removed. This flag is only valid if the element is an
58
 * of a classpath entry corresponding to the element was removed. This flag is only valid if the element is an
59
 * {@link IPackageFragmentRoot}.</li>
59
 * {@link IPackageFragmentRoot}.</li>
60
 * <li>{@link #F_INDEXATTACHED} - The index path or the index root path
61
 * of a classpath entry corresponding to the element was added. This flag is only valid if the element is an
62
 * {@link IPackageFragmentRoot}.</li>
63
 * <li>{@link #F_INDEXDETACHED} - The index path or the index root path
64
 * of a classpath entry corresponding to the element was removed. This flag is only valid if the element is an
65
 * {@link IPackageFragmentRoot}.</li>
60
 * <li>{@link #F_SUPER_TYPES} - One of the supertypes of an {@link IType} has changed</li>.
66
 * <li>{@link #F_SUPER_TYPES} - One of the supertypes of an {@link IType} has changed</li>.
61
 * </ul>
67
 * </ul>
62
 * </li>
68
 * </li>
Lines 312-317 Link Here
312
	 * @since 3.4
318
	 * @since 3.4
313
	 */
319
	 */
314
	public int F_ANNOTATIONS = 0x400000;
320
	public int F_ANNOTATIONS = 0x400000;
321
	
322
	/**
323
	 * TODO SATYAM: We probably don't need this delta..
324
	 * 
325
	 * Change flag indicating that the index file of a classpath entry
326
	 * corresponding to the element was added. This flag is only valid if the element is an
327
	 * {@link IPackageFragmentRoot}.
328
	 * 
329
	 * @since 3.8
330
	 */
331
	public int F_INDEXATTACHED = 0x800000;
332
	
333
	/**
334
	 * Change flag indicating that the index file of a classpath entry
335
	 * corresponding to the element was removed. This flag is only valid if the element is an
336
	 * {@link IPackageFragmentRoot}.
337
	 * 
338
	 * @since 3.8
339
	 */
340
	public int F_INDEXDETACHED = 0x1000000;
315
341
316
	/**
342
	/**
317
	 * Returns deltas for the children that have been added.
343
	 * Returns deltas for the children that have been added.
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IPackageFragmentRoot.java (-1 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-23 Link Here
18
 *******************************************************************************/
18
 *******************************************************************************/
19
package org.eclipse.jdt.core;
19
package org.eclipse.jdt.core;
20
20
21
import java.net.URL;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
23
24
Lines 243-248 Link Here
243
	 */
244
	 */
244
	void delete(int updateResourceFlags, int updateModelFlags, IProgressMonitor monitor) throws JavaModelException;
245
	void delete(int updateResourceFlags, int updateModelFlags, IProgressMonitor monitor) throws JavaModelException;
245
	/**
246
	/**
247
	 * Returns the URL to the index file attached to this package fragment root's binary archive.
248
	 *
249
	 * @return the URL to the corresponding index file,
250
	 *   or <code>null</code> if this package fragment root's binary archive
251
	 *   has no corresponding index file, or if this package fragment root
252
	 *   is not a binary archive
253
	 * @exception JavaModelException if this operation fails
254
	 * 
255
	 * @since 3.8
256
	 */
257
	URL getIndexPath() throws JavaModelException;
258
	/**
246
	 * Returns this package fragment root's kind encoded as an integer.
259
	 * Returns this package fragment root's kind encoded as an integer.
247
	 * A package fragment root can contain source files (i.e. files with one
260
	 * A package fragment root can contain source files (i.e. files with one
248
	 * of the {@link JavaCore#getJavaLikeExtensions() Java-like extensions},
261
	 * of the {@link JavaCore#getJavaLikeExtensions() Java-like extensions},
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathChange.java (-4 / +36 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.net.URL;
13
import java.util.ArrayList;
14
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.HashSet;
Lines 362-373 Link Here
362
				}
363
				}
363
364
364
				// check source attachment
365
				// check source attachment
366
				// TODO SATYAM: Understand this
365
				IPath newSourcePath = newResolvedClasspath[index].getSourceAttachmentPath();
367
				IPath newSourcePath = newResolvedClasspath[index].getSourceAttachmentPath();
366
				int sourceAttachmentFlags = getSourceAttachmentDeltaFlag(this.oldResolvedClasspath[i].getSourceAttachmentPath(), newSourcePath);
368
				int sourceAttachmentFlags = getSourceAttachmentDeltaFlag(this.oldResolvedClasspath[i].getSourceAttachmentPath(), newSourcePath);
367
				IPath oldRootPath = this.oldResolvedClasspath[i].getSourceAttachmentRootPath();
369
				IPath oldRootPath = this.oldResolvedClasspath[i].getSourceAttachmentRootPath();
368
				IPath newRootPath = newResolvedClasspath[index].getSourceAttachmentRootPath();
370
				IPath newRootPath = newResolvedClasspath[index].getSourceAttachmentRootPath();
369
				int sourceAttachmentRootFlags = getSourceAttachmentDeltaFlag(oldRootPath, newRootPath);
371
				int sourceAttachmentRootFlags = getSourceAttachmentDeltaFlag(oldRootPath, newRootPath);
370
				int flags = sourceAttachmentFlags | sourceAttachmentRootFlags;
372
				URL newIndexPath = ((ClasspathEntry)newResolvedClasspath[index]).getLibraryIndexLocation();
373
				int indexFlags = getIndexDeltaFlag(((ClasspathEntry)this.oldResolvedClasspath[i]).getLibraryIndexLocation(), newIndexPath);
374
				int flags = sourceAttachmentFlags | sourceAttachmentRootFlags | indexFlags;
371
				if (flags != 0) {
375
				if (flags != 0) {
372
					addClasspathDeltas(delta, this.project.computePackageFragmentRoots(this.oldResolvedClasspath[i]), flags);
376
					addClasspathDeltas(delta, this.project.computePackageFragmentRoots(this.oldResolvedClasspath[i]), flags);
373
				} else {
377
				} else {
Lines 432-437 Link Here
432
		}
436
		}
433
437
434
		return result;
438
		return result;
439
	}
440
441
	/*
442
	 * TODO SATYAM: Put a comment
443
	 */
444
	private int getIndexDeltaFlag(URL oldPath, URL newPath) {
445
		if (oldPath == null) {
446
			if (newPath != null) {
447
				return IJavaElementDelta.F_INDEXATTACHED;
448
			} else {
449
				return 0;
450
			}
451
		} else if (newPath == null) {
452
			return IJavaElementDelta.F_INDEXDETACHED;
453
		} else if (!oldPath.equals(newPath)) {
454
			return IJavaElementDelta.F_INDEXATTACHED | IJavaElementDelta.F_INDEXDETACHED;
455
		} else {
456
			return 0;
457
		}
435
	}
458
	}
436
459
437
	/*
460
	/*
Lines 511-517 Link Here
511
534
512
		for (int i = 0; i < newLength; i++) {
535
		for (int i = 0; i < newLength; i++) {
513
			int index = classpathContains(this.oldResolvedClasspath, newResolvedClasspath[i]);
536
			int index = classpathContains(this.oldResolvedClasspath, newResolvedClasspath[i]);
514
			if (index == -1) {
537
			if (index == -1 || newResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
515
				// remote projects are not indexed in this project
538
				// remote projects are not indexed in this project
516
				if (newResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT){
539
				if (newResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT){
517
					continue;
540
					continue;
Lines 524-537 Link Here
524
						boolean pathHasChanged = true;
547
						boolean pathHasChanged = true;
525
						IPath newPath = newResolvedClasspath[i].getPath();
548
						IPath newPath = newResolvedClasspath[i].getPath();
526
						for (int j = 0; j < oldLength; j++) {
549
						for (int j = 0; j < oldLength; j++) {
550
							//TODO SATYAM: Isn't index == j?
527
							IClasspathEntry oldEntry = this.oldResolvedClasspath[j];
551
							IClasspathEntry oldEntry = this.oldResolvedClasspath[j];
528
							if (oldEntry.getPath().equals(newPath)) {
552
							if (oldEntry.getPath().equals(newPath)) {
529
								pathHasChanged = false;
553
								URL oldurl = ((ClasspathEntry)oldEntry).getLibraryIndexLocation();
554
								URL newurl = ((ClasspathEntry)newResolvedClasspath[i]).getLibraryIndexLocation();
555
								if (oldurl == null && newurl == null) {
556
									pathHasChanged = false;
557
								} else if (oldurl != null && newurl != null) {
558
									pathHasChanged = !(newurl.equals(oldurl));
559
								} else if (oldurl != null) {
560
									indexManager.removeIndex(newPath);
561
								}
530
								break;
562
								break;
531
							}
563
							}
532
						}
564
						}
533
						if (pathHasChanged) {
565
						if (pathHasChanged) {
534
							indexManager.indexLibrary(newPath, this.project.getProject());
566
							indexManager.indexLibrary(newPath, this.project.getProject(),((ClasspathEntry)newResolvedClasspath[i]).getLibraryIndexLocation());
535
						}
567
						}
536
						break;
568
						break;
537
					case IClasspathEntry.CPE_SOURCE:
569
					case IClasspathEntry.CPE_SOURCE:
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java (+29 lines)
Lines 16-21 Link Here
16
import java.io.InputStream;
16
import java.io.InputStream;
17
import java.io.OutputStreamWriter;
17
import java.io.OutputStreamWriter;
18
import java.io.UnsupportedEncodingException;
18
import java.io.UnsupportedEncodingException;
19
import java.net.MalformedURLException;
20
import java.net.URL;
19
import java.util.ArrayList;
21
import java.util.ArrayList;
20
import java.util.HashMap;
22
import java.util.HashMap;
21
import java.util.HashSet;
23
import java.util.HashSet;
Lines 2164-2167 Link Here
2164
		}
2166
		}
2165
		return JavaModelStatus.VERIFIED_OK;
2167
		return JavaModelStatus.VERIFIED_OK;
2166
	}
2168
	}
2169
	
2170
	/*
2171
	 * This function computes the URL of the index location for this classpath entry.
2172
	 * It returns null if the URL is invalid.
2173
	 */
2174
	public URL getLibraryIndexLocation() {
2175
		switch(getEntryKind()) {
2176
			case IClasspathEntry.CPE_LIBRARY :
2177
			case IClasspathEntry.CPE_VARIABLE :
2178
				break;
2179
			default :
2180
				return null;
2181
		}
2182
2183
		for (int i= 0; i < this.extraAttributes.length; i++) {
2184
			IClasspathAttribute attrib= this.extraAttributes[i];
2185
			if (IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) {
2186
				String value = attrib.getValue();
2187
				try {
2188
					return new URL(value);
2189
				} catch (MalformedURLException e) {
2190
					return null;
2191
				}
2192
			}
2193
		}
2194
		return null;
2195
	}	
2167
}
2196
}
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessingState.java (-2 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-23 Link Here
18
import java.io.FileInputStream;
18
import java.io.FileInputStream;
19
import java.io.FileOutputStream;
19
import java.io.FileOutputStream;
20
import java.io.IOException;
20
import java.io.IOException;
21
import java.net.URL;
21
import java.util.*;
22
import java.util.*;
22
23
23
import org.eclipse.core.resources.*;
24
import org.eclipse.core.resources.*;
Lines 75-80 Link Here
75
	/* A table from IPath (a source attachment path from a classpath entry) to IPath (a root path) */
76
	/* A table from IPath (a source attachment path from a classpath entry) to IPath (a root path) */
76
	public HashMap sourceAttachments = new HashMap();
77
	public HashMap sourceAttachments = new HashMap();
77
78
79
	/* TODO SATYAM: Is this necessary?*/
80
	public HashMap indexMap = new HashMap();
81
	
78
	/* A table from IJavaProject to IJavaProject[] (the list of direct dependent of the key) */
82
	/* A table from IJavaProject to IJavaProject[] (the list of direct dependent of the key) */
79
	public HashMap projectDependencies = new HashMap();
83
	public HashMap projectDependencies = new HashMap();
80
84
Lines 262-267 Link Here
262
				this.otherRoots = rootInfos[1];
266
				this.otherRoots = rootInfos[1];
263
				this.sourceAttachments = rootInfos[2];
267
				this.sourceAttachments = rootInfos[2];
264
				this.projectDependencies = rootInfos[3];
268
				this.projectDependencies = rootInfos[3];
269
				this.indexMap = rootInfos[4];
265
				this.rootsAreStale = false;
270
				this.rootsAreStale = false;
266
			}
271
			}
267
		}
272
		}
Lines 274-279 Link Here
274
			this.otherRoots = rootInfos[1];
279
			this.otherRoots = rootInfos[1];
275
			this.sourceAttachments = rootInfos[2];
280
			this.sourceAttachments = rootInfos[2];
276
			this.projectDependencies = rootInfos[3];
281
			this.projectDependencies = rootInfos[3];
282
			this.indexMap = rootInfos[4];
277
			this.rootsAreStale = false;
283
			this.rootsAreStale = false;
278
		}
284
		}
279
	}
285
	}
Lines 283-288 Link Here
283
		HashMap newOtherRoots = new HashMap();
289
		HashMap newOtherRoots = new HashMap();
284
		HashMap newSourceAttachments = new HashMap();
290
		HashMap newSourceAttachments = new HashMap();
285
		HashMap newProjectDependencies = new HashMap();
291
		HashMap newProjectDependencies = new HashMap();
292
		HashMap newIndexes = new HashMap();
286
293
287
		IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
294
		IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
288
		IJavaProject[] projects;
295
		IJavaProject[] projects;
Lines 354-362 Link Here
354
				if (sourceAttachmentPath != null) {
361
				if (sourceAttachmentPath != null) {
355
					newSourceAttachments.put(sourceAttachmentPath, path);
362
					newSourceAttachments.put(sourceAttachmentPath, path);
356
				}
363
				}
364
			
365
				//TODO SATYAM: Do we need something like this?
366
				URL url = ((ClasspathEntry)entry).getLibraryIndexLocation();
367
				if (url != null) {
368
					newIndexes.put(url, path);
369
				}
357
			}
370
			}
358
		}
371
		}
359
		return new HashMap[] {newRoots, newOtherRoots, newSourceAttachments, newProjectDependencies};
372
		return new HashMap[] {newRoots, newOtherRoots, newSourceAttachments, newProjectDependencies, newIndexes};
360
	}
373
	}
361
374
362
	public synchronized ClasspathValidation[] removeClasspathValidations() {
375
	public synchronized ClasspathValidation[] removeClasspathValidations() {
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-4 / +37 lines)
Lines 590-595 Link Here
590
			}
590
			}
591
		}
591
		}
592
	}
592
	}
593
	private void checkIndexChange(IResourceDelta delta, IResource res) {
594
		IPath rootPath = (IPath)this.state.indexMap.get(externalPath(res));
595
		if (rootPath != null) {
596
			RootInfo rootInfo = rootInfo(rootPath, delta.getKind());
597
			if (rootInfo != null) {
598
				IJavaProject projectOfRoot = rootInfo.project;
599
				IPackageFragmentRoot root = null;
600
				try {
601
					// close the root so that source attachment cache is flushed
602
					root = projectOfRoot.findPackageFragmentRoot(rootPath);
603
					if (root != null) {
604
						root.close();
605
					}
606
				} catch (JavaModelException e) {
607
					// root doesn't exist: ignore
608
				}
609
				if (root == null) return;
610
				switch (delta.getKind()) {
611
					case IResourceDelta.ADDED:
612
						currentDelta().indexAttached(root);
613
						break;
614
					case IResourceDelta.CHANGED:
615
						currentDelta().indexDetached(root);
616
						currentDelta().indexAttached(root);
617
						break;
618
					case IResourceDelta.REMOVED:
619
						currentDelta().indexDetached(root);
620
						break;
621
				}
622
			}
623
		}
624
	}
593
	/*
625
	/*
594
	 * Closes the given element, which removes it from the cache of open elements.
626
	 * Closes the given element, which removes it from the cache of open elements.
595
	 */
627
	 */
Lines 996-1002 Link Here
996
									// first remove the index so that it is forced to be re-indexed
1028
									// first remove the index so that it is forced to be re-indexed
997
									this.manager.indexManager.removeIndex(entryPath);
1029
									this.manager.indexManager.removeIndex(entryPath);
998
									// then index the jar
1030
									// then index the jar
999
									this.manager.indexManager.indexLibrary(entryPath, project.getProject());
1031
									this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation());
1000
								} else {
1032
								} else {
1001
									externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
1033
									externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
1002
								}
1034
								}
Lines 1008-1014 Link Here
1008
									this.state.getExternalLibTimeStamps().put(entryPath, new Long(newTimeStamp));
1040
									this.state.getExternalLibTimeStamps().put(entryPath, new Long(newTimeStamp));
1009
									// index the new jar
1041
									// index the new jar
1010
									this.manager.indexManager.removeIndex(entryPath);
1042
									this.manager.indexManager.removeIndex(entryPath);
1011
									this.manager.indexManager.indexLibrary(entryPath, project.getProject());
1043
									this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation());
1012
								}
1044
								}
1013
							}
1045
							}
1014
						} else { // internal JAR
1046
						} else { // internal JAR
Lines 2239-2244 Link Here
2239
2271
2240
				// check source attachment change
2272
				// check source attachment change
2241
				checkSourceAttachmentChange(child, childRes);
2273
				checkSourceAttachmentChange(child, childRes);
2274
				checkIndexChange(child, childRes);
2242
2275
2243
				// find out whether the child is a package fragment root of the current project
2276
				// find out whether the child is a package fragment root of the current project
2244
				IPath childPath = externalPath(childRes);
2277
				IPath childPath = externalPath(childRes);
Lines 2628-2640 Link Here
2628
					switch (delta.getKind()) {
2661
					switch (delta.getKind()) {
2629
						case IResourceDelta.ADDED:
2662
						case IResourceDelta.ADDED:
2630
							// index the new jar
2663
							// index the new jar
2631
							indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
2664
							indexManager.indexLibrary(jarPath, root.getJavaProject().getProject(), root.getIndexPath() );
2632
							break;
2665
							break;
2633
						case IResourceDelta.CHANGED:
2666
						case IResourceDelta.CHANGED:
2634
							// first remove the index so that it is forced to be re-indexed
2667
							// first remove the index so that it is forced to be re-indexed
2635
							indexManager.removeIndex(jarPath);
2668
							indexManager.removeIndex(jarPath);
2636
							// then index the jar
2669
							// then index the jar
2637
							indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
2670
							indexManager.indexLibrary(jarPath, root.getJavaProject().getProject(), root.getIndexPath());
2638
							break;
2671
							break;
2639
						case IResourceDelta.REMOVED:
2672
						case IResourceDelta.REMOVED:
2640
							// the jar was physically removed: remove the index
2673
							// the jar was physically removed: remove the index
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElementDelta.java (-1 / +24 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 569-574 Link Here
569
	detachedDelta.changed(F_SOURCEDETACHED);
569
	detachedDelta.changed(F_SOURCEDETACHED);
570
	insertDeltaTree(element, detachedDelta);
570
	insertDeltaTree(element, detachedDelta);
571
}
571
}
572
573
/**
574
 * Creates the nested deltas resulting from a change operation.
575
 * Convenience method for creating change deltas.
576
 * The constructor should be used to create the root delta
577
 * and then a change operation should call this method.
578
 */
579
public void indexAttached(IJavaElement element) {
580
	JavaElementDelta attachedDelta = new JavaElementDelta(element);
581
	attachedDelta.changed(F_INDEXATTACHED);
582
	insertDeltaTree(element, attachedDelta);
583
}
584
/**
585
 * Creates the nested deltas resulting from a change operation.
586
 * Convenience method for creating change deltas.
587
 * The constructor should be used to create the root delta
588
 * and then a change operation should call this method.
589
 */
590
public void indexDetached(IJavaElement element) {
591
	JavaElementDelta detachedDelta = new JavaElementDelta(element);
592
	detachedDelta.changed(F_INDEXDETACHED);
593
	insertDeltaTree(element, detachedDelta);
594
}
572
/**
595
/**
573
 * Returns a string representation of this delta's
596
 * Returns a string representation of this delta's
574
 * structure suitable for debug purposes.
597
 * structure suitable for debug purposes.
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java (+2 lines)
Lines 180-185 Link Here
180
	 * Map from a package fragment root's path to a source attachment property (source path + ATTACHMENT_PROPERTY_DELIMITER + source root path)
180
	 * Map from a package fragment root's path to a source attachment property (source path + ATTACHMENT_PROPERTY_DELIMITER + source root path)
181
	 */
181
	 */
182
	public Map rootPathToAttachments = new Hashtable();
182
	public Map rootPathToAttachments = new Hashtable();
183
	//TODO SATYAM: Is this necessary
184
	public Map rootPathToIndexes = new Hashtable();
183
185
184
	public final static String CP_VARIABLE_PREFERENCES_PREFIX = JavaCore.PLUGIN_ID+".classpathVariable."; //$NON-NLS-1$
186
	public final static String CP_VARIABLE_PREFERENCES_PREFIX = JavaCore.PLUGIN_ID+".classpathVariable."; //$NON-NLS-1$
185
	public final static String CP_CONTAINER_PREFERENCES_PREFIX = JavaCore.PLUGIN_ID+".classpathContainer."; //$NON-NLS-1$
187
	public final static String CP_CONTAINER_PREFERENCES_PREFIX = JavaCore.PLUGIN_ID+".classpathContainer."; //$NON-NLS-1$
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java (+16 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.net.URL;
13
import java.util.ArrayList;
14
import java.util.ArrayList;
14
import java.util.Enumeration;
15
import java.util.Enumeration;
15
import java.util.Map;
16
import java.util.Map;
Lines 807-810 Link Here
807
	}
808
	}
808
}
809
}
809
810
811
public URL getIndexPath() {
812
	try {
813
		if (getKind() != K_BINARY) return null;
814
815
		IClasspathEntry entry = ((JavaProject) getParent()).getClasspathEntryFor(getPath());
816
		URL indexPath;
817
		if (entry != null && (indexPath = ((ClasspathEntry)entry).getLibraryIndexLocation()) != null)
818
			return indexPath;
819
	
820
	} catch (JavaModelException e) {
821
		// ignore exception
822
	}
823
	return null;
824
}
825
810
}
826
}
(-)a/org.eclipse.jdt.core/plugin.xml (-1 / +17 lines)
Lines 1-7 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
2
<?eclipse version="3.0"?>
3
<!--
3
<!--
4
    Copyright (c) 2004, 2010 IBM Corporation and others.
4
    Copyright (c) 2004, 2011 IBM Corporation and others.
5
    All rights reserved. This program and the accompanying materials
5
    All rights reserved. This program and the accompanying materials
6
    are made available under the terms of the Eclipse Public License v1.0
6
    are made available under the terms of the Eclipse Public License v1.0
7
    which accompanies this distribution, and is available at
7
    which accompanies this distribution, and is available at
Lines 158-163 Link Here
158
		class="org.eclipse.jdt.core.CheckDebugAttributes"
158
		class="org.eclipse.jdt.core.CheckDebugAttributes"
159
		library="jdtCompilerAdapter.jar">
159
		library="jdtCompilerAdapter.jar">
160
	</antTask>
160
	</antTask>
161
	<antTask
162
		name="eclipse.buildJarIndex"
163
		class="org.eclipse.jdt.core.BuildJarIndex"
164
		library="jdtCompilerAdapter.jar">
165
	</antTask>
161
</extension>
166
</extension>
162
      
167
      
163
<!-- =================================================================================== -->
168
<!-- =================================================================================== -->
Lines 196-201 Link Here
196
</extension>
201
</extension>
197
202
198
<!-- =================================================================================== -->
203
<!-- =================================================================================== -->
204
<!-- Extension: Java Generate Indexer                                                    -->
205
<!-- =================================================================================== -->
206
<extension
207
      id="JavaIndexer"
208
      point="org.eclipse.core.runtime.applications">
209
   		<application>
210
      		<run class="org.eclipse.jdt.core.index.JavaIndexerApplication" />
211
   		</application>
212
</extension>
213
214
<!-- =================================================================================== -->
199
<!-- Extension: Java Content Types                                                       -->
215
<!-- Extension: Java Content Types                                                       -->
200
<!-- =================================================================================== -->
216
<!-- =================================================================================== -->
201
<extension point="org.eclipse.core.contenttype.contentTypes">
217
<extension point="org.eclipse.core.contenttype.contentTypes">
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/index/JavaIndexer.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.index;
12
13
import java.io.IOException;
14
import org.eclipse.jdt.internal.core.search.indexing.DefaultJavaIndexer;
15
16
/**
17
 * TODO SATYAM: Write a proper javadoc
18
 * @since 3.8
19
 */
20
public class JavaIndexer {
21
22
	/**
23
	 * TODO SATYAM: Write a javadoc
24
	 * @param pathToJar
25
	 * @param pathToIndexFile
26
	 * @throws IOException
27
	 */
28
	public static void generateIndexForJar(String pathToJar, String pathToIndexFile) throws IOException {
29
		new DefaultJavaIndexer().generateIndexForJar(pathToJar, pathToIndexFile);
30
	}
31
32
}
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/index/JavaIndexerApplication.java (+154 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2011 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 *  Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.index;
12
13
import java.io.File;
14
import java.io.IOException;
15
import java.text.MessageFormat;
16
import java.util.ArrayList;
17
18
import org.eclipse.equinox.app.IApplication;
19
import org.eclipse.equinox.app.IApplicationContext;
20
import org.eclipse.osgi.util.NLS;
21
22
/**
23
 * Implements an Eclipse Application for org.eclipse.jdt.core.JavaIndexer.
24
 * 
25
 * TODO SATYAM: Improve the javadoc to include the arguments.
26
 * <p>
27
 * On MacOS, when invoked using the Eclipse executable, the "user.dir" property is set to the folder in which the
28
 * eclipse.ini file is located. This makes it harder to use relative paths to point to the files to be formatted or the
29
 * configuration file to use to set the code formatter's options.
30
 * </p>
31
 * 
32
 * 
33
 * @since 3.8
34
 * @noinstantiate This class is not intended to be instantiated by clients.
35
 * @noextend This class is not intended to be subclassed by clients.
36
 */
37
public class JavaIndexerApplication implements IApplication {
38
39
	private final static class Messages extends NLS {
40
		private static final String MESSAGES_NAME = "org.eclipse.jdt.core.index.messages";//$NON-NLS-1$
41
42
		public static String CommandLineProcessing;
43
		public static String CommandLineUsage;
44
		public static String CommandLineOnlyOutputError;
45
		public static String CommandLineOnlyOneJarError;
46
		public static String CommandLineJarNotSpecified;
47
		public static String CommandLineIndexFileNotSpecified;
48
		public static String CaughtException;
49
		public static String CommandLineJarFileNotExist;
50
51
		static {
52
			NLS.initializeMessages(MESSAGES_NAME, Messages.class);
53
		}
54
55
		public static String bind(String message) {
56
			return bind(message, null);
57
		}
58
59
		public static String bind(String message, Object binding) {
60
			return bind(message, new Object[] { binding });
61
		}
62
63
		public static String bind(String message, Object binding1, Object binding2) {
64
			return bind(message, new Object[] { binding1, binding2 });
65
		}
66
67
		public static String bind(String message, Object[] bindings) {
68
			return MessageFormat.format(message, bindings);
69
		}
70
	}
71
72
	private String jarToIndex;
73
	private String indexFile;
74
	private boolean verbose = false;
75
	private static final String PDE_LAUNCH = "-pdelaunch"; //$NON-NLS-1$
76
	private static final String ARG_HELP = "-help"; //$NON-NLS-1$
77
	private static final String ARG_VERBOSE = "-verbose"; //$NON-NLS-1$
78
	private static final String ARG_OUTPUT = "-output"; //$NON-NLS-1$
79
80
	private void displayHelp() {
81
		System.out.println(Messages.bind(Messages.CommandLineUsage));
82
	}
83
84
	private void displayError(String message) {
85
		System.err.println(message);
86
		System.out.println();
87
		displayHelp();
88
	}
89
90
	private boolean processCommandLine(String[] argsArray) {
91
		ArrayList args = new ArrayList();
92
		for (int i = 0, max = argsArray.length; i < max; i++) {
93
			args.add(argsArray[i]);
94
		}
95
		int index = 0;
96
		final int argCount = argsArray.length;
97
98
		loop: while (index < argCount) {
99
			String currentArg = argsArray[index++];
100
			if (PDE_LAUNCH.equals(currentArg)) {
101
				continue loop;
102
			} else if (ARG_HELP.equals(currentArg)) {
103
				displayHelp();
104
				return false;
105
			} else if (ARG_VERBOSE.equals(currentArg)) {
106
				this.verbose = true;
107
				continue loop;
108
			} else if (ARG_OUTPUT.equals(currentArg)) {
109
				if (this.indexFile != null || index == argCount) {
110
					displayError(Messages.bind(Messages.CommandLineOnlyOutputError));
111
					return false;
112
				}
113
				this.indexFile = argsArray[index++];
114
			} else {
115
				if (this.jarToIndex != null) {
116
					displayError(Messages.bind(Messages.CommandLineOnlyOneJarError));
117
					return false;
118
				}
119
				this.jarToIndex = currentArg;
120
			}
121
		}
122
		return true;
123
	}
124
125
	public Object start(IApplicationContext context) throws Exception {
126
		boolean execute = processCommandLine((String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS));
127
		if (execute) {
128
			if (this.jarToIndex != null && this.indexFile != null) {
129
				File f = new File(this.jarToIndex);
130
				if (!f.exists()) {
131
					System.out.println(Messages.bind(Messages.CommandLineJarFileNotExist, this.jarToIndex));
132
				}
133
				if (this.verbose) {
134
					System.out.println(Messages.bind(Messages.CommandLineProcessing, this.jarToIndex, this.indexFile));
135
				}
136
				try {
137
					JavaIndexer.generateIndexForJar(this.jarToIndex, this.indexFile);
138
				} catch (IOException e) {
139
					System.out.println(Messages.bind(Messages.CaughtException, "IOException", e.getLocalizedMessage())); //$NON-NLS-1$
140
				}
141
			} else if (this.jarToIndex == null) {
142
				System.out.println(Messages.bind(Messages.CommandLineJarNotSpecified));
143
			} else if (this.indexFile == null) {
144
				System.out.println(Messages.bind(Messages.CommandLineIndexFileNotSpecified));
145
			}
146
		}
147
		return IApplication.EXIT_OK;
148
	}
149
150
	public void stop() {
151
		// do nothing
152
	}
153
154
}
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/index/messages.properties (+28 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2006 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
CommandLineUsage=Usage: eclipse -application org.eclipse.jdt.core.JavaCodeGenerateIndex [ OPTIONS ] -output <indexFile> <jarfile>\n\
12
\n\
13
\   -output <indexFile> The index file to be generated.\n\
14
\
15
\   <jarfile>   Jar file for which index needs to be generated.\n\
16
\
17
\n\
18
\ OPTIONS:\n\
19
\n\
20
\   -help                Display this message.\n\
21
\   -verbose             Be verbose about the job.
22
CommandLineProcessing=Generating index {1} for the jar {0}.
23
CommandLineOnlyOutputError=Only one output need to be specified.
24
CommandLineOnlyOneJarError=Only one jar file need to be specified.
25
CommandLineJarNotSpecified=No jar file is specified.
26
CommandLineIndexFileNotSpecified=No index file is specified.
27
CaughtException=Exception {0} - {1}.
28
CommandLineJarFileNotExist={0} does not exist.
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java (-3 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-18 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.net.URI;
15
import java.net.URI;
16
import java.net.URL;
16
import java.util.Enumeration;
17
import java.util.Enumeration;
17
import java.util.zip.ZipEntry;
18
import java.util.zip.ZipEntry;
18
import java.util.zip.ZipFile;
19
import java.util.zip.ZipFile;
Lines 42-55 Link Here
42
	private static final char JAR_SEPARATOR = IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR.charAt(0);
43
	private static final char JAR_SEPARATOR = IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR.charAt(0);
43
	IFile resource;
44
	IFile resource;
44
	Scanner scanner;
45
	Scanner scanner;
46
	private URL indexFile;
45
47
46
	public AddJarFileToIndex(IFile resource, IndexManager manager) {
48
	public AddJarFileToIndex(IFile resource, URL indexFile, IndexManager manager) {
47
		super(resource.getFullPath(), manager);
49
		super(resource.getFullPath(), manager);
48
		this.resource = resource;
50
		this.resource = resource;
51
		this.indexFile = indexFile;
49
	}
52
	}
50
	public AddJarFileToIndex(IPath jarPath, IndexManager manager) {
53
	public AddJarFileToIndex(IPath jarPath, URL indexFile, IndexManager manager) {
51
		// external JAR scenario - no resource
54
		// external JAR scenario - no resource
52
		super(jarPath, manager);
55
		super(jarPath, manager);
56
		this.indexFile = indexFile;
53
	}
57
	}
54
	public boolean equals(Object o) {
58
	public boolean equals(Object o) {
55
		if (o instanceof AddJarFileToIndex) {
59
		if (o instanceof AddJarFileToIndex) {
Lines 71-76 Link Here
71
75
72
		if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
76
		if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
73
77
78
		if (this.indexFile != null) {
79
			//TODO SATYAM: Need to take care if the indexFile is in a jar.
80
			boolean added = this.manager.addIndex(this.containerPath, new Path(this.indexFile.getFile()));
81
			if (added) return true;	
82
		}
83
74
		try {
84
		try {
75
			// if index is already cached, then do not perform any check
85
			// if index is already cached, then do not perform any check
76
			// MUST reset the IndexManager if a jar file is changed
86
			// MUST reset the IndexManager if a jar file is changed
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexAllProject.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 77-83 Link Here
77
					if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(projectPath)) {
77
					if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(projectPath)) {
78
						// the project is also a library folder (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89815)
78
						// the project is also a library folder (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89815)
79
						// ensure a job exists to index it as a binary folder
79
						// ensure a job exists to index it as a binary folder
80
						this.manager.indexLibrary(projectPath, this.project);
80
						this.manager.indexLibrary(projectPath, this.project, ((ClasspathEntry)entry).getLibraryIndexLocation());
81
						return true;
81
						return true;
82
					}
82
					}
83
				}
83
				}
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java (-12 / +103 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.core.search.indexing;
11
package org.eclipse.jdt.internal.core.search.indexing;
12
12
13
import java.io.*;
13
import java.io.*;
14
import java.net.URL;
14
import java.util.*;
15
import java.util.*;
15
import java.util.zip.CRC32;
16
import java.util.zip.CRC32;
16
17
Lines 53-64 Link Here
53
	// key = indexLocation path, value = index state integer
54
	// key = indexLocation path, value = index state integer
54
	private SimpleLookupTable indexStates = null;
55
	private SimpleLookupTable indexStates = null;
55
	private File savedIndexNamesFile = new File(getSavedIndexesDirectory(), "savedIndexNames.txt"); //$NON-NLS-1$
56
	private File savedIndexNamesFile = new File(getSavedIndexesDirectory(), "savedIndexNames.txt"); //$NON-NLS-1$
57
	private File indexNamesMapFile = new File(getSavedIndexesDirectory(), "indexNamesMap.txt"); //$NON-NLS-1$
56
	private File participantIndexNamesFile = new File(getSavedIndexesDirectory(), "participantsIndexNames.txt"); //$NON-NLS-1$
58
	private File participantIndexNamesFile = new File(getSavedIndexesDirectory(), "participantsIndexNames.txt"); //$NON-NLS-1$
57
	private boolean javaLikeNamesChanged = true;
59
	private boolean javaLikeNamesChanged = true;
58
	public static final Integer SAVED_STATE = new Integer(0);
60
	public static final Integer SAVED_STATE = new Integer(0);
59
	public static final Integer UPDATING_STATE = new Integer(1);
61
	public static final Integer UPDATING_STATE = new Integer(1);
60
	public static final Integer UNKNOWN_STATE = new Integer(2);
62
	public static final Integer UNKNOWN_STATE = new Integer(2);
61
	public static final Integer REBUILDING_STATE = new Integer(3);
63
	public static final Integer REBUILDING_STATE = new Integer(3);
64
	public static final Integer REUSE_STATE = new Integer(4);
62
	
65
	
63
	// search participants who register indexes with the index manager
66
	// search participants who register indexes with the index manager
64
	private SimpleLookupTable participantsContainers = null;
67
	private SimpleLookupTable participantsContainers = null;
Lines 255-260 Link Here
255
					return index;
258
					return index;
256
				} catch (IOException e) {
259
				} catch (IOException e) {
257
					// failed to read the existing file or its no longer compatible
260
					// failed to read the existing file or its no longer compatible
261
					if (currentIndexState == REUSE_STATE) {
262
						// supposed to be in reuse state but error in the index file, so reindex.
263
						if (VERBOSE)
264
							Util.verbose("-> cannot reuse given index: "+indexLocationString+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
265
						this.indexLocations.put(containerPath, null);
266
						indexLocation = computeIndexLocation(containerPath);
267
						rebuildIndex(indexLocation, containerPath);
268
						return null;
269
					}
258
					if (currentIndexState != REBUILDING_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt
270
					if (currentIndexState != REBUILDING_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt
259
						if (VERBOSE)
271
						if (VERBOSE)
260
							Util.verbose("-> cannot reuse existing index: "+indexLocationString+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
272
							Util.verbose("-> cannot reuse existing index: "+indexLocationString+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
Lines 268-273 Link Here
268
				rebuildIndex(indexLocation, containerPath);
280
				rebuildIndex(indexLocation, containerPath);
269
				return null;
281
				return null;
270
			}
282
			}
283
			//TODO SATYAM: should do something if in reuse state
271
		}
284
		}
272
		// index wasn't found on disk, consider creating an empty new one
285
		// index wasn't found on disk, consider creating an empty new one
273
		if (createIfMissing) {
286
		if (createIfMissing) {
Lines 315-321 Link Here
315
			IPath containerPath = (IPath) this.indexLocations.keyForValue(indexLocation);
328
			IPath containerPath = (IPath) this.indexLocations.keyForValue(indexLocation);
316
			if (containerPath != null) {// sanity check
329
			if (containerPath != null) {// sanity check
317
				index = getIndex(containerPath, indexLocation, true /*reuse index file*/, false /*do not create if none*/);
330
				index = getIndex(containerPath, indexLocation, true /*reuse index file*/, false /*do not create if none*/);
318
				if (index != null && this.javaLikeNamesChanged && !index.isIndexForJar()) {
331
				if (index != null && this.javaLikeNamesChanged && !index.isIndexForJar()) { //TODO SATYAM: shouldn't delete the pre-index files
319
					// When a change in java like names extension has been detected, all
332
					// When a change in java like names extension has been detected, all
320
					// non jar files indexes (i.e. containing sources) need to be rebuilt.
333
					// non jar files indexes (i.e. containing sources) need to be rebuilt.
321
					// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=286379
334
					// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=286379
Lines 387-392 Link Here
387
		this.javaLikeNamesChanged = false;
400
		this.javaLikeNamesChanged = false;
388
		deleteIndexFiles();
401
		deleteIndexFiles();
389
	}
402
	}
403
	readIndexMap(indexesDirectoryPath.toOSString());
390
	return this.indexStates;
404
	return this.indexStates;
391
}
405
}
392
private IPath getParticipantsContainer(IPath indexLocation) {
406
private IPath getParticipantsContainer(IPath indexLocation) {
Lines 474-480 Link Here
474
		for (int i = 0; i < entries.length; i++) {
488
		for (int i = 0; i < entries.length; i++) {
475
			IClasspathEntry entry= entries[i];
489
			IClasspathEntry entry= entries[i];
476
			if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
490
			if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
477
				indexLibrary(entry.getPath(), project);
491
				indexLibrary(entry.getPath(), project, ((ClasspathEntry)entry).getLibraryIndexLocation());
478
		}
492
		}
479
	} catch(JavaModelException e){ // cannot retrieve classpath info
493
	} catch(JavaModelException e){ // cannot retrieve classpath info
480
	}
494
	}
Lines 488-503 Link Here
488
 * Trigger addition of a library to an index
502
 * Trigger addition of a library to an index
489
 * Note: the actual operation is performed in background
503
 * Note: the actual operation is performed in background
490
 */
504
 */
491
public void indexLibrary(IPath path, IProject requestingProject) {
505
public void indexLibrary(IPath path, IProject requestingProject, URL indexFile) {
492
	// requestingProject is no longer used to cancel jobs but leave it here just in case
506
	// requestingProject is no longer used to cancel jobs but leave it here just in case
493
	if (JavaCore.getPlugin() == null) return;
507
	if (JavaCore.getPlugin() == null) return;
494
495
	Object target = JavaModel.getTarget(path, true);
496
	IndexRequest request = null;
508
	IndexRequest request = null;
509
	Object target = JavaModel.getTarget(path, true);
497
	if (target instanceof IFile) {
510
	if (target instanceof IFile) {
498
		request = new AddJarFileToIndex((IFile) target, this);
511
		request = new AddJarFileToIndex((IFile) target, indexFile, this);
499
	} else if (target instanceof File) {
512
	} else if (target instanceof File) {
500
		request = new AddJarFileToIndex(path, this);
513
		request = new AddJarFileToIndex(path, indexFile, this);
501
	} else if (target instanceof IContainer) {
514
	} else if (target instanceof IContainer) {
502
		request = new IndexBinaryFolder((IContainer) target, this);
515
		request = new IndexBinaryFolder((IContainer) target, this);
503
	} else {
516
	} else {
Lines 508-513 Link Here
508
	if (!isJobWaiting(request))
521
	if (!isJobWaiting(request))
509
		request(request);
522
		request(request);
510
}
523
}
524
525
synchronized boolean addIndex(IPath containerPath, IPath indexFile) {
526
	this.indexStates.put(indexFile, REUSE_STATE);
527
	this.indexLocations.put(containerPath, indexFile);
528
	Index index = getIndex(containerPath, indexFile, true, false);
529
	if (index == null) {
530
		this.indexLocations.put(containerPath, null);
531
		return false;
532
	}
533
	writeIndexMapFile();
534
	return true;
535
}
536
511
/**
537
/**
512
 * Index the content of the given source folder.
538
 * Index the content of the given source folder.
513
 */
539
 */
Lines 584-592 Link Here
584
	} else if (target instanceof IFolder) {
610
	} else if (target instanceof IFolder) {
585
		request = new IndexBinaryFolder((IFolder) target, this);
611
		request = new IndexBinaryFolder((IFolder) target, this);
586
	} else if (target instanceof IFile) {
612
	} else if (target instanceof IFile) {
587
		request = new AddJarFileToIndex((IFile) target, this);
613
		request = new AddJarFileToIndex((IFile) target, null, this);
588
	} else if (target instanceof File) {
614
	} else if (target instanceof File) {
589
		request = new AddJarFileToIndex(containerPath, this);
615
		request = new AddJarFileToIndex(containerPath, null, this);
590
	}
616
	}
591
	if (request != null)
617
	if (request != null)
592
		request(request);
618
		request(request);
Lines 643-649 Link Here
643
	}
669
	}
644
	if (indexFile == null)
670
	if (indexFile == null)
645
		indexFile = new File(indexLocation.toOSString()); // index is not cached yet, but still want to delete the file
671
		indexFile = new File(indexLocation.toOSString()); // index is not cached yet, but still want to delete the file
646
	if (indexFile.exists()) {
672
	if (this.indexStates.get(indexLocation) == REUSE_STATE) {
673
		this.indexLocations.put(containerPath, null);
674
	} else if (indexFile.exists()) {
647
		if (DEBUG)
675
		if (DEBUG)
648
			Util.verbose("removing index file " + indexFile); //$NON-NLS-1$
676
			Util.verbose("removing index file " + indexFile); //$NON-NLS-1$
649
		indexFile.delete();
677
		indexFile.delete();
Lines 673-679 Link Here
673
				locations = new IPath[max];
701
				locations = new IPath[max];
674
			locations[count++] = indexLocation;
702
			locations[count++] = indexLocation;
675
			File indexFile = index.getIndexFile();
703
			File indexFile = index.getIndexFile();
676
			if (indexFile.exists()) {
704
			if (indexFile.exists() && this.indexStates.get(indexLocation) != REUSE_STATE) {
677
				if (DEBUG)
705
				if (DEBUG)
678
					Util.verbose("removing index file " + indexFile); //$NON-NLS-1$
706
					Util.verbose("removing index file " + indexFile); //$NON-NLS-1$
679
				indexFile.delete();
707
				indexFile.delete();
Lines 894-899 Link Here
894
	}
922
	}
895
	return null;
923
	return null;
896
}
924
}
925
926
private char[][] readIndexMap(String dirOSString) {
927
	try {
928
		char[] indexMaps = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.indexNamesMapFile, null);
929
		if (indexMaps.length > 0) {
930
			char[][] names = CharOperation.splitOn('\n', indexMaps);
931
			if (names.length >= 3) {
932
				// First line is DiskIndex signature + saved plugin working location (see writeSavedIndexNamesFile())
933
				String savedSignature = DiskIndex.SIGNATURE + "+" + dirOSString; //$NON-NLS-1$ //TODO SATYAM Should dirOSString need to be stored
934
				if (savedSignature.equals(new String(names[0]))) {
935
					for (int i = 1, l = names.length-1 ; i < l ; i+=2) {
936
						IPath indexPath = new Path(new String(names[i]));
937
						this.indexLocations.put(new Path(new String(names[i+1])), indexPath );
938
						this.indexStates.put(indexPath, REUSE_STATE);
939
						//TODO SATYAM: Is this good enough
940
					}
941
				}
942
					
943
			}
944
		}
945
	} catch (IOException ignored) {
946
		if (VERBOSE)
947
			Util.verbose("Failed to read saved index file names"); //$NON-NLS-1$
948
	}
949
	return null;
950
}
897
private void readParticipantsIndexNamesFile() {
951
private void readParticipantsIndexNamesFile() {
898
	SimpleLookupTable containers = new SimpleLookupTable(3);
952
	SimpleLookupTable containers = new SimpleLookupTable(3);
899
	try {
953
	try {
Lines 947-952 Link Here
947
	}
1001
	}
948
1002
949
	writeSavedIndexNamesFile();
1003
	writeSavedIndexNamesFile();
1004
	writeIndexMapFile();
950
1005
951
	if (VERBOSE) {
1006
	if (VERBOSE) {
952
		if (indexState == null) {
1007
		if (indexState == null) {
Lines 1065-1068 Link Here
1065
		}
1120
		}
1066
	}
1121
	}
1067
}
1122
}
1123
1124
private void writeIndexMapFile() {
1125
	BufferedWriter writer = null;
1126
	try {
1127
		writer = new BufferedWriter(new FileWriter(this.indexNamesMapFile));
1128
		writer.write(DiskIndex.SIGNATURE);
1129
		writer.write('+');
1130
		writer.write(getJavaPluginWorkingLocation().toOSString());
1131
		writer.write('\n');
1132
		Object[] keys = this.indexStates.keyTable;
1133
		Object[] states = this.indexStates.valueTable;
1134
		for (int i = 0, l = states.length; i < l; i++) {
1135
			IPath key = (IPath) keys[i];
1136
			if (key != null && !key.isEmpty() && states[i] == REUSE_STATE) {
1137
				IPath value = (IPath)this.indexLocations.keyForValue(key);
1138
				if (value != null) {
1139
					writer.write(key.toOSString());
1140
					writer.write('\n');
1141
					writer.write(value.toOSString());
1142
					writer.write('\n');
1143
				}
1144
			}
1145
		}
1146
	} catch (IOException ignored) {
1147
		if (VERBOSE)
1148
			Util.verbose("Failed to write saved index file names", System.err); //$NON-NLS-1$
1149
	} finally {
1150
		if (writer != null) {
1151
			try {
1152
				writer.close();
1153
			} catch (IOException e) {
1154
				// ignore
1155
			}
1156
		}
1157
	}
1158
}
1068
}
1159
}

Return to bug 356620