summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-02-23 20:49:57 (EST)
committerSteffen Pingel2012-02-23 20:49:57 (EST)
commitdd272410ed09dec302025f9fc5ffcf65ab092b77 (patch)
treed7d76c2fe2fbffb3a8af5857b412ebc57b2c7bef
parent1bed15b209c561664004a4f075d4a3e46d63fc85 (diff)
downloadorg.eclipse.mylyn.tasks-dd272410ed09dec302025f9fc5ffcf65ab092b77.zip
org.eclipse.mylyn.tasks-dd272410ed09dec302025f9fc5ffcf65ab092b77.tar.gz
org.eclipse.mylyn.tasks-dd272410ed09dec302025f9fc5ffcf65ab092b77.tar.bz2
NEW - bug 358554: [api] provide an extensible store for task-related
information https://bugs.eclipse.org/bugs/show_bug.cgi?id=358554 Change-Id: Iebf65bc3560a3b3240ff86eb453f1c76391d972a
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/context/DefaultTaskContextStore.java35
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java18
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/context/AbstractTaskContextStore.java41
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/RefactorRepositoryUrlOperation.java10
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java10
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java3
7 files changed, 72 insertions, 47 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/context/DefaultTaskContextStore.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/context/DefaultTaskContextStore.java
index c35f23c..ea879ae 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/context/DefaultTaskContextStore.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/context/DefaultTaskContextStore.java
@@ -21,6 +21,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.context.AbstractTaskContextStore;
/**
@@ -32,6 +33,8 @@ public class DefaultTaskContextStore extends AbstractTaskContextStore {
public static final String CONTEXT_FILE_EXTENSION = ".xml.zip"; //$NON-NLS-1$
+ private File directory;
+
private File contextDirectory;
@Override
@@ -40,15 +43,19 @@ public class DefaultTaskContextStore extends AbstractTaskContextStore {
}
@Override
- public void deleteContext(ITask task) {
+ public void clearContext(ITask task) {
File file = getFileForContext(task);
if (file.exists()) {
file.delete();
}
}
- public File getContextDirectory() {
- return contextDirectory;
+ @Override
+ public void deleteContext(ITask task) {
+ File file = getFileForContext(task);
+ if (file.exists()) {
+ file.delete();
+ }
}
@Override
@@ -84,11 +91,8 @@ public class DefaultTaskContextStore extends AbstractTaskContextStore {
return null;
}
- /**
- * @since 3.7
- */
@Override
- public void refactorRepositoryUrl(String oldRepositoryUrl, String newRepositoryUrl) {
+ public void refactorRepositoryUrl(TaskRepository repository, String oldRepositoryUrl, String newRepositoryUrl) {
// ignore
}
@@ -98,8 +102,21 @@ public class DefaultTaskContextStore extends AbstractTaskContextStore {
}
@Override
- public synchronized void setContextDirectory(File directory) {
- this.contextDirectory = directory;
+ public synchronized void setDirectory(File directory) {
+ this.directory = directory;
+
+ contextDirectory = new File(directory.getParent(), ITasksCoreConstants.CONTEXTS_DIRECTORY);
+ if (!contextDirectory.exists()) {
+ contextDirectory.mkdirs();
+ }
+ }
+
+ public File getDirectory() {
+ return directory;
+ }
+
+ private File getContextDirectory() {
+ return contextDirectory;
}
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java
index 72d46ea..36a06f1 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataManager.java
@@ -25,6 +25,7 @@ import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.core.CoreUtil;
import org.eclipse.mylyn.commons.core.DelegatingProgressMonitor;
import org.eclipse.mylyn.commons.core.IDelegatingProgressMonitor;
import org.eclipse.mylyn.commons.core.StatusHandler;
@@ -353,26 +354,13 @@ public class TaskDataManager implements ITaskDataManager {
// String pathName = task.getConnectorKind() + "-"
// + URLEncoder.encode(task.getRepositoryUrl(), ENCODING_UTF_8);
// String fileName = kind + "-" + URLEncoder.encode(task.getTaskId(), ENCODING_UTF_8) + EXTENSION;
- String repositoryPath = task.getConnectorKind() + "-" + encode(repositoryUrl); //$NON-NLS-1$
- String fileName = encode(task.getTaskId()) + EXTENSION;
+ String repositoryPath = task.getConnectorKind() + "-" + CoreUtil.asFileName(repositoryUrl); //$NON-NLS-1$
+ String fileName = CoreUtil.asFileName(task.getTaskId()) + EXTENSION;
File path = new File(dataPath + File.separator + FOLDER_TASKS + File.separator + repositoryPath
+ File.separator + FOLDER_DATA);
return new File(path, fileName);
}
- private static String encode(String text) {
- StringBuffer sb = new StringBuffer(text.length());
- char[] chars = text.toCharArray();
- for (char c : chars) {
- if (c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '.') {
- sb.append(c);
- } else {
- sb.append("%" + Integer.toHexString(c).toUpperCase()); //$NON-NLS-1$
- }
- }
- return sb.toString();
- }
-
private File getFile10(ITask task, String kind) {
try {
String pathName = URLEncoder.encode(task.getRepositoryUrl(), ENCODING_UTF_8);
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/context/AbstractTaskContextStore.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/context/AbstractTaskContextStore.java
index 60d7bab..613369a 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/context/AbstractTaskContextStore.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/context/AbstractTaskContextStore.java
@@ -15,6 +15,7 @@ import java.io.File;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
/**
* A store for persisting task contexts.
@@ -25,24 +26,24 @@ import org.eclipse.mylyn.tasks.core.ITask;
public abstract class AbstractTaskContextStore {
/**
- * Copies the context from <code>sourceTask</code> to <code>destinationTask</code>. Creates a new context if a
- * <code>sourceTask</code> does not have a context.
+ * Clears the context of <code>task</code>.
*
- * @return result of the copy operation
* @since 3.7
*/
- public abstract IAdaptable copyContext(ITask sourceTask, ITask destinationTask);
+ public abstract void clearContext(ITask task);
/**
- * Moves the context from <code>sourceTask</code> to <code>destinationTask</code>. Creates a new context if a
+ * Copies the context from <code>sourceTask</code> to <code>destinationTask</code>. Creates a new context if a
* <code>sourceTask</code> does not have a context.
*
- * @return result of the move operation
+ * @return result of the copy operation
* @since 3.7
*/
- public abstract IAdaptable moveContext(ITask sourceTask, ITask destinationTask);
+ public abstract IAdaptable copyContext(ITask sourceTask, ITask destinationTask);
/**
+ * Deletes the context of <code>task</code>.
+ *
* @since 3.7
*/
public abstract void deleteContext(ITask task);
@@ -63,21 +64,39 @@ public abstract class AbstractTaskContextStore {
/**
* @since 3.7
*/
- public abstract void refactorRepositoryUrl(String oldRepositoryUrl, String newRepositoryUrl);
+ public abstract void mergeContext(ITask sourceTask, ITask targetTask);
+
+ /**
+ * Moves the context from <code>sourceTask</code> to <code>destinationTask</code>. Creates a new context if a
+ * <code>sourceTask</code> does not have a context.
+ *
+ * @return result of the move operation
+ * @since 3.7
+ */
+ public abstract IAdaptable moveContext(ITask sourceTask, ITask destinationTask);
/**
* @since 3.7
*/
- public abstract void saveActiveContext();
+ public abstract void refactorRepositoryUrl(TaskRepository repository, String oldRepositoryUrl,
+ String newRepositoryUrl);
+
+ /**
+ * Returns an object for persisting task related information. The object needs to be released when it is no longer
+ * used.
+ */
+ //public abstract ICommonStorable getStorable(ITask task);
/**
* @since 3.7
*/
- public abstract void setContextDirectory(File contextStoreDir);
+ public abstract void saveActiveContext();
/**
+ * Sets the location of task file.
+ *
* @since 3.7
*/
- public abstract void mergeContext(ITask sourceTask, ITask targetTask);
+ public abstract void setDirectory(File directory);
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
index 4b951d6..0ad07bd 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
@@ -241,7 +241,7 @@ public class TaskDataStoreTest extends TestCase {
file.deleteOnExit();
storage.putTaskData(file, state);
- if (System.getProperty("java.version").compareTo("1.5") <= 0) {
+ if (System.getProperty("java.version").compareTo("1.6") < 0) {
// Java 1.5 fails to parse C1 characters with XML 1.1
try {
TaskDataState state2 = storage.getTaskDataState(file);
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/RefactorRepositoryUrlOperation.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/RefactorRepositoryUrlOperation.java
index 2ab9c80..798d587 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/RefactorRepositoryUrlOperation.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/RefactorRepositoryUrlOperation.java
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.internal.tasks.core.data.TaskDataManager;
import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
/**
* @author Rob Elves
@@ -29,11 +30,18 @@ public class RefactorRepositoryUrlOperation extends TaskListModifyOperation {
private final String newUrl;
+ private final TaskRepository repository;
+
public RefactorRepositoryUrlOperation(String oldUrl, String newUrl) {
+ this(null, oldUrl, newUrl);
+ }
+
+ public RefactorRepositoryUrlOperation(TaskRepository repository, String oldUrl, String newUrl) {
super(ITasksCoreConstants.ROOT_SCHEDULING_RULE);
Assert.isNotNull(oldUrl);
Assert.isNotNull(newUrl);
Assert.isTrue(!oldUrl.equals(newUrl));
+ this.repository = repository;
this.oldUrl = oldUrl;
this.newUrl = newUrl;
}
@@ -46,7 +54,7 @@ public class RefactorRepositoryUrlOperation extends TaskListModifyOperation {
monitor.beginTask(Messages.RefactorRepositoryUrlOperation_Repository_URL_update, IProgressMonitor.UNKNOWN);
refactorOfflineHandles(oldUrl, newUrl);
getTaskList().refactorRepositoryUrl(oldUrl, newUrl);
- TasksUiPlugin.getContextStore().refactorRepositoryUrl(oldUrl, newUrl);
+ TasksUiPlugin.getContextStore().refactorRepositoryUrl(repository, oldUrl, newUrl);
TasksUiPlugin.getTaskActivityMonitor().reloadActivityTime();
} finally {
monitor.done();
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java
index b3a80b4..7ae9bc8 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java
@@ -865,7 +865,7 @@ public class TasksUiPlugin extends AbstractUIPlugin {
public void initializeDataSources() {
taskDataManager.setDataPath(getDataDirectory());
externalizationManager.setRootFolderPath(getDataDirectory());
- getContextStore().setContextDirectory(getContextStoreDir());
+ getContextStore().setDirectory(new File(getDataDirectory(), "tasks")); //$NON-NLS-1$
externalizationManager.load();
// TODO: Move management of template repositories to TaskRepositoryManager
@@ -914,14 +914,6 @@ public class TasksUiPlugin extends AbstractUIPlugin {
}
}
- private File getContextStoreDir() {
- File storeFile = new File(getDataDirectory(), ITasksCoreConstants.CONTEXTS_DIRECTORY);
- if (!storeFile.exists()) {
- storeFile.mkdirs();
- }
- return storeFile;
- }
-
@SuppressWarnings("deprecation")
private void initializePreferences(IPreferenceStore store) {
store.setDefault(ITasksUiPreferenceConstants.PREF_DATA_DIR, getDefaultDataDirectory());
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java
index f5e7646..7ede442 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java
@@ -59,7 +59,8 @@ public class EditRepositoryWizard extends Wizard implements INewWizard {
if (oldUrl != null && newUrl != null && !oldUrl.equals(newUrl)) {
TasksUi.getTaskActivityManager().deactivateActiveTask();
- RefactorRepositoryUrlOperation operation = new RefactorRepositoryUrlOperation(oldUrl, newUrl);
+ RefactorRepositoryUrlOperation operation = new RefactorRepositoryUrlOperation(repository, oldUrl,
+ newUrl);
try {
getContainer().run(true, false, operation);
} catch (InvocationTargetException e) {