Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2012-07-25 11:04:46 -0400
committerGlyn Normington2012-07-25 11:04:46 -0400
commit72f68d8f08f27e8e82c214c093a68a76c642321d (patch)
tree174e15f4dab2b0ccb4bae59b28fdcf00348f0b6f
parent5c6cf8acf25c992ba118c09e40bd530fc1c40203 (diff)
downloadorg.eclipse.virgo.kernel-72f68d8f08f27e8e82c214c093a68a76c642321d.tar.gz
org.eclipse.virgo.kernel-72f68d8f08f27e8e82c214c093a68a76c642321d.tar.xz
org.eclipse.virgo.kernel-72f68d8f08f27e8e82c214c093a68a76c642321d.zip
385743: extract interface
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java85
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java72
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java2
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGeneratorTests.java (renamed from org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGeneratorTests.java)10
4 files changed, 96 insertions, 73 deletions
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java
new file mode 100644
index 00000000..54be3b9e
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java
@@ -0,0 +1,85 @@
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import org.eclipse.virgo.util.io.PathReference;
+
+final class GenerationalPathGenerator implements PathGenerator {
+
+ private final PathReference baseDirectory;
+
+ private long generation = 0;
+
+ private boolean hasPrevious = false; // if true, then generation != 0
+
+ private final Object monitor = new Object();
+
+ private final String baseName;
+
+ GenerationalPathGenerator(PathReference basePathReference) {
+ if (basePathReference == null) {
+ throw new IllegalArgumentException("Null path");
+ }
+ if ("".equals(basePathReference.getName())) {
+ throw new IllegalArgumentException("Empty filename");
+ }
+ this.baseDirectory = basePathReference.getParent();
+ this.baseName = basePathReference.getName();
+
+ PathReference currentPathReference = getGenerationPath(this.generation, this.baseDirectory, this.baseName);
+ currentPathReference.getParent().createDirectory();
+ currentPathReference.delete(true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PathReference getCurrentPath() {
+ synchronized (this.monitor) {
+ return getGenerationPath(this.generation);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void next() {
+ synchronized (this.monitor) {
+ if (this.generation != 0) {
+ getPreviousPath().delete(true);
+ }
+ this.generation++;
+ this.hasPrevious = true;
+
+ PathReference currentPathReference = getCurrentPath();
+ currentPathReference.getParent().createDirectory();
+ currentPathReference.delete(true);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void previous() {
+ synchronized (this.monitor) {
+ if (!this.hasPrevious) {
+ throw new IllegalStateException("No stash available");
+ }
+ getCurrentPath().delete(true);
+ this.generation--;
+ this.hasPrevious = false;
+ }
+ }
+
+ private PathReference getPreviousPath() {
+ return getGenerationPath(this.generation - 1);
+ }
+
+ private PathReference getGenerationPath(long generation) {
+ return getGenerationPath(generation, this.baseDirectory, this.baseName);
+ }
+
+ private static PathReference getGenerationPath(long generation, PathReference baseDirectory, String baseName) {
+ return baseDirectory.newChild(Long.toString(generation)).newChild(baseName);
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java
index 46405ee7..d9f0f970 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGenerator.java
@@ -3,80 +3,18 @@ package org.eclipse.virgo.kernel.install.artifact.internal;
import org.eclipse.virgo.util.io.PathReference;
-final class PathGenerator {
+interface PathGenerator {
- private final PathReference baseDirectory;
-
- private long generation = 0;
-
- private boolean hasPrevious = false; // if true, then generation != 0
-
- private final Object monitor = new Object();
-
- private final String baseName;
-
- PathGenerator(PathReference basePathReference) {
- if (basePathReference == null) {
- throw new IllegalArgumentException("Null path");
- }
- if ("".equals(basePathReference.getName())) {
- throw new IllegalArgumentException("Empty filename");
- }
- this.baseDirectory = basePathReference.getParent();
- this.baseName = basePathReference.getName();
-
- PathReference currentPathReference = getGenerationPath(this.generation, this.baseDirectory, this.baseName);
- currentPathReference.getParent().createDirectory();
- currentPathReference.delete(true);
- }
-
- public PathReference getCurrentPath() {
- synchronized (this.monitor) {
- return getGenerationPath(this.generation);
- }
- }
+ public abstract PathReference getCurrentPath();
/**
* Note that the history is only one level deep.
*/
- public void next() {
- synchronized (this.monitor) {
- if (this.generation != 0) {
- getPreviousPath().delete(true);
- }
- this.generation++;
- this.hasPrevious = true;
-
- PathReference currentPathReference = getCurrentPath();
- currentPathReference.getParent().createDirectory();
- currentPathReference.delete(true);
- }
- }
+ public abstract void next();
/**
* This may only be called if the current generation has not been used.
*/
- public void previous() {
- synchronized (this.monitor) {
- if (!this.hasPrevious) {
- throw new IllegalStateException("No stash available");
- }
- getCurrentPath().delete(true);
- this.generation--;
- this.hasPrevious = false;
- }
- }
-
- private PathReference getPreviousPath() {
- return getGenerationPath(this.generation - 1);
- }
-
- private PathReference getGenerationPath(long generation) {
- return getGenerationPath(generation, this.baseDirectory, this.baseName);
- }
-
- private static PathReference getGenerationPath(long generation, PathReference baseDirectory, String baseName) {
- return baseDirectory.newChild(Long.toString(generation)).newChild(baseName);
- }
+ public abstract void previous();
-}
+} \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java
index 44976808..44571ea9 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java
@@ -53,7 +53,7 @@ final class StandardArtifactStorage implements ArtifactStorage {
this.unpackBundles = unpackBundlesOption == null || DEPLOYER_UNPACK_BUNDLES_TRUE.equalsIgnoreCase(unpackBundlesOption);
- this.pathGenerator = new PathGenerator(baseStagingPathReference);
+ this.pathGenerator = new GenerationalPathGenerator(baseStagingPathReference);
synchronize(this.sourcePathReference);
}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGeneratorTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGeneratorTests.java
index a7174c09..6d493fb7 100644
--- a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PathGeneratorTests.java
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGeneratorTests.java
@@ -21,7 +21,7 @@ import org.eclipse.virgo.util.io.PathReference;
import org.junit.Before;
import org.junit.Test;
-public class PathGeneratorTests {
+public class GenerationalPathGeneratorTests {
private static final String TEST_PATH = "target/pathGeneratorTests/";
@@ -31,7 +31,7 @@ public class PathGeneratorTests {
@Before
public void setUp() throws Exception {
- this.artifactHistory = new PathGenerator(new PathReference(TEST_PATH + TEST_FILENAME));
+ this.artifactHistory = new GenerationalPathGenerator(new PathReference(TEST_PATH + TEST_FILENAME));
}
@Test
@@ -129,16 +129,16 @@ public class PathGeneratorTests {
@Test(expected=IllegalArgumentException.class)
public void testNullConstructorPath() {
- new PathGenerator(null);
+ new GenerationalPathGenerator(null);
}
@Test(expected=IllegalArgumentException.class)
public void testEmptyConstructorPath() {
- new PathGenerator(new PathReference(""));
+ new GenerationalPathGenerator(new PathReference(""));
}
public void testDirectorylessConstructorPath() {
- PathGenerator ph = new PathGenerator(new PathReference("a"));
+ PathGenerator ph = new GenerationalPathGenerator(new PathReference("a"));
assertEquals("a", ph.getCurrentPath().getName());
}

Back to the top