Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2006-09-15 16:22:48 -0400
committerrelves2006-09-15 16:22:48 -0400
commit11afd842fa87007e1a2d1885310f97e57db2a4ac (patch)
treedd454edd9778a6a64484c82ce29bdcf8cd0cfaaf
parent211f178e3fe1dc6cc8ded0c5e9ebafd0550406e1 (diff)
downloadorg.eclipse.mylyn.tasks-11afd842fa87007e1a2d1885310f97e57db2a4ac.tar.gz
org.eclipse.mylyn.tasks-11afd842fa87007e1a2d1885310f97e57db2a4ac.tar.xz
org.eclipse.mylyn.tasks-11afd842fa87007e1a2d1885310f97e57db2a4ac.zip
Progress on: 147779: improve the way that context is stored on disk
https://bugs.eclipse.org/bugs/show_bug.cgi?id=147779
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskListManagerTest.java6
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java34
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java44
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java78
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java4
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java1
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java96
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListDataMigrationTest.java103
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/WorkspaceAwareContextStore.java16
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportJob.java22
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java57
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataExportWizardPage.java23
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataImportWizard.java152
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskListDataMigration.java259
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskListManager.java8
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java10
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java1
17 files changed, 705 insertions, 209 deletions
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskListManagerTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskListManagerTest.java
index a3b4eecd8..c7fd07133 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskListManagerTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskListManagerTest.java
@@ -44,10 +44,10 @@ public class BugzillaTaskListManagerTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- manager = TasksUiPlugin.getTaskListManager();
- manager.resetTaskList();
+ manager = TasksUiPlugin.getTaskListManager();
manager.readExistingOrCreateNewList();
-
+ manager.resetTaskList();
+ manager.saveTaskList();
repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
TasksUiPlugin.getRepositoryManager().addRepository(repository, TasksUiPlugin.getDefault().getRepositoriesFilePath());
assertEquals(0, manager.getTaskList().getAllTasks().size());
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java
index 989c34fcc..e16599139 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java
@@ -11,7 +11,6 @@
package org.eclipse.mylar.bugzilla.tests;
-import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -22,7 +21,6 @@ import junit.framework.TestCase;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTask;
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaTaskExternalizer;
-import org.eclipse.mylar.internal.tasks.ui.util.TaskListWriter;
import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.ITaskListExternalizer;
import org.eclipse.mylar.tasks.core.Task;
@@ -37,24 +35,15 @@ public class TaskListStandaloneTest extends TestCase {
private TaskListManager manager;
- private File file;
-
- List<ITaskListExternalizer> externalizers;
-
@Override
protected void setUp() throws Exception {
super.setUp();
TasksUiPlugin.getRepositoryManager().clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath());
- externalizers = new ArrayList<ITaskListExternalizer>();
+ manager = TasksUiPlugin.getTaskListManager();
- externalizers.add(new BugzillaTaskExternalizer());
-
- TaskListWriter writer = new TaskListWriter();
- writer.setDelegateExternalizers(externalizers);
-
- file = new File("foo" + TasksUiPlugin.FILE_EXTENSION);
- file.deleteOnExit();
- manager = new TaskListManager(writer, file);
+ // file = new File("tasklist" + TasksUiPlugin.FILE_EXTENSION);
+ // file.deleteOnExit();
+ // new TaskListManager(writer, file);
manager.resetTaskList();
assertEquals("should be empty: " + manager.getTaskList().getRootTasks(), 0, manager.getTaskList()
.getRootTasks().size());
@@ -62,9 +51,8 @@ public class TaskListStandaloneTest extends TestCase {
@Override
protected void tearDown() throws Exception {
- // manager.getTaskList().clear();
manager.resetTaskList();
- // manager.setTaskList(new TaskList());
+ manager.saveTaskList();
super.tearDown();
}
@@ -117,7 +105,10 @@ public class TaskListStandaloneTest extends TestCase {
}
public void testTaskRetentionWhenConnectorMissing() {
-
+ List<ITaskListExternalizer> originalExternalizers = manager.getTaskListWriter().getExternalizers();
+ List<ITaskListExternalizer> externalizers;
+ externalizers = new ArrayList<ITaskListExternalizer>();
+ externalizers.add(new BugzillaTaskExternalizer());
// make some tasks
// save them
BugzillaTask task = new BugzillaTask("http://bugs-1", "1", true);
@@ -132,7 +123,7 @@ public class TaskListStandaloneTest extends TestCase {
// removed/disable externalizers
externalizers.clear();
manager.getTaskListWriter().setDelegateExternalizers(externalizers);
-
+
// reload tasklist ensure task didn't load
manager.resetTaskList();
manager.readExistingOrCreateNewList();
@@ -148,11 +139,12 @@ public class TaskListStandaloneTest extends TestCase {
// re-load tasklist
manager.resetTaskList();
manager.readExistingOrCreateNewList();
-
+
// ensure that task now gets loaded
assertEquals(1, manager.getTaskList().getAllTasks().size());
+ manager.getTaskListWriter().setDelegateExternalizers(originalExternalizers);
}
-
+
public void assertDatesCloseEnough(Date first, Date second) {
assertTrue(second.getTime() - first.getTime() < 100);
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java
index c22e2c2ed..27144ed48 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java
@@ -15,12 +15,16 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
+import java.io.InputStream;
import java.util.Collection;
import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
import org.eclipse.mylar.context.core.MylarStatusHandler;
import org.eclipse.mylar.tasks.core.TaskRepository;
+import org.eclipse.mylar.tasks.core.TaskRepositoryManager;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
@@ -43,15 +47,33 @@ public class TaskRepositoriesExternalizer {
public void writeRepositoriesToXML(Collection<TaskRepository> repositories, File file) {
if (repositories.isEmpty())
return;
+ ZipOutputStream outputStream = null;
try {
if (!file.exists())
file.createNewFile();
- OutputStream stream = new FileOutputStream(file);
- writer.setOutputStream(stream);
+
+ outputStream = new ZipOutputStream(new FileOutputStream(file));
+ ZipEntry zipEntry = new ZipEntry(TaskRepositoryManager.OLD_REPOSITORIES_FILE);
+ outputStream.putNextEntry(zipEntry);
+ outputStream.setMethod(ZipOutputStream.DEFLATED);
+
+ // OutputStream stream = new FileOutputStream(file);
+ writer.setOutputStream(outputStream);
writer.writeRepositoriesToStream(repositories);
- stream.close();
+ outputStream.flush();
+ outputStream.closeEntry();
+ outputStream.close();
+
} catch (IOException e) {
MylarStatusHandler.fail(e, "Could not write: " + file.getAbsolutePath(), true);
+ } finally {
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (IOException e) {
+ MylarStatusHandler.fail(e, "Unable to terminate output stream to repositories file.", false);
+ }
+ }
}
}
@@ -59,15 +81,27 @@ public class TaskRepositoriesExternalizer {
if (!file.exists())
return null;
+ InputStream inputStream = null;
try {
+ inputStream = new ZipInputStream(new FileInputStream(file));
+ ((ZipInputStream) inputStream).getNextEntry();
SaxRepositoriesContentHandler contentHandler = new SaxRepositoriesContentHandler();
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(contentHandler);
- reader.parse(new InputSource(new FileInputStream(file)));
+ reader.parse(new InputSource(inputStream));
return contentHandler.getRepositories();
} catch (Throwable e) {
file.renameTo(new File(file.getAbsolutePath() + "-save"));
+ MylarStatusHandler.log(e, "Error while reading context file");
return null;
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ MylarStatusHandler.fail(e, "Failed to close repositories input stream.", false);
+ }
+ }
}
}
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
index 65663bcdd..2443d25fd 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
@@ -12,9 +12,7 @@
package org.eclipse.mylar.tasks.core;
import java.io.File;
-import java.io.IOException;
import java.net.Proxy;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
@@ -23,10 +21,7 @@ import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
import org.eclipse.mylar.context.core.ContextCorePlugin;
-import org.eclipse.mylar.internal.context.core.util.ZipFileUtil;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask.RepositoryTaskSyncState;
/**
@@ -43,18 +38,16 @@ public abstract class AbstractRepositoryConnector {
private static final String APPLICATION_OCTET_STREAM = "application/octet-stream";
- private static final String ZIPFILE_EXTENSION = ".zip";
-
protected List<String> supportedVersions;
protected Set<RepositoryTemplate> templates = new LinkedHashSet<RepositoryTemplate>();
protected TaskList taskList;
-
+
public void init(TaskList taskList) {
this.taskList = taskList;
}
-
+
/**
* @return null if not supported
*/
@@ -74,32 +67,41 @@ public abstract class AbstractRepositoryConnector {
/**
* Reset and update the repository attributes from the server (e.g.
* products, components)
- * @param proxySettings TODO
- * @throws CoreException TODO
+ *
+ * @param proxySettings
+ * TODO
+ * @throws CoreException
+ * TODO
*/
- public abstract void updateAttributes(TaskRepository repository, Proxy proxySettings, IProgressMonitor monitor) throws CoreException;
-
+ public abstract void updateAttributes(TaskRepository repository, Proxy proxySettings, IProgressMonitor monitor)
+ throws CoreException;
+
/**
* @param id
* identifier, e.g. "123" bug Bugzilla bug 123
- * @param proxySettings TODO
+ * @param proxySettings
+ * TODO
* @return null if task could not be created
- * @throws CoreException TODO
+ * @throws CoreException
+ * TODO
*/
- public abstract ITask createTaskFromExistingKey(TaskRepository repository, String id, Proxy proxySettings) throws CoreException;
+ public abstract ITask createTaskFromExistingKey(TaskRepository repository, String id, Proxy proxySettings)
+ throws CoreException;
/**
* Implementors must execute query synchronously.
*
* @param query
- * @param repository TODO
- * @param proxySettings TODO
+ * @param repository
+ * TODO
+ * @param proxySettings
+ * TODO
* @param monitor
* @param resultCollector
* IQueryHitCollector that collects the hits found
*/
- public abstract IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository,
- Proxy proxySettings, IProgressMonitor monitor, QueryHitCollector resultCollector);
+ public abstract IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository, Proxy proxySettings,
+ IProgressMonitor monitor, QueryHitCollector resultCollector);
public abstract String getLabel();
@@ -162,30 +164,16 @@ public abstract class AbstractRepositoryConnector {
return false;
}
- // compress context file
- List<File> filesToZip = new ArrayList<File>();
- filesToZip.add(sourceContextFile);
-
- File destinationFile;
- try {
- destinationFile = File.createTempFile(sourceContextFile.getName(), ZIPFILE_EXTENSION);
- destinationFile.deleteOnExit();
- ZipFileUtil.createZipFile(destinationFile, filesToZip, new NullProgressMonitor());
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, ContextCorePlugin.PLUGIN_ID, 0,
- "Error compressing context file", e));
- }
-
try {
// TODO: 'faking' outgoing state
task.setSyncState(RepositoryTaskSyncState.OUTGOING);
- handler.uploadAttachment(repository, task, longComment, MYLAR_CONTEXT_DESCRIPTION, destinationFile,
+ handler.uploadAttachment(repository, task, longComment, MYLAR_CONTEXT_DESCRIPTION, sourceContextFile,
APPLICATION_OCTET_STREAM, false, proxySettings);
} catch (CoreException e) {
task.setSyncState(RepositoryTaskSyncState.SYNCHRONIZED);
throw e;
}
- task.setTaskData(null);
+ task.setTaskData(null);
}
return true;
}
@@ -205,18 +193,14 @@ public abstract class AbstractRepositoryConnector {
File destinationContextFile = ContextCorePlugin.getContextManager().getFileForContext(
task.getHandleIdentifier());
- // TODO what if destinationContextFile == null?
- File destinationZipFile = new File(destinationContextFile.getPath() + ZIPFILE_EXTENSION);
-
- attachmentHandler.downloadAttachment(repository, task, attachment, destinationZipFile, proxySettings);
- // if (destinationContextFile.exists()) {
- try {
- ZipFileUtil.unzipFiles(destinationZipFile, destinationPath);
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, ContextCorePlugin.PLUGIN_ID, 0,
- "Error extracting context file", e));
+
+ // TODO: add functionality for not overwriting previous context
+ if(destinationContextFile.exists()) {
+ if(!destinationContextFile.delete()) {
+ return false;
+ }
}
-
+ attachmentHandler.downloadAttachment(repository, task, attachment, destinationContextFile, proxySettings);
return true;
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java
index 1e60f6c38..ac6ea6ced 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java
@@ -31,6 +31,10 @@ import org.eclipse.mylar.internal.tasks.core.TaskRepositoriesExternalizer;
*/
public class TaskRepositoryManager {
+ public static final String OLD_REPOSITORIES_FILE = "repositories.xml";
+
+ public static final String DEFAULT_REPOSITORIES_FILE = "repositories.xml.zip";
+
public static final String PREF_REPOSITORIES = "org.eclipse.mylar.tasklist.repositories.";
private Map<String, AbstractRepositoryConnector> repositoryConnectors = new HashMap<String, AbstractRepositoryConnector>();
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
index 1f4ad38d4..8ea34ffe8 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
@@ -23,6 +23,7 @@ public class AllTasksTests {
TestSuite suite = new TestSuite("Test for org.eclipse.mylar.tasklist.tests");
// $JUnit-BEGIN$
+ suite.addTestSuite(TaskListDataMigrationTest.class);
suite.addTestSuite(TaskPlanningEditorTest.class);
suite.addTestSuite(TaskListManagerTest.class);
suite.addTestSuite(RepositoryTaskSynchronizationTest.class);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java
index c56daba53..5c8e13059 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java
@@ -11,12 +11,15 @@
package org.eclipse.mylar.tasks.tests;
import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
-import org.eclipse.mylar.context.core.InteractionEvent;
import org.eclipse.mylar.context.core.ContextCorePlugin;
+import org.eclipse.mylar.context.core.InteractionEvent;
import org.eclipse.mylar.context.tests.AbstractContextTest;
import org.eclipse.mylar.internal.context.core.MylarContext;
-import org.eclipse.mylar.internal.context.core.MylarContextManager;
import org.eclipse.mylar.internal.tasks.ui.wizards.TaskDataExportWizard;
import org.eclipse.mylar.internal.tasks.ui.wizards.TaskDataExportWizardPage;
import org.eclipse.mylar.tasks.core.ITask;
@@ -48,6 +51,8 @@ public class TaskDataExportTest extends AbstractContextTest {
protected void setUp() throws Exception {
super.setUp();
+ removeFiles(new File(TasksUiPlugin.getDefault().getDataDirectory()));
+
// Create the export wizard
wizard = new TaskDataExportWizard();
wizard.addPages();
@@ -57,7 +62,11 @@ public class TaskDataExportTest extends AbstractContextTest {
// Create test export destination directory
destinationDir = new File(TasksUiPlugin.getDefault().getDataDirectory() + File.separator + "TestDir");
- destinationDir.mkdir();
+ if(destinationDir.exists()) {
+ removeFiles(destinationDir);
+ } else {
+ destinationDir.mkdir();
+ }
assertTrue(destinationDir.exists());
// Create a task and context with an interaction event to be saved
@@ -75,12 +84,8 @@ public class TaskDataExportTest extends AbstractContextTest {
assertTrue(taskFile.exists());
}
- protected void tearDown() throws Exception {
- File[] files = destinationDir.listFiles();
- for (File file : files) {
- file.delete();
- }
-
+ protected void tearDown() throws Exception {
+ removeFiles(destinationDir);
destinationDir.delete();
assertFalse(destinationDir.exists());
ContextCorePlugin.getContextManager().deactivateContext(mockContext.getHandleIdentifier());
@@ -91,7 +96,7 @@ public class TaskDataExportTest extends AbstractContextTest {
* Tests the wizard when it has been asked to export all task data to a zip
* file
*/
- public void testExportAllToZip() {
+ public void testExportAllToZip() throws Exception {
// Set parameters in the wizard to simulate a user setting them and
// clicking "Finish"
@@ -101,29 +106,56 @@ public class TaskDataExportTest extends AbstractContextTest {
// Check that the task list file was exported
File destZipFile = new File(destinationDir + File.separator + TaskDataExportWizard.getZipFileName());
assertTrue(destZipFile.exists());
- }
-
- /** Tests the wizard when it has been asked to export all task data */
- public void testExportAll() {
+ ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(destZipFile));
+ ArrayList<String> entries = new ArrayList<String>();
- // Set parameters in the wizard to simulate a user setting them and
- // clicking "Finish"
- wizardPage.setParameters(true, true, true, true, false, destinationDir.getPath());
- wizard.performFinish();
+ ZipEntry entry = zipInputStream.getNextEntry();
+ while (entry != null) {
+ entries.add(entry.getName());
+ entry = zipInputStream.getNextEntry();
+ }
+ zipInputStream.close();
+ assertEquals(2, entries.size());
+ assertTrue(entries.contains("tasklist.xml.zip"));
+ assertTrue(entries.contains("contexts/local-1.xml.zip"));
+ }
- // Check that the task list file was exported
- File destTaskListFile = new File(destinationDir + File.separator + TasksUiPlugin.DEFAULT_TASK_LIST_FILE);
- assertTrue(destTaskListFile.exists());
-
- // Check that the activity history file was exported
- File destActivationHistoryFile = new File(destinationDir + File.separator
- + MylarContextManager.CONTEXT_HISTORY_FILE_NAME + MylarContextManager.CONTEXT_FILE_EXTENSION);
- assertTrue(destActivationHistoryFile.exists());
-
- // Check that the task context file created in setUp() was exported
- File destTaskContextFile = ContextCorePlugin.getContextManager().getFileForContext(task1.getHandleIdentifier());
- // File destTaskContextFile = new File(destinationDir + File.separator +
- // task1.getContextPath() + MylarContextManager.CONTEXT_FILE_EXTENSION);
- assertTrue(destTaskContextFile.exists());
+ // /** Tests the wizard when it has been asked to export all task data */
+ // public void testExportAll() {
+ //
+ // // Set parameters in the wizard to simulate a user setting them and
+ // // clicking "Finish"
+ // wizardPage.setParameters(true, true, true, true, false,
+ // destinationDir.getPath());
+ // wizard.performFinish();
+ //
+ // // Check that the task list file was exported
+ // File destTaskListFile = new File(destinationDir + File.separator +
+ // TasksUiPlugin.OLD_TASK_LIST_FILE);
+ // assertTrue(destTaskListFile.exists());
+ //
+ // // Check that the activity history file was exported
+ // File destActivationHistoryFile = new File(destinationDir + File.separator
+ // + MylarContextManager.CONTEXT_HISTORY_FILE_NAME +
+ // MylarContextManager.OLD_CONTEXT_FILE_EXTENSION);
+ // assertTrue(destActivationHistoryFile.exists());
+ //
+ // // Check that the task context file created in setUp() was exported
+ // File destTaskContextFile =
+ // ContextCorePlugin.getContextManager().getFileForContext(task1.getHandleIdentifier());
+ // // File destTaskContextFile = new File(destinationDir + File.separator +
+ // // task1.getContextPath() + MylarContextManager.CONTEXT_FILE_EXTENSION);
+ // assertTrue(destTaskContextFile.exists());
+ // }
+
+ private void removeFiles(File root) {
+ if (root.isDirectory()) {
+ for (File file : root.listFiles()) {
+ if (file.isDirectory()) {
+ removeFiles(file);
+ }
+ file.delete();
+ }
+ }
}
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListDataMigrationTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListDataMigrationTest.java
new file mode 100644
index 000000000..cfcba7608
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListDataMigrationTest.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers 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
+ *******************************************************************************/
+
+package org.eclipse.mylar.tasks.tests;
+
+import java.io.File;
+import java.net.URLEncoder;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylar.internal.context.core.MylarContextManager;
+import org.eclipse.mylar.tasks.ui.TaskListDataMigration;
+
+/**
+ * @author Rob Elves
+ */
+public class TaskListDataMigrationTest extends TestCase {
+
+ private String sourceDir = "testdata/tasklistdatamigrationtest";
+ private File sourceDirFile;
+ private TaskListDataMigration migrator;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ sourceDirFile = TaskTestUtil.getLocalFile(sourceDir);
+ assertNotNull(sourceDirFile);
+ deleteAllFiles(sourceDirFile);
+ migrator = new TaskListDataMigration(sourceDirFile);
+ assertTrue(sourceDirFile.exists());
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ deleteAllFiles(sourceDirFile);
+ }
+
+ public void testOldTasklistMigration() throws Exception {
+ File oldTasklistFile = new File(sourceDirFile, "tasklist.xml");
+ oldTasklistFile.createNewFile();
+ assertTrue(new File(sourceDirFile, "tasklist.xml").exists());
+ assertTrue(!new File(sourceDirFile, "tasklist.xml.zip").exists());
+ assertTrue(migrator.migrateTaskList(new NullProgressMonitor()));
+ assertFalse(new File(sourceDirFile, "tasklist.xml").exists());
+ assertFalse(!new File(sourceDirFile, "tasklist.xml.zip").exists());
+ }
+
+
+ public void testOldRepositoriesMigration() throws Exception {
+ File oldRepositoriesFile = new File(sourceDirFile, "repositories.xml");
+ oldRepositoriesFile.createNewFile();
+ assertTrue(new File(sourceDirFile, "repositories.xml").exists());
+ assertTrue(!new File(sourceDirFile, "repositories.xml.zip").exists());
+ assertTrue(migrator.migrateRepositoriesData(new NullProgressMonitor()));
+ assertFalse(new File(sourceDirFile, "repositories.xml").exists());
+ assertTrue(new File(sourceDirFile, "repositories.xml.zip").exists());
+ }
+
+ public void testOldContextMigration() throws Exception {
+ String contextFileName1 = URLEncoder.encode("http://oldcontext1.xml", MylarContextManager.CONTEXT_FILENAME_ENCODING);
+ String contextFileName2 = URLEncoder.encode("http://oldcontext2.xml", MylarContextManager.CONTEXT_FILENAME_ENCODING);
+ File oldContextFile1 = new File(sourceDirFile, contextFileName1);
+ oldContextFile1.createNewFile();
+ File oldContextFile2 = new File(sourceDirFile, contextFileName2);
+ oldContextFile2.createNewFile();
+ File contextFolder = new File(sourceDirFile, MylarContextManager.CONTEXTS_DIRECTORY);
+ assertTrue(!contextFolder.exists());
+ assertTrue(migrator.migrateTaskContextData(new NullProgressMonitor()));
+ assertFalse(oldContextFile1.exists());
+ assertFalse(oldContextFile2.exists());
+ assertTrue(contextFolder.exists());
+ assertTrue(new File(contextFolder, contextFileName1+".zip").exists());
+ assertTrue(new File(contextFolder, contextFileName2+".zip").exists());
+ }
+
+ public void testOldActivityMigration() throws Exception {
+ File oldActivityFile = new File(sourceDirFile, MylarContextManager.OLD_CONTEXT_HISTORY_FILE_NAME+MylarContextManager.OLD_CONTEXT_FILE_EXTENSION);
+ oldActivityFile.createNewFile();
+ File contextFolder = new File(sourceDirFile, MylarContextManager.CONTEXTS_DIRECTORY);
+ assertTrue(!contextFolder.exists());
+ assertTrue(migrator.migrateActivityData(new NullProgressMonitor()));
+ assertFalse(oldActivityFile.exists());
+ assertTrue(contextFolder.exists());
+ assertTrue(new File(contextFolder, MylarContextManager.CONTEXT_HISTORY_FILE_NAME+MylarContextManager.CONTEXT_FILE_EXTENSION).exists());
+ }
+
+
+ private void deleteAllFiles(File folder) {
+ for (File file: folder.listFiles()) {
+ if(file.isDirectory()) {
+ deleteAllFiles(file);
+ file.delete();
+ } else {
+ file.delete();
+ }
+ }
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/WorkspaceAwareContextStore.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/WorkspaceAwareContextStore.java
index c8ec0be38..25c11876f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/WorkspaceAwareContextStore.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/WorkspaceAwareContextStore.java
@@ -13,7 +13,10 @@ package org.eclipse.mylar.internal.tasks.ui;
import java.io.File;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylar.context.core.AbstractContextStore;
+import org.eclipse.mylar.context.core.MylarStatusHandler;
+import org.eclipse.mylar.tasks.ui.TaskListDataMigration;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
/**
@@ -21,8 +24,21 @@ import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
*/
public class WorkspaceAwareContextStore extends AbstractContextStore {
+ public WorkspaceAwareContextStore() {
+ migrateFrom06Format();
+ }
+
public File getRootDirectory() {
return new File(TasksUiPlugin.getDefault().getDataDirectory());
}
+ private void migrateFrom06Format() {
+ File dataDir = new File(TasksUiPlugin.getDefault().getDataDirectory());
+ try {
+ new TaskListDataMigration(dataDir).run(new NullProgressMonitor());
+ } catch (Exception e) {
+ MylarStatusHandler.fail(e, "Error occurred while migrating mylar data", false);
+ }
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportJob.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportJob.java
index f1bc62fb3..d5fb2e4f2 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportJob.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportJob.java
@@ -31,6 +31,7 @@ import org.eclipse.mylar.context.core.MylarStatusHandler;
import org.eclipse.mylar.internal.context.core.MylarContextManager;
import org.eclipse.mylar.internal.context.core.util.ZipFileUtil;
import org.eclipse.mylar.tasks.core.ITask;
+import org.eclipse.mylar.tasks.core.TaskRepositoryManager;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
/**
@@ -94,16 +95,25 @@ public class TaskDataExportJob implements IRunnableWithProgress {
// Map of file paths used to avoid duplicates
Map<String, String> filesToZipMap = new HashMap<String, String>();
+
+ // Create folders in zip file before contained files
+ String sourceContextsPath = TasksUiPlugin.getDefault().getDataDirectory() + File.separator
+ + MylarContextManager.CONTEXTS_DIRECTORY;
+ File contextsDirectory = new File(sourceContextsPath);
+// if(contextsDirectory.exists()) {
+// filesToZip.add(contextsDirectory);
+// }
+
if (true) {
// Repositories always exported
TasksUiPlugin.getRepositoryManager().saveRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath());
String sourceRepositoriesPath = TasksUiPlugin.getDefault().getDataDirectory() + File.separator
- + TasksUiPlugin.DEFAULT_REPOSITORIES_FILE;
+ + TaskRepositoryManager.DEFAULT_REPOSITORIES_FILE;
File sourceRepositoriesFile = new File(sourceRepositoriesPath);
if (sourceRepositoriesFile.exists()) {
File destRepositoriesFile = new File(destinationDirectory + File.separator
- + TasksUiPlugin.DEFAULT_REPOSITORIES_FILE);
+ + TaskRepositoryManager.DEFAULT_REPOSITORIES_FILE);
if (zip) {
filesToZip.add(sourceRepositoriesFile);
@@ -151,8 +161,7 @@ public class TaskDataExportJob implements IRunnableWithProgress {
if (exportActivationHistory) {
try {
- File sourceActivationHistoryFile = new File(TasksUiPlugin.getDefault().getDataDirectory()
- + File.separator + MylarContextManager.CONTEXT_HISTORY_FILE_NAME
+ File sourceActivationHistoryFile = new File(contextsDirectory, MylarContextManager.CONTEXT_HISTORY_FILE_NAME
+ MylarContextManager.CONTEXT_FILE_EXTENSION);
if (sourceActivationHistoryFile.exists()) {
@@ -164,7 +173,7 @@ public class TaskDataExportJob implements IRunnableWithProgress {
+ MylarContextManager.CONTEXT_FILE_EXTENSION);
- if (zip) {
+ if (zip) {
filesToZip.add(sourceActivationHistoryFile);
} else if(!destActivationHistoryFile.equals(sourceActivationHistoryFile)){
if (destActivationHistoryFile.exists()) {
@@ -193,7 +202,6 @@ public class TaskDataExportJob implements IRunnableWithProgress {
File destTaskFile = new File(destinationDirectory + File.separator + sourceTaskFile.getName());
-
if (zip) {
if (!filesToZipMap.containsKey(task.getHandleIdentifier())) {
filesToZip.add(sourceTaskFile);
@@ -219,7 +227,7 @@ public class TaskDataExportJob implements IRunnableWithProgress {
if (destZipFile.exists()) {
destZipFile.delete();
}
- ZipFileUtil.createZipFile(destZipFile, filesToZip, monitor);
+ ZipFileUtil.createZipFile(destZipFile, filesToZip,TasksUiPlugin.getDefault().getDataDirectory(), monitor);
} catch (Exception e) {
MylarStatusHandler.fail(e, "Could not create zip file.", true);
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java
index 369442eec..fc5944154 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java
@@ -18,6 +18,9 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -69,7 +72,7 @@ public class TaskListWriter {
private DelegatingTaskExternalizer delagatingExternalizer = new DelegatingTaskExternalizer();
private List<Node> orphanedTaskNodes = new ArrayList<Node>();
-
+
private String readVersion = "";
private boolean hasCaughtException = false;
@@ -118,19 +121,20 @@ public class TaskListWriter {
MylarStatusHandler.log("Did not externalize: " + query, this);
}
}
-// Collection<ITask> allTasks = Collections.synchronizedCollection(taskList.getAllTasks());
-// synchronized (allTasks) {
+ // Collection<ITask> allTasks =
+ // Collections.synchronizedCollection(taskList.getAllTasks());
+ // synchronized (allTasks) {
for (ITask task : new ArrayList<ITask>(taskList.getAllTasks())) {
createTaskElement(doc, root, task);
}
-
+
for (Node orphanedTaskNode : orphanedTaskNodes) {
Node tempNode = doc.importNode(orphanedTaskNode, true);
- if(tempNode != null) {
+ if (tempNode != null) {
root.appendChild(tempNode);
}
- }
-
+ }
+
doc.appendChild(root);
writeDOMtoFile(doc, outFile);
return;
@@ -162,10 +166,15 @@ public class TaskListWriter {
*/
private void writeDOMtoFile(Document doc, File file) {
try {
- OutputStream outputStream = new FileOutputStream(file);
+ ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(file));
+ ZipEntry zipEntry = new ZipEntry(TasksUiPlugin.OLD_TASK_LIST_FILE);
+ outputStream.putNextEntry(zipEntry);
+ outputStream.setMethod(ZipOutputStream.DEFLATED);
+ // OutputStream outputStream = new FileOutputStream(file);
writeDOMtoStream(doc, outputStream);
outputStream.flush();
- outputStream.close();
+ outputStream.closeEntry();
+ outputStream.close();
} catch (Exception fnfe) {
MylarStatusHandler.log(fnfe, "TaskList could not be found");
}
@@ -254,21 +263,24 @@ public class TaskListWriter {
wasRead = true;
}
}
-
+
if (!wasRead && delagatingExternalizer.canReadTask(child)) {
delagatingExternalizer.readTask(child, taskList, null, null);
wasRead = true;
}
-
- if(!wasRead) {
+
+ if (!wasRead) {
orphanedTaskNodes.add(child);
}
}
} catch (Exception e) {
// TODO: Save orphans here too?
- // If data is source of exception then error will just repeat
- // now that orphans are re-saved upon task list save. So for now we
- // log the error warning the user and make a copy of the bad tasklist.
+ // If data is source of exception then error will just
+ // repeat
+ // now that orphans are re-saved upon task list save. So
+ // for now we
+ // log the error warning the user and make a copy of the
+ // bad tasklist.
handleException(inFile, child, e);
}
}
@@ -336,7 +348,16 @@ public class TaskListWriter {
try {
// Parse the content of the given file as an XML document
// and return a new DOM Document object. Also throws IOException
- document = builder.parse(inputFile);
+ InputStream inputStream = null;
+ if (inputFile.getName().endsWith(TasksUiPlugin.DEFAULT_TASK_LIST_FILE)) {
+ // is zipped context
+ inputStream = new ZipInputStream(new FileInputStream(inputFile));
+ ((ZipInputStream) inputStream).getNextEntry();
+ } else {
+ inputStream = new FileInputStream(inputFile);
+ }
+ document = builder.parse(inputStream);
+ // document = builder.parse(inputFile);
} catch (SAXException se) {
File backup = new File(TasksUiPlugin.getDefault().getTaskListSaveManager().getBackupFilePath());
String message = "Restoring the tasklist failed. Would you like to attempt to restore from the backup?\n\nTasklist XML File location: "
@@ -557,4 +578,8 @@ public class TaskListWriter {
public void setDelegatingExternalizer(DelegatingTaskExternalizer delagatingExternalizer) {
this.delagatingExternalizer = delagatingExternalizer;
}
+
+ public List<ITaskListExternalizer> getExternalizers() {
+ return externalizers;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataExportWizardPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataExportWizardPage.java
index 7a22631c4..e8911113c 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataExportWizardPage.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataExportWizardPage.java
@@ -26,6 +26,7 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
/**
@@ -52,7 +53,7 @@ public class TaskDataExportWizardPage extends WizardPage {
private Button taskContextsCheckBox = null;
- private Button zipCheckBox = null;
+ // private Button zipCheckBox = null;
private Button browseButton = null;
@@ -73,7 +74,7 @@ public class TaskDataExportWizardPage extends WizardPage {
private final static String OVERWRITE_SETTING = "Overwrite setting";
- private final static String ZIP_SETTING = "Zip Setting";
+ // private final static String ZIP_SETTING = "Zip Setting";
public TaskDataExportWizardPage() {
super("org.eclipse.mylar.tasklist.exportPage", PAGE_TITLE, TasksUiPlugin.imageDescriptorFromPlugin(
@@ -93,11 +94,11 @@ public class TaskDataExportWizardPage extends WizardPage {
Composite container = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
container.setLayout(layout);
-
createFileSelectionControl(container);
createExportDirectoryControl(container);
- zipCheckBox = createCheckBox(container, "Export to zip file: " + TaskDataExportWizard.getZipFileName());
+ // zipCheckBox = createCheckBox(container, "Export to zip file: " +
+ // TaskDataExportWizard.getZipFileName());
overwriteCheckBox = createCheckBox(container, "Overwrite existing files without warning");
initSettings();
@@ -134,7 +135,10 @@ public class TaskDataExportWizardPage extends WizardPage {
destDirGroup.setText("Export destination folder");
destDirGroup.setLayout(new GridLayout(2, false));
destDirGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ new Label(destDirGroup, SWT.NONE).setText("Export file: "+TaskDataExportWizard.getZipFileName());
+ new Label(destDirGroup, SWT.NONE);
+
destDirText = new Text(destDirGroup, SWT.BORDER);
destDirText.setEditable(false);
destDirText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@@ -174,7 +178,7 @@ public class TaskDataExportWizardPage extends WizardPage {
taskContextsCheckBox.setSelection(true);
destDirText.setText("");
overwriteCheckBox.setSelection(true);
- zipCheckBox.setSelection(false);
+ // zipCheckBox.setSelection(false);
} else {
// Retrieve previous values from the dialog settings
taskListCheckBox.setSelection(true); // force it
@@ -186,7 +190,7 @@ public class TaskDataExportWizardPage extends WizardPage {
destDirText.setText(settings.get(DEST_DIR_SETTING));
}
overwriteCheckBox.setSelection(settings.getBoolean(OVERWRITE_SETTING));
- zipCheckBox.setSelection(settings.getBoolean(ZIP_SETTING));
+ // zipCheckBox.setSelection(settings.getBoolean(ZIP_SETTING));
}
}
@@ -202,7 +206,7 @@ public class TaskDataExportWizardPage extends WizardPage {
settings.put(CONTEXTS_SETTING, taskContextsCheckBox.getSelection());
settings.put(DEST_DIR_SETTING, destDirText.getText());
settings.put(OVERWRITE_SETTING, overwriteCheckBox.getSelection());
- settings.put(ZIP_SETTING, zipCheckBox.getSelection());
+ // settings.put(ZIP_SETTING, zipCheckBox.getSelection());
settings.put(SETTINGS_SAVED, SETTINGS_SAVED);
}
@@ -275,7 +279,8 @@ public class TaskDataExportWizardPage extends WizardPage {
/** True if the user wants to write to a zip file */
public boolean zip() {
- return zipCheckBox.getSelection();
+ // return zipCheckBox.getSelection();
+ return true;
}
/** For testing only. Sets controls to the specified values */
@@ -286,6 +291,6 @@ public class TaskDataExportWizardPage extends WizardPage {
taskActivationHistoryCheckBox.setSelection(exportActivationHistory);
taskContextsCheckBox.setSelection(exportTaskContexts);
destDirText.setText(destinationDir);
- zipCheckBox.setSelection(zip);
+ // zipCheckBox.setSelection(zip);
}
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataImportWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataImportWizard.java
index c8832cf3e..fd8a531e2 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataImportWizard.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataImportWizard.java
@@ -29,24 +29,29 @@ import java.util.zip.ZipFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.mylar.context.core.ContextCorePlugin;
import org.eclipse.mylar.context.core.MylarStatusHandler;
import org.eclipse.mylar.internal.context.core.MylarContextManager;
+import org.eclipse.mylar.internal.context.core.util.ZipFileUtil;
import org.eclipse.mylar.tasks.core.AbstractTaskContainer;
import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.TaskList;
+import org.eclipse.mylar.tasks.core.TaskRepositoryManager;
+import org.eclipse.mylar.tasks.ui.TaskListDataMigration;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
/**
- * @author Rob Elves
- * Some code leveraged from TaskDataExportWizard
+ * @author Rob Elves Some code leveraged from TaskDataExportWizard
*/
public class TaskDataImportWizard extends Wizard implements IImportWizard {
@@ -97,9 +102,10 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
* dialog.
*/
public boolean performFinish() {
-
- TasksUiPlugin.getTaskListManager().deactivateTask(TasksUiPlugin.getTaskListManager().getTaskList().getActiveTask());
-
+
+ TasksUiPlugin.getTaskListManager().deactivateTask(
+ TasksUiPlugin.getTaskListManager().getTaskList().getActiveTask());
+
File sourceDirFile = null;
File sourceZipFile = null;
File sourceTaskListFile = null;
@@ -109,7 +115,7 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
List<String> zipFilesToExtract = new ArrayList<String>();
boolean overwrite = importPage.overwrite();
boolean zip = importPage.zip();
-
+
if (zip) {
String sourceZip = importPage.getSourceZipFile();
@@ -134,19 +140,19 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
// ignore directories (shouldn't be any)
continue;
}
- if (!importPage.importTaskList()
- && entry.getName().endsWith(TasksUiPlugin.DEFAULT_TASK_LIST_FILE)) {
+ if (!importPage.importTaskList() && entry.getName().endsWith(TasksUiPlugin.OLD_TASK_LIST_FILE)) {
continue;
- }
-
+ }
+
if (!importPage.importActivationHistory()
&& entry.getName().endsWith(
MylarContextManager.CONTEXT_HISTORY_FILE_NAME
- + MylarContextManager.CONTEXT_FILE_EXTENSION)) {
+ + MylarContextManager.OLD_CONTEXT_FILE_EXTENSION)) {
continue;
}
if (!importPage.importTaskContexts()
- && entry.getName().matches(".*-\\d*" + MylarContextManager.CONTEXT_FILE_EXTENSION + "$")) {
+ && entry.getName()
+ .matches(".*-\\d*" + MylarContextManager.OLD_CONTEXT_FILE_EXTENSION + "$")) {
continue;
}
@@ -174,20 +180,22 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
// Get file paths to check for existence
String sourceDir = importPage.getSourceDirectory();
sourceDirFile = new File(sourceDir);
- if (!sourceDirFile.exists() || !sourceDirFile.isDirectory()) {
- MessageDialog.openError(getShell(), "Source location not found", "Resrouce could not be found or is not a folder.");
+ if (!sourceDirFile.exists() || !sourceDirFile.isDirectory()) {
+ MessageDialog.openError(getShell(), "Source location not found",
+ "Resource could not be found or is not a folder.");
return false;
}
// make sure selected files for import are there
- sourceTaskListFile = new File(sourceDir + File.separator + TasksUiPlugin.DEFAULT_TASK_LIST_FILE);
- sourceRepositoriesFile = new File(sourceDir + File.separator + TasksUiPlugin.DEFAULT_REPOSITORIES_FILE);
+ sourceTaskListFile = new File(sourceDir + File.separator + TasksUiPlugin.OLD_TASK_LIST_FILE);
+ sourceRepositoriesFile = new File(sourceDir + File.separator + TaskRepositoryManager.OLD_REPOSITORIES_FILE);
sourceActivationHistoryFile = new File(sourceDir + File.separator
- + MylarContextManager.CONTEXT_HISTORY_FILE_NAME + MylarContextManager.CONTEXT_FILE_EXTENSION);
+ + MylarContextManager.OLD_CONTEXT_HISTORY_FILE_NAME + MylarContextManager.OLD_CONTEXT_FILE_EXTENSION);
File[] children = sourceDirFile.listFiles();
for (int i = 0; i < children.length; i++) {
- if (children[i].getAbsolutePath().matches(".*-\\d*" + MylarContextManager.CONTEXT_FILE_EXTENSION + "$")) {
+ if (children[i].getAbsolutePath().matches(
+ ".*-\\d*" + MylarContextManager.OLD_CONTEXT_FILE_EXTENSION + "$")) {
File destContextFile = new File(TasksUiPlugin.getDefault().getDataDirectory() + File.separator
+ children[i].getName());
@@ -205,7 +213,7 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
}
}
-
+
if (importPage.importTaskList() && !sourceTaskListFile.exists()) {
MessageDialog.openError(getShell(), "File not found", sourceTaskListFile.toString() + " not found.");
return false;
@@ -244,7 +252,7 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
private File sourceTaskListFile = null;
private File sourceActivationHistoryFile = null;
-
+
private File sourceRepositoriesFile = null;
private boolean zip;
@@ -281,31 +289,31 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
if (zip) {
monitor.beginTask(JOB_LABEL, zipFilesToExtract.size() + 2);
- ZipFile zipFile;
+ //ZipFile zipFile;
try {
- zipFile = new ZipFile(sourceZipFile, ZipFile.OPEN_READ);
-
- for (String zipFileStr : zipFilesToExtract) {
- ZipEntry entry = zipFile.getEntry(zipFileStr);
- if (entry == null) {
- MylarStatusHandler.fail(new Exception("Import Exception"),
- "Problem occured extracting from zip file.", true);
- return;
- }
-
- File destinationFile = new File(TasksUiPlugin.getDefault().getDataDirectory() + File.separator
- + entry.getName());
- if (destinationFile.exists()) {
- destinationFile.delete();
- }
-
- copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(
- destinationFile)));
- monitor.worked(1);
-
- }
- zipFile.close();
+ //zipFile = new ZipFile(sourceZipFile, ZipFile.OPEN_READ);
+ ZipFileUtil.unzipFiles(sourceZipFile, TasksUiPlugin.getDefault().getDataDirectory());
+// for (String zipFileStr : zipFilesToExtract) {
+// ZipEntry entry = zipFile.getEntry(zipFileStr);
+// if (entry == null) {
+// MylarStatusHandler.fail(new Exception("Import Exception"),
+// "Problem occured extracting from zip file.", true);
+// return;
+// }
+//
+// File destinationFile = new File(TasksUiPlugin.getDefault().getDataDirectory() + File.separator
+// + entry.getName());
+// if (destinationFile.exists()) {
+// destinationFile.delete();
+// }
+//
+// copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(
+// destinationFile)));
+// monitor.worked(1);
+//
+// }
+ //zipFile.close();
} catch (IOException ioe) {
MylarStatusHandler.fail(new Exception("Import Exception"),
"Problem occured extracting from zip file.", true);
@@ -317,14 +325,17 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
}
int jobSize = 1;
- if(importTaskList) jobSize++;
- if(importActivationHistory) jobSize++;
- if(importTaskContexts) jobSize += sourceContextFiles.size();
+ if (importTaskList)
+ jobSize++;
+ if (importActivationHistory)
+ jobSize++;
+ if (importTaskContexts)
+ jobSize += sourceContextFiles.size();
monitor.beginTask(JOB_LABEL, jobSize);
-
- if(true) {
+
+ if (true) {
String destRepositoriesPath = TasksUiPlugin.getDefault().getDataDirectory() + File.separator
- + TasksUiPlugin.DEFAULT_REPOSITORIES_FILE;
+ + TaskRepositoryManager.OLD_REPOSITORIES_FILE;
File destRepositoriesFile = new File(destRepositoriesPath);
if (destRepositoriesFile.exists()) {
@@ -332,16 +343,15 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
}
if (!copy(sourceRepositoriesFile, destRepositoriesFile)) {
- MylarStatusHandler
- .fail(new Exception("Import Exception"), "Could not import repositories file.", true);
+ MylarStatusHandler.fail(new Exception("Import Exception"), "Could not import repositories file.",
+ true);
}
monitor.worked(1);
}
-
-
- if (importTaskList) {
+
+ if (importTaskList) {
String destTaskListPath = TasksUiPlugin.getDefault().getDataDirectory() + File.separator
- + TasksUiPlugin.DEFAULT_TASK_LIST_FILE;
+ + TasksUiPlugin.OLD_TASK_LIST_FILE;
File destTaskListFile = new File(destTaskListPath);
if (destTaskListFile.exists()) {
@@ -359,8 +369,8 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
if (importActivationHistory) {
try {
File destActivationHistoryFile = new File(TasksUiPlugin.getDefault().getDataDirectory()
- + File.separator + MylarContextManager.CONTEXT_HISTORY_FILE_NAME
- + MylarContextManager.CONTEXT_FILE_EXTENSION);
+ + File.separator + MylarContextManager.OLD_CONTEXT_HISTORY_FILE_NAME
+ + MylarContextManager.OLD_CONTEXT_FILE_EXTENSION);
if (destActivationHistoryFile.exists()) {
destActivationHistoryFile.delete();
@@ -445,11 +455,33 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
}
private void readTaskListData() {
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
- public void run() {
- TasksUiPlugin.getRepositoryManager().readRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath());
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ public void run() {
+
+ TaskListDataMigration migrationOperation = new TaskListDataMigration(new File(TasksUiPlugin.getDefault().getDataDirectory()));
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ Shell shell = win != null ? win.getShell() : null;
+ try {
+ new ProgressMonitorDialog(shell).run(true, false, migrationOperation);
+ } catch (Exception e) {
+ // ignore
+ }
+
+ TasksUiPlugin.getRepositoryManager().readRepositories(
+ TasksUiPlugin.getDefault().getRepositoriesFilePath());
ContextCorePlugin.getContextManager().loadActivityMetaContext();
TasksUiPlugin.getTaskListManager().resetTaskList();
+
+ String path = TasksUiPlugin.getDefault().getDataDirectory() + File.separator
+ + TasksUiPlugin.OLD_TASK_LIST_FILE;
+ File taskListFile = new File(path);
+ if (!taskListFile.exists()) {
+ path = TasksUiPlugin.getDefault().getDataDirectory() + File.separator
+ + TasksUiPlugin.DEFAULT_TASK_LIST_FILE;
+ taskListFile = new File(path);
+ }
+ TasksUiPlugin.getTaskListManager().setTaskListFile(taskListFile);
TasksUiPlugin.getTaskListManager().readExistingOrCreateNewList();
}
});
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskListDataMigration.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskListDataMigration.java
new file mode 100644
index 000000000..8462c4a38
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskListDataMigration.java
@@ -0,0 +1,259 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers 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
+ *******************************************************************************/
+
+package org.eclipse.mylar.tasks.ui;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.mylar.context.core.MylarStatusHandler;
+import org.eclipse.mylar.internal.context.core.MylarContextManager;
+import org.eclipse.mylar.internal.context.core.util.ZipFileUtil;
+import org.eclipse.mylar.tasks.core.TaskRepositoryManager;
+
+/**
+ * Migrate 0.6 -> 0.7 mylar data format
+ *
+ * @author Rob Elves
+ */
+public class TaskListDataMigration implements IRunnableWithProgress {
+
+ private File dataDirectory = null;
+
+ public TaskListDataMigration(File sourceFolder) {
+ this.dataDirectory = sourceFolder;
+ }
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ try {
+ monitor.beginTask("Task Data Migration", IProgressMonitor.UNKNOWN);
+ doMigration(monitor);
+ } finally {
+
+ }
+ }
+
+ public void doMigration(IProgressMonitor monitor) {
+ try {
+ monitor.beginTask("Mylar Data Migration", 4);
+ migrateTaskList(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
+ monitor.worked(1);
+ migrateRepositoriesData(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
+ monitor.worked(1);
+ migrateTaskContextData(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
+ monitor.worked(1);
+ migrateActivityData(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
+ monitor.worked(1);
+ } finally {
+ monitor.done();
+ }
+ }
+
+ public boolean migrateTaskList(IProgressMonitor monitor) {
+ File oldTasklistFile = new File(dataDirectory, TasksUiPlugin.OLD_TASK_LIST_FILE);
+ File newTasklistFile = new File(dataDirectory, TasksUiPlugin.DEFAULT_TASK_LIST_FILE);
+ if (!oldTasklistFile.exists())
+ return false;
+ if (newTasklistFile.exists()) {
+ if (!newTasklistFile.delete()) {
+ MylarStatusHandler.fail(null, "Could not overwrite tasklist", false);
+ return false;
+ }
+ }
+ ArrayList<File> filesToZip = new ArrayList<File>();
+ filesToZip.add(oldTasklistFile);
+ try {
+ monitor.beginTask("Migrate Tasklist Data", 1);
+ ZipFileUtil.createZipFile(newTasklistFile, filesToZip, new SubProgressMonitor(monitor, 1));
+ if (!oldTasklistFile.delete()) {
+ MylarStatusHandler.fail(null, "Could not remove old tasklist.", false);
+ return false;
+ }
+ monitor.worked(1);
+ } catch (Exception e) {
+ MylarStatusHandler.fail(e, "Error occurred while migrating old tasklist: " + e.getMessage(), true);
+ return false;
+ } finally {
+ monitor.done();
+ }
+ return true;
+ }
+
+ public boolean migrateRepositoriesData(IProgressMonitor monitor) {
+ File oldRepositoriesFile = new File(dataDirectory, TaskRepositoryManager.OLD_REPOSITORIES_FILE);
+ File newRepositoriesFile = new File(dataDirectory, TaskRepositoryManager.DEFAULT_REPOSITORIES_FILE);
+ if (!oldRepositoriesFile.exists())
+ return false;
+ if (newRepositoriesFile.exists()) {
+ if (!newRepositoriesFile.delete()) {
+ MylarStatusHandler.fail(null,
+ "Could not overwrite repositories file. Check read/write permission on data directory.", false);
+ return false;
+ }
+ }
+ ArrayList<File> filesToZip = new ArrayList<File>();
+ filesToZip.add(oldRepositoriesFile);
+ try {
+ monitor.beginTask("Migrate Repository Data", 1);
+ ZipFileUtil.createZipFile(newRepositoriesFile, filesToZip, new SubProgressMonitor(monitor, 1));
+ if (!oldRepositoriesFile.delete()) {
+ MylarStatusHandler
+ .fail(
+ null,
+ "Could not remove old repositories file. Check read/write permission on data directory.",
+ false);
+ return false;
+ }
+ monitor.worked(1);
+ } catch (Exception e) {
+ MylarStatusHandler.fail(e, "Error occurred while migrating old repositories data: " + e.getMessage(), true);
+ return false;
+ } finally {
+ monitor.done();
+ }
+ return true;
+ }
+
+ public boolean migrateTaskContextData(IProgressMonitor monitor) {
+ ArrayList<File> contextFiles = new ArrayList<File>();
+ for (File file : dataDirectory.listFiles()) {
+ if (file.getName().startsWith("http") || file.getName().startsWith("local")) {
+ if (!file.getName().endsWith(".zip")) {
+ contextFiles.add(file);
+ }
+ }
+ }
+
+ try {
+ monitor.beginTask("Task Context Migration", contextFiles.size());
+
+ File contextsFolder = new File(dataDirectory, MylarContextManager.CONTEXTS_DIRECTORY);
+ if (!contextsFolder.exists()) {
+ if (!contextsFolder.mkdir()) {
+ MylarStatusHandler.fail(null,
+ "Could not create contexts folder. Check read/write permission on data directory.", false);
+ return false;
+ }
+ }
+ for (File file : contextFiles) {
+ ArrayList<File> filesToZip = new ArrayList<File>();
+ filesToZip.add(file);
+ File newContextFile = new File(contextsFolder, file.getName()+".zip");
+ if (newContextFile.exists()) {
+ if (!newContextFile.delete()) {
+ MylarStatusHandler.fail(null,
+ "Could not overwrite context file. Check read/write permission on data directory.",
+ false);
+ return false;
+ }
+ }
+ ZipFileUtil.createZipFile(newContextFile, filesToZip, new SubProgressMonitor(monitor, 1));
+ if (!file.delete()) {
+ MylarStatusHandler.fail(null,
+ "Could not remove old context file. Check read/write permission on data directory.", false);
+ return false;
+ }
+ monitor.worked(1);
+ }
+ } catch (Exception e) {
+ MylarStatusHandler.fail(e, "Error occurred while migrating old repositories data: " + e.getMessage(), true);
+ return false;
+ } finally {
+ monitor.done();
+ }
+ return true;
+ }
+
+ public boolean migrateActivityData(IProgressMonitor monitor) {
+ File oldActivityFile = new File(dataDirectory, MylarContextManager.OLD_CONTEXT_HISTORY_FILE_NAME+MylarContextManager.OLD_CONTEXT_FILE_EXTENSION);
+ if (!oldActivityFile.exists())
+ return false;
+
+ File contextsFolder = new File(dataDirectory, MylarContextManager.CONTEXTS_DIRECTORY);
+ if (!contextsFolder.exists()) {
+ if (!contextsFolder.mkdir()) {
+ MylarStatusHandler.fail(null,
+ "Could not create contexts folder. Check read/write permission on data directory.", false);
+ return false;
+ }
+ }
+
+ File newActivityFile = new File(contextsFolder, MylarContextManager.CONTEXT_HISTORY_FILE_NAME+MylarContextManager.CONTEXT_FILE_EXTENSION);
+
+ if (newActivityFile.exists()) {
+ if (!newActivityFile.delete()) {
+ MylarStatusHandler.fail(null,
+ "Could not overwrite activity file. Check read/write permission on data directory.", false);
+ return false;
+ }
+ }
+ ArrayList<File> filesToZip = new ArrayList<File>();
+ filesToZip.add(oldActivityFile);
+ try {
+ monitor.beginTask("Migrate Activity Data", 1);
+ ZipFileUtil.createZipFile(newActivityFile, filesToZip, new SubProgressMonitor(monitor, 1));
+ if (!oldActivityFile.delete()) {
+ MylarStatusHandler
+ .fail(
+ null,
+ "Could not remove old activity file. Check read/write permission on data directory.",
+ false);
+ return false;
+ }
+ monitor.worked(1);
+ } catch (Exception e) {
+ MylarStatusHandler.fail(e, "Error occurred while migrating old activity data: " + e.getMessage(), true);
+ return false;
+ } finally {
+ monitor.done();
+ }
+ return true;
+ }
+
+}
+
+//public boolean migrateActivityData(IProgressMonitor monitor) {
+//File oldActivityFile = new File(dataDirectory, MylarContextManager.OLD_CONTEXT_HISTORY_FILE_NAME+MylarContextManager.OLD_CONTEXT_FILE_EXTENSION);
+//if (!oldActivityFile.exists())
+// return false;
+//
+//File newActivityFile = new File(dataDirectory, MylarContextManager.CONTEXT_HISTORY_FILE_NAME+MylarContextManager.CONTEXT_FILE_EXTENSION);
+//
+//if (newActivityFile.exists()) {
+// if (!newActivityFile.delete()) {
+// MylarStatusHandler.fail(null,
+// "Could not overwrite activity file. Check read/write permission on data directory.", false);
+// return false;
+// }
+//}
+//ArrayList<File> filesToZip = new ArrayList<File>();
+//filesToZip.add(oldActivityFile);
+//try {
+// monitor.beginTask("Migrate Activity Data", 1);
+// ZipFileUtil.createZipFile(newActivityFile, filesToZip, new SubProgressMonitor(monitor, 1));
+// if (!oldActivityFile.delete()) {
+// MylarStatusHandler
+// .fail(
+// null,
+// "Could not remove old activity file. Check read/write permission on data directory.",
+// false);
+// return false;
+// }
+// monitor.worked(1);
+//} catch (Exception e) {
+// MylarStatusHandler.fail(e, "Error occurred while migrating old activity data: " + e.getMessage(), true);
+// return false;
+//} finally {
+// monitor.done();
+//}
+//return true;
+//} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskListManager.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskListManager.java
index f9db6ee24..d2e5bb7cc 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskListManager.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskListManager.java
@@ -508,12 +508,12 @@ public class TaskListManager implements IPropertyChangeListener {
for (ITask task : new ArrayList<ITask>(activeTasks)) {
deactivateTask(task);
}
- taskList.refactorRepositoryUrl(oldUrl, newUrl);
-
- File dataDir = new File(TasksUiPlugin.getDefault().getDataDirectory());
+ taskList.refactorRepositoryUrl(oldUrl, newUrl);
+
+ File dataDir = new File(TasksUiPlugin.getDefault().getDataDirectory(), MylarContextManager.CONTEXTS_DIRECTORY);
if (dataDir.exists() && dataDir.isDirectory()) {
for (File file : dataDir.listFiles()) {
- int dotIndex = file.getName().lastIndexOf('.');
+ int dotIndex = file.getName().lastIndexOf(".xml");
if (dotIndex != -1) {
String storedHandle;
try {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java
index 7c064ce80..320ed537f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java
@@ -90,12 +90,12 @@ public class TasksUiPlugin extends AbstractUIPlugin implements IStartup {
public static final String DEFAULT_BACKUP_FOLDER_NAME = "backup";
- public static final String FILE_EXTENSION = ".xml";
+ public static final String FILE_EXTENSION = ".xml.zip";
- public static final String DEFAULT_TASK_LIST_FILE = "tasklist" + FILE_EXTENSION;
-
- public static final String DEFAULT_REPOSITORIES_FILE = "repositories" + FILE_EXTENSION;
+ public static final String OLD_TASK_LIST_FILE = "tasklist.xml";
+ public static final String DEFAULT_TASK_LIST_FILE = "tasklist" + FILE_EXTENSION;
+
public static final String TITLE_DIALOG = "Mylar Information";
public static final String PLUGIN_ID = "org.eclipse.mylar.tasklist";
@@ -759,7 +759,7 @@ public class TasksUiPlugin extends AbstractUIPlugin implements IStartup {
}
public String getRepositoriesFilePath() {
- return getDataDirectory() + File.separator + DEFAULT_REPOSITORIES_FILE;
+ return getDataDirectory() + File.separator + TaskRepositoryManager.DEFAULT_REPOSITORIES_FILE;
}
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
index 087a9fb21..982615fff 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
@@ -281,6 +281,7 @@ public class TracRepositoryConnectorTest extends TestCase {
int size = task.getTaskData().getAttachments().size();
File sourceContextFile = ContextCorePlugin.getContextManager().getFileForContext(task.getHandleIdentifier());
+ //System.err.println(">>> " + sourceContextFile.exists() + " " + sourceContextFile.length());
sourceContextFile.createNewFile();
sourceContextFile.deleteOnExit();

Back to the top