Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2012-07-25 13:09:26 -0400
committerGlyn Normington2012-07-25 13:09:26 -0400
commitdcb10440e8d4e991eec86a8d3d5d0a0f49b6bc28 (patch)
tree9f56e80753f9bb8b4d69d78f62c516cb602639b6
parent241a19ac499d70569545ad3d386530ef2fbdb864 (diff)
downloadorg.eclipse.virgo.kernel-dcb10440e8d4e991eec86a8d3d5d0a0f49b6bc28.tar.gz
org.eclipse.virgo.kernel-dcb10440e8d4e991eec86a8d3d5d0a0f49b6bc28.tar.xz
org.eclipse.virgo.kernel-dcb10440e8d4e991eec86a8d3d5d0a0f49b6bc28.zip
385743: introduce subclass which preserves a constant path and use this for PAR files
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractPathGenerator.java9
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/ConstantPathGenerator.java71
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java7
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactStorage.java31
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ConstantPathGeneratorTests.java159
5 files changed, 262 insertions, 15 deletions
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractPathGenerator.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractPathGenerator.java
index c8a750af..8a8b7e59 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractPathGenerator.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractPathGenerator.java
@@ -9,6 +9,15 @@ public abstract class AbstractPathGenerator {
protected final Object monitor = new Object();
+ public AbstractPathGenerator(PathReference basePathReference) {
+ if (basePathReference == null) {
+ throw new IllegalArgumentException("Null path");
+ }
+ if ("".equals(basePathReference.getName())) {
+ throw new IllegalArgumentException("Empty filename");
+ }
+ }
+
public abstract PathReference getCurrentPath();
public void next() {
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/ConstantPathGenerator.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/ConstantPathGenerator.java
new file mode 100644
index 00000000..57043fc2
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/ConstantPathGenerator.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2012 VMware Inc.
+ * 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
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import org.eclipse.virgo.util.io.PathReference;
+
+final class ConstantPathGenerator extends AbstractPathGenerator implements PathGenerator {
+
+ private final PathReference basePathReference;
+
+ private final PathReference previousPathReference;
+
+ public ConstantPathGenerator(PathReference basePathReference) {
+ super(basePathReference);
+ this.basePathReference = basePathReference;
+ this.previousPathReference = new PathReference(String.format("%s-past", this.basePathReference.getAbsolutePath()));
+
+ this.basePathReference.getParent().createDirectory();
+ this.basePathReference.delete(true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void next() {
+ if (this.basePathReference.exists()) {
+ this.previousPathReference.delete(true);
+ this.basePathReference.moveTo(this.previousPathReference);
+ }
+ super.next();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void previous() {
+ super.previous();
+ if (this.previousPathReference.exists()) {
+ this.previousPathReference.moveTo(this.basePathReference);
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PathReference getCurrentPath() {
+ return this.basePathReference;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected PathReference getPreviousPath() {
+ return this.previousPathReference;
+ }
+
+}
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
index 96cf31ca..173e3121 100644
--- 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
@@ -12,12 +12,7 @@ final class GenerationalPathGenerator extends AbstractPathGenerator implements P
private final String baseName;
GenerationalPathGenerator(PathReference basePathReference) {
- if (basePathReference == null) {
- throw new IllegalArgumentException("Null path");
- }
- if ("".equals(basePathReference.getName())) {
- throw new IllegalArgumentException("Empty filename");
- }
+ super(basePathReference);
this.baseDirectory = basePathReference.getParent();
this.baseName = basePathReference.getName();
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 44571ea9..2ecb58ec 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
@@ -29,6 +29,8 @@ final class StandardArtifactStorage implements ArtifactStorage {
private static final String DEPLOYER_UNPACK_BUNDLES_TRUE = "true";
+ private static final List<String> CONSTANT_PATH_EXTENSIONS = Arrays.asList("par", "zip");
+
private static final List<String> ALWAYS_UNPACKED_EXTENSIONS = Arrays.asList("par", "zip");
private static final List<String> CONFIGURABLY_UNPACKED_EXTENSIONS = Arrays.asList("jar", "war");
@@ -53,7 +55,8 @@ final class StandardArtifactStorage implements ArtifactStorage {
this.unpackBundles = unpackBundlesOption == null || DEPLOYER_UNPACK_BUNDLES_TRUE.equalsIgnoreCase(unpackBundlesOption);
- this.pathGenerator = new GenerationalPathGenerator(baseStagingPathReference);
+ this.pathGenerator = CONSTANT_PATH_EXTENSIONS.contains(getFileExtension(sourcePathReference)) ? new ConstantPathGenerator(
+ baseStagingPathReference) : new GenerationalPathGenerator(baseStagingPathReference);
synchronize(this.sourcePathReference);
}
@@ -89,8 +92,7 @@ final class StandardArtifactStorage implements ArtifactStorage {
private void synchronize(PathReference normalizedSourcePathReference) {
PathReference currentPathReference = this.pathGenerator.getCurrentPath();
- if (normalizedSourcePathReference != null && !normalizedSourcePathReference.isDirectory()
- && needsUnpacking(normalizedSourcePathReference.getName())) {
+ if (normalizedSourcePathReference != null && !normalizedSourcePathReference.isDirectory() && needsUnpacking(normalizedSourcePathReference)) {
try {
JarUtils.unpackTo(normalizedSourcePathReference, currentPathReference);
} catch (IOException e) {
@@ -104,17 +106,28 @@ final class StandardArtifactStorage implements ArtifactStorage {
}
}
- private boolean needsUnpacking(String name) {
- String fileName = name.toLowerCase(Locale.ENGLISH);
-
- int dotLocation = fileName.lastIndexOf('.');
- if (dotLocation == -1) {
+ private boolean needsUnpacking(PathReference pathReference) {
+ String fileExtension = getFileExtension(pathReference);
+ if (fileExtension == null) {
return false;
}
- String fileExtension = fileName.substring(dotLocation + 1);
// Always unpack .par/.zip. Unpack .jar/.war if and only if kernel property deployer.unpackBundles is either not
// specified or is "true"
return ALWAYS_UNPACKED_EXTENSIONS.contains(fileExtension) || this.unpackBundles && CONFIGURABLY_UNPACKED_EXTENSIONS.contains(fileExtension);
}
+ private static String getFileExtension(PathReference pathReference) {
+ if (pathReference == null) {
+ return null;
+ }
+ String name = pathReference.getName();
+ String fileName = name.toLowerCase(Locale.ENGLISH);
+
+ int dotLocation = fileName.lastIndexOf('.');
+ if (dotLocation == -1) {
+ return null;
+ }
+ return fileName.substring(dotLocation + 1);
+ }
+
}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ConstantPathGeneratorTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ConstantPathGeneratorTests.java
new file mode 100644
index 00000000..97933ae5
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ConstantPathGeneratorTests.java
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (c) 2012 VMware Inc.
+ * 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
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.virgo.util.io.PathReference;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ConstantPathGeneratorTests {
+
+ private static final String TEST_PATH = "target/pathGeneratorTests/";
+
+ private static final String TEST_FILENAME = "some.jar";
+
+ private PathGenerator artifactHistory;
+
+ @Before
+ public void setUp() throws Exception {
+ PathReference basePathReference = new PathReference(TEST_PATH + TEST_FILENAME);
+ basePathReference.delete(true);
+ this.artifactHistory = new ConstantPathGenerator(basePathReference);
+ }
+
+ @Test
+ public void testGetCurrentPathReference() {
+ PathReference c = this.artifactHistory.getCurrentPath();
+ checkPath(c);
+ }
+
+ @Test
+ public void testStash() {
+ PathReference original = this.artifactHistory.getCurrentPath();
+ this.artifactHistory.next();
+ PathReference c = this.artifactHistory.getCurrentPath();
+ checkPath(c);
+ assertTrue(original.equals(c));
+ }
+
+ @Test
+ public void testUnstash() {
+ PathReference original = this.artifactHistory.getCurrentPath();
+ this.artifactHistory.next();
+ this.artifactHistory.previous();
+ PathReference c = this.artifactHistory.getCurrentPath();
+ checkPath(c);
+ assertTrue(original.equals(c));
+
+ }
+
+ @Test
+ public void testRepeatedStash() {
+ PathReference original = this.artifactHistory.getCurrentPath();
+ this.artifactHistory.next();
+ PathReference next = this.artifactHistory.getCurrentPath();
+ this.artifactHistory.next();
+ PathReference last = this.artifactHistory.getCurrentPath();
+ checkPath(last);
+ assertTrue(original.equals(next));
+ assertTrue(original.equals(last));
+ }
+
+ @Test
+ public void testFileDeletionOnUnstash() {
+ this.artifactHistory.next();
+ PathReference c = this.artifactHistory.getCurrentPath();
+ c.createFile();
+ assertTrue(c.exists());
+ this.artifactHistory.previous();
+ assertFalse(c.exists());
+ }
+
+ @Test
+ public void testDirectoryDeletionOnUnstash() {
+ this.artifactHistory.next();
+ PathReference c = this.artifactHistory.getCurrentPath();
+ c.createDirectory();
+ assertTrue(c.exists());
+ this.artifactHistory.previous();
+ assertFalse(c.exists());
+ }
+
+ @Test
+ public void testFileDeletionOnDoubleStash() {
+ PathReference c = this.artifactHistory.getCurrentPath();
+ c.createFile();
+ assertTrue(c.exists());
+ this.artifactHistory.next();
+ assertFalse(c.exists());
+ this.artifactHistory.next();
+ assertFalse(c.exists());
+ }
+
+ @Test
+ public void testDirectoryDeletionOnDoubleStash() {
+ PathReference c = this.artifactHistory.getCurrentPath();
+ c.createDirectory();
+ assertTrue(c.exists());
+ this.artifactHistory.next();
+ assertFalse(c.exists());
+ this.artifactHistory.next();
+ assertFalse(c.exists());
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void testBadUnstash() {
+ this.artifactHistory.previous();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void testDoubleUnstash() {
+ this.artifactHistory.next();
+ this.artifactHistory.next();
+ this.artifactHistory.previous();
+ this.artifactHistory.previous();
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNullConstructorPath() {
+ new ConstantPathGenerator(null);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testEmptyConstructorPath() {
+ new ConstantPathGenerator(new PathReference(""));
+ }
+
+ public void testDirectorylessConstructorPath() {
+ PathGenerator ph = new ConstantPathGenerator(new PathReference("a"));
+ assertEquals("a", ph.getCurrentPath().getName());
+ }
+
+
+ private void checkPath(PathReference c) {
+ File file = c.toFile();
+ assertTrue(file.toURI().toString().indexOf(TEST_PATH) != -1);
+ assertEquals(TEST_FILENAME, c.getName());
+ assertFalse(c.exists());
+ PathReference parent = c.getParent();
+ assertTrue(parent.isDirectory());
+ assertTrue(parent.exists());
+ }
+
+}
+

Back to the top