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

(-)search/org/eclipse/jdt/internal/core/search/indexing/IndexAllProject.java (-89 / +105 lines)
Lines 52-64 Link Here
52
52
53
		if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
53
		if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
54
		if (!project.isAccessible()) return true; // nothing to do
54
		if (!project.isAccessible()) return true; // nothing to do
55
55
		
56
		Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
56
		ReadWriteMonitor monitor = null;
57
		if (index == null) return true;
58
		ReadWriteMonitor monitor = index.monitor;
59
		if (monitor == null) return true; // index got deleted since acquired
60
61
		try {
57
		try {
58
			// Get source folder entries. Libraries are done as a separate job
59
			JavaProject javaProject = (JavaProject)JavaCore.create(this.project);
60
			// Do not create marker nor log problems while getting raw classpath (see bug 41859)
61
			IClasspathEntry[] entries = javaProject.getRawClasspath(false, false);
62
			int length = entries.length;
63
			IClasspathEntry[] sourceEntries = new IClasspathEntry[length];
64
			int sourceEntriesNumber = 0;
65
			for (int i = 0; i < length; i++) {
66
				IClasspathEntry entry = entries[i];
67
				if ((entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)) 
68
					sourceEntries[sourceEntriesNumber++] = entry;
69
			}
70
			if (sourceEntriesNumber == 0) 
71
				// nothing to index
72
				// also the project might be a library folder (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89815)
73
				return true;
74
			if (sourceEntriesNumber != length)
75
				System.arraycopy(sourceEntries, 0, sourceEntries = new IClasspathEntry[sourceEntriesNumber], 0, sourceEntriesNumber);
76
	
77
			Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
78
			if (index == null) return true;
79
			monitor = index.monitor;
80
			if (monitor == null) return true; // index got deleted since acquired
81
			
62
			monitor.enterRead(); // ask permission to read
82
			monitor.enterRead(); // ask permission to read
63
83
64
			String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$
84
			String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$
Lines 70-174 Link Here
70
				indexedFileNames.put(paths[i], DELETED);
90
				indexedFileNames.put(paths[i], DELETED);
71
			final long indexLastModified = max == 0 ? 0L : index.getIndexFile().lastModified();
91
			final long indexLastModified = max == 0 ? 0L : index.getIndexFile().lastModified();
72
92
73
			JavaProject javaProject = (JavaProject)JavaCore.create(this.project);
74
			// Do not create marker nor log problems while getting raw classpath (see bug 41859)
75
			IClasspathEntry[] entries = javaProject.getRawClasspath(false, false);
76
			IWorkspaceRoot root = this.project.getWorkspace().getRoot();
93
			IWorkspaceRoot root = this.project.getWorkspace().getRoot();
77
			for (int i = 0, length = entries.length; i < length; i++) {
94
			for (int i = 0; i < sourceEntriesNumber; i++) {
78
				if (this.isCancelled) return false;
95
				if (this.isCancelled) return false;
79
96
80
				IClasspathEntry entry = entries[i];
97
				IClasspathEntry entry = sourceEntries[i];
81
				if ((entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)) { // Index only source folders. Libraries are done as a separate job
98
				IResource sourceFolder = root.findMember(entry.getPath());
82
					IResource sourceFolder = root.findMember(entry.getPath());
99
				if (sourceFolder != null) {
83
					if (sourceFolder != null) {
100
					
84
						
101
					// collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041)
85
						// collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041)
102
					final HashSet outputs = new HashSet();
86
						final HashSet outputs = new HashSet();
103
					if (sourceFolder.getType() == IResource.PROJECT) {
87
						if (sourceFolder.getType() == IResource.PROJECT) {
104
						// Do not create marker nor log problems while getting output location (see bug 41859)
88
							// Do not create marker nor log problems while getting output location (see bug 41859)
105
						outputs.add(javaProject.getOutputLocation(false, false));
89
							outputs.add(javaProject.getOutputLocation(false, false));
106
						for (int j = 0; j < sourceEntriesNumber; j++) {
90
							for (int j = 0; j < length; j++) {
107
							IPath output = sourceEntries[j].getOutputLocation();
91
								IPath output = entries[j].getOutputLocation();
108
							if (output != null) {
92
								if (output != null) {
109
								outputs.add(output);
93
									outputs.add(output);
94
								}
95
							}
110
							}
96
						}
111
						}
97
						final boolean hasOutputs = !outputs.isEmpty();
112
					}
98
						
113
					final boolean hasOutputs = !outputs.isEmpty();
99
						final char[][] inclusionPatterns = ((ClasspathEntry) entry).fullInclusionPatternChars();
114
					
100
						final char[][] exclusionPatterns = ((ClasspathEntry) entry).fullExclusionPatternChars();
115
					final char[][] inclusionPatterns = ((ClasspathEntry) entry).fullInclusionPatternChars();
101
						if (max == 0) {
116
					final char[][] exclusionPatterns = ((ClasspathEntry) entry).fullExclusionPatternChars();
102
							sourceFolder.accept(
117
					if (max == 0) {
103
								new IResourceProxyVisitor() {
118
						sourceFolder.accept(
104
									public boolean visit(IResourceProxy proxy) {
119
							new IResourceProxyVisitor() {
105
										if (isCancelled) return false;
120
								public boolean visit(IResourceProxy proxy) {
106
										switch(proxy.getType()) {
121
									if (isCancelled) return false;
107
											case IResource.FILE :
122
									switch(proxy.getType()) {
108
												if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) {
123
										case IResource.FILE :
109
													IFile file = (IFile) proxy.requestResource();
124
											if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) {
110
													if (file.getLocation() == null) return false;
125
												IFile file = (IFile) proxy.requestResource();
111
													if (exclusionPatterns != null || inclusionPatterns != null)
126
												if (file.getLocation() == null) return false;
112
														if (Util.isExcluded(file, inclusionPatterns, exclusionPatterns))
127
												if (exclusionPatterns != null || inclusionPatterns != null)
113
															return false;
128
													if (Util.isExcluded(file, inclusionPatterns, exclusionPatterns))
114
													indexedFileNames.put(file.getFullPath().toString(), file);
129
														return false;
115
												}
130
												indexedFileNames.put(file.getFullPath().toString(), file);
131
											}
132
											return false;
133
										case IResource.FOLDER :
134
											if (exclusionPatterns != null && inclusionPatterns == null) {
135
												// if there are inclusion patterns then we must walk the children
136
												if (Util.isExcluded(proxy.requestFullPath(), inclusionPatterns, exclusionPatterns, true)) 
137
												    return false;
138
											}
139
											if (hasOutputs && outputs.contains(proxy.requestFullPath()))
116
												return false;
140
												return false;
117
											case IResource.FOLDER :
118
												if (exclusionPatterns != null && inclusionPatterns == null) {
119
													// if there are inclusion patterns then we must walk the children
120
													if (Util.isExcluded(proxy.requestFullPath(), inclusionPatterns, exclusionPatterns, true)) 
121
													    return false;
122
												}
123
												if (hasOutputs && outputs.contains(proxy.requestFullPath()))
124
													return false;
125
										}
126
										return true;
127
									}
141
									}
128
								},
142
									return true;
129
								IResource.NONE
143
								}
130
							);
144
							},
131
						} else {
145
							IResource.NONE
132
							sourceFolder.accept(
146
						);
133
								new IResourceProxyVisitor() {
147
					} else {
134
									public boolean visit(IResourceProxy proxy) {
148
						sourceFolder.accept(
135
										if (isCancelled) return false;
149
							new IResourceProxyVisitor() {
136
										switch(proxy.getType()) {
150
								public boolean visit(IResourceProxy proxy) {
137
											case IResource.FILE :
151
									if (isCancelled) return false;
138
												if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) {
152
									switch(proxy.getType()) {
139
													IFile file = (IFile) proxy.requestResource();
153
										case IResource.FILE :
140
													IPath location = file.getLocation();
154
											if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) {
141
													if (location == null) return false;
155
												IFile file = (IFile) proxy.requestResource();
142
													if (exclusionPatterns != null || inclusionPatterns != null)
156
												IPath location = file.getLocation();
143
														if (Util.isExcluded(file, inclusionPatterns, exclusionPatterns))
157
												if (location == null) return false;
144
															return false;
145
													String path = file.getFullPath().toString();
146
													indexedFileNames.put(path,
147
														indexedFileNames.get(path) == null || indexLastModified < location.toFile().lastModified()
148
															? (Object) file
149
															: (Object) OK);
150
												}
151
												return false;
152
											case IResource.FOLDER :
153
												if (exclusionPatterns != null || inclusionPatterns != null)
158
												if (exclusionPatterns != null || inclusionPatterns != null)
154
													if (Util.isExcluded(proxy.requestResource(), inclusionPatterns, exclusionPatterns))
159
													if (Util.isExcluded(file, inclusionPatterns, exclusionPatterns))
155
														return false;
160
														return false;
156
												if (hasOutputs && outputs.contains(proxy.requestFullPath()))
161
												String path = file.getFullPath().toString();
162
												indexedFileNames.put(path,
163
													indexedFileNames.get(path) == null || indexLastModified < location.toFile().lastModified()
164
														? (Object) file
165
														: (Object) OK);
166
											}
167
											return false;
168
										case IResource.FOLDER :
169
											if (exclusionPatterns != null || inclusionPatterns != null)
170
												if (Util.isExcluded(proxy.requestResource(), inclusionPatterns, exclusionPatterns))
157
													return false;
171
													return false;
158
										}
172
											if (hasOutputs && outputs.contains(proxy.requestFullPath()))
159
										return true;
173
												return false;
160
									}
174
									}
161
								},
175
									return true;
162
								IResource.NONE
176
								}
163
							);
177
							},
164
						}
178
							IResource.NONE
179
						);
165
					}
180
					}
166
				}
181
				}
167
			}
182
			}
168
183
169
			Object[] names = indexedFileNames.keyTable;
184
			Object[] names = indexedFileNames.keyTable;
170
			Object[] values = indexedFileNames.valueTable;
185
			Object[] values = indexedFileNames.valueTable;
171
			for (int i = 0, length = names.length; i < length; i++) {
186
			for (int i = 0, namesLength = names.length; i < namesLength; i++) {
172
				String name = (String) names[i];
187
				String name = (String) names[i];
173
				if (name != null) {
188
				if (name != null) {
174
					if (this.isCancelled) return false;
189
					if (this.isCancelled) return false;
Lines 200-206 Link Here
200
			this.manager.removeIndex(this.containerPath);
215
			this.manager.removeIndex(this.containerPath);
201
			return false;
216
			return false;
202
		} finally {
217
		} finally {
203
			monitor.exitRead(); // free read lock
218
			if (monitor != null)
219
				monitor.exitRead(); // free read lock
204
		}
220
		}
205
		return true;
221
		return true;
206
	}
222
	}

Return to bug 89815