Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal')
-rw-r--r--org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java73
1 files changed, 58 insertions, 15 deletions
diff --git a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java
index 1d6b5af36..00ee23ea9 100644
--- a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java
+++ b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java
@@ -110,6 +110,7 @@ import org.eclipse.mylyn.tasks.core.data.TaskData;
* </p>
*
* @author David Green
+ * @author Steffen Pingel
*/
public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeListener, IRepositoryListener {
@@ -337,21 +338,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL
Assert.isNotNull(indexLocation);
this.startupDelay = startupDelay;
- if (!indexLocation.exists()) {
- rebuildIndex = true;
- if (!indexLocation.mkdirs()) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
- "Cannot create task list index folder: " + indexLocation)); //$NON-NLS-1$
- }
- }
- if (indexLocation.exists() && indexLocation.isDirectory()) {
- try {
- directory = new NIOFSDirectory(indexLocation);
- } catch (IOException e) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
- "Cannot create task list index", e)); //$NON-NLS-1$
- }
- }
+ setLocationInternal(indexLocation);
initialize();
}
@@ -393,6 +380,62 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL
this.reindexDelay = reindexDelay;
}
+ public void setLocation(File indexLocation) {
+ try {
+ waitUntilIdle();
+ } catch (InterruptedException e1) {
+ // ignore
+ }
+ setLocationInternal(indexLocation);
+ rebuildIndex = true;
+ scheduleIndexMaintenance(MaintainIndexType.STARTUP);
+ }
+
+ private void setLocationInternal(File indexLocation) {
+ final boolean newLocationExists = indexLocation.exists();
+ if (!newLocationExists) {
+ if (!indexLocation.mkdirs()) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
+ "Cannot create task list index folder: " + indexLocation)); //$NON-NLS-1$
+ }
+ }
+
+ Lock writeLock = indexReaderLock.writeLock();
+ writeLock.lock();
+ try {
+ synchronized (this) {
+ if (indexReader != null) {
+ try {
+ indexReader.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ indexReader = null;
+ }
+
+ if (indexLocation.exists() && indexLocation.isDirectory()) {
+ if (directory != null) {
+ try {
+ directory.close();
+ } catch (IOException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
+ "Cannot close index: " + e.getMessage(), e)); //$NON-NLS-1$
+ }
+ }
+ try {
+ directory = new NIOFSDirectory(indexLocation);
+ } catch (IOException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
+ "Cannot create task list index", e)); //$NON-NLS-1$
+ }
+ }
+
+ }
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
/**
* the default field used to match tasks when unspecified in the query
*/

Back to the top