Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2009-12-09 21:32:50 -0500
committerspingel2009-12-09 21:32:50 -0500
commite7a096f547988be97f06a612bb47f1a3cbf6e4a9 (patch)
tree490afeea09f5555f09f36273dc1d1da8d9c9634c
parent0a26a687076ce91eb964f80e22589133e40039d8 (diff)
downloadorg.eclipse.mylyn.tasks-e7a096f547988be97f06a612bb47f1a3cbf6e4a9.tar.gz
org.eclipse.mylyn.tasks-e7a096f547988be97f06a612bb47f1a3cbf6e4a9.tar.xz
org.eclipse.mylyn.tasks-e7a096f547988be97f06a612bb47f1a3cbf6e4a9.zip
NEW - bug 288448: Importing exported task file in Galileo does not re-import all tasks
https://bugs.eclipse.org/bugs/show_bug.cgi?id=288448
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java200
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataImportTest.java44
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-171942.zipbin0 -> 2463 bytes
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-old-tasklist.zipbin0 -> 3023 bytes
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportOperation.java7
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskDataImportWizard.java86
6 files changed, 163 insertions, 174 deletions
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 6aa414a6a..fe898ab38 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
@@ -13,13 +13,18 @@ package org.eclipse.mylyn.tasks.tests;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import junit.framework.TestCase;
+
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.commons.tests.support.CommonTestUtil;
-import org.eclipse.mylyn.context.tests.AbstractContextTest;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.TaskDataExportOperation;
import org.eclipse.mylyn.internal.tasks.ui.util.TaskDataSnapshotOperation;
@@ -31,22 +36,57 @@ import org.eclipse.swt.widgets.Shell;
* Test case for the Task Export Wizard
*
* @author Wesley Coelho
- * @author Mik Kersten (fixes)
+ * @author Mik Kersten
+ * @author Steffen Pingel
*/
-public class TaskDataExportTest extends AbstractContextTest {
+public class TaskDataExportTest extends TestCase {
+
+ private File destinationDir;
+
+ private File mylynFolder;
+
+ private final List<File> tempFiles = new ArrayList<File>();
private TaskDataExportWizard wizard;
private TaskDataExportWizardPage wizardPage;
- private File destinationDir;
+ private File createDirectory(File parent, String folderName) {
+ File file = new File(parent, folderName);
+ if (!file.exists()) {
+ assertTrue(file.mkdir());
+ tempFiles.add(file);
+ }
+ return file;
+ }
- private File mylynFolder;
+ private File createFile(File directory, String fileName) throws IOException {
+ File file = new File(directory, fileName);
+ if (!file.exists()) {
+ assertTrue(file.createNewFile());
+ tempFiles.add(file);
+ }
+ return file;
+ }
+
+ private List<String> getEntries(File file) throws IOException {
+ ArrayList<String> entries = new ArrayList<String>();
+ ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(file));
+ try {
+ ZipEntry entry = zipInputStream.getNextEntry();
+ while (entry != null) {
+ entries.add(entry.getName());
+ entry = zipInputStream.getNextEntry();
+ }
+ } finally {
+ zipInputStream.close();
+ }
+ Collections.sort(entries);
+ return entries;
+ }
@Override
protected void setUp() throws Exception {
- super.setUp();
-
// Create the export wizard
wizard = new TaskDataExportWizard();
wizard.addPages();
@@ -58,59 +98,33 @@ public class TaskDataExportTest extends AbstractContextTest {
mylynFolder = new File(TasksUiPlugin.getDefault().getDataDirectory());
destinationDir = new File(mylynFolder.getParent(), "TestDir");
CommonTestUtil.deleteFolder(destinationDir);
- destinationDir.mkdir();
+ createDirectory(destinationDir.getParentFile(), destinationDir.getName());
// Create folder/file structure
- File tasklist = new File(mylynFolder, "tasks.xml.zip");
- if (!tasklist.exists()) {
- assertTrue(tasklist.createNewFile());
- }
- File hidden = new File(mylynFolder, ".hidden");
- if (!hidden.exists()) {
- assertTrue(hidden.createNewFile());
- }
- File tasksandstuff = new File(mylynFolder, "tasksandstuff");
- if (!tasksandstuff.exists()) {
- assertTrue(tasksandstuff.mkdir());
- }
- File backup = new File(mylynFolder, "backup");
- if (!backup.exists()) {
- assertTrue(backup.mkdir());
- }
- File tasksFile = new File(tasksandstuff, "file1.xml.zip");
- if (!tasksFile.exists()) {
- assertTrue(tasksFile.createNewFile());
- }
-
- File tasksSubDir = new File(tasksandstuff, "sub");
- if (!tasksSubDir.exists()) {
- assertTrue(tasksSubDir.mkdir());
- }
-
- File tasksSubDirFile = new File(tasksSubDir, "file2.xml.zip");
- if (!tasksSubDirFile.exists()) {
- assertTrue(tasksSubDirFile.createNewFile());
- }
-
+ createFile(mylynFolder, "tasks.xml.zip");
+ createFile(mylynFolder, "tasklist.xml.zip");
+ createFile(mylynFolder, "my-tasklist.xml.zip");
+ createFile(mylynFolder, ".hidden");
+
+ createDirectory(mylynFolder, "my-attachments");
+ createDirectory(mylynFolder, "attachments");
+ createDirectory(mylynFolder, "backup");
+
+ File tasksandstuff = createDirectory(mylynFolder, "tasksandstuff");
+ createFile(tasksandstuff, "file1.xml.zip");
+ File taskSubDir = createDirectory(tasksandstuff, "sub");
+ createFile(taskSubDir, "file2.xml.zip");
}
@Override
protected void tearDown() throws Exception {
wizard.dispose();
wizardPage.dispose();
- CommonTestUtil.deleteFolder(destinationDir);
- // Create folder/file structure
- File tasklist = new File(mylynFolder, "tasks.xml.zip");
- tasklist.delete();
- File hidden = new File(mylynFolder, ".hidden");
- hidden.delete();
- File tasks = new File(mylynFolder, "tasksandstuff");
- File tasksSubDir = new File(tasks, "sub");
- File backup = new File(mylynFolder, "backup");
- CommonTestUtil.deleteFolder(backup);
- CommonTestUtil.deleteFolder(tasksSubDir);
- CommonTestUtil.deleteFolder(tasks);
- super.tearDown();
+
+ Collections.reverse(tempFiles);
+ for (File file : tempFiles) {
+ file.delete();
+ }
}
/**
@@ -124,81 +138,43 @@ public class TaskDataExportTest extends AbstractContextTest {
// check that the task list file was exported
File[] files = destinationDir.listFiles();
assertEquals(1, files.length);
- ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(files[0]));
- try {
- ArrayList<String> entries = new ArrayList<String>();
- ZipEntry entry = zipInputStream.getNextEntry();
- while (entry != null) {
- entries.add(entry.getName());
- entry = zipInputStream.getNextEntry();
- }
- assertFalse(entries.contains(".hidden"));
- assertTrue(entries.contains("tasks.xml.zip"));
- assertTrue(entries.contains("tasksandstuff/file1.xml.zip"));
- assertTrue(entries.contains("tasksandstuff/sub/file2.xml.zip"));
- assertFalse(entries.contains("backup"));
- } finally {
- zipInputStream.close();
- }
+
+ List<String> entries = getEntries(files[0]);
+ assertEquals(Arrays.asList("my-tasklist.xml.zip", "repositories.xml.zip", "tasks.xml.zip",
+ "tasksandstuff/file1.xml.zip", "tasksandstuff/sub/file2.xml.zip"), entries);
}
- public void testSnapshotWithoutContext() throws Exception {
- final TaskDataExportOperation backupJob = new TaskDataSnapshotOperation(destinationDir.getPath(),
- "testBackup.zip");
+ public void testSnapshotWithContext() throws Exception {
File activityFile = new File(mylynFolder, "contexts/activity.xml.zip");
- if (activityFile.exists()) {
- assertTrue(activityFile.delete());
+ if (!activityFile.exists()) {
+ assertTrue(activityFile.createNewFile());
}
+
+ final TaskDataExportOperation backupJob = new TaskDataSnapshotOperation(destinationDir.getPath(),
+ "testBackup.zip");
backupJob.run(new NullProgressMonitor());
+
// check that the task list file was exported
File[] files = destinationDir.listFiles();
assertEquals(1, files.length);
- ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(files[0]));
- try {
- ArrayList<String> entries = new ArrayList<String>();
- ZipEntry entry = zipInputStream.getNextEntry();
- while (entry != null) {
- entries.add(entry.getName());
- entry = zipInputStream.getNextEntry();
- }
- assertFalse(entries.contains(".hidden"));
- assertTrue(entries.contains("tasks.xml.zip"));
- assertTrue(entries.contains("repositories.xml.zip"));
- assertFalse(entries.contains("contexts/activity.xml.zip"));
- assertFalse(entries.contains("tasks"));
- assertEquals(2, entries.size());
- } finally {
- zipInputStream.close();
- }
+ List<String> entries = getEntries(files[0]);
+ assertEquals(Arrays.asList("contexts/activity.xml.zip", "repositories.xml.zip", "tasks.xml.zip"), entries);
}
- public void testSnapshotWithContext() throws Exception {
- final TaskDataExportOperation backupJob = new TaskDataSnapshotOperation(destinationDir.getPath(),
- "testBackup.zip");
+ public void testSnapshotWithoutContext() throws Exception {
File activityFile = new File(mylynFolder, "contexts/activity.xml.zip");
- if (!activityFile.exists()) {
- assertTrue(activityFile.createNewFile());
+ if (activityFile.exists()) {
+ assertTrue(activityFile.delete());
}
+
+ final TaskDataExportOperation backupJob = new TaskDataSnapshotOperation(destinationDir.getPath(),
+ "testBackup.zip");
backupJob.run(new NullProgressMonitor());
+
// check that the task list file was exported
File[] files = destinationDir.listFiles();
assertEquals(1, files.length);
- ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(files[0]));
- try {
- ArrayList<String> entries = new ArrayList<String>();
- ZipEntry entry = zipInputStream.getNextEntry();
- while (entry != null) {
- entries.add(entry.getName());
- entry = zipInputStream.getNextEntry();
- }
- assertFalse(entries.contains(".hidden"));
- assertTrue(entries.contains("tasks.xml.zip"));
- assertTrue(entries.contains("repositories.xml.zip"));
- assertTrue(entries.contains("contexts/activity.xml.zip"));
- assertFalse(entries.contains("tasks"));
- assertEquals(3, entries.size());
- } finally {
- zipInputStream.close();
- }
+ List<String> entries = getEntries(files[0]);
+ assertEquals(Arrays.asList("repositories.xml.zip", "tasks.xml.zip"), entries);
}
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataImportTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataImportTest.java
index 6b746b2d0..6e8233efd 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataImportTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataImportTest.java
@@ -11,7 +11,6 @@
package org.eclipse.mylyn.tasks.tests;
-import java.io.File;
import java.util.Collection;
import org.eclipse.mylyn.context.tests.AbstractContextTest;
@@ -26,9 +25,10 @@ import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskDataImportWizardPage;
import org.eclipse.swt.widgets.Shell;
/**
- * Test case for the Task Import Wizard
+ * Test case for the Task Import Wizard.
*
* @author Rob Elves
+ * @author Steffen Pingel
*/
public class TaskDataImportTest extends AbstractContextTest {
@@ -36,9 +36,13 @@ public class TaskDataImportTest extends AbstractContextTest {
private TaskDataImportWizardPage wizardPage = null;
- private final String sourceZipPath = "testdata/taskdataimporttest/mylardata-2007-01-19.zip";
+ private final String BACKUP_v1 = "testdata/taskdataimporttest/mylardata-2007-01-19.zip";
- private File sourceZipFile = null;
+ private final String BACKUP_v3 = "testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-171942.zip";
+
+ private final String BACKUP_OLD_v3 = "testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-old-tasklist.zip";
+
+ private TaskList taskList;
@Override
protected void setUp() throws Exception {
@@ -52,9 +56,7 @@ public class TaskDataImportTest extends AbstractContextTest {
assertNotNull(wizardPage);
TaskTestUtil.resetTaskListAndRepositories();
-
- sourceZipFile = TaskTestUtil.getLocalFile(sourceZipPath);
- assertTrue(sourceZipFile.exists());
+ taskList = TasksUiPlugin.getTaskList();
ContextCorePlugin.getContextManager().getActivityMetaContext().reset();
}
@@ -64,8 +66,7 @@ public class TaskDataImportTest extends AbstractContextTest {
wizard.dispose();
wizardPage.dispose();
ContextCorePlugin.getContextManager().resetActivityMetaContext();
- TasksUiPlugin.getRepositoryManager().clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath());
- TaskTestUtil.resetTaskList();
+ TaskTestUtil.resetTaskListAndRepositories();
super.tearDown();
}
@@ -73,14 +74,13 @@ public class TaskDataImportTest extends AbstractContextTest {
* Tests the wizard when it has been asked to import all task data from a zip file
*/
public void testImportRepositoriesZip() {
- TaskList taskList = TasksUiPlugin.getTaskList();
InteractionContext historyContext = ContextCorePlugin.getContextManager().getActivityMetaContext();
assertNotNull(taskList);
assertNotNull(historyContext);
assertTrue(taskList.getAllTasks().size() == 0);
assertTrue(historyContext.getInteractionHistory().size() == 0);
- wizardPage.setSource(true, sourceZipFile.getPath());
+ wizardPage.setSource(true, TaskTestUtil.getLocalFile(BACKUP_v1).getAbsolutePath());
wizard.performFinish();
Collection<AbstractTask> tasks = taskList.getAllTasks();
@@ -95,7 +95,6 @@ public class TaskDataImportTest extends AbstractContextTest {
}
public void testImportOverwritesAllTasks() {
- TaskList taskList = TasksUiPlugin.getTaskList();
InteractionContext historyContext = ContextCorePlugin.getContextManager().getActivityMetaContext();
assertNotNull(taskList);
assertNotNull(historyContext);
@@ -107,7 +106,7 @@ public class TaskDataImportTest extends AbstractContextTest {
Collection<AbstractTask> tasks = taskList.getAllTasks();
assertEquals(1, tasks.size());
- wizardPage.setSource(true, sourceZipFile.getPath());
+ wizardPage.setSource(true, TaskTestUtil.getLocalFile(BACKUP_v1).getAbsolutePath());
wizard.performFinish();
tasks = taskList.getAllTasks();
@@ -121,4 +120,23 @@ public class TaskDataImportTest extends AbstractContextTest {
assertTrue(historyContext.getInteractionHistory().size() > 0);
assertTrue(TasksUiPlugin.getRepositoryManager().getAllRepositories().size() > 2);
}
+
+ public void testImportBackupWithOldTaskList() {
+ wizardPage.setSource(true, TaskTestUtil.getLocalFile(BACKUP_OLD_v3).getAbsolutePath());
+ wizard.performFinish();
+
+ Collection<AbstractTask> tasks = taskList.getAllTasks();
+ assertEquals(1, tasks.size());
+ assertEquals("Task 3", tasks.iterator().next().getSummary());
+ }
+
+ public void testImportBackup() {
+ wizardPage.setSource(true, TaskTestUtil.getLocalFile(BACKUP_v3).getAbsolutePath());
+ wizard.performFinish();
+
+ Collection<AbstractTask> tasks = taskList.getAllTasks();
+ assertEquals(1, tasks.size());
+ assertEquals("Task 3", tasks.iterator().next().getSummary());
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-171942.zip b/org.eclipse.mylyn.tasks.tests/testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-171942.zip
new file mode 100644
index 000000000..2430c5391
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-171942.zip
Binary files differ
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-old-tasklist.zip b/org.eclipse.mylyn.tasks.tests/testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-old-tasklist.zip
new file mode 100644
index 000000000..e20bbd07c
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/taskdataimporttest/mylyn-v3-data-2009-12-09-old-tasklist.zip
Binary files differ
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportOperation.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportOperation.java
index 8ed4403ce..639f6368d 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportOperation.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskDataExportOperation.java
@@ -41,9 +41,7 @@ public class TaskDataExportOperation implements IRunnableWithProgress {
private static final String EXPORT_JOB_LABEL = Messages.TaskDataExportOperation_exporting_task_data;
- private static final Pattern excludeHidden = Pattern.compile("^\\."); //$NON-NLS-1$
-
- private static final Pattern excludeBackup = Pattern.compile("backup\\z"); //$NON-NLS-1$
+ private static final Pattern excludePattern = Pattern.compile("(?:^\\.|^tasklist.xml.zip\\z|attachments\\z|backup\\z)"); //$NON-NLS-1$
private final String destinationDirectory;
@@ -84,8 +82,7 @@ public class TaskDataExportOperation implements IRunnableWithProgress {
protected void selectFiles(Set<File> filesToExport) {
Set<Pattern> exclusionPatterns = new HashSet<Pattern>();
- exclusionPatterns.add(excludeHidden);
- exclusionPatterns.add(excludeBackup);
+ exclusionPatterns.add(excludePattern);
String dataRoot = TasksUiPlugin.getDefault().getDataDirectory();
File dataFolder = new File(dataRoot);
for (File file : dataFolder.listFiles()) {
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 845ddd053..4c2ae8043 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
@@ -13,7 +13,6 @@ package org.eclipse.mylyn.internal.tasks.ui.wizards;
import java.io.File;
import java.io.IOException;
-import com.ibm.icu.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.Locale;
@@ -44,6 +43,8 @@ import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
+import com.ibm.icu.text.SimpleDateFormat;
+
/**
* @author Rob Elves
*/
@@ -130,24 +131,33 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
private final String JOB_LABEL = Messages.TaskDataImportWizard_Importing_Data;
- private File sourceZipFile = null;
-
- private int numEntries = 0;
-
- private boolean restoreM2Tasklist = false;
+ private final File sourceZipFile;
public FileCopyJob(File sourceZipFile) {
this.sourceZipFile = sourceZipFile;
}
public void run(final IProgressMonitor monitor) throws CoreException {
-
try {
+ boolean hasDefaultTaskList = false;
+ int numEntries = 0;
- checkZipFile();
+ // determine properties of backup
+ ZipFile zipFile = new ZipFile(sourceZipFile, ZipFile.OPEN_READ);
+ try {
+ Enumeration<? extends ZipEntry> entries = zipFile.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = entries.nextElement();
+ if (entry.getName().equals(ITasksCoreConstants.DEFAULT_TASK_LIST_FILE)) {
+ hasDefaultTaskList = true;
+ }
+ numEntries++;
+ }
+ } finally {
+ zipFile.close();
+ }
if (numEntries > 0) {
-
monitor.beginTask(JOB_LABEL, numEntries);
Job.getJobManager().beginRule(ITasksCoreConstants.ROOT_SCHEDULING_RULE, monitor);
@@ -157,28 +167,10 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
ZipFileUtil.unzipFiles(sourceZipFile, TasksUiPlugin.getDefault().getDataDirectory(), monitor);
- if (restoreM2Tasklist) {
-
- SimpleDateFormat format = new SimpleDateFormat(ITasksCoreConstants.FILENAME_TIMESTAMP_FORMAT,
- Locale.ENGLISH);
- String date = format.format(new Date());
-
- File taskListFile = new File(TasksUiPlugin.getDefault().getDataDirectory(),
- ITasksCoreConstants.DEFAULT_TASK_LIST_FILE);
- if (taskListFile.exists()) {
- taskListFile.renameTo(new File(taskListFile.getParentFile(), taskListFile.getName()
- + PREFIX_BACKUP + date));
- }
-
- File taskListFileSnapshot = new File(TasksUiPlugin.getDefault().getDataDirectory(),
- AbstractExternalizationParticipant.SNAPSHOT_PREFIX
- + ITasksCoreConstants.DEFAULT_TASK_LIST_FILE);
- if (taskListFileSnapshot.exists()) {
- taskListFileSnapshot.renameTo(new File(taskListFile.getParentFile(),
- taskListFileSnapshot.getName() + PREFIX_BACKUP + date));
- }
-
+ if (!hasDefaultTaskList) {
+ renameTaskList();
}
+
readTaskListData();
}
} catch (IOException e) {
@@ -190,20 +182,26 @@ public class TaskDataImportWizard extends Wizard implements IImportWizard {
}
}
- private void checkZipFile() throws IOException {
- Enumeration<? extends ZipEntry> entries;
- ZipFile zipFile = new ZipFile(sourceZipFile, ZipFile.OPEN_READ);
- try {
- entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry entry = entries.nextElement();
- if (entry.getName().startsWith(ITasksCoreConstants.OLD_TASK_LIST_FILE)) {
- restoreM2Tasklist = true;
- }
- numEntries++;
- }
- } finally {
- zipFile.close();
+ /**
+ * Rename existing task list file to avoid loading that instead of the restored old one.
+ */
+ private void renameTaskList() {
+ SimpleDateFormat format = new SimpleDateFormat(ITasksCoreConstants.FILENAME_TIMESTAMP_FORMAT,
+ Locale.ENGLISH);
+ String date = format.format(new Date());
+
+ File taskListFile = new File(TasksUiPlugin.getDefault().getDataDirectory(),
+ ITasksCoreConstants.DEFAULT_TASK_LIST_FILE);
+ if (taskListFile.exists()) {
+ taskListFile.renameTo(new File(taskListFile.getParentFile(), taskListFile.getName() + PREFIX_BACKUP
+ + date));
+ }
+
+ File taskListFileSnapshot = new File(TasksUiPlugin.getDefault().getDataDirectory(),
+ AbstractExternalizationParticipant.SNAPSHOT_PREFIX + ITasksCoreConstants.DEFAULT_TASK_LIST_FILE);
+ if (taskListFileSnapshot.exists()) {
+ taskListFileSnapshot.renameTo(new File(taskListFile.getParentFile(), taskListFileSnapshot.getName()
+ + PREFIX_BACKUP + date));
}
}

Back to the top