|
From: <caw...@us...> - 2007-05-21 21:05:27
|
Revision: 2511
http://svn.sourceforge.net/rubyeclipse/?rev=2511&view=rev
Author: cawilliams
Date: 2007-05-21 14:05:24 -0700 (Mon, 21 May 2007)
Log Message:
-----------
fix to index folders when loadpath is changed.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SetLoadpathOperation.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/AddExternalFolderToIndex.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexManager.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/AddFolderToIndex.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/RemoveFolderFromindex.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SetLoadpathOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SetLoadpathOperation.java 2007-05-21 21:03:54 UTC (rev 2510)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SetLoadpathOperation.java 2007-05-21 21:05:24 UTC (rev 2511)
@@ -34,6 +34,7 @@
import org.rubypeople.rdt.core.ISourceFolderRoot;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.compiler.util.ObjectVector;
+import org.rubypeople.rdt.internal.core.search.indexing.IndexManager;
import org.rubypeople.rdt.internal.core.util.Messages;
import org.rubypeople.rdt.internal.core.util.Util;
@@ -298,7 +299,7 @@
int oldLength = oldResolvedPath.length;
int newLength = newResolvedPath.length;
-// final IndexManager indexManager = manager.getIndexManager();
+ final IndexManager indexManager = manager.getIndexManager();
Map oldRoots = null;
ISourceFolderRoot[] roots = null;
if (project.isOpen()) {
@@ -364,41 +365,41 @@
// Remove the .java files from the index for a source folder
// For a lib folder or a .jar file, remove the corresponding index if not shared.
-// if (indexManager != null) {
-// ILoadpathEntry oldEntry = oldResolvedPath[i];
-// final IPath path = oldEntry.getPath();
-// switch (changeKind) {
-// case ILoadpathEntry.CPE_SOURCE:
-// final char[][] inclusionPatterns = ((LoadpathEntry)oldEntry).fullInclusionPatternChars();
-// final char[][] exclusionPatterns = ((LoadpathEntry)oldEntry).fullExclusionPatternChars();
-// postAction(new IPostAction() {
-// public String getID() {
-// return path.toString();
-// }
-// public void run() /* throws RubyModelException */ {
-// indexManager.removeSourceFolderFromIndex(project, path, inclusionPatterns, exclusionPatterns);
-// }
-// },
-// REMOVEALL_APPEND);
-// break;
-// case ILoadpathEntry.CPE_LIBRARY:
-// final DeltaProcessingState deltaState = manager.deltaState;
-// postAction(new IPostAction() {
-// public String getID() {
-// return path.toString();
-// }
-// public void run() /* throws RubyModelException */ {
-// if (deltaState.otherRoots.get(path) == null) { // if root was not shared
-// indexManager.discardJobs(path.toString());
-// indexManager.removeIndex(path);
-// // TODO (kent) we could just remove the in-memory index and have the indexing check for timestamps
-// }
-// }
-// },
-// REMOVEALL_APPEND);
-// break;
-// }
-// }
+ if (indexManager != null) {
+ ILoadpathEntry oldEntry = oldResolvedPath[i];
+ final IPath path = oldEntry.getPath();
+ switch (changeKind) {
+ case ILoadpathEntry.CPE_SOURCE:
+ final char[][] inclusionPatterns = ((LoadpathEntry)oldEntry).fullInclusionPatternChars();
+ final char[][] exclusionPatterns = ((LoadpathEntry)oldEntry).fullExclusionPatternChars();
+ postAction(new IPostAction() {
+ public String getID() {
+ return path.toString();
+ }
+ public void run() /* throws RubyModelException */ {
+ indexManager.removeSourceFolderFromIndex(project, path, inclusionPatterns, exclusionPatterns);
+ }
+ },
+ REMOVEALL_APPEND);
+ break;
+ case ILoadpathEntry.CPE_LIBRARY:
+ final DeltaProcessingState deltaState = manager.deltaState;
+ postAction(new IPostAction() {
+ public String getID() {
+ return path.toString();
+ }
+ public void run() /* throws RubyModelException */ {
+ if (deltaState.otherRoots.get(path) == null) { // if root was not shared
+ indexManager.discardJobs(path.toString());
+ indexManager.removeIndex(path);
+ // TODO (kent) we could just remove the in-memory index and have the indexing check for timestamps
+ }
+ }
+ },
+ REMOVEALL_APPEND);
+ break;
+ }
+ }
hasDelta = true;
} else {
@@ -441,47 +442,47 @@
int changeKind = newResolvedPath[i].getEntryKind();
// Request indexing
-// if (indexManager != null) {
-// switch (changeKind) {
-// case ILoadpathEntry.CPE_LIBRARY:
-// boolean pathHasChanged = true;
-// final IPath newPath = newResolvedPath[i].getPath();
-// for (int j = 0; j < oldLength; j++) {
-// ILoadpathEntry oldEntry = oldResolvedPath[j];
-// if (oldEntry.getPath().equals(newPath)) {
-// pathHasChanged = false;
-// break;
-// }
-// }
-// if (pathHasChanged) {
-// postAction(new IPostAction() {
-// public String getID() {
-// return newPath.toString();
-// }
-// public void run() /* throws RubyModelException */ {
-// indexManager.indexLibrary(newPath, project.getProject());
-// }
-// },
-// REMOVEALL_APPEND);
-// }
-// break;
-// case ILoadpathEntry.CPE_SOURCE:
-// ILoadpathEntry entry = newResolvedPath[i];
-// final IPath path = entry.getPath();
-// final char[][] inclusionPatterns = ((LoadpathEntry)entry).fullInclusionPatternChars();
-// final char[][] exclusionPatterns = ((LoadpathEntry)entry).fullExclusionPatternChars();
-// postAction(new IPostAction() {
-// public String getID() {
-// return path.toString();
-// }
-// public void run() /* throws RubyModelException */ {
-// indexManager.indexSourceFolder(project, path, inclusionPatterns, exclusionPatterns);
-// }
-// },
-// APPEND); // append so that a removeSourceFolder action is not removed
-// break;
-// }
-// }
+ if (indexManager != null) {
+ switch (changeKind) {
+ case ILoadpathEntry.CPE_LIBRARY:
+ boolean pathHasChanged = true;
+ final IPath newPath = newResolvedPath[i].getPath();
+ for (int j = 0; j < oldLength; j++) {
+ ILoadpathEntry oldEntry = oldResolvedPath[j];
+ if (oldEntry.getPath().equals(newPath)) {
+ pathHasChanged = false;
+ break;
+ }
+ }
+ if (pathHasChanged) {
+ postAction(new IPostAction() {
+ public String getID() {
+ return newPath.toString();
+ }
+ public void run() /* throws RubyModelException */ {
+ indexManager.indexLibrary(newPath, project.getProject());
+ }
+ },
+ REMOVEALL_APPEND);
+ }
+ break;
+ case ILoadpathEntry.CPE_SOURCE:
+ ILoadpathEntry entry = newResolvedPath[i];
+ final IPath path = entry.getPath();
+ final char[][] inclusionPatterns = ((LoadpathEntry)entry).fullInclusionPatternChars();
+ final char[][] exclusionPatterns = ((LoadpathEntry)entry).fullExclusionPatternChars();
+ postAction(new IPostAction() {
+ public String getID() {
+ return path.toString();
+ }
+ public void run() /* throws RubyModelException */ {
+ indexManager.indexSourceFolder(project, path, inclusionPatterns, exclusionPatterns);
+ }
+ },
+ APPEND); // append so that a removeSourceFolder action is not removed
+ break;
+ }
+ }
needToUpdateDependents |= (changeKind == ILoadpathEntry.CPE_SOURCE) || newResolvedPath[i].isExported();
hasDelta = true;
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java 2007-05-21 21:03:54 UTC (rev 2510)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java 2007-05-21 21:05:24 UTC (rev 2511)
@@ -267,7 +267,7 @@
}
public static Collection<? extends IType> findType(String simpleTypeName) {
- SearchPattern pattern = SearchPattern.createPattern(IRubyElement.TYPE, "*", IRubySearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
+ SearchPattern pattern = SearchPattern.createPattern(IRubyElement.TYPE, "*" + simpleTypeName + "*", IRubySearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
SearchParticipant[] participants = new SearchParticipant[] {getDefaultSearchParticipant()};
IRubySearchScope scope = createWorkspaceScope();
TypeRequestor requestor = new TypeRequestor();
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/AddExternalFolderToIndex.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/AddExternalFolderToIndex.java 2007-05-21 21:03:54 UTC (rev 2510)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/AddExternalFolderToIndex.java 2007-05-21 21:05:24 UTC (rev 2511)
@@ -7,7 +7,6 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
import org.rubypeople.rdt.core.search.SearchParticipant;
import org.rubypeople.rdt.internal.compiler.util.SimpleLookupTable;
import org.rubypeople.rdt.internal.core.RubyModelManager;
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/AddFolderToIndex.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/AddFolderToIndex.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/AddFolderToIndex.java 2007-05-21 21:05:24 UTC (rev 2511)
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.core.search.indexing;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.core.SourceParser;
+import org.rubypeople.rdt.internal.core.index.Index;
+import org.rubypeople.rdt.internal.core.search.processing.JobManager;
+import org.rubypeople.rdt.internal.core.util.Util;
+
+class AddFolderToIndex extends IndexRequest {
+ IPath folderPath;
+ IProject project;
+ char[][] inclusionPatterns;
+ char[][] exclusionPatterns;
+
+ public AddFolderToIndex(IPath folderPath, IProject project, char[][] inclusionPatterns, char[][] exclusionPatterns, IndexManager manager) {
+ super(project.getFullPath(), manager);
+ this.folderPath = folderPath;
+ this.project = project;
+ this.inclusionPatterns = inclusionPatterns;
+ this.exclusionPatterns = exclusionPatterns;
+ }
+ public boolean execute(IProgressMonitor progressMonitor) {
+
+ if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
+ if (!project.isAccessible()) return true; // nothing to do
+ IResource folder = this.project.getParent().findMember(this.folderPath);
+ if (folder == null || folder.getType() == IResource.FILE) return true; // nothing to do, source folder was removed
+
+ /* ensure no concurrent write access to index */
+ Index index = this.manager.getIndex(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
+ if (index == null) return true;
+ ReadWriteMonitor monitor = index.monitor;
+ if (monitor == null) return true; // index got deleted since acquired
+
+ try {
+ monitor.enterRead(); // ask permission to read
+
+ final IPath container = this.containerPath;
+ final IndexManager indexManager = this.manager;
+ final SourceParser parser = indexManager.getSourceElementParser(RubyCore.create(this.project), null/*requestor will be set by indexer*/);
+ if (this.exclusionPatterns == null && this.inclusionPatterns == null) {
+ folder.accept(
+ new IResourceProxyVisitor() {
+ public boolean visit(IResourceProxy proxy) /* throws CoreException */{
+ if (proxy.getType() == IResource.FILE) {
+ if (org.rubypeople.rdt.internal.core.util.Util.isRubyLikeFileName(proxy.getName()))
+ indexManager.addSource((IFile) proxy.requestResource(), container, parser);
+ return false;
+ }
+ return true;
+ }
+ },
+ IResource.NONE
+ );
+ } else {
+ folder.accept(
+ new IResourceProxyVisitor() {
+ public boolean visit(IResourceProxy proxy) /* throws CoreException */{
+ switch(proxy.getType()) {
+ case IResource.FILE :
+ if (org.rubypeople.rdt.internal.core.util.Util.isRubyLikeFileName(proxy.getName())) {
+ IResource resource = proxy.requestResource();
+ if (!Util.isExcluded(resource, inclusionPatterns, exclusionPatterns))
+ indexManager.addSource((IFile)resource, container, parser);
+ }
+ return false;
+ case IResource.FOLDER :
+ if (exclusionPatterns != null && inclusionPatterns == null) {
+ // if there are inclusion patterns then we must walk the children
+ if (Util.isExcluded(proxy.requestFullPath(), inclusionPatterns, exclusionPatterns, true))
+ return false;
+ }
+ }
+ return true;
+ }
+ },
+ IResource.NONE
+ );
+ }
+ } catch (CoreException e) {
+ if (JobManager.VERBOSE) {
+ Util.verbose("-> failed to add " + this.folderPath + " to index because of the following exception:", System.err); //$NON-NLS-1$ //$NON-NLS-2$
+ e.printStackTrace();
+ }
+ return false;
+ } finally {
+ monitor.exitRead(); // free read lock
+ }
+ return true;
+ }
+ public String toString() {
+ return "adding " + this.folderPath + " to index " + this.containerPath; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexManager.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexManager.java 2007-05-21 21:03:54 UTC (rev 2510)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexManager.java 2007-05-21 21:05:24 UTC (rev 2511)
@@ -597,4 +597,31 @@
return null;
}
}
-}
+
+ /**
+ * Remove the content of the given source folder from the index.
+ */
+ public void removeSourceFolderFromIndex(RubyProject javaProject, IPath sourceFolder, char[][] inclusionPatterns, char[][] exclusionPatterns) {
+ IProject project = javaProject.getProject();
+ if (this.jobEnd > this.jobStart) {
+ // skip it if a job to index the project is already in the queue
+ IndexRequest request = new IndexAllProject(project, this);
+ if (isJobWaiting(request)) return;
+ }
+
+ this.request(new RemoveFolderFromIndex(sourceFolder, inclusionPatterns, exclusionPatterns, project, this));
+ }
+
+ /**
+ * Index the content of the given source folder.
+ */
+ public void indexSourceFolder(RubyProject javaProject, IPath sourceFolder, char[][] inclusionPatterns, char[][] exclusionPatterns) {
+ IProject project = javaProject.getProject();
+ if (this.jobEnd > this.jobStart) {
+ // skip it if a job to index the project is already in the queue
+ IndexRequest request = new IndexAllProject(project, this);
+ if (isJobWaiting(request)) return;
+ }
+ this.request(new AddFolderToIndex(sourceFolder, project, inclusionPatterns, exclusionPatterns, this));
+ }
+}
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/RemoveFolderFromindex.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/RemoveFolderFromindex.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/RemoveFolderFromindex.java 2007-05-21 21:05:24 UTC (rev 2511)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.core.search.indexing;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.rubypeople.rdt.internal.core.index.Index;
+import org.rubypeople.rdt.internal.core.search.processing.JobManager;
+import org.rubypeople.rdt.internal.core.util.Util;
+
+class RemoveFolderFromIndex extends IndexRequest {
+ IPath folderPath;
+ char[][] inclusionPatterns;
+ char[][] exclusionPatterns;
+ IProject project;
+
+ public RemoveFolderFromIndex(IPath folderPath, char[][] inclusionPatterns, char[][] exclusionPatterns, IProject project, IndexManager manager) {
+ super(project.getFullPath(), manager);
+ this.folderPath = folderPath;
+ this.inclusionPatterns = inclusionPatterns;
+ this.exclusionPatterns = exclusionPatterns;
+ this.project = project;
+ }
+ public boolean execute(IProgressMonitor progressMonitor) {
+
+ if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
+
+ /* ensure no concurrent write access to index */
+ Index index = this.manager.getIndex(this.containerPath, true, /*reuse index file*/ false /*create if none*/);
+ if (index == null) return true;
+ ReadWriteMonitor monitor = index.monitor;
+ if (monitor == null) return true; // index got deleted since acquired
+
+ try {
+ monitor.enterRead(); // ask permission to read
+ String containerRelativePath = Util.relativePath(this.folderPath, this.containerPath.segmentCount());
+ String[] paths = index.queryDocumentNames(containerRelativePath);
+ // all file names belonging to the folder or its subfolders and that are not excluded (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32607)
+ if (paths != null) {
+ if (this.exclusionPatterns == null && this.inclusionPatterns == null) {
+ for (int i = 0, max = paths.length; i < max; i++) {
+ manager.remove(paths[i], this.containerPath); // write lock will be acquired by the remove operation
+ }
+ } else {
+ for (int i = 0, max = paths.length; i < max; i++) {
+ String documentPath = this.containerPath.toString() + '/' + paths[i];
+ if (!Util.isExcluded(new Path(documentPath), this.inclusionPatterns, this.exclusionPatterns, false))
+ manager.remove(paths[i], this.containerPath); // write lock will be acquired by the remove operation
+ }
+ }
+ }
+ } catch (IOException e) {
+ if (JobManager.VERBOSE) {
+ Util.verbose("-> failed to remove " + this.folderPath + " from index because of the following exception:", System.err); //$NON-NLS-1$ //$NON-NLS-2$
+ e.printStackTrace();
+ }
+ return false;
+ } finally {
+ monitor.exitRead(); // free read lock
+ }
+ return true;
+ }
+ public String toString() {
+ return "removing " + this.folderPath + " from index " + this.containerPath; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|