diff options
author | spingel | 2008-08-18 10:58:54 +0000 |
---|---|---|
committer | spingel | 2008-08-18 10:58:54 +0000 |
commit | 51c6b1b69f8ce61be06b297fb8b466ad6c86793e (patch) | |
tree | 0882e023780b8343345ce2e1e75d457131b46f70 | |
parent | 5ae90eb10c846583b58ecf00d7c9cf23424dce4b (diff) | |
download | org.eclipse.mylyn.tasks-51c6b1b69f8ce61be06b297fb8b466ad6c86793e.tar.gz org.eclipse.mylyn.tasks-51c6b1b69f8ce61be06b297fb8b466ad6c86793e.tar.xz org.eclipse.mylyn.tasks-51c6b1b69f8ce61be06b297fb8b466ad6c86793e.zip |
NEW - bug 242179: Attributes in IRepositoryQuery can be set, but not cleared
https://bugs.eclipse.org/bugs/show_bug.cgi?id=242179
5 files changed, 149 insertions, 24 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AbstractTask.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AbstractTask.java index 1590360af..50a9461dd 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AbstractTask.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AbstractTask.java @@ -10,7 +10,6 @@ package org.eclipse.mylyn.internal.tasks.core; import java.util.Collections; import java.util.Date; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -87,7 +86,7 @@ public abstract class AbstractTask extends AbstractTaskContainer implements ITas // TODO 3.0 make private protected String taskKey; - private Map<String, String> attributes; + private AttributeMap attributeMap; private boolean changed; @@ -497,27 +496,31 @@ public abstract class AbstractTask extends AbstractTaskContainer implements ITas } public synchronized String getAttribute(String key) { - return (attributes != null) ? attributes.get(key) : null; + return (attributeMap != null) ? attributeMap.getAttribute(key) : null; } public synchronized Map<String, String> getAttributes() { - if (attributes != null) { - return new HashMap<String, String>(attributes); + if (attributeMap != null) { + return attributeMap.getAttributes(); } else { return Collections.emptyMap(); } } - public synchronized void setAttribute(String key, String value) { - Assert.isNotNull(key); - if (attributes == null) { - attributes = new HashMap<String, String>(); - } - String oldValue = attributes.get(key); - if (!areEqual(oldValue, value)) { - attributes.put(key, value); - firePropertyChange(key, oldValue, value); + public void setAttribute(String key, String value) { + String oldValue; + synchronized (this) { + if (attributeMap == null) { + attributeMap = new AttributeMap(); + } + oldValue = attributeMap.getAttribute(key); + if (!areEqual(oldValue, value)) { + attributeMap.setAttribute(key, value); + } else { + return; + } } + firePropertyChange(key, oldValue, value); } @Override diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AttributeMap.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AttributeMap.java new file mode 100644 index 000000000..82d224bb5 --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AttributeMap.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Mylyn project 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.mylyn.internal.tasks.core; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.Assert; + +/** + * @author Steffen Pingel + */ +public class AttributeMap { + + private final Map<String, String> attributes; + + public AttributeMap() { + attributes = new HashMap<String, String>(); + } + + public String getAttribute(String key) { + return attributes.get(key); + } + + public Map<String, String> getAttributes() { + return new HashMap<String, String>(attributes); + } + + public void setAttribute(String key, String value) { + Assert.isNotNull(key); + if (value == null) { + attributes.remove(key); + } else { + attributes.put(key, value); + } + } + +} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/RepositoryQuery.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/RepositoryQuery.java index a14d8e3f5..e00a036d7 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/RepositoryQuery.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/RepositoryQuery.java @@ -8,10 +8,8 @@ package org.eclipse.mylyn.internal.tasks.core; import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IStatus; import org.eclipse.mylyn.tasks.core.IRepositoryQuery; import org.eclipse.mylyn.tasks.core.ITask; @@ -36,7 +34,7 @@ public class RepositoryQuery extends AbstractTaskContainer implements IRepositor private String summary; - private Map<String, String> attributes; + private AttributeMap attributeMap; @Deprecated public RepositoryQuery(String description) { @@ -119,23 +117,22 @@ public class RepositoryQuery extends AbstractTaskContainer implements IRepositor } public synchronized String getAttribute(String key) { - return (attributes != null) ? attributes.get(key) : null; + return (attributeMap != null) ? attributeMap.getAttribute(key) : null; } public synchronized Map<String, String> getAttributes() { - if (attributes != null) { - return new HashMap<String, String>(attributes); + if (attributeMap != null) { + return attributeMap.getAttributes(); } else { return Collections.emptyMap(); } } public synchronized void setAttribute(String key, String value) { - Assert.isNotNull(key); - if (attributes == null) { - attributes = new HashMap<String, String>(); + if (attributeMap == null) { + attributeMap = new AttributeMap(); } - attributes.put(key, value); + attributeMap.setAttribute(key, value); } } 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 2af1541be..bdbd5cb05 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 @@ -34,6 +34,7 @@ public class AllTasksTests { suite.addTestSuite(TaskList06DataMigrationTest.class); suite.addTestSuite(TaskPlanningEditorTest.class); suite.addTestSuite(TaskListManagerTest.class); + suite.addTestSuite(TaskListExternalizationTest.class); suite.addTestSuite(RepositoryTaskSynchronizationTest.class); suite.addTestSuite(TaskRepositoryManagerTest.class); suite.addTestSuite(TaskRepositoriesExternalizerTest.class); diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java new file mode 100644 index 000000000..46d40628d --- /dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Mylyn project 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.mylyn.tasks.tests; + +import junit.framework.TestCase; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.mylyn.internal.tasks.core.AbstractTask; +import org.eclipse.mylyn.internal.tasks.core.TaskList; +import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; +import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; +import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector; + +public class TaskListExternalizationTest extends TestCase { + + private TaskList taskList; + + private TaskRepository repository; + + private void reloadTaskList() throws CoreException { + taskList.notifyElementsChanged(null); + TasksUiPlugin.getExternalizationManager().requestSave(); + TasksUiPlugin.getDefault().reloadDataDirectory(); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + TasksUiPlugin.getDefault().getPreferenceStore().setValue( + ITasksUiPreferenceConstants.REPOSITORY_SYNCH_SCHEDULE_ENABLED, false); + TasksUiPlugin.getTaskListManager().resetTaskList(); + + repository = new TaskRepository(MockRepositoryConnector.REPOSITORY_KIND, MockRepositoryConnector.REPOSITORY_URL); + TasksUiPlugin.getRepositoryManager().addRepository(repository); + + taskList = TasksUiPlugin.getTaskList(); + } + + @Override + protected void tearDown() throws Exception { + TasksUiPlugin.getTaskListManager().resetTaskList(); + } + + public void testTaskAttributes() throws CoreException { + AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1"); + task1.setAttribute("key", "value"); + assertEquals(1, task1.getAttributes().size()); + + reloadTaskList(); + + task1 = taskList.getTask(task1.getHandleIdentifier()); + assertNotNull(task1); + assertEquals(1, task1.getAttributes().size()); + assertEquals("value", task1.getAttribute("key")); + } + + public void testTaskAttributeDelete() throws CoreException { + AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1"); + task1.setAttribute("key", "value"); + task1.setAttribute("key", null); + assertEquals(0, task1.getAttributes().size()); + assertEquals(null, task1.getAttribute("key")); + + reloadTaskList(); + + task1 = taskList.getTask(task1.getHandleIdentifier()); + assertNotNull(task1); + assertEquals(0, task1.getAttributes().size()); + assertEquals(null, task1.getAttribute("key")); + } + +} |