summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-02-23 20:36:23 (EST)
committerSteffen Pingel2012-02-23 20:36:23 (EST)
commit30202b47ce1066c566409cf120d8568a35e92592 (patch)
tree560ef01845b0a3a3aee66e39db3e45b96f068859
parent8c46405ded77db1f6fd71f4de6da24d24f988d5d (diff)
downloadorg.eclipse.mylyn.commons-30202b47ce1066c566409cf120d8568a35e92592.zip
org.eclipse.mylyn.commons-30202b47ce1066c566409cf120d8568a35e92592.tar.gz
org.eclipse.mylyn.commons-30202b47ce1066c566409cf120d8568a35e92592.tar.bz2
RESOLVED - bug 371984: provide a generic storage API
https://bugs.eclipse.org/bugs/show_bug.cgi?id=371984 * Add support for deleting storables Change-Id: I58518c879b5fcbbbf6a8f610c8a8a001b8a75020
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/CommonStorable.java24
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/ICommonStorable.java6
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/storage/CommonStoreTest.java40
3 files changed, 68 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/CommonStorable.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/CommonStorable.java
index ae14eed..620d235 100644
--- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/CommonStorable.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/CommonStorable.java
@@ -22,6 +22,8 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.internal.commons.core.CommonsCorePlugin;
+import org.eclipse.osgi.util.NLS;
/**
* @author Steffen Pingel
@@ -41,6 +43,28 @@ class CommonStorable implements ICommonStorable {
getFile(item).delete();
}
+ public void deleteAll() throws CoreException {
+ File[] children = path.listFiles();
+ if (children != null) {
+ // validate
+ for (File child : children) {
+ if (child.isDirectory()) {
+ throw new CoreException(new Status(IStatus.ERROR, CommonsCorePlugin.ID_PLUGIN, NLS.bind(
+ "The storage location ''{0}'' contains sub directories", path)));
+ }
+ }
+
+ // delete all files
+ for (File child : children) {
+ child.delete();
+ }
+ }
+
+ if (path.exists()) {
+ path.delete();
+ }
+ }
+
public boolean exists(String handle) {
if (!path.exists()) {
return false;
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/ICommonStorable.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/ICommonStorable.java
index dc5bedb..8e34de5 100644
--- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/ICommonStorable.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/storage/ICommonStorable.java
@@ -25,12 +25,14 @@ public interface ICommonStorable {
public void delete(String handle) throws CoreException;
+ public void deleteAll() throws CoreException;
+
public boolean exists(String handle);
public InputStream read(String handle, IProgressMonitor monitor) throws IOException, CoreException;
- public OutputStream write(String handle, IProgressMonitor monitor) throws IOException, CoreException;
-
public void release();
+ public OutputStream write(String handle, IProgressMonitor monitor) throws IOException, CoreException;
+
}
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/storage/CommonStoreTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/storage/CommonStoreTest.java
index eb11e30..bec122f 100644
--- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/storage/CommonStoreTest.java
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/storage/CommonStoreTest.java
@@ -49,6 +49,46 @@ public class CommonStoreTest extends TestCase {
assertEquals(Collections.emptyList(), Arrays.asList(location.listFiles()));
}
+ public void testDeleteAll() throws Exception {
+ ICommonStorable storable = store.get(Path.EMPTY);
+ writeHello(storable, "1");
+ writeHello(storable, "2");
+ storable.deleteAll();
+ assertFalse(storable.exists("1"));
+ assertFalse(location.exists());
+ }
+
+ public void testDeleteAllSubPath() throws Exception {
+ ICommonStorable storable2 = store.get(new Path("sub2"));
+ writeHello(storable2, "1");
+ ICommonStorable storable = store.get(new Path("sub"));
+ writeHello(storable, "1");
+ writeHello(storable, "2");
+ storable.deleteAll();
+ assertFalse(storable.exists("1"));
+ assertTrue(storable2.exists("1"));
+ assertTrue(location.exists());
+ assertFalse(new File(location, "sub").exists());
+ }
+
+ public void testDeleteAllSubPathException() throws Exception {
+ ICommonStorable storable = store.get(new Path("sub"));
+ writeHello(storable, "1");
+ ICommonStorable storable2 = store.get(new Path("sub/sub2"));
+ writeHello(storable2, "1");
+ try {
+ storable.deleteAll();
+ fail("Expected CoreException");
+ } catch (CoreException expected) {
+ assertTrue(storable.exists("1"));
+ assertTrue(storable2.exists("1"));
+ }
+ storable2.deleteAll();
+ storable.deleteAll();
+ assertTrue(location.exists());
+ assertFalse(new File(location, "sub").exists());
+ }
+
public void testExists() throws Exception {
ICommonStorable storable = store.get(Path.EMPTY);
assertFalse(storable.exists("handle"));