1 11 package org.eclipse.jdt.internal.core.search.indexing; 12 13 import java.io.IOException ; 14 import java.net.URI ; 15 16 import org.eclipse.core.filesystem.EFS; 17 import org.eclipse.core.resources.IContainer; 18 import org.eclipse.core.resources.IFile; 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.resources.IResourceProxy; 21 import org.eclipse.core.resources.IResourceProxyVisitor; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; 25 import org.eclipse.jdt.internal.core.index.Index; 26 import org.eclipse.jdt.internal.core.search.processing.JobManager; 27 import org.eclipse.jdt.internal.core.util.Util; 28 29 public class IndexBinaryFolder extends IndexRequest { 30 IContainer folder; 31 32 public IndexBinaryFolder(IContainer folder, IndexManager manager) { 33 super(folder.getFullPath(), manager); 34 this.folder = folder; 35 } 36 public boolean equals(Object o) { 37 if (o instanceof IndexBinaryFolder) 38 return this.folder.equals(((IndexBinaryFolder) o).folder); 39 return false; 40 } 41 46 public boolean execute(IProgressMonitor progressMonitor) { 47 48 if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; 49 if (!this.folder.isAccessible()) return true; 51 Index index = this.manager.getIndexForUpdate(this.containerPath, true, true ); 52 if (index == null) return true; 53 ReadWriteMonitor monitor = index.monitor; 54 if (monitor == null) return true; 56 try { 57 monitor.enterRead(); 59 String [] paths = index.queryDocumentNames(""); int max = paths == null ? 0 : paths.length; 61 final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max==0 ? 33 : max+11); 62 final String OK = "OK"; final String DELETED = "DELETED"; if (paths == null) { 65 this.folder.accept(new IResourceProxyVisitor() { 66 public boolean visit(IResourceProxy proxy) { 67 if (isCancelled) return false; 68 if (proxy.getType() == IResource.FILE) { 69 if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName())) { 70 IFile file = (IFile) proxy.requestResource(); 71 String containerRelativePath = Util.relativePath(file.getFullPath(), containerPath.segmentCount()); 72 indexedFileNames.put(containerRelativePath, file); 73 } 74 return false; 75 } 76 return true; 77 } 78 }, IResource.NONE); 79 } else { 80 for (int i = 0; i < max; i++) { 81 indexedFileNames.put(paths[i], DELETED); 82 } 83 final long indexLastModified = index.getIndexFile().lastModified(); 84 this.folder.accept( 85 new IResourceProxyVisitor() { 86 public boolean visit(IResourceProxy proxy) throws CoreException { 87 if (isCancelled) return false; 88 if (proxy.getType() == IResource.FILE) { 89 if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName())) { 90 IFile file = (IFile) proxy.requestResource(); 91 URI location = file.getLocationURI(); 92 if (location != null) { 93 String containerRelativePath = Util.relativePath(file.getFullPath(), containerPath.segmentCount()); 94 indexedFileNames.put(containerRelativePath, 95 indexedFileNames.get(containerRelativePath) == null 96 || indexLastModified < 97 EFS.getStore(location).fetchInfo().getLastModified() 98 ? (Object ) file 99 : (Object ) OK); 100 } 101 } 102 return false; 103 } 104 return true; 105 } 106 }, 107 IResource.NONE 108 ); 109 } 110 111 Object [] names = indexedFileNames.keyTable; 112 Object [] values = indexedFileNames.valueTable; 113 for (int i = 0, length = names.length; i < length; i++) { 114 String name = (String ) names[i]; 115 if (name != null) { 116 if (this.isCancelled) return false; 117 118 Object value = values[i]; 119 if (value != OK) { 120 if (value == DELETED) 121 this.manager.remove(name, this.containerPath); 122 else { 123 this.manager.addBinary((IFile) value, this.containerPath); 124 } 125 } 126 } 127 } 128 129 this.manager.request(new SaveIndex(this.containerPath, this.manager)); 131 } catch (CoreException e) { 132 if (JobManager.VERBOSE) { 133 Util.verbose("-> failed to index " + this.folder + " because of the following exception:", System.err); e.printStackTrace(); 135 } 136 this.manager.removeIndex(this.containerPath); 137 return false; 138 } catch (IOException e) { 139 if (JobManager.VERBOSE) { 140 Util.verbose("-> failed to index " + this.folder + " because of the following exception:", System.err); e.printStackTrace(); 142 } 143 this.manager.removeIndex(this.containerPath); 144 return false; 145 } finally { 146 monitor.exitRead(); } 148 return true; 149 } 150 public int hashCode() { 151 return this.folder.hashCode(); 152 } 153 protected Integer updatedIndexState() { 154 return IndexManager.REBUILDING_STATE; 155 } 156 public String toString() { 157 return "indexing binary folder " + this.folder.getFullPath(); } 159 } 160 | Popular Tags |