KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > search > indexing > RemoveFolderFromIndex


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 package org.eclipse.jdt.internal.core.search.indexing;
12
13 import java.io.IOException JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.runtime.IPath;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.jdt.internal.core.index.Index;
20 import org.eclipse.jdt.internal.core.search.processing.JobManager;
21 import org.eclipse.jdt.internal.core.util.Util;
22
23 class RemoveFolderFromIndex extends IndexRequest {
24     IPath folderPath;
25     char[][] inclusionPatterns;
26     char[][] exclusionPatterns;
27     IProject project;
28
29     public RemoveFolderFromIndex(IPath folderPath, char[][] inclusionPatterns, char[][] exclusionPatterns, IProject project, IndexManager manager) {
30         super(project.getFullPath(), manager);
31         this.folderPath = folderPath;
32         this.inclusionPatterns = inclusionPatterns;
33         this.exclusionPatterns = exclusionPatterns;
34         this.project = project;
35     }
36     public boolean execute(IProgressMonitor progressMonitor) {
37
38         if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
39
40         /* ensure no concurrent write access to index */
41         Index index = this.manager.getIndex(this.containerPath, true, /*reuse index file*/ false /*create if none*/);
42         if (index == null) return true;
43         ReadWriteMonitor monitor = index.monitor;
44         if (monitor == null) return true; // index got deleted since acquired
45

46         try {
47             monitor.enterRead(); // ask permission to read
48
String JavaDoc containerRelativePath = Util.relativePath(this.folderPath, this.containerPath.segmentCount());
49             String JavaDoc[] paths = index.queryDocumentNames(containerRelativePath);
50             // 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)
51
if (paths != null) {
52                 if (this.exclusionPatterns == null && this.inclusionPatterns == null) {
53                     for (int i = 0, max = paths.length; i < max; i++) {
54                         manager.remove(paths[i], this.containerPath); // write lock will be acquired by the remove operation
55
}
56                 } else {
57                     for (int i = 0, max = paths.length; i < max; i++) {
58                         String JavaDoc documentPath = this.containerPath.toString() + '/' + paths[i];
59                         if (!Util.isExcluded(new Path(documentPath), this.inclusionPatterns, this.exclusionPatterns, false))
60                             manager.remove(paths[i], this.containerPath); // write lock will be acquired by the remove operation
61
}
62                 }
63             }
64         } catch (IOException JavaDoc e) {
65             if (JobManager.VERBOSE) {
66                 Util.verbose("-> failed to remove " + this.folderPath + " from index because of the following exception:", System.err); //$NON-NLS-1$ //$NON-NLS-2$
67
e.printStackTrace();
68             }
69             return false;
70         } finally {
71             monitor.exitRead(); // free read lock
72
}
73         return true;
74     }
75     public String JavaDoc toString() {
76         return "removing " + this.folderPath + " from index " + this.containerPath; //$NON-NLS-1$ //$NON-NLS-2$
77
}
78 }
79
Popular Tags